mirror of
https://github.com/moudsen/mailGraph
synced 2025-01-30 20:01:38 +01:00
Revised html template to be responsive. Leaving beta mode! (v1.20)
This commit is contained in:
parent
1a82a1ac85
commit
d624fa694d
@ -24,6 +24,7 @@
|
|||||||
// 1.18 2021/03/04 - Mark Oudsen - Added ability to specify Tags per trigger
|
// 1.18 2021/03/04 - Mark Oudsen - Added ability to specify Tags per trigger
|
||||||
// Shorten long "lastvalue" or "prevvalue"
|
// Shorten long "lastvalue" or "prevvalue"
|
||||||
// 1.19 2021/03/05 - Mark Oudsen - Added ability to pass Zabbix 'infoXXX' parameters for TWIG template
|
// 1.19 2021/03/05 - Mark Oudsen - Added ability to pass Zabbix 'infoXXX' parameters for TWIG template
|
||||||
|
// 1.20 2021/03/07 - Mark Oudsen - Production level version - leaving BETA from here on ...
|
||||||
// ------------------------------------------------------------------------------------------------------
|
// ------------------------------------------------------------------------------------------------------
|
||||||
//
|
//
|
||||||
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
// (C) M.J.Oudsen, mark.oudsen@puzzl.nl
|
||||||
@ -46,16 +47,16 @@
|
|||||||
|
|
||||||
// CONSTANTS
|
// CONSTANTS
|
||||||
|
|
||||||
$cVersion = 'v1.19';
|
$cVersion = 'v1.20';
|
||||||
$cCRLF = chr(10).chr(13);
|
$cCRLF = chr(10).chr(13);
|
||||||
$maskDateTime = 'Y-m-d H:i:s';
|
$maskDateTime = 'Y-m-d H:i:s';
|
||||||
|
|
||||||
// DEBUG SETTINGS
|
// DEBUG SETTINGS
|
||||||
// -- Should be FALSE for production level use
|
// -- Should be FALSE for production level use
|
||||||
|
|
||||||
$cDebug = TRUE; // Comprehensive debug logging including log storage
|
$cDebug = FALSE; // Extended debug logging mode
|
||||||
$cDebugMail = TRUE; // Include log in the mail message? (attachments)
|
$cDebugMail = FALSE; // If TRUE, includes log in the mail message (html and plain text attachments)
|
||||||
$showLog = FALSE; // Display the log - !! switch to TRUE when performing CLI debugging only !!!
|
$showLog = FALSE; // Display the log - !!! only use in combination with CLI mode !!!
|
||||||
|
|
||||||
// INCLUDE REQUIRED LIBRARIES (Composer)
|
// INCLUDE REQUIRED LIBRARIES (Composer)
|
||||||
// (configure at same location as the script is running or load in your own central library)
|
// (configure at same location as the script is running or load in your own central library)
|
||||||
@ -94,7 +95,8 @@
|
|||||||
curl_setopt($ch, CURLOPT_URL, $url);
|
curl_setopt($ch, CURLOPT_URL, $url);
|
||||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
|
||||||
curl_setopt($ch, CURLOPT_POST, TRUE);
|
curl_setopt($ch, CURLOPT_POST, TRUE);
|
||||||
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
|
curl_setopt($ch, CURLOPT_POSTFIELDS,
|
||||||
|
json_encode($data,JSON_PRETTY_PRINT|JSON_NUMERIC_CHECK));
|
||||||
|
|
||||||
// Execute Curl
|
// Execute Curl
|
||||||
$data = curl_exec($ch);
|
$data = curl_exec($ch);
|
||||||
@ -107,11 +109,11 @@
|
|||||||
$data .= 'Requested page = '.$url.$cCRLF;
|
$data .= 'Requested page = '.$url.$cCRLF;
|
||||||
$data .= 'Error = '.curl_error($ch).$cCRLF;
|
$data .= 'Error = '.curl_error($ch).$cCRLF;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
_log('> Received '.strlen($data).' bytes');
|
_log('> Received '.strlen($data).' bytes');
|
||||||
$data = json_decode($data,TRUE);
|
$data = json_decode($data,TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Close Curl
|
// Close Curl
|
||||||
curl_close($ch);
|
curl_close($ch);
|
||||||
@ -418,10 +420,10 @@
|
|||||||
|
|
||||||
// Absolute path where to store the generated images - note: script does not take care of clearing out old images!
|
// Absolute path where to store the generated images - note: script does not take care of clearing out old images!
|
||||||
$z_path = getcwd().'/'; // Absolute base path on the filesystem for this url
|
$z_path = getcwd().'/'; // Absolute base path on the filesystem for this url
|
||||||
$z_images_path = $z_path.'/images/';
|
$z_images_path = $z_path.'images/';
|
||||||
$z_template_path = $z_path.'/templates/';
|
$z_template_path = $z_path.'templates/';
|
||||||
$z_tmp_cookies = $z_path.'//tmp/';
|
$z_tmp_cookies = $z_path.'tmp/';
|
||||||
$z_log_path = $z_path.'/log/';
|
$z_log_path = $z_path.'log/';
|
||||||
|
|
||||||
// Zabbix user (requires Super Admin access rights to access image generator script)
|
// Zabbix user (requires Super Admin access rights to access image generator script)
|
||||||
$z_user = $config['zabbix_user'];
|
$z_user = $config['zabbix_user'];
|
||||||
@ -608,6 +610,7 @@
|
|||||||
|
|
||||||
// --- GET GRAPHS ASSOCIATED WITH THIS HOST ---
|
// --- GET GRAPHS ASSOCIATED WITH THIS HOST ---
|
||||||
// Note: graph.get where itemids are specified does not seem to work!
|
// Note: graph.get where itemids are specified does not seem to work!
|
||||||
|
// https://support.zabbix.com/browse/ZBX-19090
|
||||||
|
|
||||||
_log('# Retrieve associated graphs to this HOST');
|
_log('# Retrieve associated graphs to this HOST');
|
||||||
|
|
||||||
@ -778,7 +781,7 @@
|
|||||||
_log('> Filename = '.$graphFile);
|
_log('> Filename = '.$graphFile);
|
||||||
|
|
||||||
$mailData['GRAPH_URL'] = $z_url_image . $graphFile;
|
$mailData['GRAPH_URL'] = $z_url_image . $graphFile;
|
||||||
$mailData['GRAPH_ZABBIXLINK'] = $z_server.'/graphs.php?form=update&graphid='.$mailData['GRAPH_ID'];
|
$mailData['GRAPH_ZABBIXLINK'] = $z_server.'graphs.php?form=update&graphid='.$mailData['GRAPH_ID'];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prepare HTML LOG content
|
// Prepare HTML LOG content
|
||||||
@ -799,10 +802,10 @@
|
|||||||
|
|
||||||
// Prepare others
|
// Prepare others
|
||||||
|
|
||||||
$mailData['TRIGGER_URL'] = $z_server.'/triggers.php?form=update&triggerid='.$mailData['TRIGGER_ID'];
|
$mailData['TRIGGER_URL'] = $z_server.'triggers.php?form=update&triggerid='.$mailData['TRIGGER_ID'];
|
||||||
$mailData['ITEM_URL'] = $z_server.'/items.php?form=update&hostid='.$mailData['HOST_ID'].'&itemid='.$mailData['ITEM_ID'];
|
$mailData['ITEM_URL'] = $z_server.'items.php?form=update&hostid='.$mailData['HOST_ID'].'&itemid='.$mailData['ITEM_ID'];
|
||||||
$mailData['HOST_URL'] = $z_server.'/zabbix/hosts.php?form=update&hostid='.$mailData['HOST_ID'];
|
$mailData['HOST_URL'] = $z_server.'hosts.php?form=update&hostid='.$mailData['HOST_ID'];
|
||||||
$mailData['EVENTDETAILS_URL'] = $z_server.'/tr_events.php?triggerid='.$mailData['TRIGGER_ID'].'&eventid='.$mailData['EVENT_ID'];
|
$mailData['EVENTDETAILS_URL'] = $z_server.'tr_events.php?triggerid='.$mailData['TRIGGER_ID'].'&eventid='.$mailData['EVENT_ID'];
|
||||||
|
|
||||||
$mailData['EVENT_DURATION'] = $p_duration;
|
$mailData['EVENT_DURATION'] = $p_duration;
|
||||||
|
|
||||||
@ -812,6 +815,8 @@
|
|||||||
|
|
||||||
_log('# Setting up mailer');
|
_log('# Setting up mailer');
|
||||||
|
|
||||||
|
// Do we need TLS or SSL?
|
||||||
|
|
||||||
if (($p_smtp_transport=='tls') || ($p_smtp_transport=='ssl'))
|
if (($p_smtp_transport=='tls') || ($p_smtp_transport=='ssl'))
|
||||||
{
|
{
|
||||||
$transport = (new Swift_SmtpTransport($p_smtp_server, $p_smtp_port, $p_smtp_transport));
|
$transport = (new Swift_SmtpTransport($p_smtp_server, $p_smtp_port, $p_smtp_transport));
|
||||||
@ -927,4 +932,4 @@
|
|||||||
file_put_contents($z_log_path.$logName,$content);
|
file_put_contents($z_log_path.$logName,$content);
|
||||||
_log('= Log stored to '.$z_log_path.$logName);
|
_log('= Log stored to '.$z_log_path.$logName);
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
@ -1,79 +1,129 @@
|
|||||||
<html lang="en"><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8">
|
<html lang="en"><head><meta http-equiv=Content-Type content="text/html; charset=UTF-8">
|
||||||
<style>
|
<style>
|
||||||
.Resolved {
|
body {
|
||||||
background-color:#86cc89;
|
font-family: Arial,sans-serif;
|
||||||
border:1px solid #57bd5b;
|
}
|
||||||
font-family:Tahoma,Geneva,Arial,sans-serif;font-size:14px;
|
.Resolved {
|
||||||
}
|
background-color:#86cc89;
|
||||||
.Information {
|
border:1px solid #57bd5b;
|
||||||
background-color:#7499ff;
|
}
|
||||||
border:1px solid #4673f0;
|
.Information {
|
||||||
font-family:Tahoma,Geneva,Arial,sans-serif;font-size:14px;
|
background-color:#7499ff;
|
||||||
}
|
border:1px solid #4673f0;
|
||||||
.Warning {
|
}
|
||||||
background-color:#FFC859;
|
.Warning {
|
||||||
border:1px solid #E69F10;
|
background-color:#FFC859;
|
||||||
font-family:Tahoma,Geneva,Arial,sans-serif;font-size:14px;
|
border:1px solid #E69F10;
|
||||||
}
|
}
|
||||||
.Average {
|
.Average {
|
||||||
background-color:#FFA059;
|
background-color:#FFA059;
|
||||||
border:1px solid #e66e15;
|
border:1px solid #e66e15;
|
||||||
font-family:Tahoma,Geneva,Arial,sans-serif;font-size:14px;
|
}
|
||||||
}
|
.High {
|
||||||
.High {
|
background-color:#E97659;
|
||||||
background-color:#E97659;
|
border:1px solid #E45959;
|
||||||
border:1px solid #E45959;
|
}
|
||||||
font-family:Tahoma,Geneva,Arial,sans-serif;font-size:14px;
|
.Disaster {
|
||||||
}
|
background-color:#E45959;
|
||||||
.Disaster {
|
border:1px solid #DE1E09;
|
||||||
background-color:#E45959;
|
}
|
||||||
border:1px solid #DE1E09;
|
a {
|
||||||
font-family:Tahoma,Geneva,Arial,sans-serif;font-size:14px;
|
text-decoration: none;
|
||||||
}
|
color: #010059;
|
||||||
|
}
|
||||||
|
a:link {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #010059;
|
||||||
|
}
|
||||||
|
a:visited {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #010059;
|
||||||
|
}
|
||||||
|
a:active {
|
||||||
|
text-decoration: none;
|
||||||
|
color: #010059;
|
||||||
|
}
|
||||||
|
.MsgBody {
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
#maintable {
|
||||||
|
width: 800px;
|
||||||
|
}
|
||||||
|
@media screen and (max-width: 800px;) {
|
||||||
|
#maintable {
|
||||||
|
width: 100%;
|
||||||
|
max-width: 790px;
|
||||||
|
}
|
||||||
|
#mainimage {
|
||||||
|
-ms-interpolation-mode: bicubic;
|
||||||
|
width: 100%;
|
||||||
|
max-width: 790px;
|
||||||
|
max-height: 450px;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.links {
|
||||||
|
font-size: 9px;
|
||||||
|
}
|
||||||
|
.header {
|
||||||
|
font-size: 16px;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
.content {
|
||||||
|
font-size: 14px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<table style="margin: 10px;border-spacing:0 15px;border-collapse: separate;">
|
<table style="margin: 5px;border-spacing:0 10px;border-collapse: separate;" align=center>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="{{ EVENT_SEVERITY }}" style="border-radius:10px;padding: 10px 36px 10px 36px; ">
|
<td class="{{ EVENT_SEVERITY }}" style="border-radius:10px;padding:5px 18px 5px 18px; ">
|
||||||
<table class="{{ EVENT_SEVERITY }}" style="border:0; text-align:left;" cellpadding="0" cellspacing="0">
|
<table class="{{ EVENT_SEVERITY }}" style="border:0; text-align:left;" cellpadding="0" cellspacing="0">
|
||||||
<tr><td>
|
<tr>
|
||||||
<p><b>EVENT INFORMATION</b></p>
|
<td>
|
||||||
Description: <b>{{ EVENT_NAME }}</b><br/>
|
<p><span class="header">EVENT INFORMATION</span></p>
|
||||||
Host: <b>{{ HOST_NAME }}</b>
|
<span class="content">
|
||||||
|
Description: <b>{{ EVENT_NAME }}</b><br/>
|
||||||
|
Host: <b>{{ HOST_NAME }}</b>
|
||||||
{% if HOST_ERROR|length > 0 %}
|
{% if HOST_ERROR|length > 0 %}
|
||||||
({{ HOST_ERROR }})
|
({{ HOST_ERROR }})
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br/>
|
<br/>
|
||||||
{% if EVENT_OPDATE|length > 0 %}
|
{% if EVENT_OPDATE|length > 0 %}
|
||||||
Operational data: <b>{{ EVENT_OPDATA }}</b><br/>
|
Operational data: <b>{{ EVENT_OPDATA }}</b><br/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
Status: <b>{{ EVENT_STATUS }}</b><br/>
|
Status: <b>{{ EVENT_STATUS }}</b><br/>
|
||||||
Severity: <b>{{ EVENT_SEVERITY }}</b><br/>
|
Severity: <b>{{ EVENT_SEVERITY }}</b><br/>
|
||||||
{% if EVENT_SEVERITY == "Resolved" %}
|
{% if EVENT_SEVERITY == "Resolved" %}
|
||||||
Duration: <b>{{ EVENT_DURATION }}</b><br/>
|
Duration: <b>{{ EVENT_DURATION }}</b><br/>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
Item: <b>{{ ITEM_NAME }}</b><br/>
|
Item: <b>{{ ITEM_NAME }}</b><br/>
|
||||||
Previous/Last: {{ ITEM_PREVIOUSVALUE }} ==> {{ ITEM_LASTVALUE }}
|
Previous/Last: {{ ITEM_PREVIOUSVALUE }} ==> {{ ITEM_LASTVALUE }}
|
||||||
<p><a href="{{ EVENTDETAILS_URL }}">Event Details</a><br/></p>
|
</span>
|
||||||
</td></tr>
|
</td>
|
||||||
</table>
|
</tr>
|
||||||
</td>
|
</table>
|
||||||
</tr>
|
</td>
|
||||||
|
</tr>
|
||||||
{% if GRAPH_CID|length > 0 %}
|
{% if GRAPH_CID|length > 0 %}
|
||||||
<tr>
|
<tr>
|
||||||
<td align="center"><img src="{{ GRAPH_CID }}" /></td>
|
<div align=justify>
|
||||||
</tr>
|
<td align="center"><img id="mainimage" border=0 style="width: 100%; max-width: 790px" alt="Zabbix Graph" src="{{ GRAPH_CID }}" /></td>
|
||||||
|
</div>
|
||||||
|
</tr>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</table>
|
<tr>
|
||||||
<p style="font-size:10px">
|
<td class="links">
|
||||||
Event ID: <a href="{{ EVENTDETAILS_URL }}">{{ EVENT_ID }}</a> //
|
<div align=center>
|
||||||
Trigger ID: <a href="{{ TRIGGER_URL }}">{{ TRIGGER_ID }}</a> //
|
Event ID: <a href="{{ EVENTDETAILS_URL }}">{{ EVENT_ID }}</a> //
|
||||||
Item ID: <a href="{{ ITEM_URL }}">{{ ITEM_ID }}</a> //
|
Trigger ID: <a href="{{ TRIGGER_URL }}">{{ TRIGGER_ID }}</a> //
|
||||||
Host ID: <a href="{{ HOST_URL }}">{{ HOST_ID }}</a>
|
Item ID: <a href="{{ ITEM_URL }}">{{ ITEM_ID }}</a> //
|
||||||
|
Host ID: <a href="{{ HOST_URL }}">{{ HOST_ID }}</a>
|
||||||
{% if GRAPH_ZABBIXLINK|length > 0 %}
|
{% if GRAPH_ZABBIXLINK|length > 0 %}
|
||||||
// Graph ID: <a href="{{ GRAPH_ZABBIXLINK }}">{{ GRAPH_ID }}</a>
|
// Graph ID: <a href="{{ GRAPH_ZABBIXLINK }}">{{ GRAPH_ID }}</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</div>
|
||||||
|
</td>
|
||||||
|
</tr>
|
||||||
|
</table>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
Loading…
x
Reference in New Issue
Block a user