Monitor Plugin Mod - Add downtime

General discussion about Plugins for Cacti

Moderators: Developers, Moderators

Post Reply
warnesj
Cacti User
Posts: 173
Joined: Sun May 29, 2005 7:34 pm

Monitor Plugin Mod - Add downtime

Post by warnesj »

Hi all. I love cigamit's Monitor plugin. I've done a small mod on it to add a bit of downtime information to the main Monitor page.
Image
For any down host it adds text for how long it's been down for. Sure you can get the Last Fail time by hovering your mouse over any monitored system icon, but I thought it might be nice to have the downtime of a down host shown on the main page.

What you need to modify is the ./plugins/monitor/monitor.php. Find,

Code: Select all

       $s = $s2 = '';
        if ($status < 2) {
                // If the host is down, we bold the name
                $s = '<b>';
                $s2 = '</b>';
And add this code before the '}',

Code: Select all

                // If the host is down, make a downtime since message
                $dt = "";
                $sfd = time() - strtotime($row['status_fail_date']);
                $dt_d = floor($sfd/86400);
                $dt_h = floor(($sfd - ($dt_d * 86400))/3600);
                $dt_m = floor(($sfd - ($dt_d * 86400) - ($dt_h * 3600))/60);
                $dt_s = $sfd - ($dt_d * 86400) - ($dt_h * 3600) - ($dt_m * 60);
                if ($dt_d > 0 ) {
                        $dt .= $dt_d . " days<br>" . $dt_h . " hours<br>" . $dt_m . " minutes<br>" . $dt_s . " seconds";
                } elseif ($dt_h > 0 ) {
                        $dt .= $dt_h . " hours<br>" . $dt_m . " minutes<br>" . $dt_s . " seconds";
                } elseif ($dt_m > 0 ) {
                        $dt .= $dt_m . " minutes<br>" . $dt_s . " seconds";
                } else {
                        $dt .= $dt_s . " seconds";
                }
Then find (it should be just below the code that was just modified above),

Code: Select all

        print "<td valign=top><center>
                <a href=$anchor>
                        <img src='images/$i' name='$name' id='$name' onmouseover=\"return escape('$title')\" border='0'><br>
                        <font color='black'>$s$name$s2</font>
                </a></center></td>\n";
And change it to,

Code: Select all

        if ($status < 2) {
                print "<td valign=top><center>
                        <a href=$anchor>
                                <img src='images/$i' name='$name' id='$name' onmouseover=\"return escape('$title')\" border='0'><br>
                                <font color='black'>$s$name$s2</font><br><font color='red'>$s$dt$s2</font>
                        </a></center></td>\n";
        } else {
                print "<td valign=top><center>
                        <a href=$anchor>
                                <img src='images/$i' name='$name' id='$name' onmouseover=\"return escape('$title')\" border='0'><br>
                                <font color='black'>$s$name$s2</font>
                        </a></center></td>\n";
        }
Hope anyone else finds it useful.
mcutting
Cacti Guru User
Posts: 1884
Joined: Mon Oct 16, 2006 5:57 am
Location: United Kingdom
Contact:

Post by mcutting »

I like the look of this, however, it might be a better if you post the monitor.php file complete ?

Thanks
Cacti Version 0.8.8b
Cacti OS Ubuntu LTS
RRDTool Version RRDTool 1.4.7
Poller Information
Type SPINE 0.8.8b
warnesj
Cacti User
Posts: 173
Joined: Sun May 29, 2005 7:34 pm

Post by warnesj »

Your wish is my command. :)
Attachments
monitor_0.7_mod.zip
monitor.php replacement for Monitor v0.7 with host downtime displayed.
(3.03 KiB) Downloaded 725 times
User avatar
Goatmilker
Posts: 25
Joined: Tue May 08, 2007 10:07 am
Location: Belgium

Post by Goatmilker »

Hi,

I've downloaded this monitor.php file and it seem to work OK... however upon an failure it counts 12hours on top of the actual downtime?

Had a few devices going down this afternoon and all had the same issue?


Update: Today I ran some tests and I couldn't recreate the problem... False alarm it seems? I'm positive I wasn't drunk yesterday so I'll keep a close eye on it ... and my fingers on the print-screen button ;-)
Last edited by Goatmilker on Thu Jul 05, 2007 7:05 am, edited 1 time in total.
cigamit
Developer
Posts: 3369
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

Thanks, I'm testing this out in SVN now, probably will make it optional.
User avatar
sizulku
Cacti User
Posts: 110
Joined: Mon Nov 04, 2002 9:15 am
Location: ACEH
Contact:

Post by sizulku »

Cigamit,

I'm testing SVN and cacti become error and only appear tabs console and graph. any help would be great. Thanks!
cigamit
Developer
Posts: 3369
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

sizulku wrote:Cigamit,

I'm testing SVN and cacti become error and only appear tabs console and graph. any help would be great. Thanks!
Please don't test the SVN version, it requires an unreleased version of the Plugin Architecture, which includes a new function to simplify testing for realm permissions.
bengelly
Cacti User
Posts: 57
Joined: Fri Jan 26, 2007 2:28 am

Post by bengelly »

Hi all,

what rights should I apply to the monitor.php file ? the one contained originaly in the plugin has a 666 rights... the modified posted file has 755 rights...

any advice ?

Thanks
cigamit
Developer
Posts: 3369
Joined: Thu Apr 07, 2005 3:29 pm
Location: B/CS Texas
Contact:

Post by cigamit »

The permissions depends on your server. Your web server needs read access to the file. Don't rely on any permissions provided, you are responsible for the security of your server.
fernandakp
Posts: 27
Joined: Thu Jun 21, 2007 9:30 am

downtime for new version of Monitor

Post by fernandakp »

Hello,
can anyone help me to implement this in the new version of monitor (0.7-4)?
I was trying to understand but i cant do it alone...
Now monitor have a function to witch type of view. So i think that it would be easiest to implement the downtime as a function too. Then we could use it for witch type of view.

this downtime feature is very helpful for my cacti. Thank you for this great addon...
fernandakp
Posts: 27
Joined: Thu Jun 21, 2007 9:30 am

I implemented downtime for new version of monitor

Post by fernandakp »

Hi guys, it finally work out. I studied the code and i implemented the downtime , but just for the 'default' grouping with the 'list' view.
I documented very well each change made to code.
Thank you for this addon...
Attachments
monitor7_4_with_downtime.php.txt
(29.17 KiB) Downloaded 864 times
fernandakp
Posts: 27
Joined: Thu Jun 21, 2007 9:30 am

Post by fernandakp »

Hi guys, i just have noticed a little problem, but not sure if it is in my code. I have in my Cacti the dates in format 12hs (but without the am/pm info) instead of 24hrs. How can i change this? Do you know what code that have this?

Because of this config i have the downtime twelve hours more than the real one.
P.S.: I am using fast_poller.cmd for monitor.
warnesj
Cacti User
Posts: 173
Joined: Sun May 29, 2005 7:34 pm

Post by warnesj »

I know it's kind of late, but I thought I'd mention that I posted a potential fix or this in post http://forums.cacti.net/viewtopic.php?p=116207.
fernandakp
Posts: 27
Joined: Thu Jun 21, 2007 9:30 am

donwtime work OK with Cacti 0.8.7 and SPINE

Post by fernandakp »

Thanks Warnesj.
Until one weeks ago it would be helpfull...

Actually i read already upgrade to version 0.8.7 of cacti and spine. With the spine upgrade it work beautiful. thank you.
warnesj wrote:I know it's kind of late, but I thought I'd mention that I posted a potential fix or this in post http://forums.cacti.net/viewtopic.php?p=116207.
Post Reply

Who is online

Users browsing this forum: No registered users and 0 guests