-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathnotify_host
84 lines (65 loc) · 3.16 KB
/
notify_host
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
#!/usr/bin/php -c /etc/php.ini
<?php
array_shift($argv);
$f_notify_type =array_shift($argv);
$f_host_name =array_shift($argv);
$f_host_alias =array_shift($argv);
$f_host_state =array_shift($argv);
$f_host_address =array_shift($argv);
$f_host_output =array_shift($argv);
$f_long_date =array_shift($argv);
$f_serv_desc =array_shift($argv);
$f_serv_state =array_shift($argv);
$f_to =array_shift($argv);
$f_totalup =array_shift($argv);
$f_totaldown=array_shift($argv);
$f_host_url = array_shift($argv);
$f_host_group = array_shift($argv);
$f_duration = round((array_shift($argv))/60,2);
$f_attempts = array_shift($argv);
$file_name = "/usr/lib/nagios/plugins/tmp/$f_host_name.DOWN";
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);
}
$subject = "$f_notify_type HOST:$f_host_name $f_host_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>Host:</b></td><td><font color=#0000CC><b>$f_host_alias</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#eeeeee><td><b>Output:</b></td><td><font color=#005555><b>$f_host_output</b></font></td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td colspan=2> </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_host_url'><b>Dettagli Wiki</b></a></td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td colspan=2> </td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td><b>Total Servers Down:</b></td><td>$f_totaldown</td></tr>\r\n";
$body .= "<tr bgcolor=#fefefe><td><b>Total Servers Up:</b></td><td>$f_totalup</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 = $headers."Content-type: text/html\r\n";
/* Send eMail Now... */
mail($f_to, $subject, $body, $headers);
?>