23 Commity
v1.22 ... v1.28

Autor SHA1 Wiadomość Data
moudsen
ba0d474bdb Update README.md 2021-03-24 12:35:49 +01:00
moudsen
a5a0f0ace1 Update README.md 2021-03-24 12:34:34 +01:00
moudsen
8655d4ca2c Updated to v1.28 2021-03-24 12:33:10 +01:00
moudsen
76321be3f8 Update README.md 2021-03-24 12:28:39 +01:00
Mark Oudsen
9d4f00ce87 Merge branch 'main' of github.com:moudsen/mailGraph into main 2021-03-24 12:27:54 +01:00
Mark Oudsen
1278d43acb Added ability to specify SMTP username/password (v1.28) 2021-03-24 12:27:44 +01:00
moudsen
18c22abf17 Updated to v1.27 2021-03-20 14:09:51 +01:00
moudsen
0a623f3137 Updated to v1.27 2021-03-20 14:08:57 +01:00
Mark Oudsen
634134b423 Ability to add additional grapgs through Tagging of Trigger of Host and associate Template update (v1.27) 2021-03-20 14:06:08 +01:00
Mark Oudsen
58668311ee Merge branch 'main' of github.com:moudsen/mailGraph into main 2021-03-19 12:22:15 +01:00
Mark Oudsen
9052b71562 Bug fixes after refactoring in v1.25, maskerading usernames/passwords in logging (v1.26) 2021-03-19 12:22:01 +01:00
moudsen
74b6ee15c7 v1.26 released 2021-03-19 12:05:35 +01:00
Mark Oudsen
398637e582 Merge branch 'main' of github.com:moudsen/mailGraph into main 2021-03-19 12:01:50 +01:00
Mark Oudsen
9e40060cdd Bug fixes after refactoring in v1.25, maskerading usernames/passwords in logging (v1.26) 2021-03-19 12:01:41 +01:00
moudsen
e85400b0de Update README.md 2021-03-17 14:03:15 +01:00
Mark Oudsen
e05fcbfba7 Merge branch 'main' of github.com:moudsen/mailGraph into main 2021-03-17 13:57:34 +01:00
Mark Oudsen
66b504a66c Refactoring for optimized flow and relevant data retrieval (v1.25) 2021-03-17 13:57:25 +01:00
moudsen
bc0c83b544 Update README.md 2021-03-17 13:07:08 +01:00
Mark Oudsen
17cdbea2bd Refactoring for optimized flow and relevant data retrieval (v1.25) 2021-03-17 13:03:54 +01:00
Mark Oudsen
fb51354649 Added ability to configure HTTP proxy (v1.24) 2021-03-12 16:33:44 +01:00
Mark Oudsen
78061964c4 Added ability to configure HTTP proxy (v1.24) 2021-03-12 16:23:47 +01:00
Mark Oudsen
1c9786c549 Bugfix (v1.23) 2021-03-12 15:41:48 +01:00
Mark Oudsen
37b1ea7ea2 Added Stacked,Pie and Exploded graph type support (v1.23) 2021-03-12 15:38:46 +01:00
7 zmienionych plików z 529 dodań i 171 usunięć

Wyświetl plik

@@ -1,7 +1,16 @@
## mailGraph (v1.22) ## mailGraph (v1.28)
Zabbix Media module and scripts for sending e-mail alerts with graphs. Zabbix Media module and scripts for sending e-mail alerts with graphs.
**Please use the Wiki for information on how to install, configure and use MailGraph in Zabbix.** **Please use the Wiki for information on how to install, configure and use MailGraph in Zabbix.**
## UPGRADE NOTES
### v1.27
If you upgrade to v1.27 please be aware of the additional features for adding Tags to Trigger and Host to add additional graphs and the associated `html.template` updates that come alone with it (otherwise the new graphs will not show ...).
### v1.25 and higher
Template data provisioning and code has fundamentally changed. If you upgrade from an earlier version as v1.25, make sure you understand the changes in templates/html.template (now making use of arrays for lists of items).
## Example message ## Example message
The below message is just an example of what MailGraph is capable of. The template engine used ("Twig") however allows for a fully customized message creation to your needs!
[![](images/Example-mail-message-v122.png?raw=true)](images/Example-mail-message-v122.png) [![](images/Example-mail-message-v122.png?raw=true)](images/Example-mail-message-v122.png)

Wyświetl plik

@@ -1,21 +1,21 @@
{ {
"script_baseurl": "https:\/\/domain.com\/", "script_baseurl": "https:\/\/mydomain.com\/",
"cli_itemId": 0, "cli_itemId": 0,
"cli_triggerId": 0, "cli_triggerId": 0,
"cli_eventId": 0, "cli_eventId": 0,
"cli_eventValue": 0,
"cli_duration": 0, "cli_duration": 0,
"cli_recipient": "recipient@domain.com", "cli_recipient": "recipient@mydomain.com",
"cli_subject": "[TEST] {{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}", "cli_subject": "[TEST] {{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
"cli_baseURL": "https:\/\/domain.com\/zabbix\/", "cli_baseURL": "https:\/\/mydomain.com\/zabbix\/",
"cli_period": "30m", "cli_period": "30m",
"cli_period_header": "Last 30 minutes", "cli_period_header": "Last 30 minutes",
"cli_debug": 1, "cli_debug": 1,
"cli_proxy": "",
"zabbix_user": "alogicalusername", "zabbix_user": "alogicalusername",
"zabbix_user_pwd": "astrongpassword", "zabbix_user_pwd": "astrongpassword",
"zabbix_api_user": "alogicalusername", "zabbix_api_user": "alogicalusername",
"zabbix_api_pwd": "astrongpassword", "zabbix_api_pwd": "astrongpassword",
"mail_from": "sender@domain.com", "mail_from": "sender@mydomain.com",
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}", "subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
"smtp_server": "localhost", "smtp_server": "localhost",
"smtp_port": 25, "smtp_port": 25,

Wyświetl plik

@@ -1,21 +1,21 @@
{ {
"script_baseurl": "https:\/\/domain.com\/", "script_baseurl": "https:\/\/mydomain.com\/",
"cli_itemId": 0, "cli_itemId": 0,
"cli_triggerId": 0, "cli_triggerId": 0,
"cli_eventId": 0, "cli_eventId": 0,
"cli_eventValue": 0,
"cli_duration": 0, "cli_duration": 0,
"cli_recipient": "recipient@domain.com", "cli_recipient": "recipient@mydomain.com",
"cli_subject": "[TEST] {{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}", "cli_subject": "[TEST] {{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
"cli_baseURL": "https:\/\/domain.com\/zabbix\/", "cli_baseURL": "https:\/\/mydomain.com\/zabbix\/",
"cli_periods": "10m,4h,2d,7d", "cli_periods": "10m,4h,2d,7d",
"cli_periods_headers": "Last 10 minutes,Last 4 hours,Last 2 days,Last 7 days", "cli_periods_headers": "Last 10 minutes,Last 4 hours,Last 2 days,Last 7 days",
"cli_debug": 1, "cli_debug": 1,
"cli_proxy": "",
"zabbix_user": "alogicalusername", "zabbix_user": "alogicalusername",
"zabbix_user_pwd": "astrongpassword", "zabbix_user_pwd": "astrongpassword",
"zabbix_api_user": "alogicalusername", "zabbix_api_user": "alogicalusername",
"zabbix_api_pwd": "astrongpassword", "zabbix_api_pwd": "astrongpassword",
"mail_from": "sender@domain.com", "mail_from": "sender@mydomain.com",
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}", "subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
"smtp_server": "localhost", "smtp_server": "localhost",
"smtp_port": 25, "smtp_port": 25,

Wyświetl plik

@@ -7,16 +7,17 @@ try {
result = { tags: {} }; result = { tags: {} };
// Set HTTP proxy if required // Set HTTP proxy if required
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') { req.setProxy(params.HTTPProxy); } if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
req.setProxy(params.HTTPProxy);
fields.HTTPProxy = params.HTTPProxy;
}
// Declare output type // Declare output type
req.AddHeader('Content-Type: application/json'); req.AddHeader('Content-Type: application/json');
// Must have fields // Must have fields
fields.itemId = params.itemId; fields.itemId = params.itemId;
fields.triggerId = params.triggerId;
fields.eventId = params.eventId; fields.eventId = params.eventId;
fields.eventValue = params.eventValue;
fields.recipient = params.recipient; fields.recipient = params.recipient;
fields.baseURL = params.baseURL; fields.baseURL = params.baseURL;
fields.duration = params.duration; fields.duration = params.duration;

Wyświetl plik

@@ -28,6 +28,14 @@
// 1.21 2021/03/09 - Mark Oudsen - Reverted graph.get code back to original code as it was not a bug but // 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)! // 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.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
// ------------------------------------------------------------------------------------------------------ // ------------------------------------------------------------------------------------------------------
// //
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl // (C) M.J.Oudsen, mark.oudsen@puzzl.nl
@@ -50,14 +58,15 @@
// CONSTANTS // CONSTANTS
$cVersion = 'v1.22'; $cVersion = 'v1.28';
$cCRLF = chr(10).chr(13); $cCRLF = chr(10).chr(13);
$maskDateTime = 'Y-m-d H:i:s'; $maskDateTime = 'Y-m-d H:i:s';
$maxGraphs = 4;
// DEBUG SETTINGS // DEBUG SETTINGS
// -- Should be FALSE for production level use // -- Should be FALSE for production level use
$cDebug = FALSE; // Extended debug logging mode $cDebug = TRUE; // Extended debug logging mode
$cDebugMail = FALSE; // If TRUE, includes log in the mail message (html and plain text attachments) $cDebugMail = FALSE; // If TRUE, includes log in the mail message (html and plain text attachments)
$showLog = FALSE; // Display the log - !!! only use in combination with CLI mode !!! $showLog = FALSE; // Display the log - !!! only use in combination with CLI mode !!!
@@ -81,16 +90,23 @@
global $cCRLF; global $cCRLF;
global $cVersion; global $cVersion;
global $cDebug; global $cDebug;
global $HTTPProxy;
// Initialize Curl instance // Initialize Curl instance
_log('% postJSON: '.$url); _log('% postJSON: '.$url);
if ($cDebug) { _log('> POST data'.json_encode($data)); } if ($cDebug) { _log('> POST data: '.json_encode(maskOutputContent($data))); }
$ch = curl_init(); $ch = curl_init();
// Set options // Set options
curl_setopt($ch, CURLOPT_USERAGENT, 'Zabbix-mailGraph - '.$cVersion); curl_setopt($ch, CURLOPT_USERAGENT, 'Zabbix-mailGraph - '.$cVersion);
if ((isset($HTTPProxy)) && ($HTTPProxy!=''))
{
_log('% Using proxy: '.$HTTPProxy);
curl_setopt($ch, CURLOPT_PROXY, $HTTPProxy);
}
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4); curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
@@ -141,13 +157,36 @@
global $z_url_api; global $z_url_api;
global $cVersion; global $cVersion;
global $cCRLF; global $cCRLF;
global $HTTPProxy;
// Unique names // Unique names
$thisTime = time(); $thisTime = time();
// Relative web calls // Relative web calls
$z_url_index = $z_server ."index.php"; $z_url_index = $z_server ."index.php";
$z_url_graph = $z_server ."chart2.php";
switch($graphType)
{
// 0: Normal
// 1: Stacked
case 0:
case 1:
$z_url_graph = $z_server ."chart2.php";
break;
// 2: Pie
// 3: Exploded
case 2:
case 3:
$z_url_graph = $z_server ."chart6.php";
break;
default:
// Catch all ...
_log('% Graph type #'.$graphType.' unknown; forcing "Normal"');
$z_url_graph = $z_server ."chart2.php";
}
$z_url_fetch = $z_url_graph ."?graphid=" .$graphid ."&width=" .$width ."&height=" .$height . $z_url_fetch = $z_url_graph ."?graphid=" .$graphid ."&width=" .$width ."&height=" .$height .
"&graphtype=".$graphType."&legend=".$showLegend."&profileIdx=web.graphs.filter". "&graphtype=".$graphType."&legend=".$showLegend."&profileIdx=web.graphs.filter".
"&from=now-".$period."&to=now"; "&from=now-".$period."&to=now";
@@ -168,6 +207,12 @@
curl_setopt($ch, CURLOPT_HEADER, false); curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Zabbix-mailGraph - '.$cVersion); curl_setopt($ch, CURLOPT_USERAGENT, 'Zabbix-mailGraph - '.$cVersion);
if ((isset($HTTPProxy)) && ($HTTPProxy!=''))
{
_log('% Using proxy: '.$HTTPProxy);
curl_setopt($ch, CURLOPT_PROXY, $HTTPProxy);
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
@@ -227,6 +272,22 @@
if ($showLog) { echo $logString.$cCRLF; } if ($showLog) { echo $logString.$cCRLF; }
} }
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Catch PHP warnings/notices/errors
function catchPHPerrors($errno, $errstr, $errfile, $errline)
{
// --- Just log ...
_log('!! ('.$errno.') "'.$errstr.'" at line #'.$errline.' of "'.$errfile.'"');
// --- We do not take care of any errors, etc.
return FALSE;
}
set_error_handler("catchPHPerrors");
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// Read configuration file // Read configuration file
@@ -269,41 +330,51 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// Create easy to read duration // Check the array for information we do not want to share in any logging
function getNiceDuration($durationInSeconds) function maskOutputFields($info)
{ {
$duration = ''; foreach($info as $aKey=>$aValue)
$days = floor($durationInSeconds / 86400);
$durationInSeconds -= $days * 86400;
$hours = floor($durationInSeconds / 3600);
$durationInSeconds -= $hours * 3600;
$minutes = floor($durationInSeconds / 60);
$seconds = $durationInSeconds - $minutes * 60;
if ($days>0)
{ {
$duration .= $days . ' day'; switch($aKey)
if ($days!=1) { $duration .= 's'; } {
case 'zabbix_user':
case 'zabbix_user_pwd':
case 'zabbix_api_user':
case 'zabbix_api_pwd':
$info[$aKey] = '<masked>';
break;
}
} }
if ($hours>0) return($info);
}
// Check the array if it contains information that should not be logged
function maskOutputContent($info)
{
global $config;
foreach($info as $infoKey=>$infoValue)
{ {
$duration .= ' ' . $hours . ' hr'; if (is_array($infoValue)) { $info[$infoKey] = maskOutputContent($infoValue); }
if ($hours!=1) { $duration .= 's'; }
foreach($config as $aKey=>$aValue)
{
switch($aKey)
{
case 'zabbix_user':
case 'zabbix_user_pwd':
case 'zabbix_api_user':
case 'zabbix_api_pwd':
if ($aValue==$infoValue) { $info[$infoKey] = '<masked>'; };
break;
}
}
} }
if ($minutes>0) return($info);
{
$duration .= ' ' . $minutes . ' min';
if ($minutes!=1) { $duration .= 's'; }
}
if ($seconds>=0) { $duration .= ' ' . $seconds . ' sec'; }
if ($seconds!=1) { $duration .= 's'; }
return $duration;
} }
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -315,7 +386,8 @@
// [CONFIGURE] Change only when you want to place your config file somewhere else ... // [CONFIGURE] Change only when you want to place your config file somewhere else ...
$config = readConfig(getcwd().'/config/config.json'); $config = readConfig(getcwd().'/config/config.json');
_log('# Configuration taken from config.json'.$cCRLF.json_encode($config,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK)); _log('# Configuration taken from config.json'.$cCRLF.
json_encode(maskOutputFields($config),JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
// --- POST DATA --- // --- POST DATA ---
@@ -325,6 +397,8 @@
// --- CLI DATA --- // --- CLI DATA ---
$HTTPProxy = '';
// Facilitate CLI based testing // Facilitate CLI based testing
if (isset($argc)) if (isset($argc))
{ {
@@ -336,27 +410,27 @@
// MANDATORY // MANDATORY
$problemData['itemId'] = $config['cli_itemId']; $problemData['itemId'] = $config['cli_itemId'];
$problemData['triggerId'] = $config['cli_triggerId'];
$problemData['eventId'] = $config['cli_eventId']; $problemData['eventId'] = $config['cli_eventId'];
$problemData['eventValue'] = $config['cli_eventValue'];
$problemData['recipient'] = $config['cli_recipient']; $problemData['recipient'] = $config['cli_recipient'];
$problemData['baseURL'] = $config['cli_baseURL']; $problemData['baseURL'] = $config['cli_baseURL'];
$problemData['duration'] = $config['cli_duration']; $problemData['duration'] = $config['cli_duration'];
$problemData['subject'] = $config['cli_subject'];
$problemData['period'] = $config['cli_period'];
// OPTIONAL // OPTIONAL
if (isset($config['cli_subject'])) { $problemData['subject'] = $config['cli_subject']; }
if (isset($config['cli_period'])) { $problemData['period'] = $config['cli_period']; }
if (isset($config['cli_period_header'])) { $problemData['period_header'] = $config['cli_period_header']; } if (isset($config['cli_period_header'])) { $problemData['period_header'] = $config['cli_period_header']; }
if (isset($config['cli_periods'])) { $problemData['periods'] = $config['cli_periods']; } if (isset($config['cli_periods'])) { $problemData['periods'] = $config['cli_periods']; }
if (isset($config['cli_periods_headers'])) { $problemData['periods_headers'] = $config['cli_periods_headers']; } if (isset($config['cli_periods_headers'])) { $problemData['periods_headers'] = $config['cli_periods_headers']; }
if (isset($config['cli_debug'])) { $problemData['debug'] = $config['cli_debug']; } if (isset($config['cli_debug'])) { $problemData['debug'] = $config['cli_debug']; }
if (isset($config['cli_proxy'])) { $problemData['HTTPProxy'] = $config['cli_proxy']; }
// Switch on CLI log display // Switch on CLI log display
$showLog = TRUE; $showLog = TRUE;
} }
} }
_log('# Data passed to MailGraph main routine and used for processing'.$cCRLF.json_encode($problemData,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK)); _log('# Data passed to MailGraph main routine and used for processing'.
$cCRLF.json_encode($problemData,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
// --- CHECK AND SET P_ VARIABLES --- // --- CHECK AND SET P_ VARIABLES ---
// FROM POST OR CLI DATA // FROM POST OR CLI DATA
@@ -364,18 +438,12 @@
if (!isset($problemData['itemId'])) { echo "Missing ITEM ID?\n"; die; } if (!isset($problemData['itemId'])) { echo "Missing ITEM ID?\n"; die; }
$p_itemId = intval($problemData['itemId']); $p_itemId = intval($problemData['itemId']);
if (!isset($problemData['triggerId'])) { echo "Missing TRIGGER ID?\n"; die; }
$p_triggerId = intval($problemData['triggerId']);
if (!isset($problemData['eventId'])) { echo "Missing EVENT ID?\n"; die; } if (!isset($problemData['eventId'])) { echo "Missing EVENT ID?\n"; die; }
$p_eventId = intval($problemData['eventId']); $p_eventId = intval($problemData['eventId']);
if (!isset($problemData['recipient'])) { echo "Missing RECIPIENT?\n"; die; } if (!isset($problemData['recipient'])) { echo "Missing RECIPIENT?\n"; die; }
$p_recipient = $problemData['recipient']; $p_recipient = $problemData['recipient'];
if (!isset($problemData['eventValue'])) { echo "Missing EVENTVALUE?\n"; die; }
$p_eventValue = intval($problemData['eventValue']);
if (!isset($problemData['duration'])) { echo "Missing DURATION?\n"; die; } if (!isset($problemData['duration'])) { echo "Missing DURATION?\n"; die; }
$p_duration = intval($problemData['duration']); $p_duration = intval($problemData['duration']);
@@ -397,6 +465,8 @@
$p_period = '48h'; $p_period = '48h';
if (isset($problemData['period'])) { $p_period = $problemData['period']; } if (isset($problemData['period'])) { $p_period = $problemData['period']; }
if (isset($problemData['HTTPProxy'])) { $HTTPProxy = $problemData['HTTPPRoxy']; }
// DYNAMIC VARIABLES FROM ZABBIX // DYNAMIC VARIABLES FROM ZABBIX
foreach($problemData as $aKey=>$aValue) foreach($problemData as $aKey=>$aValue)
@@ -419,6 +489,12 @@
$p_smtp_strict = 'yes'; $p_smtp_strict = 'yes';
if ((isset($config['smtp_strict'])) && ($config['smtp_strict']=='no')) { $p_smtp_strict = 'no'; } if ((isset($config['smtp_strict'])) && ($config['smtp_strict']=='no')) { $p_smtp_strict = 'no'; }
$p_smtp_username = '';
if (isset($config['smtp_username'])) { $p_smtp_username = $config['smtp_username']; }
$p_smtp_password = '';
if (isset($config['smtp_password'])) { $p_smtp_password = $config['smtp_password']; }
$p_graph_match = 'any'; $p_graph_match = 'any';
if ((isset($config['graph_match'])) && ($config['graph_match']=='exact')) { $p_graph_match = 'exact'; } if ((isset($config['graph_match'])) && ($config['graph_match']=='exact')) { $p_graph_match = 'exact'; }
@@ -470,7 +546,9 @@
$mailData['BASE_URL'] = $p_URL; $mailData['BASE_URL'] = $p_URL;
$mailData['SUBJECT'] = $p_subject; $mailData['SUBJECT'] = $p_subject;
// -------------
// --- LOGIN --- // --- LOGIN ---
// -------------
_log('# LOGIN to Zabbix'); _log('# LOGIN to Zabbix');
@@ -490,7 +568,51 @@
_log('> Token = '.$token); _log('> Token = '.$token);
// ------------------------------
// --- READ EVENT INFORMATION ---
// ------------------------------
_log('# Retreiving EVENT information');
$request = array('jsonrpc'=>'2.0',
'method'=>'event.get',
'params'=>array('eventids'=>$p_eventId,
'output'=>'extend',
'selectRelatedObject'=>'extend',
'selectSuppressionData'=>'extend'),
'auth'=>$token,
'id'=>nextRequestID());
$thisEvent = postJSON($z_url_api,$request);
_log('> Event data'.$cCRLF.json_encode($thisEvent,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
if (!isset($thisEvent['result'][0])) { echo '! No response data received?'.$cCRLF; die; }
$mailData['EVENT_ID'] = $thisEvent['result'][0]['eventid'];
$mailData['EVENT_NAME'] = $thisEvent['result'][0]['name'];
$mailData['EVENT_OPDATA'] = $thisEvent['result'][0]['opdata'];
$mailData['EVENT_SUPPRESSED'] = $thisEvent['result'][0]['suppressed'];
$mailData['EVENT_VALUE'] = $thisEvent['result'][0]['relatedObject']['value'];
switch($mailData['EVENT_VALUE'])
{
case 0: // Recovering
$mailData['EVENT_SEVERITY'] = 'Resolved';
$mailData['EVENT_STATUS'] = 'Recovered';
break;
case 1: // Triggered/Active
$_severity = array('Not classified','Information','Warning','Average','High','Disaster');
$mailData['EVENT_SEVERITY'] = $_severity[$thisEvent['result'][0]['severity']];
$mailData['EVENT_STATUS'] = 'Triggered/Active';
break;
}
$p_triggerId = $thisEvent['result'][0]['relatedObject']['triggerid'];
// ------------------------
// --- GET TRIGGER INFO --- // --- GET TRIGGER INFO ---
// ------------------------
_log('# Retrieve TRIGGER information'); _log('# Retrieve TRIGGER information');
@@ -518,6 +640,9 @@
// --- Custom settings? // --- Custom settings?
$forceGraph = 0; $forceGraph = 0;
$triggerScreen = 0;
$triggerScreenPeriod = '';
$triggerScreenPeriodHeader = '';
foreach($thisTrigger['result'][0]['tags'] as $aTag) foreach($thisTrigger['result'][0]['tags'] as $aTag)
{ {
@@ -567,18 +692,33 @@
$problemData['debug'] = 1; $problemData['debug'] = 1;
_log('+ Mail debug log enabled'); _log('+ Mail debug log enabled');
break; break;
case 'mailGraph.screen':
$triggerScreen = intval($aTag['value']);
_log('+ Trigger screen = '.$triggerScreen);
break;
case 'mailGraph.screenPeriod':
$triggerScreenPeriod = $aTag['value'];
_log('+ Trigger screen period = '.$triggerScreenPeriod);
break;
case 'mailGraph.screenPeriodHeader':
$triggerScreenPeriodHeader = $aTag['value'];
_log('+ Trigger screen header = '.$triggerScreenPeriodHeader);
break;
} }
} }
// ---------------------
// --- GET ITEM INFO --- // --- GET ITEM INFO ---
// ---------------------
_log('# Retrieve ITEM information'); _log('# Retrieve ITEM information');
$itemId = $thisTrigger['result'][0]['functions'][0]['itemid'];
$request = array('jsonrpc'=>'2.0', $request = array('jsonrpc'=>'2.0',
'method'=>'item.get', 'method'=>'item.get',
'params'=>array('itemids'=>$itemId, 'params'=>array('itemids'=>$p_itemId,
'output'=>'extend'), 'output'=>'extend'),
'auth'=>$token, 'auth'=>$token,
'id'=>nextRequestID()); 'id'=>nextRequestID());
@@ -603,7 +743,9 @@
if (strlen($mailData['ITEM_LASTVALUE'])>50) { $mailData['ITEM_LASTVALUE'] = substr($mailData['ITEM_LASTVALUE'],0,50).' ...'; } if (strlen($mailData['ITEM_LASTVALUE'])>50) { $mailData['ITEM_LASTVALUE'] = substr($mailData['ITEM_LASTVALUE'],0,50).' ...'; }
if (strlen($mailData['ITEM_PREVIOUSVALUE'])>50) { $mailData['ITEM_PREVIOUSVALUE'] = substr($mailData['ITEM_PREVIOUSVALUE'],0,50).' ...'; } if (strlen($mailData['ITEM_PREVIOUSVALUE'])>50) { $mailData['ITEM_PREVIOUSVALUE'] = substr($mailData['ITEM_PREVIOUSVALUE'],0,50).' ...'; }
// ---------------------
// --- GET HOST INFO --- // --- GET HOST INFO ---
// ---------------------
_log('# Retrieve HOST information'); _log('# Retrieve HOST information');
@@ -612,7 +754,8 @@
$request = array('jsonrpc'=>'2.0', $request = array('jsonrpc'=>'2.0',
'method'=>'host.get', 'method'=>'host.get',
'params'=>array('hostids'=>$hostId, 'params'=>array('hostids'=>$hostId,
'output'=>'extend'), 'output'=>'extend',
'selectTags'=>'extend'),
'auth'=>$token, 'auth'=>$token,
'id'=>nextRequestID()); 'id'=>nextRequestID());
@@ -626,6 +769,33 @@
$mailData['HOST_ERROR'] = $thisHost['result'][0]['error']; $mailData['HOST_ERROR'] = $thisHost['result'][0]['error'];
$mailData['HOST_DESCRIPTION'] = $thisHost['result'][0]['description']; $mailData['HOST_DESCRIPTION'] = $thisHost['result'][0]['description'];
// --- Custom settings?
$hostScreen = 0;
$hostScreenPeriod = '';
$hostScreenPeriodHeader = '';
foreach($thisHost['result'][0]['tags'] as $aTag)
{
switch ($aTag['tag'])
{
case 'mailGraph.screen':
$hostScreen = intval($aTag['value']);
_log('+ Host screen (from TAG) = '.$hostScreen);
break;
case 'mailGraph.screenPeriod':
$hostScreenPeriod = $aTag['value'];
_log('+ Host screen period (from TAG) = '.$hostScreenPeriod);
break;
case 'mailGraph.screenPeriodHeader':
$hostScreenPeriodHeader = $aTag['value'];
_log('+ Host screen period header (from TAG) = '.$hostScreenPeriodHeader);
break;
}
}
_log('# Retreive HOST macro information'); _log('# Retreive HOST macro information');
$request = array('jsonrpc'=>'2.0', $request = array('jsonrpc'=>'2.0',
@@ -638,7 +808,30 @@
$thisMacros = postJSON($z_url_api,$request); $thisMacros = postJSON($z_url_api,$request);
_log('> Host macro data'.$cCRLF.json_encode($thisMacros,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK)); _log('> Host macro data'.$cCRLF.json_encode($thisMacros,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
// --- GET GRAPHS ASSOCIATED WITH THIS HOST --- foreach($thisMacros['result'] as $aMacro)
{
switch($aMacro['macro'])
{
case 'mailGraph.screen':
$hostScreen = intval($aMacro['value']);
_log('+ Host screen (from MACRO) = '.$hostScreen);
break;
case 'mailGraph.screenPeriod':
$hostScreenPeriod = $aMacro['value'];
_log('+ Host screen period (from MACRO) = '.$hostScreenPeriod);
break;
case 'mailGraph.screenPeriodHeader':
$hostScreenPeriodHeader = $aMacro['value'];
_log('+ Host screen header (from MACRO) = '.$hostScreenPeriodHeader);
break;
}
}
// ------------------------------------------------------------------
// --- GET GRAPHS ASSOCIATED WITH THIS HOST AND THE TRIGGER ITEMS ---
// ------------------------------------------------------------------
_log('# Retrieve associated graphs to this HOST and the TRIGGER ITEMS'); _log('# Retrieve associated graphs to this HOST and the TRIGGER ITEMS');
@@ -667,9 +860,11 @@
if ($forceGraph>0) if ($forceGraph>0)
{ {
_log('# Retrieving FORCED graph information'); // --------------------------------------------
// --- GET GRAPH ASSOCIATED WITH FORCEGRAPH --- // --- GET GRAPH ASSOCIATED WITH FORCEGRAPH ---
// --------------------------------------------
_log('# Retrieving FORCED graph information');
$request = array('jsonrpc'=>'2.0', $request = array('jsonrpc'=>'2.0',
'method'=>'graph.get', 'method'=>'graph.get',
@@ -680,7 +875,8 @@
'id'=>nextRequestID()); 'id'=>nextRequestID());
$forceGraphInfo = postJSON($z_url_api,$request); $forceGraphInfo = postJSON($z_url_api,$request);
_log('> Forced graph data'.$cCRLF.json_encode($forceGraphInfo,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK)); _log('> Forced graph data'.$cCRLF.
json_encode($forceGraphInfo,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
if (!isset($forceGraphInfo['result'][0])) if (!isset($forceGraphInfo['result'][0]))
{ {
@@ -689,11 +885,13 @@
} }
} }
// --------------------------------------------------------
// --- FIND MATCHING GRAPH ITEMS WITH OUR TRIGGER ITEMS --- // --- FIND MATCHING GRAPH ITEMS WITH OUR TRIGGER ITEMS ---
// --------------------------------------------------------
_log('# Matching retreived graph information with our trigger items'); _log('# Matching retreived graph information with our trigger items');
// Look for graphs across all functions inside the item // --- Look for graphs across all functions inside the item
$itemIds = array(); $itemIds = array();
@@ -720,7 +918,7 @@
{ {
if ($aGraphItem['itemid']==$anItemId) if ($aGraphItem['itemid']==$anItemId)
{ {
if ($anItemId=$itemId) if ($anItemId==$p_itemId)
{ {
_log('+ Graph #'.$aGraphItem['graphid'].' full match found (item #'.$aGraphItem['itemid'].')'); _log('+ Graph #'.$aGraphItem['graphid'].' full match found (item #'.$aGraphItem['itemid'].')');
$matchedGraphs[] = $aGraph; $matchedGraphs[] = $aGraph;
@@ -737,47 +935,95 @@
_log('> Graphs found (matching/partial) = '.sizeof($matchedGraphs).' / '.sizeof($otherGraphs)); _log('> Graphs found (matching/partial) = '.sizeof($matchedGraphs).' / '.sizeof($otherGraphs));
// --- READ EVENT INFORMATION --- // ---------------------------------------------------------------------------
// --- FIND MATCHING GRAPH ITEMS WITH TRIGGER AND/OR HOST SCREEN REFERENCE ---
// ---------------------------------------------------------------------------
_log('# Retreiving EVENT information'); function _sort($a,$b)
$request = array('jsonrpc'=>'2.0',
'method'=>'event.get',
'params'=>array('eventids'=>$p_eventId,
'output'=>'extend'),
'auth'=>$token,
'id'=>nextRequestID());
$thisEvent = postJSON($z_url_api,$request);
_log('> Event data'.$cCRLF.json_encode($thisEvent,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
if (!isset($thisEvent['result'][0])) { echo '! No response data received?'.$cCRLF; die; }
$mailData['EVENT_ID'] = $thisEvent['result'][0]['eventid'];
$mailData['EVENT_NAME'] = $thisEvent['result'][0]['name'];
$mailData['EVENT_OPDATA'] = $thisEvent['result'][0]['opdata'];
$mailData['EVENT_VALUE'] = $p_eventValue;
switch($p_eventValue)
{ {
case 0: // Recovering if ($a['screen']['y']>$b['screen']['y']) { return(1); }
$mailData['EVENT_SEVERITY'] = 'Resolved'; if ($a['screen']['y']<$b['screen']['y']) { return(-1); }
break; if ($a['screen']['x']>$b['screen']['x']) { return(1); }
if ($a['screen']['x']<$b['screen']['x']) { return(-1); }
case 1: // Triggered/Active return(0);
$_severity = array('Not classified','Information','Warning','Average','High','Disaster');
$mailData['EVENT_SEVERITY'] = $_severity[$thisEvent['result'][0]['severity']];
break;
} }
$_status = array('Recovered','Triggered/Active'); function fetchGraphsFromScreen($screenId)
$mailData['EVENT_STATUS'] = $_status[$p_eventValue]; {
global $token;
global $z_url_api;
global $cCRLF;
// --- Pick up the SCREEN ITEMS associated to the SCREEN
$request = array('jsonrpc'=>'2.0',
'method'=>'screen.get',
'params'=>array('screenids'=>$screenId,
'output'=>'extend',
'selectScreenItems'=>'extend'),
'auth'=>$token,
'id'=>nextRequestID());
$screenGraphs = postJSON($z_url_api,$request);
_log('> Screen items data for screen #'.$screenId.$cCRLF.json_encode($screenGraphs,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
// --- Filter on specific type(s) and enrich the graph data
$result = array();
foreach($screenGraphs['result'][0]['screenitems'] as $anItem)
{
switch($anItem['resourcetype'])
{
case 0: // Graph
$request = array('jsonrpc'=>'2.0',
'method'=>'graph.get',
'params'=>array('graphids'=>$anItem['resourceid'],
'expandName'=>1,
'output'=>'extend'),
'auth'=>$token,
'id'=>nextRequestID());
$screenGraph = postJSON($z_url_api,$request);
_log('+ Graph data for screen item #'.$anItem['screenitemid'].$cCRLF.
json_encode($screenGraph,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
$result[] = array('screen'=>$anItem,'name'=>$screenGraphs['result'][0]['name'],'graph'=>$screenGraph['result'][0]);
break;
}
}
// --- Sort the result according to SCREEN x,y position
usort($result,"_sort");
// --- Done
return($result);
}
$triggerGraphs = array();
if ($triggerScreen>0)
{
_log('# Fetching graph information for TRIGGER for screen #'.$hostScreen);
$triggerGraphs = fetchGraphsFromScreen($triggerScreen);
_log('> Graphs found = '.sizeof($triggerGraphs));
}
if ($hostScreen>0)
{
_log('# Fetching graph information for HOST for screen #'.$hostScreen);
$hostGraphs = fetchGraphsFromScreen($hostScreen);
_log('> Graphs found = '.sizeof($hostGraphs));
}
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// Fetch Graph ////////////////////////////////////////////////////////////////////////////////////////// // Fetch Graph(s) ///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// Determine number of periods for this graph // Determine number of periods for the ITEM graphs
$p_periods = array(); $p_periods = array();
$p_periods_headers = array(); $p_periods_headers = array();
@@ -816,8 +1062,12 @@
} }
} }
while (sizeof($p_periods)>4) { array_pop($p_periods); } // Strip off any excessive elements from the end
while (sizeof($p_periods_headers)>4) { array_pop($p_periods_headers); }
while (sizeof($p_periods)>$maxGraphs) { array_pop($p_periods); }
while (sizeof($p_periods_headers)>$maxGraphs) { array_pop($p_periods_headers); }
// Fetching of the ITEM graphs
$graphFiles = array(); $graphFiles = array();
$graphURL = ''; $graphURL = '';
@@ -863,14 +1113,78 @@
$graphFiles[] = $graphFile; $graphFiles[] = $graphFile;
$mailData['GRAPH_URL'.($aKey+1)] = $z_url_image . $graphFile; $mailData['GRAPHS_I'][$aKey]['PATH'] = $z_images_path . $graphFile;
$mailData['GRAPH_HEADER'.($aKey+1)] = $p_periods_headers[$aKey]; $mailData['GRAPHS_I'][$aKey]['URL'] = $z_url_image . $graphFile;
$mailData['GRAPHS_I'][$aKey]['HEADER'] = $p_periods_headers[$aKey];
} }
$mailData['GRAPH_ZABBIXLINK'] = $z_server.'graphs.php?form=update&graphid='.$mailData['GRAPH_ID']; $mailData['GRAPH_ZABBIXLINK'] = $z_server.'graphs.php?form=update&graphid='.$mailData['GRAPH_ID'];
} }
// Prepare HTML LOG content // Fetch graphs associated to TRIGGER or HOST screen references obtained earlier
function addGraphs($varName,$info,$period,$periodHeader)
{
global $p_graphWidth;
global $p_graphHeight;
global $p_showLegend;
global $z_url_image;
global $z_images_path;
global $z_server;
global $mailData;
$files = array();
foreach($info as $aKey=>$anItem)
{
$graphFile = GraphImageById($anItem['graph']['graphid'],
$p_graphWidth,$p_graphHeight,
$anItem['graph']['graphtype'],
$p_showLegend,$period);
$mailData['GRAPHS_'.$varName][$aKey]['URL'] = $z_url_image . $graphFile;
$mailData['GRAPHS_'.$varName][$aKey]['PATH'] = $z_images_path . $graphFile;
}
$mailData['GRAPHS_'.$varName.'_LINK'] = $z_server.'screens.php?elementid='.$info[0]['screen']['screenid'];
$mailData['GRAPHS_'.$varName.'_HEADER'] = $info[0]['name'];
$mailData['GRAPHS_'.$varName.'_PERIODHEADER'] = $periodHeader;
}
if (sizeof($triggerGraphs)>0)
{
if ($triggerScreenPeriod=='')
{
$triggerScreenPeriod = $p_periods[0];
$triggerScreenPeriodHeader = $p_periods_headers[0];
}
if ($triggerScreenPeriodHeader=='') { $triggerScreenPeriodHeader = $triggerScreenPeriod; }
addGraphs('T',$triggerGraphs,$triggerScreenPeriod,$triggerScreenPeriodHeader);
$mailData['TRIGGER_SCREEN'] = $triggerScreen;
}
if (sizeof($hostGraphs)>0)
{
if ($hostScreenPeriod=='')
{
$hostScreenPeriod = $p_periods[0];
$hostScreenPeriodHeader = $p_periods_headers[0];
}
if ($hostScreenPeriodHeader=='') { $hostScreenPeriodHeader = $hostScreenPeriod; }
addGraphs('H',$hostGraphs,$hostScreenPeriod,$hostScreenPeriodHeader);
$mailData['HOST_SCREEN'] = $hostScreen;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Prepare HTML LOG content /////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
$mailData['LOG_HTML'] = implode('</br/>',$logging); $mailData['LOG_HTML'] = implode('</br/>',$logging);
$mailData['LOG_HTML'] = str_replace($cCRLF,'<br/>',$mailData['LOG_HTML']); $mailData['LOG_HTML'] = str_replace($cCRLF,'<br/>',$mailData['LOG_HTML']);
@@ -935,11 +1249,18 @@
$transport = (new Swift_SmtpTransport($p_smtp_server, $p_smtp_port)); $transport = (new Swift_SmtpTransport($p_smtp_server, $p_smtp_port));
} }
// Username/password?
if ($p_smtp_username!='') { $transport->setUsername($p_smtp_username); }
if ($p_smtp_password!='') { $transport->setPassword($p_smtp_password); }
// Start actual mail(er)
$mailer = new Swift_Mailer($transport); $mailer = new Swift_Mailer($transport);
$message = (new Swift_Message()); $message = (new Swift_Message());
// Fetch mailer ID from this message (no Swift function available for it ...) // --- Fetch mailer ID from this message (no Swift function available for it ...)
// --- "Message-ID: <...id...@swift.generated>" // --- "Message-ID: <...id...@swift.generated>"
$content = $message->toString(); $content = $message->toString();
@@ -964,19 +1285,26 @@
$twig = new \Twig\Environment($loader); $twig = new \Twig\Environment($loader);
if (sizeof($graphFiles)>0) // --- Embed the images
function embedGraphs($graphs,$varName,$type)
{ {
// Embed the image(s) global $message;
global $mailData;
$graphReference = 1; foreach($graphs as $aKey=>$anItem)
foreach($graphFiles as $graphFile)
{ {
$mailData['GRAPH_CID'.$graphReference++] = $message->embed(Swift_Image::fromPath($z_images_path.$graphFile)); $mailData['GRAPHS_'.$varName][$aKey]['CID'] = $message->embed(Swift_Image::fromPath($mailData['GRAPHS_'.$varName][$aKey]['PATH']));
_log('> Embedded graph image '.$z_images_path.$graphFile); _log('> Embedded graph image ('.$type.') '.$mailData['GRAPHS_'.$varName][$aKey]['PATH']);
} }
} }
embedGraphs($graphFiles,'I','ITEM');
embedGraphs($triggerGraphs,'T','TRIGGER');
embedGraphs($hostGraphs,'H','HOST');
// --- Render the content
$bodyHTML = $twig->render('html', $mailData); $bodyHTML = $twig->render('html', $mailData);
$bodyPlain = $twig->render('plain', $mailData); $bodyPlain = $twig->render('plain', $mailData);
$mailSubject = $twig->render('subject', $mailData); $mailSubject = $twig->render('subject', $mailData);
@@ -1009,6 +1337,10 @@
$response = array('messageId.mailGraph'=>$messageId); $response = array('messageId.mailGraph'=>$messageId);
echo json_encode($response).$cCRLF; echo json_encode($response).$cCRLF;
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Wrap up //////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Store log? // Store log?
if (($cDebug) || (isset($problemData['debug']))) if (($cDebug) || (isset($problemData['debug'])))
@@ -1016,7 +1348,7 @@
unset($mailData['LOG_HTML']); unset($mailData['LOG_HTML']);
unset($mailData['LOG_PLAIN']); unset($mailData['LOG_PLAIN']);
$content = implode(chr(10),$logging).$cCRLF.$cCRLF.'=== MAILDATA ==='.$cCRLF.$cCRLF.json_encode($mailData,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK); $content = implode(chr(10),$logging).$cCRLF.$cCRLF.'=== VALUES AVAILABLE FOR TWIG TEMPLATE ==='.$cCRLF.$cCRLF.json_encode($mailData,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK);
$content = str_replace(chr(13),'',$content); $content = str_replace(chr(13),'',$content);
$logName = 'log.'.$p_eventId.'.'.date('YmdHis').'.dump'; $logName = 'log.'.$p_eventId.'.'.date('YmdHis').'.dump';

Wyświetl plik

@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<zabbix_export> <zabbix_export>
<version>5.0</version> <version>5.0</version>
<date>2021-03-10T18:50:24Z</date> <date>2021-03-17T12:55:43Z</date>
<media_types> <media_types>
<media_type> <media_type>
<name>MailGraph</name> <name>MailGraph</name>
@@ -19,10 +19,6 @@
<name>eventId</name> <name>eventId</name>
<value>{EVENT.ID}</value> <value>{EVENT.ID}</value>
</parameter> </parameter>
<parameter>
<name>eventValue</name>
<value>{EVENT.VALUE}</value>
</parameter>
<parameter> <parameter>
<name>graphHeight</name> <name>graphHeight</name>
<value>120</value> <value>120</value>
@@ -35,6 +31,10 @@
<name>HTTPProxy</name> <name>HTTPProxy</name>
<value/> <value/>
</parameter> </parameter>
<parameter>
<name>infoTest</name>
<value>Test</value>
</parameter>
<parameter> <parameter>
<name>itemId</name> <name>itemId</name>
<value>{ITEM.ID}</value> <value>{ITEM.ID}</value>
@@ -59,10 +59,6 @@
<name>subject</name> <name>subject</name>
<value>{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}</value> <value>{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}</value>
</parameter> </parameter>
<parameter>
<name>triggerId</name>
<value>{TRIGGER.ID}</value>
</parameter>
<parameter> <parameter>
<name>URL</name> <name>URL</name>
<value>https://mydomain.com/mailGraph.php</value> <value>https://mydomain.com/mailGraph.php</value>
@@ -77,16 +73,17 @@
result = { tags: {} };&#13; result = { tags: {} };&#13;
&#13; &#13;
// Set HTTP proxy if required&#13; // Set HTTP proxy if required&#13;
if (typeof params.HTTPProxy === 'string' &amp;&amp; params.HTTPProxy.trim() !== '') { req.setProxy(params.HTTPProxy); }&#13; if (typeof params.HTTPProxy === 'string' &amp;&amp; params.HTTPProxy.trim() !== '') {&#13;
req.setProxy(params.HTTPProxy);&#13;
fields.HTTPProxy = params.HTTPProxy;&#13;
}&#13;
&#13; &#13;
// Declare output type&#13; // Declare output type&#13;
req.AddHeader('Content-Type: application/json');&#13; req.AddHeader('Content-Type: application/json');&#13;
&#13; &#13;
// Must have fields&#13; // Must have fields&#13;
fields.itemId = params.itemId;&#13; fields.itemId = params.itemId;&#13;
fields.triggerId = params.triggerId;&#13;
fields.eventId = params.eventId;&#13; fields.eventId = params.eventId;&#13;
fields.eventValue = params.eventValue;&#13;
fields.recipient = params.recipient;&#13; fields.recipient = params.recipient;&#13;
fields.baseURL = params.baseURL;&#13; fields.baseURL = params.baseURL;&#13;
fields.duration = params.duration;&#13; fields.duration = params.duration;&#13;
@@ -135,6 +132,8 @@ Customization:&#13;
- &quot;graphWidth&quot; and &quot;graphWidth&quot; can be defined for the image size&#13; - &quot;graphWidth&quot; and &quot;graphWidth&quot; can be defined for the image size&#13;
- &quot;showLegend&quot; can be defined to show or hide the legend of the graph&#13; - &quot;showLegend&quot; can be defined to show or hide the legend of the graph&#13;
- &quot;subject&quot; can be defined for a customized subject for the mail message&#13; - &quot;subject&quot; can be defined for a customized subject for the mail message&#13;
- &quot;periods&quot; and &quot;periods_headers&quot; can be defined for displaying multiple periods of the same graph, or&#13;
- &quot;period&quot; and &quot;period_header&quot; can be defined to display a single graph&#13;
&#13; &#13;
The html.template and plain.template files can be adjusted (TWIG format).&#13; The html.template and plain.template files can be adjusted (TWIG format).&#13;
&#13; &#13;

Wyświetl plik

@@ -114,49 +114,6 @@
</table> </table>
</td> </td>
</tr> </tr>
{% if GRAPH_CID1|length > 0 %}
<tr>
<div align=justify>
<td align="center">
<span class="graphHeader">{{ GRAPH_HEADER1 }}</span><br/>
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID1 }}" />
</td>
</div>
</tr>
{% endif %}
{% if GRAPH_CID2|length > 0 %}
<tr>
<div align=justify>
<td align="center">
<hr/>
<span class="graphHeader">{{ GRAPH_HEADER2 }}</span><br/>
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID2 }}" />
</td>
</div>
</tr>
{% endif %}
{% if GRAPH_CID3|length > 0 %}
<tr>
<div align=justify>
<td align="center">
<hr/>
<span class="graphHeader">{{ GRAPH_HEADER3 }}</span><br/>
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID3 }}" />
</td>
</div>
</tr>
{% endif %}
{% if GRAPH_CID4|length > 0 %}
<tr>
<div align=justify>
<td align="center">
<hr/>
<span class="graphHeader">{{ GRAPH_HEADER4 }}</span><br/>
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID4 }}" />
</td>
</div>
</tr>
{% endif %}
<tr> <tr>
<td class="links"> <td class="links">
<div align=center> <div align=center>
@@ -170,6 +127,66 @@
</div> </div>
</td> </td>
</tr> </tr>
{% for aGraph in GRAPHS_I %}
<tr>
<div align=justify>
<td align="center">
<span class="graphHeader">{{ aGraph.HEADER }}</span><br/>
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ aGraph.CID }}" />
</td>
</div>
</tr>
{% endfor %}
{% if TRIGGER_SCREEN > 0 %}
<tr>
<div align=justify>
<td align="center">
<span class="graphHeader">{{ GRAPHS_T_HEADER }} - {{ GRAPHS_T_PERIODHEADER }}</span>
</td>
</div>
</tr>
<tr>
<td class="links">
<div align="center">
Screen ID: <a href="{{ GRAPHS_T_LINK }}">{{ TRIGGER_SCREEN }}</a>
</div>
</td>
</tr>
{% for aGraph in GRAPHS_T %}
<tr>
<div align=justify>
<td align="center">
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ aGraph.CID }}" />
</td>
</div>
</tr>
{% endfor %}
{% endif %}
{% if HOST_SCREEN > 0 %}
<tr>
<div align=justify>
<td align="center">
<span class="graphHeader">{{ GRAPHS_H_HEADER }} - {{ GRAPHS_H_PERIODHEADER }}</span>
</td>
</div>
</tr>
<tr>
<td class="links">
<div align="center">
Screen ID: <a href="{{ GRAPHS_H_LINK }}">{{ HOST_SCREEN }}</a>
</div>
</td>
</tr>
{% for aGraph in GRAPHS_H %}
<tr>
<div align=justify>
<td align="center">
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ aGraph.CID }}" />
</td>
</div>
</tr>
{% endfor %}
{% endif %}
</table> </table>
</body> </body>
</html> </html>