v2.11 - mailGraph.xml now with correct format

This commit is contained in:
moudsen 2023-07-02 12:36:17 +02:00 committed by GitHub
parent 32b8582757
commit 39ada5d6ff
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,56 +1,71 @@
zabbix_export: <?xml version="1.0" encoding="UTF-8"?>
version: '5.4' <zabbix_export>
date: '2023-07-01T10:54:39Z' <version>5.4</version>
media_types: <date>2023-07-02T10:34:30Z</date>
- <media_types>
name: MailGraph <media_type>
type: WEBHOOK <name>MailGraph</name>
parameters: <type>WEBHOOK</type>
- <parameters>
name: baseURL <parameter>
value: 'https://myzabbix.example.com/' <name>baseURL</name>
- <value>https://zbx.puzzl.nl/zabbix/</value>
name: duration </parameter>
value: '{EVENT.DURATION}' <parameter>
- <name>duration</name>
name: eventId <value>{EVENT.DURATION}</value>
value: '{EVENT.ID}' </parameter>
- <parameter>
name: graphHeight <name>eventId</name>
value: '120' <value>{EVENT.ID}</value>
- </parameter>
name: graphWidth <parameter>
value: '300' <name>graphHeight</name>
- <value>120</value>
name: HTTPProxy </parameter>
value: '' <parameter>
- <name>graphWidth</name>
name: infoTest <value>300</value>
value: Test </parameter>
- <parameter>
name: itemId <name>HTTPProxy</name>
value: '{ITEM.ID}' <value/>
- </parameter>
name: periods <parameter>
value: '10m,4h,1d,7d' <name>infoTest</name>
- <value>Test</value>
name: periods_headers </parameter>
value: 'Last 10 minutes,Last 4 hours,Last day,Last 7 days' <parameter>
- <name>itemId</name>
name: recipient <value>{ITEM.ID}</value>
value: '{ALERT.SENDTO}' </parameter>
- <parameter>
name: showLegend <name>periods</name>
value: '0' <value>10m,4h,1d,7d</value>
- </parameter>
name: subject <parameter>
value: '{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}' <name>periods_headers</name>
- <value>Last 10 minutes,Last 4 hours,Last day,Last 7 days</value>
name: URL </parameter>
value: 'https://myzabbix.example.com/mailGraph.php' <parameter>
script: | <name>recipient</name>
// mailGraph v2.11 <value>{ALERT.SENDTO}</value>
try { </parameter>
<parameter>
<name>showLegend</name>
<value>0</value>
</parameter>
<parameter>
<name>subject</name>
<value>{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}</value>
</parameter>
<parameter>
<name>URL</name>
<value>https://zbx.puzzl.nl/mailGraph.php</value>
</parameter>
</parameters>
<script>// mailGraph v2.11
try {
// Pickup parameters // Pickup parameters
params = JSON.parse(value), params = JSON.parse(value),
req = new HttpRequest(), req = new HttpRequest(),
@ -59,7 +74,7 @@ zabbix_export:
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;
} }
@ -116,7 +131,7 @@ zabbix_export:
if (req.getStatus() != 200) { throw JSON.parse(resp).errors[0]; } if (req.getStatus() != 200) { throw JSON.parse(resp).errors[0]; }
// If no datas returned, report it and stop // If no datas returned, report it and stop
if (resp.charAt(0) == "!") { if (resp.charAt(0) == &quot;!&quot;) {
throw '[MailGraph Webhook] No data received from mailGraph! Likely the event ID provided does not exist? Check mailGraph logging'; throw '[MailGraph Webhook] No data received from mailGraph! Likely the event ID provided does not exist? Check mailGraph logging';
} }
@ -124,75 +139,77 @@ zabbix_export:
msg = JSON.parse(resp); msg = JSON.parse(resp);
result.tags.__message_id = msg.messageId; result.tags.__message_id = msg.messageId;
Zabbix.Log(4, '[MailGraph Webhook] Message sent with identification "' + msg.messageId + '"'); Zabbix.Log(4, '[MailGraph Webhook] Message sent with identification &quot;' + msg.messageId + '&quot;');
// Pass the result back to Zabbix // Pass the result back to Zabbix
return JSON.stringify(result); return JSON.stringify(result);
} }
catch (error) catch (error)
{ {
// In case something went wrong in the processing, pass the error back to Zabbix // In case something went wrong in the processing, pass the error back to Zabbix
Zabbix.Log(127, 'MailGraph notification failed: '+error); Zabbix.Log(127, 'MailGraph notification failed: '+error);
throw 'MailGraph notification failed : '+error; throw 'MailGraph notification failed : '+error;
} }</script>
process_tags: 'YES' <process_tags>YES</process_tags>
description: | <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.
The "URL" must point to the location of the processing script. If a proxy is required, define "HTTPProxy" for the proxy address.
Customization: Customization:
- "graphWidth" and "graphWidth" can be defined for the image size - &quot;graphWidth&quot; and &quot;graphWidth&quot; can be defined for the image size
- "showLegend" can be defined to show or hide the legend of the graph - &quot;showLegend&quot; can be defined to show or hide the legend of the graph
- "subject" can be defined for a customized subject for the mail message - &quot;subject&quot; 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 - &quot;periods&quot; and &quot;periods_headers&quot; can be defined for displaying multiple periods of the same graph, or
- "period" and "period_header" can be defined to display a single graph - &quot;period&quot; and &quot;period_header&quot; can be defined to display a single graph
The html.template and plain.template files can be adjusted (TWIG format). The html.template and plain.template files can be adjusted (TWIG format).
More details are available at https://github.com/moudsen/mailGraph More details are available at https://github.com/moudsen/mailGraph</description>
message_templates: <message_templates>
- <message_template>
event_source: TRIGGERS <event_source>TRIGGERS</event_source>
operation_mode: PROBLEM <operation_mode>PROBLEM</operation_mode>
subject: 'Problem: {EVENT.NAME}' <subject>Problem: {EVENT.NAME}</subject>
message: | <message>Problem started at {EVENT.TIME} on {EVENT.DATE}
Problem started at {EVENT.TIME} on {EVENT.DATE} Problem name: {EVENT.NAME}
Problem name: {EVENT.NAME} Host: {HOST.NAME}
Host: {HOST.NAME} Severity: {EVENT.SEVERITY}
Severity: {EVENT.SEVERITY} Operational data: {EVENT.OPDATA}
Operational data: {EVENT.OPDATA} Original problem ID: {EVENT.ID}
Original problem ID: {EVENT.ID} {TRIGGER.URL}
{TRIGGER.URL}
eventId: {EVENT.ID} eventId: {EVENT.ID}
TriggerId: {TRIGGER.ID} TriggerId: {TRIGGER.ID}
itemId: {ITEM.ID] itemId: {ITEM.ID]</message>
- </message_template>
event_source: TRIGGERS <message_template>
operation_mode: RECOVERY <event_source>TRIGGERS</event_source>
subject: 'Resolved in {EVENT.DURATION}: {EVENT.RECOVERY.NAME}' <operation_mode>RECOVERY</operation_mode>
message: | <subject>Resolved in {EVENT.DURATION}: {EVENT.RECOVERY.NAME}</subject>
Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE} <message>Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
Problem name: {EVENT.RECOVERY.NAME} Problem name: {EVENT.RECOVERY.NAME}
Problem duration: {EVENT.DURATION} Problem duration: {EVENT.DURATION}
Host: {HOST.NAME} Host: {HOST.NAME}
Severity: {EVENT.SEVERITY} Severity: {EVENT.SEVERITY}
Original problem ID: {EVENT.ID} Original problem ID: {EVENT.ID}
{TRIGGER.URL} {TRIGGER.URL}
eventId: {EVENT.ID} eventId: {EVENT.ID}
TriggerId: {TRIGGER.ID} TriggerId: {TRIGGER.ID}
itemId: {ITEM.ID] itemId: {ITEM.ID]</message>
- </message_template>
event_source: TRIGGERS <message_template>
operation_mode: UPDATE <event_source>TRIGGERS</event_source>
subject: 'Updated problem in {EVENT.AGE}: {EVENT.NAME}' <operation_mode>UPDATE</operation_mode>
message: | <subject>Updated problem in {EVENT.AGE}: {EVENT.NAME}</subject>
{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}. <message>{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
{EVENT.UPDATE.MESSAGE} {EVENT.UPDATE.MESSAGE}
Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}. Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.
eventId: {EVENT.ID}
TriggerId: {TRIGGER.ID}
itemId: {ITEM.ID]
eventId: {EVENT.ID}
TriggerId: {TRIGGER.ID}
itemId: {ITEM.ID]</message>
</message_template>
</message_templates>
</media_type>
</media_types>
</zabbix_export>