diff --git a/README.md b/README.md index 95eec1f..b986b7a 100644 --- a/README.md +++ b/README.md @@ -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 ## +_(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. diff --git a/javascript/READ.ME b/javascript/READ.ME index 82fc370..408a2ad 100644 --- a/javascript/READ.ME +++ b/javascript/READ.ME @@ -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. -A distinction is now made for the following Zabbix versions: - -Zabbix <6.2 - use "zabbix.mailGraph.js" -Zabbix >=6.2 - - -Please make sure you install the right javascript in your environment! +Issue #32 has been resolved. The javascript code now works for Zabbix 5.4, 6.0 LTS and 6.4. diff --git a/javascript/zabbix.mailGraph.js b/javascript/zabbix.mailGraph.js index 739fbd6..844ede1 100644 --- a/javascript/zabbix.mailGraph.js +++ b/javascript/zabbix.mailGraph.js @@ -1,19 +1,19 @@ try { // Pickup parameters params = JSON.parse(value), - req = new CurlHttpRequest(), + req = new HttpRequest(), fields = {}, resp = '', result = { tags: {} }; // 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); fields.HTTPProxy = params.HTTPProxy; } // Declare output type - req.AddHeader('Content-Type: application/json'); + req.addHeader('Content-Type: application/json'); // Must have fields fields.itemId = params.itemId; @@ -40,11 +40,11 @@ try { // Post information to the processing script 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); // 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 resp = JSON.parse(resp); diff --git a/mailGraph.php b/mailGraph.php index f1f4efc..f346190 100644 --- a/mailGraph.php +++ b/mailGraph.php @@ -8,6 +8,8 @@ // 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.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 @@ -40,10 +42,13 @@ // 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 @@ -65,7 +70,7 @@ ///////////////////////////////////////////////////////////////////////////////////////////////////////// // CONSTANTS - $cVersion = 'v2.020'; + $cVersion = 'v2.10'; $cCRLF = chr(10).chr(13); $maskDateTime = 'Y-m-d H:i:s'; $maxGraphs = 4; @@ -515,7 +520,7 @@ $p_eventId = intval($problemData['eventId']); 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; } $p_duration = intval($problemData['duration']); @@ -589,9 +594,19 @@ $z_pass = $config['zabbix_user_pwd']; // Zabbix API user (requires Super Admin access rights) - // TODO: Check if information retreival can be done with less rigths - $z_api_user = $config['zabbix_api_user']; - $z_api_pass = $config['zabbix_api_pwd']; + // --- 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']; + } + + if (isset($config['zabbix_api_pwd'])) + { + $z_api_pass = $config['zabbix_api_pwd']; + } // Mail sender $mailFrom = array($config['mail_from']=>'Zabbix Mailgraph'); @@ -627,7 +642,7 @@ $request = array('jsonrpc'=>'2.0', 'method'=>'user.login', - 'params'=>array('user'=>$z_api_user, + 'params'=>array('username'=>$z_api_user, 'password'=>$z_api_pass), 'id'=>nextRequestID(), 'auth'=>null); @@ -703,7 +718,7 @@ 'selectTags'=>'extend', 'expandComment'=>1, 'expandDescription'=>1, - 'expandExpression'=>1), + 'expandExpresion'=>1), 'auth'=>$token, 'id'=>nextRequestID()); @@ -1015,7 +1030,7 @@ else { $otherGraphs[] = $aGraph; - _log('~ Graph #'.$aGraphItem['graphid'].' partial match found (item #'.$aGraphItem['itemid'].')'); + _log('~ Graph #'.$aGraphItem['graphid'].' partial match found (item #'.$GraphItem['itemid'].')'); } } } diff --git a/mailGraph.xml b/mailGraph.xml index e934dc2..9171b4e 100755 --- a/mailGraph.xml +++ b/mailGraph.xml @@ -1,12 +1,12 @@ - 5.0 - 2021-03-17T12:55:43Z + 6.0 + 2023-06-29T23:22:52Z MailGraph WEBHOOK - + baseURL https://mydomain.com/zabbix/ @@ -64,124 +64,125 @@ https://mydomain.com/mailGraph.php - YES - The "URL" must point to the location of the processing script. If a proxy is required, define "HTTPProxy" for the proxy address. - -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). - + The "URL" must point to the location of the processing script. If a proxy is required, define "HTTPProxy" for the proxy address. + +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). + More details are available at https://github.com/moudsen/mailGraph TRIGGERS PROBLEM Problem: {EVENT.NAME} - Problem started at {EVENT.TIME} on {EVENT.DATE} -Problem name: {EVENT.NAME} -Host: {HOST.NAME} -Severity: {EVENT.SEVERITY} -Operational data: {EVENT.OPDATA} -Original problem ID: {EVENT.ID} -{TRIGGER.URL} - -eventId: {EVENT.ID} -TriggerId: {TRIGGER.ID} + Problem started at {EVENT.TIME} on {EVENT.DATE} +Problem name: {EVENT.NAME} +Host: {HOST.NAME} +Severity: {EVENT.SEVERITY} +Operational data: {EVENT.OPDATA} +Original problem ID: {EVENT.ID} +{TRIGGER.URL} + +eventId: {EVENT.ID} +TriggerId: {TRIGGER.ID} itemId: {ITEM.ID] TRIGGERS RECOVERY - Resolved in {EVENT.DURATION}: {EVENT.NAME} - Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE} -Problem name: {EVENT.NAME} -Problem duration: {EVENT.DURATION} -Host: {HOST.NAME} -Severity: {EVENT.SEVERITY} -Original problem ID: {EVENT.ID} -{TRIGGER.URL} - -eventId: {EVENT.ID} -TriggerId: {TRIGGER.ID} + Resolved in {EVENT.DURATION}: {EVENT.RECOVERY.NAME} + Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE} +Problem name: {EVENT.RECOVERY.NAME} +Problem duration: {EVENT.DURATION} +Host: {HOST.NAME} +Severity: {EVENT.SEVERITY} +Original problem ID: {EVENT.ID} +{TRIGGER.URL} + +eventId: {EVENT.ID} +TriggerId: {TRIGGER.ID} itemId: {ITEM.ID] TRIGGERS UPDATE Updated problem in {EVENT.AGE}: {EVENT.NAME} - {USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}. -{EVENT.UPDATE.MESSAGE} - -Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}. - -eventId: {EVENT.ID} -TriggerId: {TRIGGER.ID} + {USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}. +{EVENT.UPDATE.MESSAGE} + +Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}. + +eventId: {EVENT.ID} +TriggerId: {TRIGGER.ID} itemId: {ITEM.ID]