mirror of
https://github.com/moudsen/mailGraph
synced 2025-10-28 16:17:39 +01:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8bc476ed63 | ||
|
|
e80a2a56a3 | ||
|
|
4b28d3f066 | ||
|
|
93535d4006 | ||
|
|
b9622da72f | ||
|
|
56fb68ae9c | ||
|
|
fa51c3e59e | ||
|
|
4ae62b3a1f | ||
|
|
0731b87d44 | ||
|
|
bdf4b05a6b | ||
|
|
df16444665 | ||
|
|
bccd134523 | ||
|
|
27c1d64511 | ||
|
|
8597658670 | ||
|
|
b7e2062486 | ||
|
|
2955ffc404 | ||
|
|
2976a4af9c | ||
|
|
2882367308 | ||
|
|
8b4885038a | ||
|
|
f541719fbe | ||
|
|
9edab245d8 | ||
|
|
341bd561ab | ||
|
|
e2f657f3dd | ||
|
|
82a8fe4121 | ||
|
|
bee76b63c0 | ||
|
|
ba0d474bdb | ||
|
|
a5a0f0ace1 | ||
|
|
8655d4ca2c | ||
|
|
76321be3f8 | ||
|
|
9d4f00ce87 | ||
|
|
1278d43acb | ||
|
|
18c22abf17 | ||
|
|
0a623f3137 | ||
|
|
634134b423 |
55
README.md
55
README.md
@@ -1,10 +1,55 @@
|
|||||||
## mailGraph (v1.26)
|
## mailGraph v2.10 release ##
|
||||||
Zabbix Media module and scripts for sending e-mail alerts with graphs.
|
_(2023/06/30)_
|
||||||
|
|
||||||
**Please use the Wiki for information on how to install, configure and use MailGraph in Zabbix.**
|
_This version has been verified with Zabbix 5.4, 6.0 LTS and 6.4._
|
||||||
|
|
||||||
## Upgrade notes
|
Minor updates to the mailGraph code
|
||||||
Per v1.25 and higher the 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).
|
- When not defining zabbix_api_user and zabbix_api_pwd in the configuration file the zbx_user and zbx_user_pwd wll be used
|
||||||
|
|
||||||
|
Modified files
|
||||||
|
- mailGraph.php
|
||||||
|
- mailGraph.xml
|
||||||
|
- javascript/zabbix.mailGraph.js
|
||||||
|
|
||||||
|
For those upgrading to the latest release without installing the media type:
|
||||||
|
- copy new mailGraph.php over existing mailGraph.php
|
||||||
|
- open the Media type MailGraph in Zabbix and edit the javascript
|
||||||
|
-- replace the script contents with the contents of javascript/zabbix.mailGraph.js
|
||||||
|
|
||||||
|
Changes are in effect immediately, no need to restart any services.
|
||||||
|
|
||||||
|
## Zabbix 6.4.x testing ##
|
||||||
|
_(2023/06/30)_
|
||||||
|
|
||||||
|
Zabbix 6.4 verification has succesfully completed.
|
||||||
|
- Refactored code to remove deprecated and removed functions since Zabbix 6.4.0
|
||||||
|
-- Zabbix Javascript now using HttpRequest instead of CurlHttpRequest (function name changes implemented)
|
||||||
|
-- Zabbix API user.login is now based on "username" (instead of "user")
|
||||||
|
|
||||||
|
Sidenotes
|
||||||
|
- Zabbix logging still shows deprecation messages however it is believed these are internal to Zabbix and not related to mailGraph
|
||||||
|
|
||||||
|
_(2023/06/29)_
|
||||||
|
|
||||||
|
Zabbix 6.4.x verification is in progress. Required intermediate release to fix one major issue (Zabbix login parameters deprecation) and some minor coding updates.
|
||||||
|
Expect to continue with automatic configuration within the next 2 months.
|
||||||
|
|
||||||
|
## Zabbix 6.2.x testing ##
|
||||||
|
_(2022/10/10)_
|
||||||
|
|
||||||
|
Testing completed. No immediate issues found.
|
||||||
|
|
||||||
|
_(2022/08/22)_
|
||||||
|
|
||||||
|
Zabbix 6.2.x testing is in progress. Once completed the next effort will be to deliver on automatic configuration detection and automatic updates.
|
||||||
|
|
||||||
|
## IMPORTANT NOTE ##
|
||||||
|
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**
|
||||||
|
**Please use the Wiki for information on how to install, configure and use MailGraph in Zabbix**
|
||||||
|
|
||||||
## Example message
|
## Example message
|
||||||
|
The below message is just an example of what MailGraph is capable of. The template engine ("Twig") allows for a fully customized message creation to your needs! It is also possible to add more Zabbix fields. If you need additional fields just raise an issue ticket and ask and I'll see what I can do.
|
||||||
|
|
||||||
[](images/Example-mail-message-v122.png)
|
[](images/Example-mail-message-v122.png)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
$content = file_get_contents($argv[1]);
|
$content = file_get_contents($argv[1]);
|
||||||
$data = json_decode($content,TRUE);
|
$data = json_decode($content,TRUE);
|
||||||
|
|
||||||
if ($data==NULL)
|
if (($data==NULL) && (sizeof($content)>2))
|
||||||
{
|
{
|
||||||
echo 'Invalid JSON format in config file?!'.$cCRLF;
|
echo 'Invalid JSON format in config file?!'.$cCRLF;
|
||||||
die;
|
die;
|
||||||
|
|||||||
BIN
images/Example-Zabbix-MediaType-Config.png
Normal file
BIN
images/Example-Zabbix-MediaType-Config.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 85 KiB |
1
javascript/READ.ME
Normal file
1
javascript/READ.ME
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Issue #32 has been resolved. The javascript code now works for Zabbix 5.4, 6.0 LTS and 6.4.
|
||||||
@@ -1,19 +1,19 @@
|
|||||||
try {
|
try {
|
||||||
// Pickup parameters
|
// Pickup parameters
|
||||||
params = JSON.parse(value),
|
params = JSON.parse(value),
|
||||||
req = new CurlHttpRequest(),
|
req = new HttpRequest(),
|
||||||
fields = {},
|
fields = {},
|
||||||
resp = '',
|
resp = '',
|
||||||
result = { tags: {} };
|
result = { tags: {} };
|
||||||
|
|
||||||
// Set HTTP proxy if required
|
// Set HTTP proxy if required
|
||||||
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
|
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
|
||||||
req.setProxy(params.HTTPProxy);
|
req.setProxy(params.HTTPProxy);
|
||||||
fields.HTTPProxy = 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;
|
||||||
@@ -40,11 +40,11 @@ try {
|
|||||||
|
|
||||||
// Post information to the processing script
|
// Post information to the processing script
|
||||||
Zabbix.Log(4, '[MailGraph Webhook] Sending request: ' + params.URL + '?' + JSON.stringify(fields));
|
Zabbix.Log(4, '[MailGraph Webhook] Sending request: ' + params.URL + '?' + JSON.stringify(fields));
|
||||||
var resp = req.Post(params.URL,JSON.stringify(fields));
|
var resp = req.post(params.URL,JSON.stringify(fields));
|
||||||
Zabbix.Log(4, '[Mailgraph Webhook] Receiving response:' + resp);
|
Zabbix.Log(4, '[Mailgraph Webhook] Receiving response:' + resp);
|
||||||
|
|
||||||
// If there was an error, report it
|
// If there was an error, report it
|
||||||
if (req.Status() != 200) { throw JSON.parse(resp).errors[0]; }
|
if (req.getStatus() != 200) { throw JSON.parse(resp).errors[0]; }
|
||||||
|
|
||||||
// We expect the message id back from the processing script
|
// We expect the message id back from the processing script
|
||||||
resp = JSON.parse(resp);
|
resp = JSON.parse(resp);
|
||||||
|
|||||||
460
mailGraph.php
460
mailGraph.php
@@ -8,6 +8,8 @@
|
|||||||
// upon an alert message.
|
// 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.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.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.10 2021/02/27 - Mark Oudsen - Moved all configuration outside code
|
||||||
@@ -33,6 +35,20 @@
|
|||||||
// 1.25 2021/03/16 - Mark Oudsen - Refactoring for optimized flow and relevant data retrieval
|
// 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)
|
// 1.26 2021/03/19 - Mark Oudsen - Bugfixes after refactor (wrong itemId and incorrect eventValue)
|
||||||
// Suppressing Zabbix username-password in log
|
// 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 2 tested with Zabbix 5.4, 6.0 LTS and 6.4 - tested with latest Composer libraries
|
||||||
|
// ------------------------------------------------------------------------------------------------------
|
||||||
|
// 2.00 2021/12/16 - Mark Oudsen - itemId not always provisioned by Zabbix
|
||||||
|
// Several fixes on warning - several small bug fixes
|
||||||
|
// 2.01 2021/12/16 - Mark Oudsen - Screens are no longer available - reverting to using Dashboards now
|
||||||
|
// 2.02 2022/01/30 - Mark Oudsen - Added cleanup routine for old logs and images
|
||||||
|
// 2.10 2023/06/30 - Mark Oudsen - Refactored deprecated code - now compatible with Zabbix 6.4
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
||||||
@@ -54,18 +70,22 @@
|
|||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
|
$cVersion = 'v2.10';
|
||||||
$cVersion = 'v1.26';
|
|
||||||
$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 !!!
|
||||||
|
|
||||||
|
// Limit server level output errors
|
||||||
|
|
||||||
|
error_reporting(E_ERROR | E_PARSE);
|
||||||
|
|
||||||
// INCLUDE REQUIRED LIBRARIES (Composer)
|
// INCLUDE REQUIRED LIBRARIES (Composer)
|
||||||
// (configure at same location as the script is running or load in your own central library)
|
// (configure at same location as the script is running or load in your own central library)
|
||||||
// -- swiftmailer/swiftmailer https://swiftmailer.symfony.com/docs/introduction.html
|
// -- swiftmailer/swiftmailer https://swiftmailer.symfony.com/docs/introduction.html
|
||||||
@@ -95,23 +115,24 @@
|
|||||||
$ch = curl_init();
|
$ch = curl_init();
|
||||||
|
|
||||||
// Set options
|
// Set options
|
||||||
curl_setopt($ch, CURLOPT_USERAGENT, 'Zabbix-mailGraph - '.$cVersion);
|
|
||||||
|
|
||||||
if ((isset($HTTPProxy)) && ($HTTPProxy!=''))
|
if ((isset($HTTPProxy)) && ($HTTPProxy!=''))
|
||||||
{
|
{
|
||||||
_log('% Using proxy: '.$HTTPProxy);
|
if ($cDebug) { _log('% Using proxy: '.$HTTPProxy); }
|
||||||
curl_setopt($ch, CURLOPT_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_CONNECTTIMEOUT, 20);
|
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 20);
|
||||||
|
|
||||||
|
curl_setopt($ch, CURLOPT_POST, TRUE);
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
|
||||||
|
|
||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
||||||
curl_setopt($ch, CURLOPT_POST, TRUE);
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
|
||||||
json_encode($data,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
|
curl_setopt($ch, CURLOPT_USERAGENT, 'Zabbix-mailGraph - '.$cVersion);
|
||||||
|
|
||||||
// Execute Curl
|
// Execute Curl
|
||||||
$data = curl_exec($ch);
|
$data = curl_exec($ch);
|
||||||
@@ -120,9 +141,10 @@
|
|||||||
{
|
{
|
||||||
_log('! Failed: '.curl_error($ch));
|
_log('! Failed: '.curl_error($ch));
|
||||||
|
|
||||||
$data = 'An error occurred while retreiving the requested page.'.$cCRLF;
|
$data = array();
|
||||||
$data .= 'Requested page = '.$url.$cCRLF;
|
$data[] = 'An error occurred while retreiving the requested page.';
|
||||||
$data .= 'Error = '.curl_error($ch).$cCRLF;
|
$data[] .= 'Requested page = '.$url;
|
||||||
|
$data[] .= 'Error = '.curl_error($ch);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -268,6 +290,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
|
||||||
@@ -357,6 +395,40 @@
|
|||||||
return($info);
|
return($info);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// Cleanup 'path': remove files with 'ext' older than 'daysOld'
|
||||||
|
|
||||||
|
function cleanupDir($path, $ext, $daysOld)
|
||||||
|
{
|
||||||
|
_log('- Scanning "'.$path.'"');
|
||||||
|
|
||||||
|
$files = glob($path.'/*'.$ext);
|
||||||
|
$now = time();
|
||||||
|
|
||||||
|
$filesRemoved = 0;
|
||||||
|
$filesKept = 0;
|
||||||
|
|
||||||
|
foreach ($files as $file)
|
||||||
|
{
|
||||||
|
if (is_file($file))
|
||||||
|
{
|
||||||
|
if ($now - filemtime($file) >= (60 * 60 * 24 * $daysOld))
|
||||||
|
{
|
||||||
|
_log('> Removing "'.$file.'"');
|
||||||
|
unlink($file);
|
||||||
|
$filesRemoved++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$filesKept++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_log(': Done. Cleaned up '.$filesRemoved.' file(s), kept '.$filesKept.' file(s)');
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
// Initialize ///////////////////////////////////////////////////////////////////////////////////////////
|
// Initialize ///////////////////////////////////////////////////////////////////////////////////////////
|
||||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
@@ -384,6 +456,10 @@
|
|||||||
{
|
{
|
||||||
if (($argc>1) && ($argv[1]=='test'))
|
if (($argc>1) && ($argv[1]=='test'))
|
||||||
{
|
{
|
||||||
|
// Switch on CLI log display
|
||||||
|
$showLog = TRUE;
|
||||||
|
|
||||||
|
_log('<<< mailGraph '.$cVersion.' >>>');
|
||||||
_log('# Invoked from CLI');
|
_log('# Invoked from CLI');
|
||||||
|
|
||||||
// Assumes that config.json file has the correct information
|
// Assumes that config.json file has the correct information
|
||||||
@@ -403,25 +479,48 @@
|
|||||||
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']; }
|
if (isset($config['cli_proxy'])) { $problemData['HTTPProxy'] = $config['cli_proxy']; }
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($argc>1) && ($argv[1]=='cleanup'))
|
||||||
|
{
|
||||||
// Switch on CLI log display
|
// Switch on CLI log display
|
||||||
$showLog = TRUE;
|
$showLog = TRUE;
|
||||||
|
|
||||||
|
// Check for configuration of retention period for images and logs
|
||||||
|
_log('<<< mailGraph '.$cVersion.' >>>');
|
||||||
|
_log('# Invoked from CLI');
|
||||||
|
|
||||||
|
// Set defaults
|
||||||
|
$retImages = 30;
|
||||||
|
$retLogs = 14;
|
||||||
|
|
||||||
|
// Check if configured settings
|
||||||
|
if (isset($config['retention_images'])) { $retImages = intval($config['retention_images']); }
|
||||||
|
if (isset($config['retention_logs'])) { $retLogs = intval($config['retention_logs']); }
|
||||||
|
|
||||||
|
_log('Cleaning up IMAGES ('.$retImages.' days) and LOGS ('.$retLogs.' days)');
|
||||||
|
|
||||||
|
cleanupDir(getcwd().'/images', '.png', $retImages);
|
||||||
|
cleanupDir(getcwd().'/log', '.dump', $retLogs);
|
||||||
|
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_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
|
||||||
|
|
||||||
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['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'];
|
$nt = $problemData['recipient'];
|
||||||
|
|
||||||
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']);
|
||||||
@@ -444,7 +543,7 @@
|
|||||||
$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']; }
|
if (isset($problemData['HTTPProxy'])) { $HTTPProxy = $problemData['HTTPProxy']; }
|
||||||
|
|
||||||
// DYNAMIC VARIABLES FROM ZABBIX
|
// DYNAMIC VARIABLES FROM ZABBIX
|
||||||
|
|
||||||
@@ -468,6 +567,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'; }
|
||||||
|
|
||||||
@@ -489,9 +594,19 @@
|
|||||||
$z_pass = $config['zabbix_user_pwd'];
|
$z_pass = $config['zabbix_user_pwd'];
|
||||||
|
|
||||||
// Zabbix API user (requires Super Admin access rights)
|
// Zabbix API user (requires Super Admin access rights)
|
||||||
// TODO: Check if information retreival can be done with less rigths
|
// --- Copy from Zabbix user and override when defined in configuration
|
||||||
|
$z_api_user = $z_user;
|
||||||
|
$z_api_pass = $z_pass;
|
||||||
|
|
||||||
|
if (isset($config['zabbix_api_user']))
|
||||||
|
{
|
||||||
$z_api_user = $config['zabbix_api_user'];
|
$z_api_user = $config['zabbix_api_user'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($config['zabbix_api_pwd']))
|
||||||
|
{
|
||||||
$z_api_pass = $config['zabbix_api_pwd'];
|
$z_api_pass = $config['zabbix_api_pwd'];
|
||||||
|
}
|
||||||
|
|
||||||
// Mail sender
|
// Mail sender
|
||||||
$mailFrom = array($config['mail_from']=>'Zabbix Mailgraph');
|
$mailFrom = array($config['mail_from']=>'Zabbix Mailgraph');
|
||||||
@@ -527,7 +642,7 @@
|
|||||||
|
|
||||||
$request = array('jsonrpc'=>'2.0',
|
$request = array('jsonrpc'=>'2.0',
|
||||||
'method'=>'user.login',
|
'method'=>'user.login',
|
||||||
'params'=>array('user'=>$z_api_user,
|
'params'=>array('username'=>$z_api_user,
|
||||||
'password'=>$z_api_pass),
|
'password'=>$z_api_pass),
|
||||||
'id'=>nextRequestID(),
|
'id'=>nextRequestID(),
|
||||||
'auth'=>null);
|
'auth'=>null);
|
||||||
@@ -537,7 +652,13 @@
|
|||||||
$token = '';
|
$token = '';
|
||||||
if (isset($result['result'])) { $token = $result['result']; }
|
if (isset($result['result'])) { $token = $result['result']; }
|
||||||
|
|
||||||
if ($token=='') { echo 'Error logging in to Zabbix? ('.$z_url_api.')'; die; }
|
if ($token=='')
|
||||||
|
{
|
||||||
|
echo 'Error logging in to Zabbix? ('.$z_url_api.'): '.$cCRLF;
|
||||||
|
echo var_dump($request).$cCRLF;
|
||||||
|
echo var_dump($result).$cCRLF;
|
||||||
|
die;
|
||||||
|
}
|
||||||
|
|
||||||
_log('> Token = '.$token);
|
_log('> Token = '.$token);
|
||||||
|
|
||||||
@@ -594,10 +715,10 @@
|
|||||||
'params'=>array('triggerids'=>$p_triggerId,
|
'params'=>array('triggerids'=>$p_triggerId,
|
||||||
'output'=>'extend',
|
'output'=>'extend',
|
||||||
'selectFunctions'=>'extend',
|
'selectFunctions'=>'extend',
|
||||||
'selectTags'=>'extend'),
|
'selectTags'=>'extend',
|
||||||
'expandComment'=>1,
|
'expandComment'=>1,
|
||||||
'expandDescription'=>1,
|
'expandDescription'=>1,
|
||||||
'expandExpression'=>1,
|
'expandExpresion'=>1),
|
||||||
'auth'=>$token,
|
'auth'=>$token,
|
||||||
'id'=>nextRequestID());
|
'id'=>nextRequestID());
|
||||||
|
|
||||||
@@ -613,6 +734,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)
|
||||||
{
|
{
|
||||||
@@ -662,6 +786,31 @@
|
|||||||
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!isset($p_itemId))
|
||||||
|
{
|
||||||
|
foreach($thisTrigger['result'][0]['functions'] as $aFunction)
|
||||||
|
{
|
||||||
|
$p_itemId = $aFunction['itemid'];
|
||||||
|
_log('- Item ID taken from trigger (first) function = '.$p_itemId);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -709,7 +858,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());
|
||||||
|
|
||||||
@@ -720,9 +870,36 @@
|
|||||||
|
|
||||||
$mailData['HOST_ID'] = $thisHost['result'][0]['hostid'];
|
$mailData['HOST_ID'] = $thisHost['result'][0]['hostid'];
|
||||||
$mailData['HOST_NAME'] = $thisHost['result'][0]['name'];
|
$mailData['HOST_NAME'] = $thisHost['result'][0]['name'];
|
||||||
$mailData['HOST_ERROR'] = $thisHost['result'][0]['error'];
|
if (isset($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',
|
||||||
@@ -735,9 +912,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));
|
||||||
|
|
||||||
// --------------------------------------------
|
foreach($thisMacros['result'] as $aMacro)
|
||||||
// --- GET GRAPHS ASSOCIATED WITH THIS HOST ---
|
{
|
||||||
// --------------------------------------------
|
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');
|
||||||
|
|
||||||
@@ -781,7 +979,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]))
|
||||||
{
|
{
|
||||||
@@ -831,7 +1030,7 @@
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
$otherGraphs[] = $aGraph;
|
$otherGraphs[] = $aGraph;
|
||||||
_log('~ Graph #'.$aGraphItem['graphid'].' partial match found (item #'.$aGraphItem['itemid'].')');
|
_log('~ Graph #'.$aGraphItem['graphid'].' partial match found (item #'.$GraphItem['itemid'].')');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -840,11 +1039,96 @@
|
|||||||
|
|
||||||
_log('> Graphs found (matching/partial) = '.sizeof($matchedGraphs).' / '.sizeof($otherGraphs));
|
_log('> Graphs found (matching/partial) = '.sizeof($matchedGraphs).' / '.sizeof($otherGraphs));
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
// --- FIND MATCHING GRAPH ITEMS WITH TRIGGER AND/OR HOST SCREEN REFERENCE ---
|
||||||
|
// ---------------------------------------------------------------------------
|
||||||
|
|
||||||
|
function _sort($a,$b)
|
||||||
|
{
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
}
|
||||||
|
|
||||||
|
$hostGraphs = array();
|
||||||
|
|
||||||
|
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();
|
||||||
@@ -883,8 +1167,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 = '';
|
||||||
@@ -930,14 +1218,78 @@
|
|||||||
|
|
||||||
$graphFiles[] = $graphFile;
|
$graphFiles[] = $graphFile;
|
||||||
|
|
||||||
$mailData['GRAPHS'][$aKey]['URL'] = $z_url_image . $graphFile;
|
$mailData['GRAPHS_I'][$aKey]['PATH'] = $z_images_path . $graphFile;
|
||||||
$mailData['GRAPHS'][$aKey]['HEADER'] = $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']);
|
||||||
@@ -1002,11 +1354,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();
|
||||||
@@ -1031,19 +1390,26 @@
|
|||||||
|
|
||||||
$twig = new \Twig\Environment($loader);
|
$twig = new \Twig\Environment($loader);
|
||||||
|
|
||||||
if (sizeof($graphFiles)>0)
|
// --- Embed the images
|
||||||
{
|
|
||||||
// Embed the image(s)
|
|
||||||
|
|
||||||
$graphReference = 0;
|
function embedGraphs($graphs,$varName,$type)
|
||||||
|
|
||||||
foreach($graphFiles as $graphFile)
|
|
||||||
{
|
{
|
||||||
$mailData['GRAPHS'][$graphReference++]['CID'] = $message->embed(Swift_Image::fromPath($z_images_path.$graphFile));
|
global $message;
|
||||||
_log('> Embedded graph image '.$z_images_path.$graphFile);
|
global $mailData;
|
||||||
|
|
||||||
|
foreach($graphs as $aKey=>$anItem)
|
||||||
|
{
|
||||||
|
$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);
|
$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);
|
||||||
@@ -1076,6 +1442,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'])))
|
||||||
|
|||||||
203
mailGraph.xml
203
mailGraph.xml
@@ -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>6.0</version>
|
||||||
<date>2021-03-17T12:55:43Z</date>
|
<date>2023-06-29T23:22:52Z</date>
|
||||||
<media_types>
|
<media_types>
|
||||||
<media_type>
|
<media_type>
|
||||||
<name>MailGraph</name>
|
<name>MailGraph</name>
|
||||||
@@ -64,124 +64,125 @@
|
|||||||
<value>https://mydomain.com/mailGraph.php</value>
|
<value>https://mydomain.com/mailGraph.php</value>
|
||||||
</parameter>
|
</parameter>
|
||||||
</parameters>
|
</parameters>
|
||||||
<script>try {
|
|
||||||
// Pickup parameters
|
<script>try {
|
||||||
params = JSON.parse(value),
|
// Pickup parameters
|
||||||
req = new CurlHttpRequest(),
|
params = JSON.parse(value),
|
||||||
fields = {},
|
req = new HttpRequest(),
|
||||||
resp = '',
|
fields = {},
|
||||||
result = { tags: {} };
|
resp = '',
|
||||||
|
result = { tags: {} };
|
||||||
// Set HTTP proxy if required
|
|
||||||
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
|
// Set HTTP proxy if required
|
||||||
req.setProxy(params.HTTPProxy);
|
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
|
||||||
fields.HTTPProxy = params.HTTPProxy;
|
req.setProxy(params.HTTPProxy);
|
||||||
}
|
fields.HTTPProxy = params.HTTPProxy;
|
||||||
|
}
|
||||||
// Declare output type
|
|
||||||
req.AddHeader('Content-Type: application/json');
|
// Declare output type
|
||||||
|
req.addHeader('Content-Type: application/json');
|
||||||
// Must have fields
|
|
||||||
fields.itemId = params.itemId;
|
// Must have fields
|
||||||
fields.eventId = params.eventId;
|
fields.itemId = params.itemId;
|
||||||
fields.recipient = params.recipient;
|
fields.eventId = params.eventId;
|
||||||
fields.baseURL = params.baseURL;
|
fields.recipient = params.recipient;
|
||||||
fields.duration = params.duration;
|
fields.baseURL = params.baseURL;
|
||||||
|
fields.duration = params.duration;
|
||||||
// Optional fields
|
|
||||||
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
|
// Optional fields
|
||||||
if (typeof params.graphHeight === 'string') { fields.graphHeight = params.graphHeight; }
|
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
|
||||||
if (typeof params.subject === 'string') { fields.subject = params.subject; }
|
if (typeof params.graphHeight === 'string') { fields.graphHeight = params.graphHeight; }
|
||||||
if (typeof params.showLegend === 'string') { fields.showLegend = params.showLegend; }
|
if (typeof params.subject === 'string') { fields.subject = params.subject; }
|
||||||
if (typeof params.periods === 'string') { fields.periods = params.periods; }
|
if (typeof params.showLegend === 'string') { fields.showLegend = params.showLegend; }
|
||||||
if (typeof params.periods_headers === 'string') { fields.periods_headers = params.periods_headers; }
|
if (typeof params.periods === 'string') { fields.periods = params.periods; }
|
||||||
if (typeof params.debug === 'string') { fields.debug = params.debug; }
|
if (typeof params.periods_headers === 'string') { fields.periods_headers = params.periods_headers; }
|
||||||
|
if (typeof params.debug === 'string') { fields.debug = params.debug; }
|
||||||
// Add generic fields
|
|
||||||
Object.keys(params).forEach(function(key) {
|
// Add generic fields
|
||||||
if (key.substring(0, 4) == 'info') {
|
Object.keys(params).forEach(function(key) {
|
||||||
fields[key] = params[key];
|
if (key.substring(0, 4) == 'info') {
|
||||||
}
|
fields[key] = params[key];
|
||||||
});
|
}
|
||||||
|
});
|
||||||
// Post information to the processing script
|
|
||||||
Zabbix.Log(4, '[MailGraph Webhook] Sending request: ' + params.URL + '?' + JSON.stringify(fields));
|
// Post information to the processing script
|
||||||
var resp = req.Post(params.URL,JSON.stringify(fields));
|
Zabbix.Log(4, '[MailGraph Webhook] Sending request: ' + params.URL + '?' + JSON.stringify(fields));
|
||||||
Zabbix.Log(4, '[Mailgraph Webhook] Receiving response:' + resp);
|
var resp = req.post(params.URL,JSON.stringify(fields));
|
||||||
|
Zabbix.Log(4, '[Mailgraph Webhook] Receiving response:' + resp);
|
||||||
// If there was an error, report it
|
|
||||||
if (req.Status() != 200) { throw JSON.parse(resp).errors[0]; }
|
// If there was an error, report it
|
||||||
|
if (req.getStatus() != 200) { throw JSON.parse(resp).errors[0]; }
|
||||||
// We expect the message id back from the processing script
|
|
||||||
resp = JSON.parse(resp);
|
// We expect the message id back from the processing script
|
||||||
result.tags.__message_id = resp.messageId;
|
resp = JSON.parse(resp);
|
||||||
|
result.tags.__message_id = resp.messageId;
|
||||||
// Pass the result back to Zabbix
|
|
||||||
return JSON.stringify(result);
|
// Pass the result back to Zabbix
|
||||||
}
|
return JSON.stringify(result);
|
||||||
catch (error)
|
}
|
||||||
{
|
catch (error)
|
||||||
// In case something went wrong in the processing, pass the error back to Zabbix
|
{
|
||||||
Zabbix.Log(127, 'MailGraph notification failed : '+error);
|
// In case something went wrong in the processing, pass the error back to Zabbix
|
||||||
throw 'MailGraph notification failed : '+error;
|
Zabbix.Log(127, 'MailGraph notification failed : '+error);
|
||||||
|
throw 'MailGraph notification failed : '+error;
|
||||||
}</script>
|
}</script>
|
||||||
<process_tags>YES</process_tags>
|
<process_tags>YES</process_tags>
|
||||||
<description>The "URL" must point to the location of the processing script. If a proxy is required, define "HTTPProxy" for the proxy address.
|
<description>The "URL" must point to the location of the processing script. If a proxy is required, define "HTTPProxy" for the proxy address.
|
||||||
|
|
||||||
Customization:
|
Customization:
|
||||||
- "graphWidth" and "graphWidth" can be defined for the image size
|
- "graphWidth" and "graphWidth" can be defined for the image size
|
||||||
- "showLegend" can be defined to show or hide the legend of the graph
|
- "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
|
- "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
|
- "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
|
- "period" and "period_header" can be defined to display a single graph
|
||||||
|
|
||||||
The html.template and plain.template files can be adjusted (TWIG format).
|
The html.template and plain.template files can be adjusted (TWIG format).
|
||||||
|
|
||||||
More details are available at https://github.com/moudsen/mailGraph</description>
|
More details are available at https://github.com/moudsen/mailGraph</description>
|
||||||
<message_templates>
|
<message_templates>
|
||||||
<message_template>
|
<message_template>
|
||||||
<event_source>TRIGGERS</event_source>
|
<event_source>TRIGGERS</event_source>
|
||||||
<operation_mode>PROBLEM</operation_mode>
|
<operation_mode>PROBLEM</operation_mode>
|
||||||
<subject>Problem: {EVENT.NAME}</subject>
|
<subject>Problem: {EVENT.NAME}</subject>
|
||||||
<message>Problem started at {EVENT.TIME} on {EVENT.DATE}
|
<message>Problem started at {EVENT.TIME} on {EVENT.DATE}
|
||||||
Problem name: {EVENT.NAME}
|
Problem name: {EVENT.NAME}
|
||||||
Host: {HOST.NAME}
|
Host: {HOST.NAME}
|
||||||
Severity: {EVENT.SEVERITY}
|
Severity: {EVENT.SEVERITY}
|
||||||
Operational data: {EVENT.OPDATA}
|
Operational data: {EVENT.OPDATA}
|
||||||
Original problem ID: {EVENT.ID}
|
Original problem ID: {EVENT.ID}
|
||||||
{TRIGGER.URL}
|
{TRIGGER.URL}
|
||||||
|
|
||||||
eventId: {EVENT.ID}
|
eventId: {EVENT.ID}
|
||||||
TriggerId: {TRIGGER.ID}
|
TriggerId: {TRIGGER.ID}
|
||||||
itemId: {ITEM.ID]</message>
|
itemId: {ITEM.ID]</message>
|
||||||
</message_template>
|
</message_template>
|
||||||
<message_template>
|
<message_template>
|
||||||
<event_source>TRIGGERS</event_source>
|
<event_source>TRIGGERS</event_source>
|
||||||
<operation_mode>RECOVERY</operation_mode>
|
<operation_mode>RECOVERY</operation_mode>
|
||||||
<subject>Resolved in {EVENT.DURATION}: {EVENT.NAME}</subject>
|
<subject>Resolved in {EVENT.DURATION}: {EVENT.RECOVERY.NAME}</subject>
|
||||||
<message>Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
|
<message>Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
|
||||||
Problem name: {EVENT.NAME}
|
Problem name: {EVENT.RECOVERY.NAME}
|
||||||
Problem duration: {EVENT.DURATION}
|
Problem duration: {EVENT.DURATION}
|
||||||
Host: {HOST.NAME}
|
Host: {HOST.NAME}
|
||||||
Severity: {EVENT.SEVERITY}
|
Severity: {EVENT.SEVERITY}
|
||||||
Original problem ID: {EVENT.ID}
|
Original problem ID: {EVENT.ID}
|
||||||
{TRIGGER.URL}
|
{TRIGGER.URL}
|
||||||
|
|
||||||
eventId: {EVENT.ID}
|
eventId: {EVENT.ID}
|
||||||
TriggerId: {TRIGGER.ID}
|
TriggerId: {TRIGGER.ID}
|
||||||
itemId: {ITEM.ID]</message>
|
itemId: {ITEM.ID]</message>
|
||||||
</message_template>
|
</message_template>
|
||||||
<message_template>
|
<message_template>
|
||||||
<event_source>TRIGGERS</event_source>
|
<event_source>TRIGGERS</event_source>
|
||||||
<operation_mode>UPDATE</operation_mode>
|
<operation_mode>UPDATE</operation_mode>
|
||||||
<subject>Updated problem in {EVENT.AGE}: {EVENT.NAME}</subject>
|
<subject>Updated problem in {EVENT.AGE}: {EVENT.NAME}</subject>
|
||||||
<message>{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
|
<message>{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
|
||||||
{EVENT.UPDATE.MESSAGE}
|
{EVENT.UPDATE.MESSAGE}
|
||||||
|
|
||||||
Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.
|
Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.
|
||||||
|
|
||||||
eventId: {EVENT.ID}
|
eventId: {EVENT.ID}
|
||||||
TriggerId: {TRIGGER.ID}
|
TriggerId: {TRIGGER.ID}
|
||||||
itemId: {ITEM.ID]</message>
|
itemId: {ITEM.ID]</message>
|
||||||
</message_template>
|
</message_template>
|
||||||
</message_templates>
|
</message_templates>
|
||||||
|
|||||||
@@ -114,16 +114,6 @@
|
|||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% for aGraph in GRAPHS %}
|
|
||||||
<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 %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="links">
|
<td class="links">
|
||||||
<div align=center>
|
<div align=center>
|
||||||
@@ -137,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>
|
||||||
Reference in New Issue
Block a user