Report Downtime in Thold Email

Support questions about the Threshold plugin

Moderators: Developers, Moderators

Post Reply
scottsta
Posts: 9
Joined: Sat Jun 17, 2006 9:58 am

Report Downtime in Thold Email

Post by scottsta »

Has anyone implemented any code in the setup.php file which will report the 'downtime' after a device comes backup following an outage ?

The status_rec_date and status_fail_date are obviously key here ?

Has anyone done it ?

thanks
User avatar
sebbs
Cacti User
Posts: 97
Joined: Mon Jan 22, 2007 9:41 am
Location: Ottawa,Canada

no replies?

Post by sebbs »

its too bad no one replied...would of been something useful.
If all else fails, rm -rf /
cigamit
Developer
Posts: 3369
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

I will see what I can do, as I can see how this could be useful.
User avatar
sebbs
Cacti User
Posts: 97
Joined: Mon Jan 22, 2007 9:41 am
Location: Ottawa,Canada

awesome!

Post by sebbs »

you guys rock! sent you a donation! haah.
If all else fails, rm -rf /
warnesj
Cacti User
Posts: 173
Joined: Sun May 29, 2005 7:34 pm

Post by warnesj »

I think I have this working now. I had to modify some of the Cacti "core" code though. Here is what I did,
  1. I needed to modify the ./lib/functions.php script to change the status_fail_date format so that is would be stored using a 24 clock time. By default Cacti uses 12 hour clock time but no indicator of whether the time is in AM or PM :-?. This change has seemed to have no effect on any other aspect of how my Cacti installation is functioning. So look on lines 487 and 493 for

    Code: Select all

    $hosts[$host_id]["status_fail_date"] = date("Y-m-d h:i:s");
    And change it to,

    Code: Select all

    $hosts[$host_id]["status_fail_date"] = date("Y-m-d H:i:s");
    The difference is the capital H in the date formatting.
  2. Then I modified the ./plugin/thold/setup.php script to add a bit more information to the email message. So look near line 134 for

    Code: Select all

            if ($status != HOST_DOWN) {
                    $subject = "Host Notice : " . $hosts[$host_id]["hostname"] . " returned from DOWN state";
                    $msg= $subject;
    And add this code snippet immediately after it,

    Code: Select all

    # Modified to include downtime duration in the message
                    $sql = "select status_fail_date from host where id = '" . $host_id . "'";
                    $result = db_fetch_assoc($sql);
                    $downtime = time() - strtotime($result[0]['status_fail_date']);
                    $downtime_days = floor($downtime/86400);
                    $downtime_hours = floor(($downtime - ($downtime_days * 86400))/3600);
                    $downtime_minutes = floor(($downtime - ($downtime_days * 86400) - ($downtime_hours * 3600))/60);
                    $downtime_seconds = $downtime - ($downtime_days * 86400) - ($downtime_hours * 3600) - ($downtime_minutes * 60);
                    $msg .= ".<br><br>Host had been down for ";
                    if ($downtime_days > 0 ) {
                            $msg .= $downtime_days . " days, " . $downtime_hours . " hours, " . $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
                    } elseif ($downtime_hours > 0 ) {
                            $msg .= $downtime_hours . " hours, " . $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
                    } elseif ($downtime_minutes > 0 ) {
                            $msg .= $downtime_minutes . " minutes, " . $downtime_seconds . " seconds ";
                    } else {
                            $msg .= $downtime_seconds . " seconds ";
                    }
                    $msg .= "since " . $result[0]['status_fail_date'] . ".";
    NOTE:The above code should appear after the $msg= $subject; command and before the thold_mail($alert_email, '', $subject, $msg, ''); command.
That should produce an email message similar to this,
Host Notice : XXX.XXX.XXX.XXX returned from DOWN state.

Host had been down for 19 minutes, 40 seconds since 2007-02-23 18:20:31.
I hope you find it useful.
Post Reply

Who is online

Users browsing this forum: No registered users and 2 guests