mirror of
https://github.com/moudsen/mailGraph
synced 2025-10-29 16:47:39 +01:00
Compare commits
53 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
32b8582757 | ||
|
|
9c42ee4b89 | ||
|
|
fa7fba040a | ||
|
|
3a4a7ab23e | ||
|
|
7075b40ad1 | ||
|
|
8bc476ed63 | ||
|
|
e80a2a56a3 | ||
|
|
4b28d3f066 | ||
|
|
93535d4006 | ||
|
|
b9622da72f | ||
|
|
56fb68ae9c | ||
|
|
fa51c3e59e | ||
|
|
4ae62b3a1f | ||
|
|
0731b87d44 | ||
|
|
bdf4b05a6b | ||
|
|
df16444665 | ||
|
|
bccd134523 | ||
|
|
27c1d64511 | ||
|
|
8597658670 | ||
|
|
b7e2062486 | ||
|
|
2955ffc404 | ||
|
|
2976a4af9c | ||
|
|
2882367308 | ||
|
|
8b4885038a | ||
|
|
f541719fbe | ||
|
|
9edab245d8 | ||
|
|
341bd561ab | ||
|
|
e2f657f3dd | ||
|
|
82a8fe4121 | ||
|
|
bee76b63c0 | ||
|
|
ba0d474bdb | ||
|
|
a5a0f0ace1 | ||
|
|
8655d4ca2c | ||
|
|
76321be3f8 | ||
|
|
9d4f00ce87 | ||
|
|
1278d43acb | ||
|
|
18c22abf17 | ||
|
|
0a623f3137 | ||
|
|
634134b423 | ||
|
|
58668311ee | ||
|
|
9052b71562 | ||
|
|
74b6ee15c7 | ||
|
|
398637e582 | ||
|
|
9e40060cdd | ||
|
|
e85400b0de | ||
|
|
e05fcbfba7 | ||
|
|
66b504a66c | ||
|
|
bc0c83b544 | ||
|
|
17cdbea2bd | ||
|
|
fb51354649 | ||
|
|
78061964c4 | ||
|
|
1c9786c549 | ||
|
|
37b1ea7ea2 |
64
README.md
64
README.md
@@ -1,7 +1,65 @@
|
|||||||
## mailGraph (v1.22)
|
## mailGraph v2.11 release ##
|
||||||
Zabbix Media module and scripts for sending e-mail alerts with graphs.
|
_(2023/07/01)_
|
||||||
|
|
||||||
**Please use the Wiki for information on how to install, configure and use MailGraph in Zabbix.**
|
_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
|
||||||
|
- Added pre- and postchecking of variables to the Zabbix javascript - this will prevent the 'invalid JSON' messages and provide better feedback for errors
|
||||||
|
- When testing MailGraph it is now possible to set the eventId to zero - a random problem will be picked up via the API
|
||||||
|
- Zabbix Media Type XML reverted back to version 5.4 (for backwards compatibility)
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
## 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
|
||||||
|
|
||||||
|
## 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.
|
||||||
|
Expect to continue with automatic configuration within the next 2 months.
|
||||||
|
|
||||||
|
## Zabbix 6.2.x testing ##
|
||||||
|
_(2022/10/10)_
|
||||||
|
|
||||||
|
Testing completed. No immediate issues found.
|
||||||
|
|
||||||
|
_(2022/08/22)_
|
||||||
|
|
||||||
|
Zabbix 6.2.x testing is in progress. Once completed the next effort will be to deliver on automatic configuration detection and automatic updates.
|
||||||
|
|
||||||
|
## IMPORTANT NOTE ##
|
||||||
|
As a result of a major functional change in Zabbix 5.4 (Screens no longer exist and are all moved into Dashboards) the mailGraph.screen macro no longer functions under Zabbix 5.4+. A code rewrite is in progress to deal with detecting the Zabbix version and to pick dashboard.get instead of screen.get as a source list for the graphs that should be included in the mail message.
|
||||||
|
|
||||||
|
**v1.x is no longer supported; please upgrade to the current v2 release**
|
||||||
|
**Please use the Wiki for information on how to install, configure and use MailGraph in Zabbix**
|
||||||
|
|
||||||
## Example message
|
## Example message
|
||||||
|
The below message is just an example of what MailGraph is capable of. The template engine ("Twig") allows for a fully customized message creation to your needs! It is also possible to add more Zabbix fields. If you need additional fields just raise an issue ticket and ask and I'll see what I can do.
|
||||||
|
|
||||||
[](images/Example-mail-message-v122.png)
|
[](images/Example-mail-message-v122.png)
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
{
|
{
|
||||||
"script_baseurl": "https:\/\/domain.com\/",
|
"script_baseurl": "https:\/\/mydomain.com\/",
|
||||||
"cli_itemId": 0,
|
"cli_itemId": 0,
|
||||||
"cli_triggerId": 0,
|
"cli_triggerId": 0,
|
||||||
"cli_eventId": 0,
|
"cli_eventId": 0,
|
||||||
"cli_eventValue": 0,
|
|
||||||
"cli_duration": 0,
|
"cli_duration": 0,
|
||||||
"cli_recipient": "recipient@domain.com",
|
"cli_recipient": "recipient@mydomain.com",
|
||||||
"cli_subject": "[TEST] {{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
"cli_subject": "[TEST] {{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
||||||
"cli_baseURL": "https:\/\/domain.com\/zabbix\/",
|
"cli_baseURL": "https:\/\/mydomain.com\/zabbix\/",
|
||||||
"cli_period": "30m",
|
"cli_period": "30m",
|
||||||
"cli_period_header": "Last 30 minutes",
|
"cli_period_header": "Last 30 minutes",
|
||||||
"cli_debug": 1,
|
"cli_debug": 1,
|
||||||
|
"cli_proxy": "",
|
||||||
"zabbix_user": "alogicalusername",
|
"zabbix_user": "alogicalusername",
|
||||||
"zabbix_user_pwd": "astrongpassword",
|
"zabbix_user_pwd": "astrongpassword",
|
||||||
"zabbix_api_user": "alogicalusername",
|
"zabbix_api_user": "alogicalusername",
|
||||||
"zabbix_api_pwd": "astrongpassword",
|
"zabbix_api_pwd": "astrongpassword",
|
||||||
"mail_from": "sender@domain.com",
|
"mail_from": "sender@mydomain.com",
|
||||||
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
||||||
"smtp_server": "localhost",
|
"smtp_server": "localhost",
|
||||||
"smtp_port": 25,
|
"smtp_port": 25,
|
||||||
|
|||||||
@@ -1,21 +1,21 @@
|
|||||||
{
|
{
|
||||||
"script_baseurl": "https:\/\/domain.com\/",
|
"script_baseurl": "https:\/\/mydomain.com\/",
|
||||||
"cli_itemId": 0,
|
"cli_itemId": 0,
|
||||||
"cli_triggerId": 0,
|
"cli_triggerId": 0,
|
||||||
"cli_eventId": 0,
|
"cli_eventId": 0,
|
||||||
"cli_eventValue": 0,
|
|
||||||
"cli_duration": 0,
|
"cli_duration": 0,
|
||||||
"cli_recipient": "recipient@domain.com",
|
"cli_recipient": "recipient@mydomain.com",
|
||||||
"cli_subject": "[TEST] {{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
"cli_subject": "[TEST] {{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
||||||
"cli_baseURL": "https:\/\/domain.com\/zabbix\/",
|
"cli_baseURL": "https:\/\/mydomain.com\/zabbix\/",
|
||||||
"cli_periods": "10m,4h,2d,7d",
|
"cli_periods": "10m,4h,2d,7d",
|
||||||
"cli_periods_headers": "Last 10 minutes,Last 4 hours,Last 2 days,Last 7 days",
|
"cli_periods_headers": "Last 10 minutes,Last 4 hours,Last 2 days,Last 7 days",
|
||||||
"cli_debug": 1,
|
"cli_debug": 1,
|
||||||
|
"cli_proxy": "",
|
||||||
"zabbix_user": "alogicalusername",
|
"zabbix_user": "alogicalusername",
|
||||||
"zabbix_user_pwd": "astrongpassword",
|
"zabbix_user_pwd": "astrongpassword",
|
||||||
"zabbix_api_user": "alogicalusername",
|
"zabbix_api_user": "alogicalusername",
|
||||||
"zabbix_api_pwd": "astrongpassword",
|
"zabbix_api_pwd": "astrongpassword",
|
||||||
"mail_from": "sender@domain.com",
|
"mail_from": "sender@mydomain.com",
|
||||||
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
||||||
"smtp_server": "localhost",
|
"smtp_server": "localhost",
|
||||||
"smtp_port": 25,
|
"smtp_port": 25,
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
$content = file_get_contents($argv[1]);
|
$content = file_get_contents($argv[1]);
|
||||||
$data = json_decode($content,TRUE);
|
$data = json_decode($content,TRUE);
|
||||||
|
|
||||||
if ($data==NULL)
|
if (($data==NULL) && (sizeof($content)>2))
|
||||||
{
|
{
|
||||||
echo 'Invalid JSON format in config file?!'.$cCRLF;
|
echo 'Invalid JSON format in config file?!'.$cCRLF;
|
||||||
die;
|
die;
|
||||||
|
|||||||
BIN
images/Example-Zabbix-MediaType-Config.png
Normal file
BIN
images/Example-Zabbix-MediaType-Config.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 85 KiB |
1
javascript/READ.ME
Normal file
1
javascript/READ.ME
Normal file
@@ -0,0 +1 @@
|
|||||||
|
Issue #32 has been resolved. The javascript code now works for Zabbix 5.4, 6.0 LTS and 6.4.
|
||||||
@@ -1,25 +1,39 @@
|
|||||||
|
// mailGraph v2.11
|
||||||
try {
|
try {
|
||||||
// Pickup parameters
|
// Pickup parameters
|
||||||
params = JSON.parse(value),
|
params = JSON.parse(value),
|
||||||
req = new CurlHttpRequest(),
|
req = new HttpRequest(),
|
||||||
fields = {},
|
fields = {},
|
||||||
resp = '',
|
resp = '',
|
||||||
result = { tags: {} };
|
result = { tags: {} };
|
||||||
|
|
||||||
// Set HTTP proxy if required
|
// Set HTTP proxy if required
|
||||||
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') { req.setProxy(params.HTTPProxy); }
|
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
|
||||||
|
req.setProxy(params.HTTPProxy);
|
||||||
|
fields.HTTPProxy = params.HTTPProxy;
|
||||||
|
}
|
||||||
|
|
||||||
// Declare output type
|
// Declare output type
|
||||||
req.AddHeader('Content-Type: application/json');
|
req.addHeader('Content-Type: application/json');
|
||||||
|
|
||||||
// Must have fields
|
// Must have fields
|
||||||
fields.itemId = params.itemId;
|
fields.itemId = params.itemId * 1;
|
||||||
fields.triggerId = params.triggerId;
|
fields.eventId = params.eventId * 1;
|
||||||
fields.eventId = params.eventId;
|
|
||||||
fields.eventValue = params.eventValue;
|
|
||||||
fields.recipient = params.recipient;
|
fields.recipient = params.recipient;
|
||||||
fields.baseURL = params.baseURL;
|
fields.baseURL = params.baseURL;
|
||||||
fields.duration = params.duration;
|
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.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!';
|
||||||
|
}
|
||||||
|
|
||||||
// Optional fields
|
// Optional fields
|
||||||
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
|
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
|
||||||
@@ -39,15 +53,27 @@ try {
|
|||||||
|
|
||||||
// Post information to the processing script
|
// Post information to the processing script
|
||||||
Zabbix.Log(4, '[MailGraph Webhook] Sending request: ' + params.URL + '?' + JSON.stringify(fields));
|
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);
|
Zabbix.Log(4, '[Mailgraph Webhook] Received response:' + resp);
|
||||||
|
|
||||||
// If there was an error, report it
|
// If blank the email address is likely incorrect
|
||||||
if (req.Status() != 200) { throw JSON.parse(resp).errors[0]; }
|
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
|
// We expect the message id back from the processing script
|
||||||
resp = JSON.parse(resp);
|
msg = JSON.parse(resp);
|
||||||
result.tags.__message_id = resp.messageId;
|
|
||||||
|
result.tags.__message_id = msg.messageId;
|
||||||
|
Zabbix.Log(4, '[MailGraph Webhook] Message sent with identification "' + msg.messageId + '"');
|
||||||
|
|
||||||
// Pass the result back to Zabbix
|
// Pass the result back to Zabbix
|
||||||
return JSON.stringify(result);
|
return JSON.stringify(result);
|
||||||
|
|||||||
686
mailGraph.php
686
mailGraph.php
File diff suppressed because it is too large
Load Diff
389
mailGraph.xml
389
mailGraph.xml
@@ -1,191 +1,198 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
zabbix_export:
|
||||||
<zabbix_export>
|
version: '5.4'
|
||||||
<version>5.0</version>
|
date: '2023-07-01T10:54:39Z'
|
||||||
<date>2021-03-10T18:50:24Z</date>
|
media_types:
|
||||||
<media_types>
|
-
|
||||||
<media_type>
|
name: MailGraph
|
||||||
<name>MailGraph</name>
|
type: WEBHOOK
|
||||||
<type>WEBHOOK</type>
|
parameters:
|
||||||
<parameters>
|
-
|
||||||
<parameter>
|
name: baseURL
|
||||||
<name>baseURL</name>
|
value: 'https://myzabbix.example.com/'
|
||||||
<value>https://mydomain.com/zabbix/</value>
|
-
|
||||||
</parameter>
|
name: duration
|
||||||
<parameter>
|
value: '{EVENT.DURATION}'
|
||||||
<name>duration</name>
|
-
|
||||||
<value>{EVENT.DURATION}</value>
|
name: eventId
|
||||||
</parameter>
|
value: '{EVENT.ID}'
|
||||||
<parameter>
|
-
|
||||||
<name>eventId</name>
|
name: graphHeight
|
||||||
<value>{EVENT.ID}</value>
|
value: '120'
|
||||||
</parameter>
|
-
|
||||||
<parameter>
|
name: graphWidth
|
||||||
<name>eventValue</name>
|
value: '300'
|
||||||
<value>{EVENT.VALUE}</value>
|
-
|
||||||
</parameter>
|
name: HTTPProxy
|
||||||
<parameter>
|
value: ''
|
||||||
<name>graphHeight</name>
|
-
|
||||||
<value>120</value>
|
name: infoTest
|
||||||
</parameter>
|
value: Test
|
||||||
<parameter>
|
-
|
||||||
<name>graphWidth</name>
|
name: itemId
|
||||||
<value>300</value>
|
value: '{ITEM.ID}'
|
||||||
</parameter>
|
-
|
||||||
<parameter>
|
name: periods
|
||||||
<name>HTTPProxy</name>
|
value: '10m,4h,1d,7d'
|
||||||
<value/>
|
-
|
||||||
</parameter>
|
name: periods_headers
|
||||||
<parameter>
|
value: 'Last 10 minutes,Last 4 hours,Last day,Last 7 days'
|
||||||
<name>itemId</name>
|
-
|
||||||
<value>{ITEM.ID}</value>
|
name: recipient
|
||||||
</parameter>
|
value: '{ALERT.SENDTO}'
|
||||||
<parameter>
|
-
|
||||||
<name>periods</name>
|
name: showLegend
|
||||||
<value>10m,4h,1d,7d</value>
|
value: '0'
|
||||||
</parameter>
|
-
|
||||||
<parameter>
|
name: subject
|
||||||
<name>periods_headers</name>
|
value: '{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}'
|
||||||
<value>Last 10 minutes,Last 4 hours,Last day,Last 7 days</value>
|
-
|
||||||
</parameter>
|
name: URL
|
||||||
<parameter>
|
value: 'https://myzabbix.example.com/mailGraph.php'
|
||||||
<name>recipient</name>
|
script: |
|
||||||
<value>{ALERT.SENDTO}</value>
|
// mailGraph v2.11
|
||||||
</parameter>
|
try {
|
||||||
<parameter>
|
// Pickup parameters
|
||||||
<name>showLegend</name>
|
params = JSON.parse(value),
|
||||||
<value>0</value>
|
req = new HttpRequest(),
|
||||||
</parameter>
|
fields = {},
|
||||||
<parameter>
|
resp = '',
|
||||||
<name>subject</name>
|
result = { tags: {} };
|
||||||
<value>{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}</value>
|
|
||||||
</parameter>
|
// Set HTTP proxy if required
|
||||||
<parameter>
|
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
|
||||||
<name>triggerId</name>
|
req.setProxy(params.HTTPProxy);
|
||||||
<value>{TRIGGER.ID}</value>
|
fields.HTTPProxy = params.HTTPProxy;
|
||||||
</parameter>
|
}
|
||||||
<parameter>
|
|
||||||
<name>URL</name>
|
// Declare output type
|
||||||
<value>https://mydomain.com/mailGraph.php</value>
|
req.addHeader('Content-Type: application/json');
|
||||||
</parameter>
|
|
||||||
</parameters>
|
// Must have fields
|
||||||
<script>try {
|
fields.itemId = params.itemId * 1;
|
||||||
// Pickup parameters
|
fields.eventId = params.eventId * 1;
|
||||||
params = JSON.parse(value),
|
fields.recipient = params.recipient;
|
||||||
req = new CurlHttpRequest(),
|
fields.baseURL = params.baseURL;
|
||||||
fields = {},
|
fields.duration = params.duration * 1;
|
||||||
resp = '',
|
|
||||||
result = { tags: {} };
|
if (isNaN(fields.eventId)) {
|
||||||
|
throw '[MailGraph Webhook] Invalid event ID? Integer required (use actual event ID from Zabbix!)';
|
||||||
// Set HTTP proxy if required
|
}
|
||||||
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') { req.setProxy(params.HTTPProxy); }
|
|
||||||
|
if (isNaN(fields.duration)) {
|
||||||
// Declare output type
|
throw '[MailGraph Webhook] Invalid duration? Integer required (set to zero if unknown)!';
|
||||||
req.AddHeader('Content-Type: application/json');
|
}
|
||||||
|
|
||||||
// Must have fields
|
if (fields.recipient.charAt(0) == '{') {
|
||||||
fields.itemId = params.itemId;
|
throw '[MailGraph Webhook] Please define recipient for the test message!';
|
||||||
fields.triggerId = params.triggerId;
|
}
|
||||||
fields.eventId = params.eventId;
|
|
||||||
fields.eventValue = params.eventValue;
|
// Optional fields
|
||||||
fields.recipient = params.recipient;
|
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
|
||||||
fields.baseURL = params.baseURL;
|
if (typeof params.graphHeight === 'string') { fields.graphHeight = params.graphHeight; }
|
||||||
fields.duration = params.duration;
|
if (typeof params.subject === 'string') { fields.subject = params.subject; }
|
||||||
|
if (typeof params.showLegend === 'string') { fields.showLegend = params.showLegend; }
|
||||||
// Optional fields
|
if (typeof params.periods === 'string') { fields.periods = params.periods; }
|
||||||
if (typeof params.graphWidth === 'string') { fields.graphWidth = params.graphWidth; }
|
if (typeof params.periods_headers === 'string') { fields.periods_headers = params.periods_headers; }
|
||||||
if (typeof params.graphHeight === 'string') { fields.graphHeight = params.graphHeight; }
|
if (typeof params.debug === 'string') { fields.debug = params.debug; }
|
||||||
if (typeof params.subject === 'string') { fields.subject = params.subject; }
|
|
||||||
if (typeof params.showLegend === 'string') { fields.showLegend = params.showLegend; }
|
// Add generic fields
|
||||||
if (typeof params.periods === 'string') { fields.periods = params.periods; }
|
Object.keys(params).forEach(function(key) {
|
||||||
if (typeof params.periods_headers === 'string') { fields.periods_headers = params.periods_headers; }
|
if (key.substring(0, 4) == 'info') {
|
||||||
if (typeof params.debug === 'string') { fields.debug = params.debug; }
|
fields[key] = params[key];
|
||||||
|
}
|
||||||
// Add generic fields
|
});
|
||||||
Object.keys(params).forEach(function(key) {
|
|
||||||
if (key.substring(0, 4) == 'info') {
|
// Post information to the processing script
|
||||||
fields[key] = params[key];
|
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);
|
||||||
|
|
||||||
// Post information to the processing script
|
// If blank the email address is likely incorrect
|
||||||
Zabbix.Log(4, '[MailGraph Webhook] Sending request: ' + params.URL + '?' + JSON.stringify(fields));
|
if (resp==null) {
|
||||||
var resp = req.Post(params.URL,JSON.stringify(fields));
|
throw '[MailGraph Webhook] No data received from mailGraph! Likely the email processing failed? Check mailGraph logging';
|
||||||
Zabbix.Log(4, '[Mailgraph Webhook] Receiving response:' + resp);
|
}
|
||||||
|
|
||||||
// If there was an error, report it
|
// If there was an error, report it and stop
|
||||||
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
|
// If no datas returned, report it and stop
|
||||||
resp = JSON.parse(resp);
|
if (resp.charAt(0) == "!") {
|
||||||
result.tags.__message_id = resp.messageId;
|
throw '[MailGraph Webhook] No data received from mailGraph! Likely the event ID provided does not exist? Check mailGraph logging';
|
||||||
|
}
|
||||||
// Pass the result back to Zabbix
|
|
||||||
return JSON.stringify(result);
|
// We expect the message id back from the processing script
|
||||||
}
|
msg = JSON.parse(resp);
|
||||||
catch (error)
|
|
||||||
{
|
result.tags.__message_id = msg.messageId;
|
||||||
// In case something went wrong in the processing, pass the error back to Zabbix
|
Zabbix.Log(4, '[MailGraph Webhook] Message sent with identification "' + msg.messageId + '"');
|
||||||
Zabbix.Log(127, 'MailGraph notification failed : '+error);
|
|
||||||
throw 'MailGraph notification failed : '+error;
|
// Pass the result back to Zabbix
|
||||||
}</script>
|
return JSON.stringify(result);
|
||||||
<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.
|
catch (error)
|
||||||
|
{
|
||||||
Customization:
|
// In case something went wrong in the processing, pass the error back to Zabbix
|
||||||
- "graphWidth" and "graphWidth" can be defined for the image size
|
Zabbix.Log(127, 'MailGraph notification failed: '+error);
|
||||||
- "showLegend" can be defined to show or hide the legend of the graph
|
throw 'MailGraph notification failed : '+error;
|
||||||
- "subject" can be defined for a customized subject for the mail message
|
}
|
||||||
|
process_tags: 'YES'
|
||||||
The html.template and plain.template files can be adjusted (TWIG format).
|
description: |
|
||||||
|
The "URL" must point to the location of the processing script. If a proxy is required, define "HTTPProxy" for the proxy address.
|
||||||
More details are available at https://github.com/moudsen/mailGraph</description>
|
|
||||||
<message_templates>
|
Customization:
|
||||||
<message_template>
|
- "graphWidth" and "graphWidth" can be defined for the image size
|
||||||
<event_source>TRIGGERS</event_source>
|
- "showLegend" can be defined to show or hide the legend of the graph
|
||||||
<operation_mode>PROBLEM</operation_mode>
|
- "subject" can be defined for a customized subject for the mail message
|
||||||
<subject>Problem: {EVENT.NAME}</subject>
|
- "periods" and "periods_headers" can be defined for displaying multiple periods of the same graph, or
|
||||||
<message>Problem started at {EVENT.TIME} on {EVENT.DATE}
|
- "period" and "period_header" can be defined to display a single graph
|
||||||
Problem name: {EVENT.NAME}
|
|
||||||
Host: {HOST.NAME}
|
The html.template and plain.template files can be adjusted (TWIG format).
|
||||||
Severity: {EVENT.SEVERITY}
|
|
||||||
Operational data: {EVENT.OPDATA}
|
More details are available at https://github.com/moudsen/mailGraph
|
||||||
Original problem ID: {EVENT.ID}
|
message_templates:
|
||||||
{TRIGGER.URL}
|
-
|
||||||
|
event_source: TRIGGERS
|
||||||
eventId: {EVENT.ID}
|
operation_mode: PROBLEM
|
||||||
TriggerId: {TRIGGER.ID}
|
subject: 'Problem: {EVENT.NAME}'
|
||||||
itemId: {ITEM.ID]</message>
|
message: |
|
||||||
</message_template>
|
Problem started at {EVENT.TIME} on {EVENT.DATE}
|
||||||
<message_template>
|
Problem name: {EVENT.NAME}
|
||||||
<event_source>TRIGGERS</event_source>
|
Host: {HOST.NAME}
|
||||||
<operation_mode>RECOVERY</operation_mode>
|
Severity: {EVENT.SEVERITY}
|
||||||
<subject>Resolved in {EVENT.DURATION}: {EVENT.NAME}</subject>
|
Operational data: {EVENT.OPDATA}
|
||||||
<message>Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
|
Original problem ID: {EVENT.ID}
|
||||||
Problem name: {EVENT.NAME}
|
{TRIGGER.URL}
|
||||||
Problem duration: {EVENT.DURATION}
|
|
||||||
Host: {HOST.NAME}
|
eventId: {EVENT.ID}
|
||||||
Severity: {EVENT.SEVERITY}
|
TriggerId: {TRIGGER.ID}
|
||||||
Original problem ID: {EVENT.ID}
|
itemId: {ITEM.ID]
|
||||||
{TRIGGER.URL}
|
-
|
||||||
|
event_source: TRIGGERS
|
||||||
eventId: {EVENT.ID}
|
operation_mode: RECOVERY
|
||||||
TriggerId: {TRIGGER.ID}
|
subject: 'Resolved in {EVENT.DURATION}: {EVENT.RECOVERY.NAME}'
|
||||||
itemId: {ITEM.ID]</message>
|
message: |
|
||||||
</message_template>
|
Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
|
||||||
<message_template>
|
Problem name: {EVENT.RECOVERY.NAME}
|
||||||
<event_source>TRIGGERS</event_source>
|
Problem duration: {EVENT.DURATION}
|
||||||
<operation_mode>UPDATE</operation_mode>
|
Host: {HOST.NAME}
|
||||||
<subject>Updated problem in {EVENT.AGE}: {EVENT.NAME}</subject>
|
Severity: {EVENT.SEVERITY}
|
||||||
<message>{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
|
Original problem ID: {EVENT.ID}
|
||||||
{EVENT.UPDATE.MESSAGE}
|
{TRIGGER.URL}
|
||||||
|
|
||||||
Current problem status is {EVENT.STATUS}, age is {EVENT.AGE}, acknowledged: {EVENT.ACK.STATUS}.
|
eventId: {EVENT.ID}
|
||||||
|
TriggerId: {TRIGGER.ID}
|
||||||
eventId: {EVENT.ID}
|
itemId: {ITEM.ID]
|
||||||
TriggerId: {TRIGGER.ID}
|
-
|
||||||
itemId: {ITEM.ID]</message>
|
event_source: TRIGGERS
|
||||||
</message_template>
|
operation_mode: UPDATE
|
||||||
</message_templates>
|
subject: 'Updated problem in {EVENT.AGE}: {EVENT.NAME}'
|
||||||
</media_type>
|
message: |
|
||||||
</media_types>
|
{USER.FULLNAME} {EVENT.UPDATE.ACTION} problem at {EVENT.UPDATE.DATE} {EVENT.UPDATE.TIME}.
|
||||||
</zabbix_export>
|
{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]
|
||||||
|
|
||||||
|
|||||||
@@ -114,49 +114,6 @@
|
|||||||
</table>
|
</table>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% if GRAPH_CID1|length > 0 %}
|
|
||||||
<tr>
|
|
||||||
<div align=justify>
|
|
||||||
<td align="center">
|
|
||||||
<span class="graphHeader">{{ GRAPH_HEADER1 }}</span><br/>
|
|
||||||
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID1 }}" />
|
|
||||||
</td>
|
|
||||||
</div>
|
|
||||||
</tr>
|
|
||||||
{% endif %}
|
|
||||||
{% if GRAPH_CID2|length > 0 %}
|
|
||||||
<tr>
|
|
||||||
<div align=justify>
|
|
||||||
<td align="center">
|
|
||||||
<hr/>
|
|
||||||
<span class="graphHeader">{{ GRAPH_HEADER2 }}</span><br/>
|
|
||||||
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID2 }}" />
|
|
||||||
</td>
|
|
||||||
</div>
|
|
||||||
</tr>
|
|
||||||
{% endif %}
|
|
||||||
{% if GRAPH_CID3|length > 0 %}
|
|
||||||
<tr>
|
|
||||||
<div align=justify>
|
|
||||||
<td align="center">
|
|
||||||
<hr/>
|
|
||||||
<span class="graphHeader">{{ GRAPH_HEADER3 }}</span><br/>
|
|
||||||
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID3 }}" />
|
|
||||||
</td>
|
|
||||||
</div>
|
|
||||||
</tr>
|
|
||||||
{% endif %}
|
|
||||||
{% if GRAPH_CID4|length > 0 %}
|
|
||||||
<tr>
|
|
||||||
<div align=justify>
|
|
||||||
<td align="center">
|
|
||||||
<hr/>
|
|
||||||
<span class="graphHeader">{{ GRAPH_HEADER4 }}</span><br/>
|
|
||||||
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID4 }}" />
|
|
||||||
</td>
|
|
||||||
</div>
|
|
||||||
</tr>
|
|
||||||
{% endif %}
|
|
||||||
<tr>
|
<tr>
|
||||||
<td class="links">
|
<td class="links">
|
||||||
<div align=center>
|
<div align=center>
|
||||||
@@ -170,6 +127,66 @@
|
|||||||
</div>
|
</div>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
{% for aGraph in GRAPHS_I %}
|
||||||
|
<tr>
|
||||||
|
<div align=justify>
|
||||||
|
<td align="center">
|
||||||
|
<span class="graphHeader">{{ aGraph.HEADER }}</span><br/>
|
||||||
|
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ aGraph.CID }}" />
|
||||||
|
</td>
|
||||||
|
</div>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% if TRIGGER_SCREEN > 0 %}
|
||||||
|
<tr>
|
||||||
|
<div align=justify>
|
||||||
|
<td align="center">
|
||||||
|
<span class="graphHeader">{{ GRAPHS_T_HEADER }} - {{ GRAPHS_T_PERIODHEADER }}</span>
|
||||||
|
</td>
|
||||||
|
</div>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="links">
|
||||||
|
<div align="center">
|
||||||
|
Screen ID: <a href="{{ GRAPHS_T_LINK }}">{{ TRIGGER_SCREEN }}</a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% for aGraph in GRAPHS_T %}
|
||||||
|
<tr>
|
||||||
|
<div align=justify>
|
||||||
|
<td align="center">
|
||||||
|
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ aGraph.CID }}" />
|
||||||
|
</td>
|
||||||
|
</div>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
|
{% if HOST_SCREEN > 0 %}
|
||||||
|
<tr>
|
||||||
|
<div align=justify>
|
||||||
|
<td align="center">
|
||||||
|
<span class="graphHeader">{{ GRAPHS_H_HEADER }} - {{ GRAPHS_H_PERIODHEADER }}</span>
|
||||||
|
</td>
|
||||||
|
</div>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td class="links">
|
||||||
|
<div align="center">
|
||||||
|
Screen ID: <a href="{{ GRAPHS_H_LINK }}">{{ HOST_SCREEN }}</a>
|
||||||
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
{% for aGraph in GRAPHS_H %}
|
||||||
|
<tr>
|
||||||
|
<div align=justify>
|
||||||
|
<td align="center">
|
||||||
|
<img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ aGraph.CID }}" />
|
||||||
|
</td>
|
||||||
|
</div>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
Reference in New Issue
Block a user