mirror of
https://github.com/moudsen/mailGraph
synced 2025-01-30 11:51:38 +01:00
v2.10 - Removed deprecated function dependencies
This commit is contained in:
parent
e80a2a56a3
commit
8bc476ed63
30
README.md
30
README.md
@ -1,4 +1,34 @@
|
||||
## 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
|
||||
|
||||
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.
|
||||
|
||||
## 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.
|
||||
|
@ -1,7 +1 @@
|
||||
As per the details captured in issue #32 the javascript code portion of this Media Type has changed due to a platform/library change at Zabbix side.
|
||||
A distinction is now made for the following Zabbix versions:
|
||||
|
||||
Zabbix <6.2 - use "zabbix.mailGraph.js"
|
||||
Zabbix >=6.2 - <coming soon>
|
||||
|
||||
Please make sure you install the right javascript in your environment!
|
||||
Issue #32 has been resolved. The javascript code now works for Zabbix 5.4, 6.0 LTS and 6.4.
|
||||
|
@ -1,19 +1,19 @@
|
||||
try {
|
||||
// Pickup parameters
|
||||
params = JSON.parse(value),
|
||||
req = new CurlHttpRequest(),
|
||||
req = new HttpRequest(),
|
||||
fields = {},
|
||||
resp = '',
|
||||
result = { tags: {} };
|
||||
|
||||
// Set HTTP proxy if required
|
||||
if (typeof params.HTTPProxy === 'string' && params.HTTPProxy.trim() !== '') {
|
||||
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');
|
||||
req.addHeader('Content-Type: application/json');
|
||||
|
||||
// Must have fields
|
||||
fields.itemId = params.itemId;
|
||||
@ -40,11 +40,11 @@ try {
|
||||
|
||||
// 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));
|
||||
var resp = req.post(params.URL,JSON.stringify(fields));
|
||||
Zabbix.Log(4, '[Mailgraph Webhook] Receiving response:' + resp);
|
||||
|
||||
// If there was an error, report it
|
||||
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
|
||||
resp = JSON.parse(resp);
|
||||
|
@ -8,6 +8,8 @@
|
||||
// upon an alert message.
|
||||
//
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
// Release 1 tested with Zabbix 5.4 and 6.0 LTS
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
// 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
|
||||
@ -40,10 +42,13 @@
|
||||
// 2021/07/05 - Mark Oudsen - Minor detail added: CLI debug mode now also outputs version
|
||||
// 2021/07/07 - Mark Oudsen - Fixed HTTPProxy typo in code (instead of HTTPPRoxy)
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
// Release 2 tested with Zabbix 5.4, 6.0 LTS and 6.4 - tested with latest Composer libraries
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
// 2.00 2021/12/16 - Mark Oudsen - itemId not always provisioned by Zabbix
|
||||
// Several fixes on warning - several small bug fixes
|
||||
// 2.01 2021/12/16 - Mark Oudsen - Screens are no longer available - reverting to using Dashboards now
|
||||
// 2.02 2022/01/30 - Mark Oudsen - Added cleanup routine for old logs and images
|
||||
// 2.10 2023/06/30 - Mark Oudsen - Refactored deprecated code - now compatible with Zabbix 6.4
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
||||
@ -65,7 +70,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CONSTANTS
|
||||
$cVersion = 'v2.020';
|
||||
$cVersion = 'v2.10';
|
||||
$cCRLF = chr(10).chr(13);
|
||||
$maskDateTime = 'Y-m-d H:i:s';
|
||||
$maxGraphs = 4;
|
||||
@ -515,7 +520,7 @@
|
||||
$p_eventId = intval($problemData['eventId']);
|
||||
|
||||
if (!isset($problemData['recipient'])) { echo "Missing RECIPIENT?\n"; die; }
|
||||
$p_recipient = $problemData['recipient'];
|
||||
$nt = $problemData['recipient'];
|
||||
|
||||
if (!isset($problemData['duration'])) { echo "Missing DURATION?\n"; die; }
|
||||
$p_duration = intval($problemData['duration']);
|
||||
@ -589,9 +594,19 @@
|
||||
$z_pass = $config['zabbix_user_pwd'];
|
||||
|
||||
// Zabbix API user (requires Super Admin access rights)
|
||||
// TODO: Check if information retreival can be done with less rigths
|
||||
$z_api_user = $config['zabbix_api_user'];
|
||||
$z_api_pass = $config['zabbix_api_pwd'];
|
||||
// --- Copy from Zabbix user and override when defined in configuration
|
||||
$z_api_user = $z_user;
|
||||
$z_api_pass = $z_pass;
|
||||
|
||||
if (isset($config['zabbix_api_user']))
|
||||
{
|
||||
$z_api_user = $config['zabbix_api_user'];
|
||||
}
|
||||
|
||||
if (isset($config['zabbix_api_pwd']))
|
||||
{
|
||||
$z_api_pass = $config['zabbix_api_pwd'];
|
||||
}
|
||||
|
||||
// Mail sender
|
||||
$mailFrom = array($config['mail_from']=>'Zabbix Mailgraph');
|
||||
@ -627,7 +642,7 @@
|
||||
|
||||
$request = array('jsonrpc'=>'2.0',
|
||||
'method'=>'user.login',
|
||||
'params'=>array('user'=>$z_api_user,
|
||||
'params'=>array('username'=>$z_api_user,
|
||||
'password'=>$z_api_pass),
|
||||
'id'=>nextRequestID(),
|
||||
'auth'=>null);
|
||||
@ -703,7 +718,7 @@
|
||||
'selectTags'=>'extend',
|
||||
'expandComment'=>1,
|
||||
'expandDescription'=>1,
|
||||
'expandExpression'=>1),
|
||||
'expandExpresion'=>1),
|
||||
'auth'=>$token,
|
||||
'id'=>nextRequestID());
|
||||
|
||||
@ -1015,7 +1030,7 @@
|
||||
else
|
||||
{
|
||||
$otherGraphs[] = $aGraph;
|
||||
_log('~ Graph #'.$aGraphItem['graphid'].' partial match found (item #'.$aGraphItem['itemid'].')');
|
||||
_log('~ Graph #'.$aGraphItem['graphid'].' partial match found (item #'.$GraphItem['itemid'].')');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
205
mailGraph.xml
205
mailGraph.xml
@ -1,12 +1,12 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<zabbix_export>
|
||||
<version>5.0</version>
|
||||
<date>2021-03-17T12:55:43Z</date>
|
||||
<version>6.0</version>
|
||||
<date>2023-06-29T23:22:52Z</date>
|
||||
<media_types>
|
||||
<media_type>
|
||||
<name>MailGraph</name>
|
||||
<type>WEBHOOK</type>
|
||||
<parameters>
|
||||
<parameters>
|
||||
<parameter>
|
||||
<name>baseURL</name>
|
||||
<value>https://mydomain.com/zabbix/</value>
|
||||
@ -64,124 +64,125 @@
|
||||
<value>https://mydomain.com/mailGraph.php</value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<script>try {
|
||||
// Pickup parameters
|
||||
params = JSON.parse(value),
|
||||
req = new CurlHttpRequest(),
|
||||
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;
|
||||
}
|
||||
|
||||
// Declare output type
|
||||
req.AddHeader('Content-Type: application/json');
|
||||
|
||||
// Must have fields
|
||||
fields.itemId = params.itemId;
|
||||
fields.eventId = params.eventId;
|
||||
fields.recipient = params.recipient;
|
||||
fields.baseURL = params.baseURL;
|
||||
fields.duration = params.duration;
|
||||
|
||||
// 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] Receiving response:' + resp);
|
||||
|
||||
// If there was an error, report it
|
||||
if (req.Status() != 200) { throw JSON.parse(resp).errors[0]; }
|
||||
|
||||
// We expect the message id back from the processing script
|
||||
resp = JSON.parse(resp);
|
||||
result.tags.__message_id = resp.messageId;
|
||||
|
||||
// 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>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;
|
||||
}
|
||||
|
||||
// Declare output type
|
||||
req.addHeader('Content-Type: application/json');
|
||||
|
||||
// Must have fields
|
||||
fields.itemId = params.itemId;
|
||||
fields.eventId = params.eventId;
|
||||
fields.recipient = params.recipient;
|
||||
fields.baseURL = params.baseURL;
|
||||
fields.duration = params.duration;
|
||||
|
||||
// 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] Receiving response:' + resp);
|
||||
|
||||
// If there was an error, report it
|
||||
if (req.getStatus() != 200) { throw JSON.parse(resp).errors[0]; }
|
||||
|
||||
// We expect the message id back from the processing script
|
||||
resp = JSON.parse(resp);
|
||||
result.tags.__message_id = resp.messageId;
|
||||
|
||||
// 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).
|
||||
|
||||
<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}
|
||||
<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.NAME}</subject>
|
||||
<message>Problem has been resolved at {EVENT.RECOVERY.TIME} on {EVENT.RECOVERY.DATE}
|
||||
Problem name: {EVENT.NAME}
|
||||
Problem duration: {EVENT.DURATION}
|
||||
Host: {HOST.NAME}
|
||||
Severity: {EVENT.SEVERITY}
|
||||
Original problem ID: {EVENT.ID}
|
||||
{TRIGGER.URL}
|
||||
|
||||
eventId: {EVENT.ID}
|
||||
TriggerId: {TRIGGER.ID}
|
||||
<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}
|
||||
<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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user