Bug fixes (v1.11)

This commit is contained in:
Mark Oudsen 2021-02-28 21:31:46 +01:00
parent 3ec9004db9
commit 6289a1cbdb
5 changed files with 35 additions and 18 deletions

View File

@ -6,6 +6,7 @@
"cli_eventValue": 0,
"cli_duration": 0,
"cli_recipient": "recipient@domain.com",
"cli_subject": "\"{{ HOST_NAME }}\": ({{ EVENT_SEVERITY }}) {{ EVENT_NAME }}"
"cli_baseURL": "https:\/\/domain.com\/zabbix\/",
"zabbix_user": "alogicalusername",
"zabbix_pwd": "astrongpassword",

View File

@ -11,6 +11,7 @@
// 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
// 1.11 2021/02/28 - Mark Oudsen - Bug fixes
// ------------------------------------------------------------------------------------------------------
//
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
@ -36,7 +37,7 @@
// CONSTANTS
$cVersion = 'v1.01';
$cVersion = 'v1.11';
$cCRLF = chr(10).chr(13);
$maskDateTime = 'Y-m-d H:i:s';
@ -315,6 +316,7 @@
$problemData['recipient'] = $config['cli_recipient'];
$problemData['baseURL'] = $config['cli_baseURL'];
$problemData['duration'] = $config['cli_duration'];
$problemData['subject'] = $config['cli_subject'];
// Switch on CLI log display
$showLog = TRUE;
@ -337,13 +339,13 @@
$p_eventValue = intval($problemData['eventValue']);
if (!isset($problemData['duration'])) { echo "Missing DURATION?\n"; die; }
$p_duration = $problemData['duration'];
$p_duration = intval($problemData['duration']);
if (!isset($problemData['baseURL'])) { echo "Missing URL?\n"; die; }
$p_URL = $problemData['baseURL'];
$p_subject = '{{ EVENT_SEVERITY }}: {{ EVENT_NAME }}';
if ((isset($problemData['subject'])) && ($problemData['subject']!='')) { $p_subject = $problemData['subject']; }
if (isset($problemData['subject'])) { $p_subject = $problemData['subject']; }
$p_graphWidth = 450;
if (isset($problemData['graphWidth'])) { $p_graphWidth = intval($problemData['graphWidth']); }
@ -423,7 +425,9 @@
/////////////////////////////////////////////////////////////////////////////////////////////////////////
$mailData = array();
$mailData['baseURL'] = $p_URL;
$mailData['BASE_URL'] = $p_URL;
$mailData['SUBJECT'] = $p_subject;
// --- LOGIN ---
@ -496,7 +500,7 @@
// --- GET HOST INFO ---
_log('# Retrieve HOST information ');
_log('# Retrieve HOST information');
$hostId = $thisItem['result'][0]['hostid'];
@ -515,6 +519,18 @@
$mailData['HOST_ERROR'] = $thisHost['result'][0]['error'];
$mailData['HOST_DESCRIPTION'] = $thisHost['result'][0]['description'];
_log('# Retreive HOST macro information');
$request = array('jsonrpc'=>'2.0',
'method'=>'usermacro.get',
'params'=>array('hostids'=>$hostId,
'output'=>'extend'),
'auth'=>$token,
'id'=>nextRequestID());
$thisMacros = postJSON($z_url_api,$request);
_log('> Host macro data'.$cCRLF.json_encode($thisMacros,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
// --- GET GRAPHS ASSOCIATED WITH THIS ITEM ---
_log('# Retrieve associated graphs to this item');
@ -685,7 +701,7 @@
$loader = new \Twig\Loader\ArrayLoader([
'html' => file_get_contents($z_template_path.'html.template'),
'plain' => file_get_contents($z_template_path.'plain.template'),
'subject' => $p_subject,
'subject' => $mailData['SUBJECT'],
]);
$twig = new \Twig\Environment($loader);
@ -703,7 +719,7 @@
// Prepare message
$message->setSubject($thisEvent['result'][0]['name'])
$message->setSubject($mailSubject)
->setFrom($mailFrom)
->setTo($p_recipient)
->setBody($bodyHTML, 'text/html')
@ -739,6 +755,6 @@
$content = implode(chr(10),$logging).$cCRLF.$cCRLF.'=== MAILDATA ==='.$cCRLF.$cCRLF.json_encode($mailData,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK);
$content = str_replace(chr(13),'',$content);
file_put_contents($z_log_path.'log.'.$p_eventId.'.dump',$content);
file_put_contents($z_log_path.'log.'.$p_eventId.'.'.date('YmdHis').'.dump',$content);
}
?>

View File

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<zabbix_export>
<version>5.0</version>
<date>2021-02-27T16:34:16Z</date>
<date>2021-02-28T20:27:03Z</date>
<media_types>
<media_type>
<name>MailGraph</name>
@ -9,7 +9,7 @@
<parameters>
<parameter>
<name>baseURL</name>
<value>https://zbx.puzzl.nl/zabbix/</value>
<value>https://domain.com/zabbix/</value>
</parameter>
<parameter>
<name>duration</name>
@ -49,7 +49,7 @@
</parameter>
<parameter>
<name>subject</name>
<value>{{ EVENT_SEVERITY }} --- {{ EVENT_NAME }}</value>
<value>{{ HOST_NAME }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME }}</value>
</parameter>
<parameter>
<name>triggerId</name>
@ -57,7 +57,7 @@
</parameter>
<parameter>
<name>URL</name>
<value>https://zbx.puzzl.nl/mailGraph.php</value>
<value>https://domain.com/mailGraph.php</value>
</parameter>
</parameters>
<script>try {&#13;

View File

@ -51,9 +51,9 @@
{% if EVENT_SEVERITY == "Resolved" %}
Duration: <b>{{ EVENT_DURATION }}</b><br/>
{% endif %}
Item: <b>{{ ITEM_NAME }}</b> ({{ ITEM_KEY }})<br/>
Item: <b>{{ ITEM_NAME }}</b><br/>
Previous/Last: {{ ITEM_PREVIOUSVALUE }} ==&gt; {{ ITEM_LASTVALUE }}
<p><a href="{{ EVENT_URL }}">Event Details</a><br/></p>
<p><a href="{{ EVENTDETAILS_URL }}">Event Details</a><br/></p>
</td></tr>
</table>
</td>
@ -65,10 +65,10 @@
{% endif %}
</table>
<p style="font-size:10px">
Event ID: <a href="{{ EVENT_URL }}">{{ EVENT_ID }}</a> //
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>
</p>
</body>
</html>
</html>

View File

@ -18,12 +18,12 @@ Description: {{ TRIGGER_DESCRIPTION }}
ITEM #{{ ITEM_ID }}
Name: {{ ITEM_NAME }}
Key: {{ ITEM_KEY }}
Value: {{ ITEM_LASTVALUE }}
Previous: {{ ITEM_PREVIOUSVALUE }}
HOST
Name: {{ HOST_NAME }}
EVENT DETAILS
{{ baseURL }}/tr_events.php?triggerid={TRIGGER_ID}&eventid={EVENT_ID}
{{ EVENTDETAILS_URL }}