-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnotify_service
105 lines (86 loc) · 4.12 KB
/
notify_service
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#!/usr/bin/php -c /etc/php.ini
<?php
array_shift($argv);
$f_notify_type =array_shift($argv); /*1*/
$f_host_name =array_shift($argv); /*2*/
$f_host_alias =array_shift($argv); /*3*/
$f_host_state =array_shift($argv); /*4*/
$f_host_address =array_shift($argv); /*5*/
$f_serv_output =array_shift($argv); /*6*/
$f_long_date =array_shift($argv); /*7*/
$f_serv_desc =array_shift($argv); /*8*/
$f_serv_state =array_shift($argv); /*9*/
$f_to =array_shift($argv); /*10*/
$f_duration = round((array_shift($argv))/60,2); /*11*/
$f_exectime =array_shift($argv); /*12*/
$f_totwarnings =array_shift($argv); /*13*/
$f_totcritical =array_shift($argv); /*14*/
$f_totunknowns =array_shift($argv); /*15*/
$f_lastserviceok = array_shift($argv); /*16*/
$f_lastwarning = array_shift($argv); /*17*/
$f_attempts = array_shift($argv); /*18*/
$f_host_url = array_shift($argv); /*19*/
$f_serv_url = array_shift($argv); /*20*/
$f_host_group = array_shift($argv); /*21*/
$f_color="#dddddd";
if($f_serv_state=="WARNING") {$f_color="#f48400";}
if($f_serv_state=="CRITICAL") {$f_color="#f40000";}
if($f_serv_state=="OK") {$f_color="#00b71a";}
if($f_serv_state=="UNKNOWN") {$f_color="#cc00de";}
// Check If File Exists ###########
$file_name = "/usr/lib/nagios/plugins/tmp/$f_host_name.$f_serv_desc.txt";
if($f_notify_type=="PROBLEM")
{
$currenttime = time();
if ($f_attempts==1)
{
if(file_exists($file_name)==true) {unlink($file_name);}
$currenttime = $currenttime+round(($f_duration * 60),0);
file_put_contents($file_name, "$currenttime");
}
}
if($f_notify_type=="RECOVERY")
{
$currenttime = time();
$oldtime = time();
if (file_exists($file_name)==true)
{
$oldtime = intval(file_get_contents($file_name));
}
$f_duration = round(($currenttime - $oldtime)/60,2);
}
// Check If File a service url note exists, if so use that otherwise use host url
if ( strpos($f_serv_url, 'http') !== false )
{
$f_url = $f_serv_url;
} else {
$f_url = $f_host_url;
}
$f_serv_output = str_replace("(","/",$f_serv_output);
$f_serv_output = str_replace(")","/",$f_serv_output);
$f_serv_output = str_replace("[","/",$f_serv_output);
$f_serv_output = str_replace("]","/",$f_serv_output);
$subject = "$f_notify_type Service:$f_host_name/$f_serv_desc [$f_serv_state]";
$from ="centreon-engine@centreon";
$body = "<html><body><table border=0 width='98%' cellpadding=0 cellspacing=0><tr><td valign='top'>\r\n";
$body .= "<table border=0 cellpadding=0 cellspacing=0 width='97%'>";
$body .= "<tr bgcolor=$f_color><td width='140'><b><font color=#ffffff>Notification:</font></b></td><td><font ";
$body .= "color=#ffffff><b>$f_notify_type [$f_serv_state]</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td colspan=2> </td></tr>\r\n";
$body .= "<tr bgcolor=#eeeeee><td><b>Service:</b></td><td><font color=#0000CC><b>$f_serv_desc</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#eeeeee><td><b>Output:</b></td><td><font color=#005555><b>$f_serv_output</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td colspan=2> </td></tr>\r\n";
$body .= "<tr bgcolor=#eeeeee><td><b>Server:</b></td><td><font color=#0000CC><b>$f_host_alias</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#eeeeee><td><b>Address:</b></td><td><font color=#005555><b>$f_host_address</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td><b>Hostgroup:</b></td><td><font color=#005555><b>$f_host_group</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td colspan=2> </td></tr>\r\n";
$body .= "<tr bgcolor=#eeeeee><td><b>Date/Time:</b></td><td><font color=#005555><b>$f_long_date</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td><b>Wiki Info:</b></td><td><a href='$f_url'><b>Dettagli Wiki</b></a></td></tr>\r\n";
$body .= "<tr bgcolor=#eeeeee><td><b>State Duration:</b></td><td><font color=#005555><b>$f_duration</b> mins.</font></td></tr> \r\n";
$body .= "</body></html> \r\n";
$headers = "From: $from\r\n";
$headers .= "Content-type: text/html\r\n";
/* Send eMail Now... */
$m_true = mail($f_to, $subject, $body, $headers);
echo $m_true;
?>