mirror of
https://github.com/moudsen/mailGraph
synced 2025-10-28 16:17:39 +01:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
97dba8f197 | ||
|
|
288b0adaf7 | ||
|
|
2859d427f7 | ||
|
|
0cd169a9d2 | ||
|
|
8269195795 | ||
|
|
6da6da77fb | ||
|
|
00a67cbb65 | ||
|
|
bf970029ea | ||
|
|
9f3bfb5c69 | ||
|
|
504422f452 |
21
README.md
21
README.md
@@ -20,6 +20,21 @@ More information can be found in the Wiki.
|
||||
## Installation ##
|
||||
Please refer to the Wiki how to get mailGraph installed and configured on your system.
|
||||
|
||||
## mailGraph v2.14 release ##
|
||||
_(2023/07/10)_
|
||||
|
||||
_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
|
||||
- Adding the ability to define FROM details for the emails generated by mailGraph
|
||||
- `smtp_from_address` to set the from mail address (if not set uses mailing system default). Note: obsolete `mail_from` but retained for backwards compatibility.
|
||||
- `smtp_from_name` to set the name that goes with the mail address (if not set uses "mailGraph").
|
||||
- Adding the ability to define REPLY_TO details for the emails generated by mailGraph
|
||||
- `smtp_reply_address` to set the reply-to mail address (if not set, no reply-to will be added to the message).
|
||||
- `smtp_reply_name` to set the reply-to name of the mailbox (if not set defaults to "mailGraph feedback").
|
||||
- Adding a new URL for use in the template:
|
||||
- `ACK_URL` points to the function in Zabbix for editing and submitting an Acknowledge statement.
|
||||
|
||||
## mailGraph v2.13 release ##
|
||||
_(2023/07/03)_
|
||||
|
||||
@@ -43,6 +58,12 @@ Release notes
|
||||
- Addressed any PHP message (deprecation or error) - mailGraph debug output is now "clean" in PHP 7.4.x and PHP 8.2.x
|
||||
- Increased maximum number of graphs from 4 to 8
|
||||
|
||||
**Please consider to move to PHPMailer as soon as possible as Swiftmailer is abandoned. Installation instructions are included on the wiki.**
|
||||
|
||||
Principal approach: `composer require phpmailer/phpmailer`, install mailGraph v2.12 or higher.
|
||||
|
||||
In case Swiftmailer is no longer used elsewhere you can consider to remove this package with `swiftmailer/swiftmailer`.
|
||||
|
||||
## mailGraph v2.11 release ##
|
||||
_(2023/07/01)_
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
{
|
||||
"script_baseurl": "https:\/\/mydomain.com\/",
|
||||
"cli_itemId": 0,
|
||||
"cli_triggerId": 0,
|
||||
"cli_eventId": 0,
|
||||
"cli_duration": 0,
|
||||
"cli_recipient": "recipient@mydomain.com",
|
||||
@@ -15,14 +13,19 @@
|
||||
"zabbix_user_pwd": "astrongpassword",
|
||||
"zabbix_api_user": "alogicalusername",
|
||||
"zabbix_api_pwd": "astrongpassword",
|
||||
"mail_from": "sender@mydomain.com",
|
||||
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
||||
"smtp_server": "localhost",
|
||||
"smtp_port": 25,
|
||||
"smtp_transport": "none",
|
||||
"smtp_from_address": "mailgraph@mydomain.com",
|
||||
"smtp_from_name": "mailGraph",
|
||||
"smtp_reply_address": "feedback@mydomain.com",
|
||||
"smtp_from_name": "mailGraph response mailbox",
|
||||
"smtp_strict": "yes",
|
||||
"graph_match": "any",
|
||||
"period": "20m",
|
||||
"period_header": "Last 20 minutes",
|
||||
"retention_images": 7,
|
||||
"retention_logs": 14,
|
||||
"debug": 0
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
{
|
||||
"script_baseurl": "https:\/\/mydomain.com\/",
|
||||
"cli_itemId": 0,
|
||||
"cli_triggerId": 0,
|
||||
"cli_eventId": 0,
|
||||
"cli_duration": 0,
|
||||
"cli_recipient": "recipient@mydomain.com",
|
||||
@@ -15,12 +13,15 @@
|
||||
"zabbix_user_pwd": "astrongpassword",
|
||||
"zabbix_api_user": "alogicalusername",
|
||||
"zabbix_api_pwd": "astrongpassword",
|
||||
"mail_from": "sender@mydomain.com",
|
||||
"subject": "{{ HOST_NAME|raw }}: ({{ EVENT_SEVERITY }}) {{ EVENT_NAME|raw }}",
|
||||
"smtp_server": "localhost",
|
||||
"smtp_port": 25,
|
||||
"smtp_transport": "none",
|
||||
"smtp_strict": "yes",
|
||||
"smtp_from_address": "mailgraph@mydomain.com",
|
||||
"smtp_from_name": "mailGraph",
|
||||
"smtp_reply_address": "feedback@mydomain.com",
|
||||
"smtp_from_name": "mailGraph response mailbox",
|
||||
"graph_match": "any",
|
||||
"periods": "10m,4h,2d,7d",
|
||||
"periods_headers": "Last 10 minutes,Last 4 hours,Last 2 days,Last 7 days",
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// mailGraph v2.13
|
||||
// mailGraph v2.14
|
||||
try {
|
||||
// Pickup parameters
|
||||
params = JSON.parse(value),
|
||||
@@ -16,7 +16,7 @@ try {
|
||||
// Declare output type
|
||||
req.addHeader('Content-Type: application/json');
|
||||
|
||||
// Must have fields
|
||||
// Pick up fields relevant for mailGraph API level call
|
||||
fields.itemId = params.itemId * 1;
|
||||
fields.eventId = params.eventId * 1;
|
||||
fields.recipient = params.recipient;
|
||||
|
||||
103
mailGraph.php
103
mailGraph.php
@@ -53,6 +53,11 @@
|
||||
// Added ability to locate latest problems for testing purposes
|
||||
// 2.12 2023/07/02 - Mark Oudsen - Replaced SwiftMailer with PHPMailer (based on AutoTLS)
|
||||
// 2.13 2023/07/03 - Mark Oudsen - Bugfixes speciifally on links into Zabbix (missing context or info)
|
||||
// 2.14 2023/07/10 - Mark Oudsen - Adding ability to set 'From' and 'ReplyTo' addresses in configuration
|
||||
// Adding ACK_URL for utilization in the template to point to Ack page
|
||||
// Small refactor on itemId variable processing (no longer mandatory)
|
||||
// Additional logic added to random eventId to explain in case of issues
|
||||
// Fixed missing flag for fetching web url related items
|
||||
// ------------------------------------------------------------------------------------------------------
|
||||
//
|
||||
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
||||
@@ -87,7 +92,7 @@
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
// CONSTANTS
|
||||
$cVersion = 'v2.13';
|
||||
$cVersion = 'v2.14';
|
||||
$cCRLF = chr(10).chr(13);
|
||||
$maskDateTime = 'Y-m-d H:i:s';
|
||||
$maxGraphs = 8;
|
||||
@@ -488,16 +493,17 @@
|
||||
_log('<<< mailGraph '.$cVersion.' >>>');
|
||||
_log('# Invoked from CLI');
|
||||
|
||||
// Assumes that config.json file has the correct information
|
||||
// Assumes that config.json file has the correct information for MANDATORY information
|
||||
|
||||
// MANDATORY
|
||||
$problemData['itemId'] = $config['cli_itemId'];
|
||||
$problemData['eventId'] = $config['cli_eventId'];
|
||||
$problemData['eventId'] = 0;
|
||||
|
||||
$problemData['recipient'] = $config['cli_recipient'];
|
||||
$problemData['baseURL'] = $config['cli_baseURL'];
|
||||
$problemData['duration'] = $config['cli_duration'];
|
||||
|
||||
// OPTIONAL
|
||||
if (isset($config['cli_eventId'])) { $problemData['eventId'] = $config['cli_eventId']; }
|
||||
if (isset($config['cli_subject'])) { $problemData['subject'] = $config['cli_subject']; }
|
||||
if (isset($config['cli_period'])) { $problemData['period'] = $config['cli_period']; }
|
||||
if (isset($config['cli_period_header'])) { $problemData['period_header'] = $config['cli_period_header']; }
|
||||
@@ -505,6 +511,10 @@
|
||||
if (isset($config['cli_periods_headers'])) { $problemData['periods_headers'] = $config['cli_periods_headers']; }
|
||||
if (isset($config['cli_debug'])) { $problemData['debug'] = $config['cli_debug']; }
|
||||
if (isset($config['cli_proxy'])) { $problemData['HTTPProxy'] = $config['cli_proxy']; }
|
||||
|
||||
// BACKWARDS COMPATIBILITY - obsolete from Zabbix 6.2 onwards
|
||||
$problemData['itemId'] = 0;
|
||||
if (isset($config['cli_itemId'])) { $problemData['itemId'] = $config['cli_itemId']; }
|
||||
}
|
||||
|
||||
if (($argc>1) && ($argv[1]=='cleanup'))
|
||||
@@ -592,6 +602,27 @@
|
||||
$p_smtp_password = '';
|
||||
if (isset($config['smtp_password'])) { $p_smtp_password = $config['smtp_password']; }
|
||||
|
||||
$p_smtp_from_address = '';
|
||||
if (isset($config['smtp_from_address'])) { $p_smtp_from_address = $config['smtp_from_address']; }
|
||||
|
||||
$p_smtp_from_name = 'mailGraph';
|
||||
if (isset($config['smtp_from_name'])) { $p_smtp_from_name = $config['smtp_from_name']; }
|
||||
|
||||
$p_smtp_reply_address = '';
|
||||
if (isset($config['smtp_reply_address'])) { $p_smtp_reply_address = $config['smtp_reply_address']; }
|
||||
|
||||
$p_smtp_reply_name = 'mailGraph feedback';
|
||||
if (isset($config['smtp_reply_name'])) { $p_smtp_reply_name = $config['smtp_reply_name']; }
|
||||
|
||||
// >>> Backwards compatibility but smtp_from_address is leading (<v2.14)
|
||||
$mailFrom = '';
|
||||
if (isset($config['mail_from'])) { $mailFrom = $config['mail_from']; }
|
||||
|
||||
if (($p_smtp_from_address=='') && ($mailFrom!=''))
|
||||
{
|
||||
$p_smtp_from_address = $mailFrom;
|
||||
}
|
||||
|
||||
$p_graph_match = 'any';
|
||||
if ((isset($config['graph_match'])) && ($config['graph_match']=='exact')) { $p_graph_match = 'exact'; }
|
||||
|
||||
@@ -608,6 +639,19 @@
|
||||
$z_tmp_cookies = $z_path.'tmp/';
|
||||
$z_log_path = $z_path.'log/';
|
||||
|
||||
// If tmp or log does not exist, create them
|
||||
if (!is_dir($z_tmp_cookies))
|
||||
{
|
||||
mkdir($z_tmp_cookies);
|
||||
_log('+ created TMP directory "'.$z_tmp_cookies.'"');
|
||||
}
|
||||
|
||||
if (!is_dir($z_log_path))
|
||||
{
|
||||
mkdir($z_log_path);
|
||||
_log('+ created LOG directory "'.$z_log_path.'"');
|
||||
}
|
||||
|
||||
// Zabbix user (requires Super Admin access rights to access image generator script)
|
||||
$z_user = $config['zabbix_user'];
|
||||
$z_pass = $config['zabbix_user_pwd'];
|
||||
@@ -628,9 +672,6 @@
|
||||
$z_api_pass = $config['zabbix_api_pwd'];
|
||||
}
|
||||
|
||||
// Mail sender
|
||||
$mailFrom = $config['mail_from'];
|
||||
|
||||
// Derived variables - do not change!
|
||||
$z_server = $p_URL; // Zabbix server URL from config
|
||||
$z_url_api = $z_server ."api_jsonrpc.php"; // Zabbix API URL
|
||||
@@ -716,9 +757,29 @@
|
||||
'id'=>nextRequestID());
|
||||
|
||||
$thisProblems = postJSON($z_url_api, $request);
|
||||
_log('> Problem data'.$cCRLF.json_encode($thisProblems,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
|
||||
_log('> Problem data (recent)'.$cCRLF.json_encode($thisProblems,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
|
||||
|
||||
if (!isset($thisProblems['result'][0])) { echo '! No response data received?'.$cCRLF; die; }
|
||||
if (!isset($thisProblems['result'][0]))
|
||||
{
|
||||
_log('- No response data received. Retrying with less recent problems ... ');
|
||||
|
||||
$request = array('jsonrpc'=>'2.0',
|
||||
'method'=>'problem.get',
|
||||
'params'=>array('output'=>'extend',
|
||||
'recent'=>'false',
|
||||
'limit'=>1),
|
||||
'auth'=>$token,
|
||||
'id'=>nextRequestID());
|
||||
|
||||
$thisProblems = postJSON($z_url_api, $request);
|
||||
_log('> Problem data (not recent)'.$cCRLF.json_encode($thisProblems,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
|
||||
|
||||
if (!isset($thisProblems['result'][0]))
|
||||
{
|
||||
_log('! Cannot continue: mailGraph is unable to pick a random event via the Zabbix API. It is highly likely that no active problems exist? Please retry or determine and set an event ID manually and retry.');
|
||||
die;
|
||||
}
|
||||
}
|
||||
|
||||
$p_eventId = $thisProblems['result'][0]['eventid'];
|
||||
_log('> Picked up random last event #'.$p_eventId);
|
||||
@@ -866,6 +927,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
// If no specific itemId is requested take the first item found on the items list from the host
|
||||
if (!isset($p_itemId))
|
||||
{
|
||||
foreach($thisTrigger['result'][0]['functions'] as $aFunction)
|
||||
@@ -885,7 +947,8 @@
|
||||
$request = array('jsonrpc'=>'2.0',
|
||||
'method'=>'item.get',
|
||||
'params'=>array('itemids'=>$p_itemId,
|
||||
'output'=>'extend'),
|
||||
'webitems'=>'true',
|
||||
'output'=>'extend'),
|
||||
'auth'=>$token,
|
||||
'id'=>nextRequestID());
|
||||
|
||||
@@ -1359,7 +1422,10 @@
|
||||
$mailData['LOG_HTML'] = str_replace($cCRLF,'<br/>',$mailData['LOG_HTML']);
|
||||
$mailData['LOG_HTML'] = str_replace('<br/>','<br/>'.$cCRLF,$mailData['LOG_HTML']);
|
||||
|
||||
$mailData['LOG_HTML'] = '<html lang="en"><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8">'.$cCRLF.
|
||||
$mailData['LOG_HTML'] = '<html lang="en"><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8"></head>'.$cCRLF.
|
||||
'<style type="text/css">'.$cCRLF.
|
||||
'body { font-family: courier, courier new, serif; font-size: 12px; }'.$cCRLF.
|
||||
'</style>'.$cCRLF.
|
||||
'<body>'.$cCRLF.
|
||||
$mailData['LOG_HTML'].$cCRLF.
|
||||
'</body>'.$cCRLF.
|
||||
@@ -1374,6 +1440,7 @@
|
||||
$mailData['TRIGGER_URL'] = $z_server.'triggers.php?form=update&triggerid='.$mailData['TRIGGER_ID'].'&context=host';
|
||||
$mailData['ITEM_URL'] = $z_server.'items.php?form=update&hostid='.$mailData['HOST_ID'].'&itemid='.$mailData['ITEM_ID'].'&context=host';
|
||||
$mailData['HOST_URL'] = $z_server.'hosts.php?form=update&hostid='.$mailData['HOST_ID'];
|
||||
$mailData['ACK_URL'] = $z_server.'zabbix.php?action=popup&popup_action=acknowledge.edit&eventids[]='.$mailData['EVENT_ID'];
|
||||
$mailData['EVENTDETAILS_URL'] = $z_server.'tr_events.php?triggerid='.$mailData['TRIGGER_ID'].'&eventid='.$mailData['EVENT_ID'];
|
||||
|
||||
$mailData['EVENT_DURATION'] = $p_duration;
|
||||
@@ -1411,8 +1478,18 @@
|
||||
];
|
||||
}
|
||||
|
||||
// --- Define from and recipient
|
||||
$mail->setFrom($mailFrom, 'mailGraph');
|
||||
// --- Define from
|
||||
$mail->Sender = $p_smtp_from_address;
|
||||
$mail->SetFrom($p_smtp_from_address, $p_smtp_from_name, FALSE);
|
||||
|
||||
// --- Define reply-to
|
||||
if ($p_smtp_reply_address!='')
|
||||
{
|
||||
$mail->clearReplyTos();
|
||||
$mail->addReplyTo($p_smtp_reply_address, $p_smtp_reply_name);
|
||||
}
|
||||
|
||||
// --- Add recipient
|
||||
$mail->addAddress($p_recipient);
|
||||
|
||||
// --- Prepare embedding of the graphs by attaching and generating "cid" (content-id) information
|
||||
|
||||
@@ -35,10 +35,6 @@
|
||||
<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>
|
||||
@@ -64,7 +60,7 @@
|
||||
<value>https://myzabbix.example.com/mailGraph.php</value>
|
||||
</parameter>
|
||||
</parameters>
|
||||
<script>// mailGraph v2.13
|
||||
<script>// mailGraph v2.14
|
||||
try {
|
||||
// Pickup parameters
|
||||
params = JSON.parse(value),
|
||||
@@ -82,7 +78,7 @@ try {
|
||||
// Declare output type
|
||||
req.addHeader('Content-Type: application/json');
|
||||
|
||||
// Must have fields
|
||||
// Pick up relevant fields for mailGraph API level call
|
||||
fields.itemId = params.itemId * 1;
|
||||
fields.eventId = params.eventId * 1;
|
||||
fields.recipient = params.recipient;
|
||||
|
||||
@@ -124,6 +124,7 @@
|
||||
{% if GRAPH_ZABBIXLINK|length > 0 %}
|
||||
// Graph ID: <a href="{{ GRAPH_ZABBIXLINK }}">{{ GRAPH_ID }}</a>
|
||||
{% endif %}
|
||||
// <a href="{{ ACK_URL }}">Ack</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@@ -189,4 +190,4 @@
|
||||
{% endif %}
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user