torstentfk New User
Joined: 08 Mar 2006 Posts: 15
|
Posted: Wed Mar 08, 2006 7:50 am Post subject: reboot-monitor |
|
|
Hi,
just like in cacti-forum I would like to get this reboot-monitor patch into the thold-release. Please check it and make changes as needed:
Hello,
last week a switch rebooted and we did not recognize it.
So I changed the thold functions (here is allready an email-function included) so that cacti checks the uptime, stores it in the host-db and sets a flag if the device has rebooted. This flag is cleared in the next poller run.
Alter the host-table:
| Code: |
mysql
ALTER TABLE `host` ADD `uptime` VARCHAR(20) NULL DEFAULT '0' , ADD `reboot` VARCHAR( 3 ) NULL DEFAULT '0';
|
in plugin/thold/check-thold.php insert this lines after line 92 and
before "foreach ($queryrows as $q_row) ":
| Code: |
#-------reboot-monitor
$sql = "SELECT description, hostname, id, uptime FROM host where reboot ='1' AND uptime > 1";
## $result = db_fetch_assoc($sql) or die (mysql_error());
## changed to:
$result = db_fetch_assoc($sql);
foreach ($result as $item)
{
$msg= " Device ". $item["description"]." has rebooted an came up at ".date("h:i:s d-m-Y");
$subject = "Reboot of ".$item["hostname"] ;
$file_array =array();
if ($deadnotify)
{ thold_mail($global_alert_address, '', $subject, $msg, $file_array);
print("Reboot detected on " . $item["hostname"]."\n");
}
}
#-------reboot-monitor
|
in cmd.php insert this lines:
Line 106 add:
At line 259 near $new_host = false;
insert this right after it:
$last_host2 = $last_host;
Some line further insert quite after the "else" of this block
| Code: |
if (($item["snmp_version"] == 0) || (($item["snmp_community"] == "") && ($item["snmp_version"] != 3))) {
cacti_log("Host[$host_id] DS[$data_source] ERROR: Invalid SNMP Data Source. Please either delete it from the database, or correct it.", $print_data_to_stdout);
$output = "U";
}else {
|
insert this block:
| Code: |
if ($last_host2 != $current_host)
{
$last_host2 = $current_host;
$snmp_uptime = cacti_snmp_get($item["hostname"], $item["snmp_community"], ".1.3.6.1.2.1.1.3.0", $item["snmp_version"], $item["snmp_username"], $item["snmp_password"], $item["snmp_port"], $item["snmp_timeout"], SNMP_WEBUI);
if ($snmp_uptime > 10 )
{
$old_uptime= db_fetch_cell("SELECT uptime FROM host WHERE id='" . $item["host_id"] . "'");
cacti_log("Uptime of " . $item["hostname"] . ",ID:" . $item["host_id"] . " - old=$old_uptime cur
:$snmp_uptime",$print_data_to_stdout);
if ( $old_uptime > $snmp_uptime )
{ db_execute("update host set reboot='1' where id='" . $item["host_id"] . "'");
cacti_log("REBOOT detected of device " . $item["hostname"] . ": Old:".$old_uptime." Current
:".$snmp_uptime ,$print_data_to_stdout);
}
else
{ db_execute("update host set reboot='0' where id='" . $item["host_id"] . "'"); }
db_execute("update host set uptime=$snmp_uptime where id='" . $item["host_id"] . "'");
}
else
{cacti_log("Could not fetch Uptime of " . $item["hostname"] . ",ID:" . $item["host_id"],$print_da
ta_to_stdout); }
}
|
Finally I changed host.php:
at line 784 I inserted host.uptime so that this look like
| Code: |
host.avg_time,
host.availability ,
host.uptime
from host
$sql_where
order by host.description
|
and at line 828 I inserted at the end of the <td>s:
| Code: |
<td><?php print (round($host["uptime"]/8640000, 1));?>d</td>
|
Now cacti stores for each host the uptime and set the flag. Thold checks for this flag and send an email to the admins (only if dead host notification is enabled).
Torsten
|
|