24 Commits
v1.28 ... v2.02

Author SHA1 Message Date
moudsen
e80a2a56a3 Update README.md, June 29, 2023 2023-06-29 16:16:52 +02:00
moudsen
4b28d3f066 Announcing different javascript code for the Media Type for Zabbix 6.2+ 2022-09-26 12:27:00 +02:00
moudsen
93535d4006 Update README.md 2022-08-22 11:58:34 +02:00
moudsen
b9622da72f Update README.md 2022-03-16 23:05:50 +01:00
moudsen
56fb68ae9c Rework scope change to include Zabbix 6.0 LTS testing 2022-02-22 17:35:28 +01:00
Mark Oudsen
fa51c3e59e Merge branch 'main' of github.com:moudsen/mailGraph into main 2022-01-30 16:44:58 +01:00
Mark Oudsen
4ae62b3a1f v2.02 - Added cleanup option 2022-01-30 16:44:43 +01:00
moudsen
0731b87d44 v2.02 updates 2022-01-30 16:43:14 +01:00
moudsen
bdf4b05a6b Update README.md 2021-12-16 13:57:57 +01:00
moudsen
df16444665 Update README.md 2021-12-16 13:55:03 +01:00
Mark Oudsen
bccd134523 Merge branch 'main' of github.com:moudsen/mailGraph into main 2021-12-16 13:46:43 +01:00
Mark Oudsen
27c1d64511 v2.0 - Bugfixes and dealing with API changes in Zabbix 5.4 such itemId no longer passed by Zabbix itself 2021-12-16 13:46:18 +01:00
moudsen
8597658670 v1.31 updates 2021-10-06 13:54:11 +02:00
Mark Oudsen
b7e2062486 Merge branch 'main' of github.com:moudsen/mailGraph into main 2021-10-06 11:15:33 +02:00
Mark Oudsen
2955ffc404 (v1.31) Removal of trival errors and fix for 'json error' messages in Zabbix on clean install and default PHP settings 2021-10-06 11:15:17 +02:00
moudsen
2976a4af9c Fixed a bug when configuration file is empty 2021-07-17 23:45:50 +02:00
moudsen
2882367308 Minor bugfixes notification (fixed in current v1.29) 2021-07-07 19:54:46 +02:00
moudsen
8b4885038a Minor bugfix where HTTPProxy variable was not picked up correctly due to type 2021-07-07 19:39:02 +02:00
moudsen
f541719fbe Added example to show how Zabbix Media Type configuration looks like 2021-07-07 12:37:01 +02:00
Mark Oudsen
9edab245d8 Merge branch 'main' of github.com:moudsen/mailGraph into main 2021-07-05 22:47:37 +02:00
Mark Oudsen
341bd561ab Now shows mailGraph version when invoked from CLI (for testing) 2021-07-05 22:47:05 +02:00
moudsen
e2f657f3dd Updated to v1.29 2021-04-03 16:31:10 +02:00
Mark Oudsen
82a8fe4121 Merge branch 'main' of github.com:moudsen/mailGraph into main 2021-04-03 16:29:40 +02:00
Mark Oudsen
bee76b63c0 Bugfix - Stricter JSONRPC version check by Zabbix (v1.29) 2021-04-03 16:29:26 +02:00
5 changed files with 140 additions and 34 deletions

View File

@@ -1,16 +1,25 @@
## mailGraph (v1.28)
Zabbix Media module and scripts for sending e-mail alerts with graphs.
## Zabbix 6.4.x testing ##
_(2023/06/29)_
**Please use the Wiki for information on how to install, configure and use MailGraph in Zabbix.**
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.
## 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 ...).
## Zabbix 6.2.x testing ##
_(2022/10/10)_
### 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).
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
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!
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?raw=true)](images/Example-mail-message-v122.png)

View File

@@ -27,7 +27,7 @@
$content = file_get_contents($argv[1]);
$data = json_decode($content,TRUE);
if ($data==NULL)
if (($data==NULL) && (sizeof($content)>2))
{
echo 'Invalid JSON format in config file?!'.$cCRLF;
die;

Binary file not shown.

After

Width:  |  Height:  |  Size: 85 KiB

7
javascript/READ.ME Normal file
View File

@@ -0,0 +1,7 @@
As per the details captured in issue #32 the javascript code portion of this Media Type has changed due to a platform/library change at Zabbix side.
A distinction is now made for the following Zabbix versions:
Zabbix <6.2 - use "zabbix.mailGraph.js"
Zabbix >=6.2 - <coming soon>
Please make sure you install the right javascript in your environment!

View File

@@ -36,6 +36,14 @@
// 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)
// ------------------------------------------------------------------------------------------------------
// 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
// ------------------------------------------------------------------------------------------------------
//
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
@@ -57,8 +65,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// CONSTANTS
$cVersion = 'v1.28';
$cVersion = 'v2.020';
$cCRLF = chr(10).chr(13);
$maskDateTime = 'Y-m-d H:i:s';
$maxGraphs = 4;
@@ -66,10 +73,14 @@
// DEBUG SETTINGS
// -- Should be FALSE for production level use
$cDebug = TRUE; // 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 !!!
// Limit server level output errors
error_reporting(E_ERROR | E_PARSE);
// INCLUDE REQUIRED LIBRARIES (Composer)
// (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
@@ -99,23 +110,24 @@
$ch = curl_init();
// Set options
curl_setopt($ch, CURLOPT_USERAGENT, 'Zabbix-mailGraph - '.$cVersion);
if ((isset($HTTPProxy)) && ($HTTPProxy!=''))
{
_log('% Using proxy: '.$HTTPProxy);
if ($cDebug) { _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);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS,
json_encode($data,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_USERAGENT, 'Zabbix-mailGraph - '.$cVersion);
// Execute Curl
$data = curl_exec($ch);
@@ -124,9 +136,10 @@
{
_log('! Failed: '.curl_error($ch));
$data = 'An error occurred while retreiving the requested page.'.$cCRLF;
$data .= 'Requested page = '.$url.$cCRLF;
$data .= 'Error = '.curl_error($ch).$cCRLF;
$data = array();
$data[] = 'An error occurred while retreiving the requested page.';
$data[] .= 'Requested page = '.$url;
$data[] .= 'Error = '.curl_error($ch);
}
else
{
@@ -377,6 +390,40 @@
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 ///////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -404,6 +451,10 @@
{
if (($argc>1) && ($argv[1]=='test'))
{
// Switch on CLI log display
$showLog = TRUE;
_log('<<< mailGraph '.$cVersion.' >>>');
_log('# Invoked from CLI');
// Assumes that config.json file has the correct information
@@ -423,9 +474,31 @@
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']; }
}
if (($argc>1) && ($argv[1]=='cleanup'))
{
// Switch on CLI log display
$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);
}
}
@@ -435,8 +508,8 @@
// --- CHECK AND SET P_ VARIABLES ---
// FROM POST OR CLI DATA
if (!isset($problemData['itemId'])) { echo "Missing ITEM ID?\n"; die; }
$p_itemId = intval($problemData['itemId']);
// if (!isset($problemData['itemId'])) { echo "Missing ITEM ID?\n"; die; }
// $p_itemId = intval($problemData['itemId']);
if (!isset($problemData['eventId'])) { echo "Missing EVENT ID?\n"; die; }
$p_eventId = intval($problemData['eventId']);
@@ -465,7 +538,7 @@
$p_period = '48h';
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
@@ -564,7 +637,13 @@
$token = '';
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);
@@ -621,10 +700,10 @@
'params'=>array('triggerids'=>$p_triggerId,
'output'=>'extend',
'selectFunctions'=>'extend',
'selectTags'=>'extend'),
'expandComment'=>1,
'expandDescription'=>1,
'expandExpression'=>1,
'selectTags'=>'extend',
'expandComment'=>1,
'expandDescription'=>1,
'expandExpression'=>1),
'auth'=>$token,
'id'=>nextRequestID());
@@ -710,6 +789,16 @@
}
}
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;
}
}
// ---------------------
// --- GET ITEM INFO ---
// ---------------------
@@ -766,7 +855,7 @@
$mailData['HOST_ID'] = $thisHost['result'][0]['hostid'];
$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'];
// --- Custom settings?
@@ -1011,6 +1100,7 @@
_log('> Graphs found = '.sizeof($triggerGraphs));
}
$hostGraphs = array();
if ($hostScreen>0)
{
@@ -1354,6 +1444,6 @@
$logName = 'log.'.$p_eventId.'.'.date('YmdHis').'.dump';
file_put_contents($z_log_path.$logName,$content);
_log('= Log stored to '.$z_log_path.$logName);
_log('= Log stored to '.$z_log_path.$logName);
}
?>