FAQFAQ   SearchSearch   RegisterRegister   ProfileProfile   Log inLog in 

reboot-monitor

 
Post new topic   Reply to topic    CactiUsers.org Forum Index -> Feature Request
View previous topic :: View next topic  
Author Message
torstentfk
New User


Joined: 08 Mar 2006
Posts: 15

PostPosted: Wed Mar 08, 2006 7:50 am    Post subject: reboot-monitor Reply with quote

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
Back to top
View user's profile
jimmy
Site Admin


Joined: 11 Nov 2004
Posts: 1607

PostPosted: Wed Mar 08, 2006 9:11 am    Post subject: Reply with quote

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.
Back to top
View user's profile Visit poster's website
gilles
New User


Joined: 09 May 2006
Posts: 2

PostPosted: Fri May 19, 2006 11:17 am    Post subject: Reply with quote

uptime plugin has been updated :

http://cactiusers.org/forums/viewtopic.php?p=1224#1224
Back to top
View user's profile
Display posts from previous:   
Post new topic   Reply to topic    CactiUsers.org Forum Index -> Feature Request All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum
Forums Sitemap