v2.16 - Adding ACKNOWLEDGES message information

This commit is contained in:
Mark Oudsen 2023-08-16 22:50:00 +02:00
parent 624ce29a39
commit ededded428
5 changed files with 84 additions and 10 deletions

View File

@ -20,14 +20,22 @@ More information can be found in the Wiki.
## Installation ##
Please refer to the Wiki how to get mailGraph installed and configured on your system.
## mailGraph v2.16 release ##
_(2023/08/16)_
_This version has been verified with Zabbix 5.4 and 6.0 LTS and is expected to work with 6.4 and later (based on v2.10 testing)_
Release notes
- Adding [ACKNOWLEDGES] message information for processing in the TWIG template to allow inclusion of "Action" information in the mail messages (eg. who acknowledged/changed problem status). Refer to the Wiki "Templates" section for more detailed information.
## mailGraph v2.15 release ##
_(2023/08/16)_
_This version has been verified with Zabbix 5.4 and 6.0 LTS and is expected to work with 6.4 and later (based on v2.10 testing)_
Release notes
- Fixed new error condition found in Zabbix 5.4.12 where zeroed or blank parameters for a webhook are no longer added as parameters in the Javascript.
- Refactored error handling inside the Javascript to distinguish automatically between 'email ID response' or a debug or warning level message (this prevents the code of throwing an unknown error like 'Invalid JSON').
- Fixed issue with Zabbix 5.4.12 where parameters that are blank or zero did no longer get passed to the Javascript hence causing basic checks to fail. Javascript and parameter checks in mailGraph.php have been adjusted and optimized.
- Refactored the Javascript error handling to get rid of the "Invalid JSON offset" message and to deal with individual error conditions while presenting a better error message on the root cause of the concerning issue.
## mailGraph v2.14 release ##
_(2023/07/10)_

View File

@ -1,4 +1,4 @@
// mailGraph v2.15
// mailGraph v2.16
// Function to test string
function isJSON(str) {

View File

@ -60,6 +60,7 @@
// Fixed missing flag for fetching web url related items
// 2.15 2023/08/16 - Mark Oudsen - Bugfix for Zabbix 5.4 where empty or zeroed variables are no longer
// passed by Zabbix (hence resulting in weird errors)
// 2.16 2023/08/16 - Mark Oudsen - Adding ability to use ACKNOWLEDGE messages in the mail message
// ------------------------------------------------------------------------------------------------------
//
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
@ -94,7 +95,7 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// CONSTANTS
$cVersion = 'v2.15';
$cVersion = 'v2.16';
$cCRLF = chr(10).chr(13);
$maskDateTime = 'Y-m-d H:i:s';
$maxGraphs = 8;
@ -462,6 +463,44 @@
_log(': Done. Cleaned up '.$filesRemoved.' file(s), kept '.$filesKept.' file(s)');
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Zabbix translator functions
function zabbixTStoString($linuxTime)
{
return date("Y-m-d H:i:s", $linuxTime);
}
function zabbixActionToString($actionMask)
{
$values = [];
if ($actionMask & 1) { $values[] = "Close problem"; }
if ($actionMask & 2) { $values[] = "Acknowledge event"; }
if ($actionMask & 4) { $values[] = "Add message"; }
if ($actionMask & 8) { $values[] = "Change severity"; }
if ($actionMask & 16) { $values[] = "Unacknowledge event"; }
if ($actionMask & 32) { $values[] = "Suppress event"; }
if ($actionMask & 64) { $values[] = "Unsuppress event"; }
if ($actionMask & 128) { $values[] = "Change event rank to cause"; }
if ($actionMask & 256) { $values[] = "Change event rank to sympton"; }
return implode(", ", $values);
}
function zabbixSeverityToString($severity)
{
switch ($severity) {
case 0: return('Not classified');
case 1: return('Information');
case 2: return('Warning');
case 3: return('Average');
case 4: return('High');
case 5: return('Disaster');
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////
// Initialize ///////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////
@ -801,7 +840,8 @@
'params'=>array('eventids'=>$p_eventId,
'output'=>'extend',
'selectRelatedObject'=>'extend',
'selectSuppressionData'=>'extend'),
'selectSuppressionData'=>'extend',
'select_acknowledges'=>'extend'),
'auth'=>$token,
'id'=>nextRequestID());
@ -830,6 +870,17 @@
break;
}
// --- Collect and attach acknowledge messages for this event
if (sizeof($thisEvent['result'][0]['acknowledges']>0)) {
foreach($thisEvent['result'][0]['acknowledges'] as $aCount=>$anAck) {
$mailData['ACKNOWLEDGES'][$aCount] = $anAck;
$mailData['ACKNOWLEDGES'][$aCount]['_clock'] = zabbixTStoString($anAck['clock']);
$mailData['ACKNOWLEDGES'][$aCount]['_actions'] = zabbixActionToString($anAck['action']);
$mailData['ACKNOWLEDGES'][$aCount]['_old_severity'] = zabbixSeverityToString($anAck['old_severity']);
$mailData['ACKNOWLEDGES'][$aCount]['_new_severity'] = zabbixSeverityToString($anAck['new_severity']);
}
}
$p_triggerId = $thisEvent['result'][0]['relatedObject']['triggerid'];
// ------------------------

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.4</version>
<date>2023-08-16T12:05:37Z</date>
<date>2023-08-16T20:38:38Z</date>
<media_types>
<media_type>
<name>MailGraph</name>
@ -60,7 +60,7 @@
<value>https://myzabbix.com/mailGraph.php</value>
</parameter>
</parameters>
<script>// mailGraph v2.15
<script>// mailGraph v2.16
// Function to test string
function isJSON(str) {
@ -213,4 +213,3 @@ Trigger ID: {TRIGGER.ID}</message>
</media_type>
</media_types>
</zabbix_export>

View File

@ -81,6 +81,9 @@
.content {
font-size: 14px;
}
.acknowledge {
font-size: 10px;
}
</style>
</head>
<body>
@ -112,6 +115,18 @@
</td>
</tr>
</table>
{% if ACKNOWLEDGES|length > 0 %}
<br/>
{% for anAck in ACKNOWLEDGES %}
<table style="border:0; text-align:left;" cellpadding="5" cellspacing="0">
<tr>
<td class="acknowledge">
<b>{{ anAck._clock }}</b><br/><em>({{ anAck.username }}, {{ anAck.name }} {{ anAck.surname }})</em><br/>[{{ anAck._actions }}]<br/>{{ anAck.message }}
</td>
</tr>
</table>
{% endfor %}
{% endif %}
</td>
</tr>
<tr>
@ -120,11 +135,12 @@
Event ID: <a href="{{ EVENTDETAILS_URL }}">{{ EVENT_ID }}</a> //
Trigger ID: <a href="{{ TRIGGER_URL }}">{{ TRIGGER_ID }}</a> //
Item ID: <a href="{{ ITEM_URL }}">{{ ITEM_ID }}</a> //
Host ID: <a href="{{ HOST_URL }}">{{ HOST_ID }}</a>
Host ID: <a href="{{ HOST_URL }}">{{ HOST_ID }}</a> //
<a href="{{ HOST_PROBLEMS_URL }}">Problems</a>
{% if GRAPH_ZABBIXLINK|length > 0 %}
// Graph ID: <a href="{{ GRAPH_ZABBIXLINK }}">{{ GRAPH_ID }}</a>
{% endif %}
// <a href="{{ ACK_URL }}">Ack</a>
// <a href="{{ ACK_URL }}">Ack</a>
</div>
</td>
</tr>