v2.10 - Removed deprecated function dependencies

This commit is contained in:
Mark Oudsen 2023-06-30 08:48:59 +02:00
parent e80a2a56a3
commit 8bc476ed63
5 changed files with 162 additions and 122 deletions

View File

@ -1,4 +1,34 @@
## mailGraph v2.10 release ##
_(2023/06/30)_
_This version has been verified with Zabbix 5.4, 6.0 LTS and 6.4._
Minor updates to the mailGraph code
- 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 ## ## 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)_ _(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. 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.

View File

@ -1,7 +1 @@
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. Issue #32 has been resolved. The javascript code now works for Zabbix 5.4, 6.0 LTS and 6.4.
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

@ -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' &amp;&amp; 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);

View File

@ -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
@ -40,10 +42,13 @@
// 2021/07/05 - Mark Oudsen - Minor detail added: CLI debug mode now also outputs version // 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) // 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 // 2.00 2021/12/16 - Mark Oudsen - itemId not always provisioned by Zabbix
// Several fixes on warning - several small bug fixes // 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.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.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
@ -65,7 +70,7 @@
///////////////////////////////////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////////////////////////////////////
// CONSTANTS // CONSTANTS
$cVersion = 'v2.020'; $cVersion = 'v2.10';
$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; $maxGraphs = 4;
@ -515,7 +520,7 @@
$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']);
@ -589,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 = $config['zabbix_api_user']; $z_api_user = $z_user;
$z_api_pass = $config['zabbix_api_pwd']; $z_api_pass = $z_pass;
if (isset($config['zabbix_api_user']))
{
$z_api_user = $config['zabbix_api_user'];
}
if (isset($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');
@ -627,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);
@ -703,7 +718,7 @@
'selectTags'=>'extend', 'selectTags'=>'extend',
'expandComment'=>1, 'expandComment'=>1,
'expandDescription'=>1, 'expandDescription'=>1,
'expandExpression'=>1), 'expandExpresion'=>1),
'auth'=>$token, 'auth'=>$token,
'id'=>nextRequestID()); 'id'=>nextRequestID());
@ -1015,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'].')');
} }
} }
} }

View File

@ -1,12 +1,12 @@
<?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>
<type>WEBHOOK</type> <type>WEBHOOK</type>
<parameters> <parameters>
<parameter> <parameter>
<name>baseURL</name> <name>baseURL</name>
<value>https://mydomain.com/zabbix/</value> <value>https://mydomain.com/zabbix/</value>
@ -64,124 +64,125 @@
<value>https://mydomain.com/mailGraph.php</value> <value>https://mydomain.com/mailGraph.php</value>
</parameter> </parameter>
</parameters> </parameters>
<script>try {&#13;
// Pickup parameters&#13; <script>try {
params = JSON.parse(value),&#13; // Pickup parameters
req = new CurlHttpRequest(),&#13; params = JSON.parse(value),
fields = {},&#13; req = new HttpRequest(),
resp = '',&#13; fields = {},
result = { tags: {} };&#13; resp = '',
&#13; result = { tags: {} };
// Set HTTP proxy if required&#13;
if (typeof params.HTTPProxy === 'string' &amp;&amp; params.HTTPProxy.trim() !== '') {&#13; // Set HTTP proxy if required
req.setProxy(params.HTTPProxy);&#13; if (typeof params.HTTPProxy === 'string' &amp;&amp; params.HTTPProxy.trim() !== '') {
fields.HTTPProxy = params.HTTPProxy;&#13; req.setProxy(params.HTTPProxy);
}&#13; fields.HTTPProxy = params.HTTPProxy;
&#13; }
// Declare output type&#13;
req.AddHeader('Content-Type: application/json');&#13; // Declare output type
&#13; req.addHeader('Content-Type: application/json');
// Must have fields&#13;
fields.itemId = params.itemId;&#13; // Must have fields
fields.eventId = params.eventId;&#13; fields.itemId = params.itemId;
fields.recipient = params.recipient;&#13; fields.eventId = params.eventId;
fields.baseURL = params.baseURL;&#13; fields.recipient = params.recipient;
fields.duration = params.duration;&#13; fields.baseURL = params.baseURL;
&#13; fields.duration = params.duration;
// Optional fields&#13;
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }&#13; // Optional fields
if (typeof params.graphHeight === 'string') { fields.graphHeight = params.graphHeight; }&#13; if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
if (typeof params.subject === 'string') { fields.subject = params.subject; }&#13; if (typeof params.graphHeight === 'string') { fields.graphHeight = params.graphHeight; }
if (typeof params.showLegend === 'string') { fields.showLegend = params.showLegend; }&#13; if (typeof params.subject === 'string') { fields.subject = params.subject; }
if (typeof params.periods === 'string') { fields.periods = params.periods; }&#13; if (typeof params.showLegend === 'string') { fields.showLegend = params.showLegend; }
if (typeof params.periods_headers === 'string') { fields.periods_headers = params.periods_headers; }&#13; if (typeof params.periods === 'string') { fields.periods = params.periods; }
if (typeof params.debug === 'string') { fields.debug = params.debug; }&#13; if (typeof params.periods_headers === 'string') { fields.periods_headers = params.periods_headers; }
&#13; if (typeof params.debug === 'string') { fields.debug = params.debug; }
// Add generic fields&#13;
Object.keys(params).forEach(function(key) {&#13; // Add generic fields
if (key.substring(0, 4) == 'info') {&#13; Object.keys(params).forEach(function(key) {
fields[key] = params[key];&#13; if (key.substring(0, 4) == 'info') {
}&#13; fields[key] = params[key];
});&#13; }
&#13; });
// Post information to the processing script&#13;
Zabbix.Log(4, '[MailGraph Webhook] Sending request: ' + params.URL + '?' + JSON.stringify(fields));&#13; // Post information to the processing script
var resp = req.Post(params.URL,JSON.stringify(fields));&#13; Zabbix.Log(4, '[MailGraph Webhook] Sending request: ' + params.URL + '?' + JSON.stringify(fields));
Zabbix.Log(4, '[Mailgraph Webhook] Receiving response:' + resp);&#13; var resp = req.post(params.URL,JSON.stringify(fields));
&#13; Zabbix.Log(4, '[Mailgraph Webhook] Receiving response:' + resp);
// If there was an error, report it&#13;
if (req.Status() != 200) { throw JSON.parse(resp).errors[0]; }&#13; // If there was an error, report it
&#13; if (req.getStatus() != 200) { throw JSON.parse(resp).errors[0]; }
// We expect the message id back from the processing script&#13;
resp = JSON.parse(resp);&#13; // We expect the message id back from the processing script
result.tags.__message_id = resp.messageId;&#13; resp = JSON.parse(resp);
&#13; result.tags.__message_id = resp.messageId;
// Pass the result back to Zabbix&#13;
return JSON.stringify(result);&#13; // Pass the result back to Zabbix
}&#13; return JSON.stringify(result);
catch (error)&#13; }
{&#13; catch (error)
// In case something went wrong in the processing, pass the error back to Zabbix&#13; {
Zabbix.Log(127, 'MailGraph notification failed : '+error);&#13; // In case something went wrong in the processing, pass the error back to Zabbix
throw 'MailGraph notification failed : '+error;&#13; 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 &quot;URL&quot; must point to the location of the processing script. If a proxy is required, define &quot;HTTPProxy&quot; for the proxy address.&#13; <description>The &quot;URL&quot; must point to the location of the processing script. If a proxy is required, define &quot;HTTPProxy&quot; for the proxy address.
&#13;
Customization:&#13; Customization:
- &quot;graphWidth&quot; and &quot;graphWidth&quot; can be defined for the image size&#13; - &quot;graphWidth&quot; and &quot;graphWidth&quot; can be defined for the image size
- &quot;showLegend&quot; can be defined to show or hide the legend of the graph&#13; - &quot;showLegend&quot; can be defined to show or hide the legend of the graph
- &quot;subject&quot; can be defined for a customized subject for the mail message&#13; - &quot;subject&quot; can be defined for a customized subject for the mail message
- &quot;periods&quot; and &quot;periods_headers&quot; can be defined for displaying multiple periods of the same graph, or&#13; - &quot;periods&quot; and &quot;periods_headers&quot; can be defined for displaying multiple periods of the same graph, or
- &quot;period&quot; and &quot;period_header&quot; can be defined to display a single graph&#13; - &quot;period&quot; and &quot;period_header&quot; can be defined to display a single graph
&#13;
The html.template and plain.template files can be adjusted (TWIG format).&#13; The html.template and plain.template files can be adjusted (TWIG format).
&#13;
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}&#13; <message>Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem name: {EVENT.NAME}&#13; Problem name: {EVENT.NAME}
Host: {HOST.NAME}&#13; Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}&#13; Severity: {EVENT.SEVERITY}
Operational data: {EVENT.OPDATA}&#13; Operational data: {EVENT.OPDATA}
Original problem ID: {EVENT.ID}&#13; Original problem ID: {EVENT.ID}
{TRIGGER.URL}&#13; {TRIGGER.URL}
&#13;
eventId: {EVENT.ID}&#13; eventId: {EVENT.ID}
TriggerId: {TRIGGER.ID}&#13; 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}&#13; <message>Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.NAME}&#13; Problem name: {EVENT.RECOVERY.NAME}
Problem duration: {EVENT.DURATION}&#13; Problem duration: {EVENT.DURATION}
Host: {HOST.NAME}&#13; Host: {HOST.NAME}
Severity: {EVENT.SEVERITY}&#13; Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID}&#13; Original problem ID: {EVENT.ID}
{TRIGGER.URL}&#13; {TRIGGER.URL}
&#13;
eventId: {EVENT.ID}&#13; eventId: {EVENT.ID}
TriggerId: {TRIGGER.ID}&#13; 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}.&#13; <message>{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE}&#13; {EVENT.UPDATE.MESSAGE}
&#13;
Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.&#13; Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.
&#13;
eventId: {EVENT.ID}&#13; eventId: {EVENT.ID}
TriggerId: {TRIGGER.ID}&#13; TriggerId: {TRIGGER.ID}
itemId: {ITEM.ID]</message> itemId: {ITEM.ID]</message>
</message_template> </message_template>
</message_templates> </message_templates>