mirror of
https://github.com/moudsen/mailGraph
synced 2025-01-30 20:01:38 +01:00
v2.11 - mailGraph.xml now with correct format
This commit is contained in:
parent
32b8582757
commit
39ada5d6ff
379
mailGraph.xml
379
mailGraph.xml
@ -1,198 +1,215 @@
|
||||
zabbix_export:
|
||||
version: '5.4'
|
||||
date: '2023-07-01T10:54:39Z'
|
||||
media_types:
|
||||
-
|
||||
name: MailGraph
|
||||
type: WEBHOOK
|
||||
parameters:
|
||||
-
|
||||
name: baseURL
|
||||
value: 'https://myzabbix.example.com/'
|
||||
-
|
||||
name: duration
|
||||
value: '{EVENT.DURATION}'
|
||||
-
|
||||
name: eventId
|
||||
value: '{EVENT.ID}'
|
||||
-
|
||||
name: graphHeight
|
||||
value: '120'
|
||||
-
|
||||
name: graphWidth
|
||||
value: '300'
|
||||
-
|
||||
name: HTTPProxy
|
||||
value: ''
|
||||
-
|
||||
name: infoTest
|
||||
value: Test
|
||||
-
|
||||
name: itemId
|
||||
value: '{ITEM.ID}'
|
||||
-
|
||||
name: periods
|
||||
value: '10m,4h,1d,7d'
|
||||
-
|
||||
name: periods_headers
|
||||
value: 'Last 10 minutes,Last 4 hours,Last day,Last 7 days'
|
||||
-
|
||||
name: recipient
|
||||
value: '{ALERT.SENDTO}'
|
||||
-
|
||||
name: showLegend
|
||||
value: '0'
|
||||
-
|
||||
name: subject
|
||||
value: '{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}'
|
||||
-
|
||||
name: URL
|
||||
value: 'https://myzabbix.example.com/mailGraph.php'
|
||||
script: |
|
||||
// mailGraph v2.11
|
||||
try {
|
||||
// Pickup parameters
|
||||
params = JSON.parse(value),
|
||||
req = new HttpRequest(),
|
||||
fields = {},
|
||||
resp = '',
|
||||
result = { tags: {} };
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<zabbix_export>
|
||||
<version>5.4</version>
|
||||
<date>2023-07-02T10:34:30Z</date>
|
||||
<media_types>
|
||||
<media_type>
|
||||
<name>MailGraph</name>
|
||||
<type>WEBHOOK</type>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<name>baseURL</name>
|
||||
<value>https://zbx.puzzl.nl/zabbix/</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>duration</name>
|
||||
<value>{EVENT.DURATION}</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>eventId</name>
|
||||
<value>{EVENT.ID}</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>graphHeight</name>
|
||||
<value>120</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>graphWidth</name>
|
||||
<value>300</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>HTTPProxy</name>
|
||||
<value/>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>infoTest</name>
|
||||
<value>Test</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>itemId</name>
|
||||
<value>{ITEM.ID}</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>periods</name>
|
||||
<value>10m,4h,1d,7d</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>periods_headers</name>
|
||||
<value>Last 10 minutes,Last 4 hours,Last day,Last 7 days</value>
|
||||
</parameter>
|
||||
<parameter>
|
||||
<name>recipient</name>
|
||||
<value>{ALERT.SENDTO}</value>
|
||||
</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
|
||||
params = JSON.parse(value),
|
||||
req = new HttpRequest(),
|
||||
fields = {},
|
||||
resp = '',
|
||||
result = { tags: {} };
|
||||
|
||||
// Set HTTP proxy if required
|
||||
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
|
||||
req.setProxy(params.HTTPProxy);
|
||||
fields.HTTPProxy = params.HTTPProxy;
|
||||
}
|
||||
// Set HTTP proxy if required
|
||||
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');
|
||||
// Declare output type
|
||||
req.addHeader('Content-Type: application/json');
|
||||
|
||||
// Must have fields
|
||||
fields.itemId = params.itemId * 1;
|
||||
fields.eventId = params.eventId * 1;
|
||||
fields.recipient = params.recipient;
|
||||
fields.baseURL = params.baseURL;
|
||||
fields.duration = params.duration * 1;
|
||||
// Must have fields
|
||||
fields.itemId = params.itemId * 1;
|
||||
fields.eventId = params.eventId * 1;
|
||||
fields.recipient = params.recipient;
|
||||
fields.baseURL = params.baseURL;
|
||||
fields.duration = params.duration * 1;
|
||||
|
||||
if (isNaN(fields.eventId)) {
|
||||
throw '[MailGraph Webhook] Invalid event ID? Integer required (use actual event ID from Zabbix!)';
|
||||
}
|
||||
if (isNaN(fields.eventId)) {
|
||||
throw '[MailGraph Webhook] Invalid event ID? Integer required (use actual event ID from Zabbix!)';
|
||||
}
|
||||
|
||||
if (isNaN(fields.duration)) {
|
||||
throw '[MailGraph Webhook] Invalid duration? Integer required (set to zero if unknown)!';
|
||||
}
|
||||
if (isNaN(fields.duration)) {
|
||||
throw '[MailGraph Webhook] Invalid duration? Integer required (set to zero if unknown)!';
|
||||
}
|
||||
|
||||
if (fields.recipient.charAt(0) == '{') {
|
||||
throw '[MailGraph Webhook] Please define recipient for the test message!';
|
||||
}
|
||||
if (fields.recipient.charAt(0) == '{') {
|
||||
throw '[MailGraph Webhook] Please define recipient for the test message!';
|
||||
}
|
||||
|
||||
// Optional fields
|
||||
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
|
||||
if (typeof params.graphHeight === 'string') { fields.graphHeight = params.graphHeight; }
|
||||
if (typeof params.subject === 'string') { fields.subject = params.subject; }
|
||||
if (typeof params.showLegend === 'string') { fields.showLegend = params.showLegend; }
|
||||
if (typeof params.periods === 'string') { fields.periods = params.periods; }
|
||||
if (typeof params.periods_headers === 'string') { fields.periods_headers = params.periods_headers; }
|
||||
if (typeof params.debug === 'string') { fields.debug = params.debug; }
|
||||
// Optional fields
|
||||
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
|
||||
if (typeof params.graphHeight === 'string') { fields.graphHeight = params.graphHeight; }
|
||||
if (typeof params.subject === 'string') { fields.subject = params.subject; }
|
||||
if (typeof params.showLegend === 'string') { fields.showLegend = params.showLegend; }
|
||||
if (typeof params.periods === 'string') { fields.periods = params.periods; }
|
||||
if (typeof params.periods_headers === 'string') { fields.periods_headers = params.periods_headers; }
|
||||
if (typeof params.debug === 'string') { fields.debug = params.debug; }
|
||||
|
||||
// Add generic fields
|
||||
Object.keys(params).forEach(function(key) {
|
||||
if (key.substring(0, 4) == 'info') {
|
||||
fields[key] = params[key];
|
||||
}
|
||||
});
|
||||
|
||||
// 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));
|
||||
Zabbix.Log(4, '[Mailgraph Webhook] Received response:' + resp);
|
||||
|
||||
// If blank the email address is likely incorrect
|
||||
if (resp==null) {
|
||||
throw '[MailGraph Webhook] No data received from mailGraph! Likely the email processing failed? Check mailGraph logging';
|
||||
}
|
||||
|
||||
// If there was an error, report it and stop
|
||||
if (req.getStatus() != 200) { throw JSON.parse(resp).errors[0]; }
|
||||
|
||||
// If no datas returned, report it and stop
|
||||
if (resp.charAt(0) == "!") {
|
||||
throw '[MailGraph Webhook] No data received from mailGraph! Likely the event ID provided does not exist? Check mailGraph logging';
|
||||
}
|
||||
|
||||
// We expect the message id back from the processing script
|
||||
msg = JSON.parse(resp);
|
||||
|
||||
result.tags.__message_id = msg.messageId;
|
||||
Zabbix.Log(4, '[MailGraph Webhook] Message sent with identification "' + msg.messageId + '"');
|
||||
|
||||
// Pass the result back to Zabbix
|
||||
return JSON.stringify(result);
|
||||
// Add generic fields
|
||||
Object.keys(params).forEach(function(key) {
|
||||
if (key.substring(0, 4) == 'info') {
|
||||
fields[key] = params[key];
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
// In case something went wrong in the processing, pass the error back to Zabbix
|
||||
Zabbix.Log(127, 'MailGraph notification failed: '+error);
|
||||
throw 'MailGraph notification failed : '+error;
|
||||
}
|
||||
process_tags: 'YES'
|
||||
description: |
|
||||
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
|
||||
// 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));
|
||||
Zabbix.Log(4, '[Mailgraph Webhook] Received response:' + resp);
|
||||
|
||||
The html.template and plain.template files can be adjusted (TWIG format).
|
||||
// If blank the email address is likely incorrect
|
||||
if (resp==null) {
|
||||
throw '[MailGraph Webhook] No data received from mailGraph! Likely the email processing failed? Check mailGraph logging';
|
||||
}
|
||||
|
||||
More details are available at https://github.com/moudsen/mailGraph
|
||||
message_templates:
|
||||
-
|
||||
event_source: TRIGGERS
|
||||
operation_mode: PROBLEM
|
||||
subject: 'Problem: {EVENT.NAME}'
|
||||
message: |
|
||||
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}
|
||||
// If there was an error, report it and stop
|
||||
if (req.getStatus() != 200) { throw JSON.parse(resp).errors[0]; }
|
||||
|
||||
eventId: {EVENT.ID}
|
||||
TriggerId: {TRIGGER.ID}
|
||||
itemId: {ITEM.ID]
|
||||
-
|
||||
event_source: TRIGGERS
|
||||
operation_mode: RECOVERY
|
||||
subject: 'Resolved in {EVENT.DURATION}: {EVENT.RECOVERY.NAME}'
|
||||
message: |
|
||||
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}
|
||||
// If no datas returned, report it and stop
|
||||
if (resp.charAt(0) == "!") {
|
||||
throw '[MailGraph Webhook] No data received from mailGraph! Likely the event ID provided does not exist? Check mailGraph logging';
|
||||
}
|
||||
|
||||
eventId: {EVENT.ID}
|
||||
TriggerId: {TRIGGER.ID}
|
||||
itemId: {ITEM.ID]
|
||||
-
|
||||
event_source: TRIGGERS
|
||||
operation_mode: UPDATE
|
||||
subject: 'Updated problem in {EVENT.AGE}: {EVENT.NAME}'
|
||||
message: |
|
||||
{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
|
||||
{EVENT.UPDATE.MESSAGE}
|
||||
// We expect the message id back from the processing script
|
||||
msg = JSON.parse(resp);
|
||||
|
||||
Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.
|
||||
result.tags.__message_id = msg.messageId;
|
||||
Zabbix.Log(4, '[MailGraph Webhook] Message sent with identification "' + msg.messageId + '"');
|
||||
|
||||
eventId: {EVENT.ID}
|
||||
TriggerId: {TRIGGER.ID}
|
||||
itemId: {ITEM.ID]
|
||||
// Pass the result back to Zabbix
|
||||
return JSON.stringify(result);
|
||||
}
|
||||
catch (error)
|
||||
{
|
||||
// In case something went wrong in the processing, pass the error back to Zabbix
|
||||
Zabbix.Log(127, 'MailGraph notification failed: '+error);
|
||||
throw 'MailGraph notification failed : '+error;
|
||||
}</script>
|
||||
<process_tags>YES</process_tags>
|
||||
<description>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</description>
|
||||
<message_templates>
|
||||
<message_template>
|
||||
<event_source>TRIGGERS</event_source>
|
||||
<operation_mode>PROBLEM</operation_mode>
|
||||
<subject>Problem: {EVENT.NAME}</subject>
|
||||
<message>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]</message>
|
||||
</message_template>
|
||||
<message_template>
|
||||
<event_source>TRIGGERS</event_source>
|
||||
<operation_mode>RECOVERY</operation_mode>
|
||||
<subject>Resolved in {EVENT.DURATION}: {EVENT.RECOVERY.NAME}</subject>
|
||||
<message>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]</message>
|
||||
</message_template>
|
||||
<message_template>
|
||||
<event_source>TRIGGERS</event_source>
|
||||
<operation_mode>UPDATE</operation_mode>
|
||||
<subject>Updated problem in {EVENT.AGE}: {EVENT.NAME}</subject>
|
||||
<message>{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]</message>
|
||||
</message_template>
|
||||
</message_templates>
|
||||
</media_type>
|
||||
</media_types>
|
||||
</zabbix_export>
|
||||
|
Loading…
x
Reference in New Issue
Block a user