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
Report Downtime in Thold Email
Moderators: Developers, Moderators
no replies?
its too bad no one replied...would of been something useful.
If all else fails, rm -rf /
I think I have this working now. I had to modify some of the Cacti "core" code though. Here is what I did,
- 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 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.Code: Select all
$hosts[$host_id]["status_fail_date"] = date("Y-m-d H:i:s");
- 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 And add this code snippet immediately after it,
Code: Select all
if ($status != HOST_DOWN) { $subject = "Host Notice : " . $hosts[$host_id]["hostname"] . " returned from DOWN state"; $msg= $subject;
NOTE:The above code should appear after the $msg= $subject; command and before the thold_mail($alert_email, '', $subject, $msg, ''); command.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'] . ".";
I hope you find it useful.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.
Who is online
Users browsing this forum: No registered users and 2 guests