8 Commits
v2.16 ... v2.18

4 changed files with 106 additions and 120 deletions

View File

@@ -20,72 +20,23 @@ More information can be found in the Wiki.
## Installation ##
Please refer to the Wiki how to get mailGraph installed and configured on your system.
## mailGraph v2.16 release ##
_(2023/08/16)_
## Announcement - Zabbix 5.x maintenance for mailGraph end-of-life - mailGraph 3.x development in progress ##
_(2023/11/01)_
_This version has been verified with Zabbix 5.4 and 6.0 LTS and is expected to work with 6.4 and later (based on v2.10 testing)_
As per November 2023 the maintenance on mailGraph v2.x for Zabbix 5.x will stop in conjunction with the Zabbix lifecycle policy (https://www.zabbix.com/life_cycle_and_release_policy) as Zabbix 5 is nearing it's end of life.
Release notes
- Adding [ACKNOWLEDGES] message information for processing in the TWIG template to allow inclusion of "Action" information in the mail messages (eg. who acknowledged/changed problem status). Refer to the Wiki "Templates" section for more detailed information.
In conjunction mailGraph v2.x is now frozen and I'm setting up a roadmap for mailGraph v3.x starting new development in Alfa mode as November 2023. This new code is not expected to be published until start of 2024.
## mailGraph v2.15 release ##
_(2023/08/16)_
Principal bug fixing on mailGraph v2.x (logic failure or similar) will continue but only for Zabbix 6.x onwards.
_This version has been verified with Zabbix 5.4 and 6.0 LTS and is expected to work with 6.4 and later (based on v2.10 testing)_
Release notes
- Fixed issue with Zabbix 5.4.12 where parameters that are blank or zero did no longer get passed to the Javascript hence causing basic checks to fail. Javascript and parameter checks in mailGraph.php have been adjusted and optimized.
- Refactored the Javascript error handling to get rid of the "Invalid JSON offset" message and to deal with individual error conditions while presenting a better error message on the root cause of the concerning issue.
## mailGraph v2.14 release ##
_(2023/07/10)_
_This version has been verified with Zabbix 5.4 and 6.0 LTS and is expected to work with 6.4 and later (based on v2.10 testing)_
Release notes
- Adding the ability to define FROM details for the emails generated by mailGraph
- `smtp_from_address` to set the from mail address (if not set uses mailing system default). Note: obsolete `mail_from` but retained for backwards compatibility.
- `smtp_from_name` to set the name that goes with the mail address (if not set uses "mailGraph").
- Adding the ability to define REPLY_TO details for the emails generated by mailGraph
- `smtp_reply_address` to set the reply-to mail address (if not set, no reply-to will be added to the message).
- `smtp_reply_name` to set the reply-to name of the mailbox (if not set defaults to "mailGraph feedback").
- Adding a new URL for use in the template:
- `ACK_URL` points to the function in Zabbix for editing and submitting an Acknowledge statement.
## mailGraph v2.13 release ##
_(2023/07/03)_
_This version has been verified with Zabbix 5.4 and 6.0 LTS and is expected to work with 6.4 and later (based on v2.10 testing)_
Release notes
- Fixed references into Zabbix
- Trigger was missing "context" parameter
- Item was missing "context" parameter
- Problems reference to this host was not generated at all
## mailGraph v2.12 release ##
_(2023/07/02)_
_This version has been verified with Zabbix 5.4 and 6.0 LTS and is expected to work with 6.4 and later (based on v2.10 testing)_
Release notes
- Replaced Swiftmailer with PHPMailer
- Configuration option "smtp_transport" removed (using PHPMailer AutoTLS)
- Code cleanup (markup and obsolete related parts)
- Addressed any PHP message (deprecation or error) - mailGraph debug output is now "clean" in PHP 7.4.x and PHP 8.2.x
- Increased maximum number of graphs from 4 to 8
**Please consider to move to PHPMailer as soon as possible as Swiftmailer is abandoned. Installation instructions are included on the wiki.**
Principal approach: `composer require phpmailer/phpmailer`, install mailGraph v2.12 or higher.
In case Swiftmailer is no longer used elsewhere you can consider to remove this package with `swiftmailer/swiftmailer`.
I'm open to new feature requests - please raise an issue for this in this Github space.
## Special thank you ##
I would like to express my gratitude to the following people that have actively contributed to bring bugs and improvements to my attention:
- [pqvindesland](https://github.com/pqvindesland)
- [BernardLinz](https://github.com/BernhardLinz)
- [WMP](https://github.com/WMP)
- [dima-online](https://github.com/dima-online)
## IMPORTANT NOTE for users of mailGraph v1 and Zabbix versions under 5.4 ##
As a result of a major functional change in Zabbix 5.4 (Screens no longer exist and are all moved into Dashboards) the mailGraph.screen macro no longer functions under Zabbix 5.4+. A code rewrite is in progress to deal with detecting the Zabbix version and to pick dashboard.get instead of screen.get as a source list for the graphs that should be included in the mail message.
**v1.x is no longer supported; please upgrade to the current v2 release**
## IMPORTANT NOTE for users of mailGraph v2 and older and Zabbix versions under 6.0 ##
As per November 2023, mailGraph is no longer maintained for Zabbix 5 and older.

View File

@@ -16,12 +16,12 @@
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
"smtp_server": "localhost",
"smtp_port": 25,
"smtp_transport": "none",
"smtp_security": "none",
"smtp_strict": "yes",
"smtp_from_address": "mailgraph@mydomain.com",
"smtp_from_name": "mailGraph",
"smtp_reply_address": "feedback@mydomain.com",
"smtp_from_name": "mailGraph response mailbox",
"smtp_strict": "yes",
"smtp_reply_name": "mailGraph response mailbox",
"graph_match": "any",
"period": "20m",
"period_header": "Last 20 minutes",

View File

@@ -16,12 +16,12 @@
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
"smtp_server": "localhost",
"smtp_port": 25,
"smtp_transport": "none",
"smtp_security": "none",
"smtp_strict": "yes",
"smtp_from_address": "mailgraph@mydomain.com",
"smtp_from_name": "mailGraph",
"smtp_reply_address": "feedback@mydomain.com",
"smtp_from_name": "mailGraph response mailbox",
"smtp_reply_name": "mailGraph response mailbox",
"graph_match": "any",
"periods": "10m,4h,2d,7d",
"periods_headers": "Last 10 minutes,Last 4 hours,Last 2 days,Last 7 days",

View File

@@ -8,39 +8,7 @@
// upon an alert message.
//
// ------------------------------------------------------------------------------------------------------
// Release 1 tested with Zabbix 5.4 and 6.0 LTS
// ------------------------------------------------------------------------------------------------------
// 1.00 2021/02/26 - Mark Oudsen - MVP version, ready for distribution
// 1.01 2021/02/27 - Mark Oudsen - Enhanced search for associated graphs to an item // bug fixes
// 1.10 2021/02/27 - Mark Oudsen - Moved all configuration outside code
// 1.11 2021/02/28 - Mark Oudsen - Bugfixes
// 1.12 2021/03/01 - Mark Oudsen - Bugfixes
// Adding mail server configuration via config.json
// 1.13 2021/03/01 - Mark Oudsen - Added smtp options to encrypt none,ssl,tls
// 1.14 2021/03/01 - Mark Oudsen - Added smtp strict certificates yes|no via config.json
// 1.15 2021/03/01 - Mark Oudsen - Revised relevant graph locator; allowing other item graphs if current
// item does not have a graph associated
// 1.16 2021/03/02 - Mark Oudsen - Found issue with graph.get not returning graphs to requested item ids
// Workaround programmed (fetch host graphs, search for certain itemids)
// 1.17 2021/03/02 - Mark Oudsen - Added ability to specify period of time displayed in the graph
// 1.18 2021/03/04 - Mark Oudsen - Added ability to specify Tags per trigger
// Shorten long "lastvalue" or "prevvalue"
// 1.19 2021/03/05 - Mark Oudsen - Added ability to pass Zabbix 'infoXXX' parameters for TWIG template
// 1.20 2021/03/07 - Mark Oudsen - Production level version - leaving BETA from here on ...
// 1.21 2021/03/09 - Mark Oudsen - Reverted graph.get code back to original code as it was not a bug but
// a wrongly typed requested (should be ARRAY, not comma separated)!
// 1.22 2021/03/10 - Mark Oudsen - Added ability to embed multiple periods (1-4) of the same graph
// 1.23 2021/03/12 - Mark Oudsen - Added graph support for 'Stacked', 'Pie' and 'Exploded'
// 1.24 2021/03/12 - Mark Oudsen - Added support for HTTP proxy
// 1.25 2021/03/16 - Mark Oudsen - Refactoring for optimized flow and relevant data retrieval
// 1.26 2021/03/19 - Mark Oudsen - Bugfixes after refactor (wrong itemId and incorrect eventValue)
// Suppressing Zabbix username-password in log
// 1.27 2021/03/19 - Mark Oudsen - Added ability to define "mailGraph.screen" tag to embed graphs from
// Added PHP informational and warnings to log for easier debug/spotting
// 1.28 2021/03/24 - Mark Oudsen - Added ability to specify username/password for TLS/SSL
// 1.29 2021/04/03 - Mark Oudsen - Bugfix due to stricter JSONRPC version check since Zabbix 5.0.10
// 2021/07/05 - Mark Oudsen - Minor detail added: CLI debug mode now also outputs version
// 2021/07/07 - Mark Oudsen - Fixed HTTPProxy typo in code (instead of HTTPPRoxy)
// Release 1 tested with Zabbix 5.4 and 6.0 LTS (history available on GitHub)
// ------------------------------------------------------------------------------------------------------
// Release 2 tested with Zabbix 5.4, 6.0 LTS and 6.4 - tested with latest Composer libraries
// ------------------------------------------------------------------------------------------------------
@@ -61,6 +29,18 @@
// 2.15 2023/08/16 - Mark Oudsen - Bugfix for Zabbix 5.4 where empty or zeroed variables are no longer
// passed by Zabbix (hence resulting in weird errors)
// 2.16 2023/08/16 - Mark Oudsen - Adding ability to use ACKNOWLEDGE messages in the mail message
// 2.17 2024/12/30 - Mark Oudsen - Fixed #47 mailData initializaton (wrong location) - BernardLinz
// Fixed #46 invalid GraphId on trigger tag - BernardLinz
// Fixed #44 config.json.template wrong var name - WMP
// Fixed #45 handling of international characters - Dima-online
// Tested with latest PHPMailer (6.9.3) and TWIG (3.11.3), PHP 7.4
// Tested with PHP 8.3, TWIG (3.18.0)
// 2.18 2025/01/10 - Mark Oudsen - SCREEN tag information is only processed for Zabbix versions <= 5
// 2025/01/14 - Mark Oudsen - Fixed #51 SMTPS (implicit) or STARTTLS (explicit)
// ------------------------------------------------------------------------------------------------------
// Release 3 placeholder for Zabbix 7.0 LTS and 7.2+
// ------------------------------------------------------------------------------------------------------
// v2.18 Testing on Zabbix 7.0 LTS (in progress), Zabbix 7.2 (in progress)
// ------------------------------------------------------------------------------------------------------
//
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
@@ -69,6 +49,25 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// Notes
// -----
// 1) mailGraph is following the environmental requirements from Zabbix, supporting PHP 7.4-8.3 ad per
// - https://www.zabbix.com/documentation/6.0/en/manual/installation/requirements
// - https://www.zabbix.com/documentation/6.4/en/manual/installation/requirements
//
// 2) TWIG 3.18.0 is available on PHP 8 only (seemless upgrade when using composer update)
//
// 3) Testing of composer libraries updates is limited to every 6 to 12 months
// - In case you encounter an issue, please raise an issue on GitHub
// https://github.com/moudsen/mailGraph/issues
//
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
//
@@ -88,14 +87,14 @@
// MAIN SEQUENCE
// -------------
// 1) Fetch trigger, item, host, graph, event information via Zabbix API via CURL
// 2) Fetch Graph(s) associated to the item/trigger (if any) via Zabbix URL login via CURL
// 3) Build and send mail message from template using Swift/TWIG
// 2) Fetch Graph(s) associated to the item/trigger (if any) via Zabbix URL via CURL
// 3) Build and send mail message from template using PHPmailer//TWIG
//
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// CONSTANTS
$cVersion = 'v2.16';
$cVersion = 'v2.18';
$cCRLF = chr(10).chr(13);
$maskDateTime = 'Y-m-d H:i:s';
$maxGraphs = 8;
@@ -114,7 +113,6 @@
// INCLUDE REQUIRED LIBRARIES (Composer)
// (configure at same location as the script is running or load in your own central library)
// -- phpmailer/phpmailer https://github.com/PHPMailer/PHPMailer
// -- swiftmailer/swiftmailer https://swiftmailer.symfony.com/docs/introduction.html
// -- twig/twig https://twig.symfony.com/doc/3.x/templates.html
// Change only required if you decide to use a local/central library, otherwise leave as is
@@ -513,6 +511,10 @@
_log('# Configuration taken from config.json'.$cCRLF.
json_encode(maskOutputFields($config),JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
// --- MAIL DATA ---
$mailData = array();
// --- POST DATA ---
// Read POST data
@@ -640,6 +642,10 @@
$p_smtp_strict = 'yes';
if ((isset($config['smtp_strict'])) && ($config['smtp_strict']=='no')) { $p_smtp_strict = 'no'; }
$p_smtp_security = 'none';
if ((isset($config['smtp_security'])) && ($config['smtp_security']=='smtps')) { $p_smtp_security = 'smtps'; }
if ((isset($config['smtp_security'])) && ($config['smtp_security']=='starttls')) { $p_smtp_security = 'starttls'; }
$p_smtp_username = '';
if (isset($config['smtp_username'])) { $p_smtp_username = $config['smtp_username']; }
@@ -740,8 +746,6 @@
// Fetch information via API ////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
$mailData = array();
$mailData['BASE_URL'] = $p_URL;
$mailData['SUBJECT'] = $p_subject;
@@ -787,6 +791,7 @@
$result = postJSON($z_url_api, $request);
$apiVersion = $result['result'];
$apiVersionMajor = substr($apiVersion,0,01);
_log('> API version '.$apiVersion);
@@ -877,7 +882,7 @@
}
// --- Collect and attach acknowledge messages for this event
if (isset($thisEvent['result'][0]['acknowledges'])) {
if (sizeof($thisEvent['result'][0]['acknowledges']>0)) {
foreach($thisEvent['result'][0]['acknowledges'] as $aCount=>$anAck) {
$mailData['ACKNOWLEDGES'][$aCount] = $anAck;
$mailData['ACKNOWLEDGES'][$aCount]['_clock'] = zabbixTStoString($anAck['clock']);
@@ -973,18 +978,26 @@
break;
case 'mailGraph.screen':
$triggerScreen = intval($aTag['value']);
_log('+ Trigger screen = '.$triggerScreen);
if ($apiVersionMajor<="5") {
$triggerScreen = intval($aTag['value']);
_log('+ Trigger screen = '.$triggerScreen);
} else {
_log('- Trigger screen value ignored');
}
break;
case 'mailGraph.screenPeriod':
$triggerScreenPeriod = $aTag['value'];
_log('+ Trigger screen period = '.$triggerScreenPeriod);
if ($apiVersionMajor<="5") {
$triggerScreenPeriod = $aTag['value'];
_log('+ Trigger screen period = '.$triggerScreenPeriod);
}
break;
case 'mailGraph.screenPeriodHeader':
$triggerScreenPeriodHeader = $aTag['value'];
_log('+ Trigger screen header = '.$triggerScreenPeriodHeader);
if ($apiVersionMajor<="5") {
$triggerScreenPeriodHeader = $aTag['value'];
_log('+ Trigger screen header = '.$triggerScreenPeriodHeader);
}
break;
}
}
@@ -1370,7 +1383,7 @@
{
if ($forceGraph>0)
{
$theGraph = $forceGraphInfo;
$theGraph = $forceGraphInfo['result'][0];
$theType = 'Forced';
}
else
@@ -1518,12 +1531,41 @@
try
{
// If debugging is required change to '1'
$mail->SMTPDebug = 0;
// Initialize for international characters
$mail->CharSet = "UTF-8";
$mail->Encoding = "base64";
// --- Inialize SMTP parameters
$mail->isSMTP();
$mail->Host = $p_smtp_server;
$mail->Port = $p_smtp_port;
// --- Initialize transport security
switch($p_smtp_security) {
case 'smtps':
_log('> Using SMTPS transport encryption method');
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS;
break;
case 'starttls':
_log('> Using STARTTLS transport encryption method');
$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS;
break;
default:
_log('> Plain transport (no encryption)');
}
// --- Disable strict certificate checking?
if ($p_smtp_strict=='no')
{
_log('> No strict TLS checking');
$mail->SMTPOptions = [
'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ]
];
}
// --- Authentication required?
if ($p_smtp_username!="")
{
@@ -1532,14 +1574,6 @@
$mail->Password = $p_smtp_password;
}
// --- Disable strict certificate checking?
if ($p_smtp_strict=='no')
{
$mail->SMTPOptions = [
'ssl' => [ 'verify_peer' => false, 'verify_peer_name' => false, 'allow_self_signed' => true ]
];
}
// --- Define from
$mail->Sender = $p_smtp_from_address;
$mail->SetFrom($p_smtp_from_address, $p_smtp_from_name, FALSE);
@@ -1629,6 +1663,7 @@
{
echo "! Failed to send message".$cCRLF;
echo "! Error message: ".$e->getMessage().$cCRLF;
echo "! Check your mail server and/or transport settings!".$cCRLF;
_log("! Failed: ".$e->getMessage());
}