mirror of
https://github.com/moudsen/mailGraph
synced 2025-10-28 16:17:39 +01:00
Compare commits
23 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ba0d474bdb | ||
|
|
a5a0f0ace1 | ||
|
|
8655d4ca2c | ||
|
|
76321be3f8 | ||
|
|
9d4f00ce87 | ||
|
|
1278d43acb | ||
|
|
18c22abf17 | ||
|
|
0a623f3137 | ||
|
|
634134b423 | ||
|
|
58668311ee | ||
|
|
9052b71562 | ||
|
|
74b6ee15c7 | ||
|
|
398637e582 | ||
|
|
9e40060cdd | ||
|
|
e85400b0de | ||
|
|
e05fcbfba7 | ||
|
|
66b504a66c | ||
|
|
bc0c83b544 | ||
|
|
17cdbea2bd | ||
|
|
fb51354649 | ||
|
|
78061964c4 | ||
|
|
1c9786c549 | ||
|
|
37b1ea7ea2 |
11
README.md
11
README.md
@@ -1,7 +1,16 @@
|
||||
## mailGraph (v1.22)
|
||||
## mailGraph (v1.28)
|
||||
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.**
|
||||
|
||||
## 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
|
||||
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)
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"script_baseurl": "https:\/\/domain.com\/",
|
||||
"script_baseurl": "https:\/\/mydomain.com\/",
|
||||
"cli_itemId": 0,
|
||||
"cli_triggerId": 0,
|
||||
"cli_eventId": 0,
|
||||
"cli_eventValue": 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_baseURL": "https:\/\/domain.com\/zabbix\/",
|
||||
"cli_baseURL": "https:\/\/mydomain.com\/zabbix\/",
|
||||
"cli_period": "30m",
|
||||
"cli_period_header": "Last 30 minutes",
|
||||
"cli_debug": 1,
|
||||
"cli_proxy": "",
|
||||
"zabbix_user": "alogicalusername",
|
||||
"zabbix_user_pwd": "astrongpassword",
|
||||
"zabbix_api_user": "alogicalusername",
|
||||
"zabbix_api_pwd": "astrongpassword",
|
||||
"mail_from": "sender@domain.com",
|
||||
"mail_from": "sender@mydomain.com",
|
||||
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
||||
"smtp_server": "localhost",
|
||||
"smtp_port": 25,
|
||||
|
||||
@@ -1,21 +1,21 @@
|
||||
{
|
||||
"script_baseurl": "https:\/\/domain.com\/",
|
||||
"script_baseurl": "https:\/\/mydomain.com\/",
|
||||
"cli_itemId": 0,
|
||||
"cli_triggerId": 0,
|
||||
"cli_eventId": 0,
|
||||
"cli_eventValue": 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_baseURL": "https:\/\/domain.com\/zabbix\/",
|
||||
"cli_baseURL": "https:\/\/mydomain.com\/zabbix\/",
|
||||
"cli_periods": "10m,4h,2d,7d",
|
||||
"cli_periods_headers": "Last 10 minutes,Last 4 hours,Last 2 days,Last 7 days",
|
||||
"cli_debug": 1,
|
||||
"cli_proxy": "",
|
||||
"zabbix_user": "alogicalusername",
|
||||
"zabbix_user_pwd": "astrongpassword",
|
||||
"zabbix_api_user": "alogicalusername",
|
||||
"zabbix_api_pwd": "astrongpassword",
|
||||
"mail_from": "sender@domain.com",
|
||||
"mail_from": "sender@mydomain.com",
|
||||
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
||||
"smtp_server": "localhost",
|
||||
"smtp_port": 25,
|
||||
|
||||
@@ -7,16 +7,17 @@ try {
|
||||
result = { tags: {} };
|
||||
|
||||
// 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
|
||||
req.AddHeader('Content-Type: application/json');
|
||||
|
||||
// Must have fields
|
||||
fields.itemId = params.itemId;
|
||||
fields.triggerId = params.triggerId;
|
||||
fields.eventId = params.eventId;
|
||||
fields.eventValue = params.eventValue;
|
||||
fields.recipient = params.recipient;
|
||||
fields.baseURL = params.baseURL;
|
||||
fields.duration = params.duration;
|
||||
|
||||
532
mailGraph.php
532
mailGraph.php
@@ -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
|
||||
// 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
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
||||
@@ -50,14 +58,15 @@
|
||||
|
||||
// CONSTANTS
|
||||
|
||||
$cVersion = 'v1.22';
|
||||
$cVersion = 'v1.28';
|
||||
$cCRLF = chr(10).chr(13);
|
||||
$maskDateTime = 'Y-m-d H:i:s';
|
||||
$maxGraphs = 4;
|
||||
|
||||
// DEBUG SETTINGS
|
||||
// -- 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)
|
||||
$showLog = FALSE; // Display the log - !!! only use in combination with CLI mode !!!
|
||||
|
||||
@@ -81,16 +90,23 @@
|
||||
global $cCRLF;
|
||||
global $cVersion;
|
||||
global $cDebug;
|
||||
global $HTTPProxy;
|
||||
|
||||
// Initialize Curl instance
|
||||
_log('% postJSON: '.$url);
|
||||
if ($cDebug) { _log('> POST data'.json_encode($data)); }
|
||||
if ($cDebug) { _log('> POST data: '.json_encode(maskOutputContent($data))); }
|
||||
|
||||
$ch = curl_init();
|
||||
|
||||
// Set options
|
||||
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_RETURNTRANSFER, TRUE);
|
||||
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
|
||||
@@ -141,13 +157,36 @@
|
||||
global $z_url_api;
|
||||
global $cVersion;
|
||||
global $cCRLF;
|
||||
global $HTTPProxy;
|
||||
|
||||
// Unique names
|
||||
$thisTime = time();
|
||||
|
||||
// Relative web calls
|
||||
$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 .
|
||||
"&graphtype=".$graphType."&legend=".$showLegend."&profileIdx=web.graphs.filter".
|
||||
"&from=now-".$period."&to=now";
|
||||
@@ -168,6 +207,12 @@
|
||||
curl_setopt($ch, CURLOPT_HEADER, false);
|
||||
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_BINARYTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
|
||||
@@ -227,6 +272,22 @@
|
||||
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
|
||||
@@ -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 = '';
|
||||
|
||||
$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)
|
||||
foreach($info as $aKey=>$aValue)
|
||||
{
|
||||
$duration .= $days . ' day';
|
||||
if ($days!=1) { $duration .= 's'; }
|
||||
switch($aKey)
|
||||
{
|
||||
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 ($hours!=1) { $duration .= 's'; }
|
||||
if (is_array($infoValue)) { $info[$infoKey] = maskOutputContent($infoValue); }
|
||||
|
||||
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)
|
||||
{
|
||||
$duration .= ' ' . $minutes . ' min';
|
||||
if ($minutes!=1) { $duration .= 's'; }
|
||||
}
|
||||
|
||||
if ($seconds>=0) { $duration .= ' ' . $seconds . ' sec'; }
|
||||
if ($seconds!=1) { $duration .= 's'; }
|
||||
|
||||
return $duration;
|
||||
return($info);
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
@@ -315,7 +386,8 @@
|
||||
// [CONFIGURE] Change only when you want to place your config file somewhere else ...
|
||||
$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 ---
|
||||
|
||||
@@ -325,6 +397,8 @@
|
||||
|
||||
// --- CLI DATA ---
|
||||
|
||||
$HTTPProxy = '';
|
||||
|
||||
// Facilitate CLI based testing
|
||||
if (isset($argc))
|
||||
{
|
||||
@@ -336,27 +410,27 @@
|
||||
|
||||
// MANDATORY
|
||||
$problemData['itemId'] = $config['cli_itemId'];
|
||||
$problemData['triggerId'] = $config['cli_triggerId'];
|
||||
$problemData['eventId'] = $config['cli_eventId'];
|
||||
$problemData['eventValue'] = $config['cli_eventValue'];
|
||||
$problemData['recipient'] = $config['cli_recipient'];
|
||||
$problemData['baseURL'] = $config['cli_baseURL'];
|
||||
$problemData['duration'] = $config['cli_duration'];
|
||||
$problemData['subject'] = $config['cli_subject'];
|
||||
$problemData['period'] = $config['cli_period'];
|
||||
|
||||
// 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_periods'])) { $problemData['periods'] = $config['cli_periods']; }
|
||||
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_proxy'])) { $problemData['HTTPProxy'] = $config['cli_proxy']; }
|
||||
|
||||
// Switch on CLI log display
|
||||
$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 ---
|
||||
// FROM POST OR CLI DATA
|
||||
@@ -364,18 +438,12 @@
|
||||
if (!isset($problemData['itemId'])) { echo "Missing ITEM ID?\n"; die; }
|
||||
$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; }
|
||||
$p_eventId = intval($problemData['eventId']);
|
||||
|
||||
if (!isset($problemData['recipient'])) { echo "Missing RECIPIENT?\n"; die; }
|
||||
$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; }
|
||||
$p_duration = intval($problemData['duration']);
|
||||
|
||||
@@ -397,6 +465,8 @@
|
||||
$p_period = '48h';
|
||||
if (isset($problemData['period'])) { $p_period = $problemData['period']; }
|
||||
|
||||
if (isset($problemData['HTTPProxy'])) { $HTTPProxy = $problemData['HTTPPRoxy']; }
|
||||
|
||||
// DYNAMIC VARIABLES FROM ZABBIX
|
||||
|
||||
foreach($problemData as $aKey=>$aValue)
|
||||
@@ -419,6 +489,12 @@
|
||||
$p_smtp_strict = 'yes';
|
||||
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';
|
||||
if ((isset($config['graph_match'])) && ($config['graph_match']=='exact')) { $p_graph_match = 'exact'; }
|
||||
|
||||
@@ -470,7 +546,9 @@
|
||||
$mailData['BASE_URL'] = $p_URL;
|
||||
$mailData['SUBJECT'] = $p_subject;
|
||||
|
||||
// -------------
|
||||
// --- LOGIN ---
|
||||
// -------------
|
||||
|
||||
_log('# LOGIN to Zabbix');
|
||||
|
||||
@@ -490,7 +568,51 @@
|
||||
|
||||
_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 ---
|
||||
// ------------------------
|
||||
|
||||
_log('# Retrieve TRIGGER information');
|
||||
|
||||
@@ -518,6 +640,9 @@
|
||||
// --- Custom settings?
|
||||
|
||||
$forceGraph = 0;
|
||||
$triggerScreen = 0;
|
||||
$triggerScreenPeriod = '';
|
||||
$triggerScreenPeriodHeader = '';
|
||||
|
||||
foreach($thisTrigger['result'][0]['tags'] as $aTag)
|
||||
{
|
||||
@@ -567,18 +692,33 @@
|
||||
$problemData['debug'] = 1;
|
||||
_log('+ Mail debug log enabled');
|
||||
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 ---
|
||||
// ---------------------
|
||||
|
||||
_log('# Retrieve ITEM information');
|
||||
|
||||
$itemId = $thisTrigger['result'][0]['functions'][0]['itemid'];
|
||||
|
||||
$request = array('jsonrpc'=>'2.0',
|
||||
'method'=>'item.get',
|
||||
'params'=>array('itemids'=>$itemId,
|
||||
'params'=>array('itemids'=>$p_itemId,
|
||||
'output'=>'extend'),
|
||||
'auth'=>$token,
|
||||
'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_PREVIOUSVALUE'])>50) { $mailData['ITEM_PREVIOUSVALUE'] = substr($mailData['ITEM_PREVIOUSVALUE'],0,50).' ...'; }
|
||||
|
||||
// ---------------------
|
||||
// --- GET HOST INFO ---
|
||||
// ---------------------
|
||||
|
||||
_log('# Retrieve HOST information');
|
||||
|
||||
@@ -612,7 +754,8 @@
|
||||
$request = array('jsonrpc'=>'2.0',
|
||||
'method'=>'host.get',
|
||||
'params'=>array('hostids'=>$hostId,
|
||||
'output'=>'extend'),
|
||||
'output'=>'extend',
|
||||
'selectTags'=>'extend'),
|
||||
'auth'=>$token,
|
||||
'id'=>nextRequestID());
|
||||
|
||||
@@ -626,6 +769,33 @@
|
||||
$mailData['HOST_ERROR'] = $thisHost['result'][0]['error'];
|
||||
$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');
|
||||
|
||||
$request = array('jsonrpc'=>'2.0',
|
||||
@@ -638,7 +808,30 @@
|
||||
$thisMacros = postJSON($z_url_api,$request);
|
||||
_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');
|
||||
|
||||
@@ -667,9 +860,11 @@
|
||||
|
||||
if ($forceGraph>0)
|
||||
{
|
||||
_log('# Retrieving FORCED graph information');
|
||||
|
||||
// --------------------------------------------
|
||||
// --- GET GRAPH ASSOCIATED WITH FORCEGRAPH ---
|
||||
// --------------------------------------------
|
||||
|
||||
_log('# Retrieving FORCED graph information');
|
||||
|
||||
$request = array('jsonrpc'=>'2.0',
|
||||
'method'=>'graph.get',
|
||||
@@ -680,7 +875,8 @@
|
||||
'id'=>nextRequestID());
|
||||
|
||||
$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]))
|
||||
{
|
||||
@@ -689,11 +885,13 @@
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------
|
||||
// --- FIND MATCHING GRAPH ITEMS 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();
|
||||
|
||||
@@ -720,7 +918,7 @@
|
||||
{
|
||||
if ($aGraphItem['itemid']==$anItemId)
|
||||
{
|
||||
if ($anItemId=$itemId)
|
||||
if ($anItemId==$p_itemId)
|
||||
{
|
||||
_log('+ Graph #'.$aGraphItem['graphid'].' full match found (item #'.$aGraphItem['itemid'].')');
|
||||
$matchedGraphs[] = $aGraph;
|
||||
@@ -737,47 +935,95 @@
|
||||
|
||||
_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');
|
||||
|
||||
$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)
|
||||
function _sort($a,$b)
|
||||
{
|
||||
case 0: // Recovering
|
||||
$mailData['EVENT_SEVERITY'] = 'Resolved';
|
||||
break;
|
||||
|
||||
case 1: // Triggered/Active
|
||||
$_severity = array('Not classified','Information','Warning','Average','High','Disaster');
|
||||
$mailData['EVENT_SEVERITY'] = $_severity[$thisEvent['result'][0]['severity']];
|
||||
break;
|
||||
if ($a['screen']['y']>$b['screen']['y']) { return(1); }
|
||||
if ($a['screen']['y']<$b['screen']['y']) { return(-1); }
|
||||
if ($a['screen']['x']>$b['screen']['x']) { return(1); }
|
||||
if ($a['screen']['x']<$b['screen']['x']) { return(-1); }
|
||||
return(0);
|
||||
}
|
||||
|
||||
$_status = array('Recovered','Triggered/Active');
|
||||
$mailData['EVENT_STATUS'] = $_status[$p_eventValue];
|
||||
function fetchGraphsFromScreen($screenId)
|
||||
{
|
||||
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_headers = array();
|
||||
@@ -816,8 +1062,12 @@
|
||||
}
|
||||
}
|
||||
|
||||
while (sizeof($p_periods)>4) { array_pop($p_periods); }
|
||||
while (sizeof($p_periods_headers)>4) { array_pop($p_periods_headers); }
|
||||
// Strip off any excessive elements from the end
|
||||
|
||||
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();
|
||||
$graphURL = '';
|
||||
@@ -863,14 +1113,78 @@
|
||||
|
||||
$graphFiles[] = $graphFile;
|
||||
|
||||
$mailData['GRAPH_URL'.($aKey+1)] = $z_url_image . $graphFile;
|
||||
$mailData['GRAPH_HEADER'.($aKey+1)] = $p_periods_headers[$aKey];
|
||||
$mailData['GRAPHS_I'][$aKey]['PATH'] = $z_images_path . $graphFile;
|
||||
$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'];
|
||||
}
|
||||
|
||||
// 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'] = str_replace($cCRLF,'<br/>',$mailData['LOG_HTML']);
|
||||
@@ -935,11 +1249,18 @@
|
||||
$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);
|
||||
|
||||
$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>"
|
||||
|
||||
$content = $message->toString();
|
||||
@@ -964,19 +1285,26 @@
|
||||
|
||||
$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($graphFiles as $graphFile)
|
||||
foreach($graphs as $aKey=>$anItem)
|
||||
{
|
||||
$mailData['GRAPH_CID'.$graphReference++] = $message->embed(Swift_Image::fromPath($z_images_path.$graphFile));
|
||||
_log('> Embedded graph image '.$z_images_path.$graphFile);
|
||||
$mailData['GRAPHS_'.$varName][$aKey]['CID'] = $message->embed(Swift_Image::fromPath($mailData['GRAPHS_'.$varName][$aKey]['PATH']));
|
||||
_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);
|
||||
$bodyPlain = $twig->render('plain', $mailData);
|
||||
$mailSubject = $twig->render('subject', $mailData);
|
||||
@@ -1009,6 +1337,10 @@
|
||||
$response = array('messageId.mailGraph'=>$messageId);
|
||||
echo json_encode($response).$cCRLF;
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// Wrap up //////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// Store log?
|
||||
|
||||
if (($cDebug) || (isset($problemData['debug'])))
|
||||
@@ -1016,7 +1348,7 @@
|
||||
unset($mailData['LOG_HTML']);
|
||||
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);
|
||||
|
||||
$logName = 'log.'.$p_eventId.'.'.date('YmdHis').'.dump';
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<zabbix_export>
|
||||
<version>5.0</version>
|
||||
<date>2021-03-10T18:50:24Z</date>
|
||||
<date>2021-03-17T12:55:43Z</date>
|
||||
<media_types>
|
||||
<media_type>
|
||||
<name>MailGraph</name>
|
||||
@@ -19,10 +19,6 @@
|
||||
<name>eventId</name>
|
||||
<value>{EVENT.ID}</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>eventValue</name>
|
||||
<value>{EVENT.VALUE}</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>graphHeight</name>
|
||||
<value>120</value>
|
||||
@@ -35,6 +31,10 @@
|
||||
<name>HTTPProxy</name>
|
||||
<value/>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>infoTest</name>
|
||||
<value>Test</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>itemId</name>
|
||||
<value>{ITEM.ID}</value>
|
||||
@@ -59,10 +59,6 @@
|
||||
<name>subject</name>
|
||||
<value>{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>triggerId</name>
|
||||
<value>{TRIGGER.ID}</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>URL</name>
|
||||
<value>https://mydomain.com/mailGraph.php</value>
|
||||
@@ -77,16 +73,17 @@
|
||||
result = { tags: {} };
|
||||
|
||||
// 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
|
||||
req.AddHeader('Content-Type: application/json');
|
||||
|
||||
// Must have fields
|
||||
fields.itemId = params.itemId;
|
||||
fields.triggerId = params.triggerId;
|
||||
fields.eventId = params.eventId;
|
||||
fields.eventValue = params.eventValue;
|
||||
fields.recipient = params.recipient;
|
||||
fields.baseURL = params.baseURL;
|
||||
fields.duration = params.duration;
|
||||
@@ -135,6 +132,8 @@ Customization:
|
||||
- "graphWidth" and "graphWidth" can be defined for the image size
|
||||
- "showLegend" can be defined to show or hide the legend of the graph
|
||||
- "subject" can be defined for a customized subject for the mail message
|
||||
- "periods" and "periods_headers" can be defined for displaying multiple periods of the same graph, or
|
||||
- "period" and "period_header" can be defined to display a single graph
|
||||
|
||||
The html.template and plain.template files can be adjusted (TWIG format).
|
||||
|
||||
|
||||
@@ -114,49 +114,6 @@
|
||||
</table>
|
||||
</td>
|
||||
</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>
|
||||
<td class="links">
|
||||
<div align=center>
|
||||
@@ -170,6 +127,66 @@
|
||||
</div>
|
||||
</td>
|
||||
</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>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user