Cactiusers.org


It is currently Tue Feb 07, 2012 5:25 pm




Post new topic Reply to topic  [ 3 posts ] 
 reboot-monitor 
Author Message
New User

Joined: Wed Mar 08, 2006 7:12 am
Posts: 17
Post 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:
Code:
         $snmp_uptime = 0;



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


Wed Mar 08, 2006 7:50 am
Site Admin

Joined: Thu Nov 11, 2004 11:12 am
Posts: 2007
Post 
It would actually have to be integrated into the Plugin Architecture itself, as it modifies a few Cacti files, not the threshold files. I will take a look at it and see what I can do.


Wed Mar 08, 2006 9:11 am
New User

Joined: Tue May 09, 2006 4:36 pm
Posts: 2
Post 
uptime plugin has been updated :

http://cactiusers.org/forums/viewtopic.php?p=1224#1224


Fri May 19, 2006 11:17 am
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 


Who is online

Users browsing this forum: No registered users and 0 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for: