[HOWTO] Availability Reporting

If you figure out how to do something interesting/cool in Cacti and want to share it with the community, please post your experience here.

Moderators: Developers, Moderators

Uitty
Posts: 4
Joined: Tue Jan 26, 2010 5:34 am

Post by Uitty »

Cool script and how-to. Just what we were looking for!
istein001
Cacti User
Posts: 54
Joined: Fri Feb 22, 2008 4:44 pm
Location: Houston

Missing PHP in header

Post by istein001 »

Script wouldn't execute out of the box with php5/BSD. Noticed after unzipping this it merely had "<?" in the header, adding "<?php" got it to execute.

FYI in case anyone else hits this. Nice scripts, going to run a few days and see how it pans out. 30 Day availability report would be very useful.
ptaylor874
Posts: 45
Joined: Fri Jan 04, 2008 11:45 am

Re: [HOWTO] Availability Reporting

Post by ptaylor874 »

On the script execution issue on PHP5/BSD - There's a setting in your php.ini file that controls that. I don't know when, but I think they changed the default php.ini value to only allow the long tags (<?php) vs. the short tags (<?). I recently ran into the same issue on a newly installed box here - not for Cacti, though - but for a different system that I had lots of scripts on. Since this is the new default, I'm trying to write my newer stuff using this style... When/If I put out a newer version of this script, I'll probably change it to that style, since it works whether someone's configured for long or short tags...

Glad everyone is getting good use out of this script.
MERB
Posts: 3
Joined: Fri Oct 08, 2010 12:01 am

Re: [HOWTO] Availability Reporting

Post by MERB »

I love this report thanks!

Although is there a way to have the report display only the devices above a certain % as I would like to cut the workstations from the report and only see the servers, printers, WiFi access points etc

Other than that it's great thanks again
ptaylor874
Posts: 45
Joined: Fri Jan 04, 2008 11:45 am

Re: [HOWTO] Availability Reporting

Post by ptaylor874 »

You have some good options in the availabilityReport.php file..

For each of the $daily, $weekly, and $monthly filters, there is an option ['topX'] which allows you to set the topX you want to see on the report.. (Top 10, top 25, etc)

In addition, there is an option ['availPercent'] where you can set the percentage of Availability you want to show... So, if you only want to see ones with 99.1% availability, set it to 99.1...

Note that either the TopX value needs to be 0 or the AvailPercent needs to be zero - You can either do TopX, or AvailPercent, not both on the same report... You could have a TopX monthly, while having an availPercent for the Daily and Weekly, though, if you want.

Another thing that is available is the $filter variable. If you have any experience using SQL statements, you can come up with a very specific string to include only those hosts you are interested in seeing reports on. The easiest way is to ensure all of the same device type have something in common in the description. For example, if your devices are Printers, include "prn" in the description, if they are workstations, include "wks" in the name, etc.

If your devices are appropriately named (in Cacti, at least), to exclude workstations, you could do something like:
$filter = 'AND description not like "%wks%" ';

or if you have some appropriately named device types that you want to filter on... (This would assume that your printers are named so they end in "prn", servers end in "svr", and your access points end in "ap":

$filter = 'AND ((description like "%prn") OR (description like "%svr") OR (description like "%ap"))'

So, if you are willing to put in some work to appropriately name your devices in Cacti (or your devices already have an appropriate naming scheme) it should be pretty easy to customize exactly the devices you want to show up.

On the above statemnts, "%" is basically a wildcard character.. So, %wks% would include a device with "wks" anywhere in the name. Similarly, "%wks" would return only devices that end in "wks".

If you have just a few of some devices with similar names you want to key on, you can use the ? wildcard character, which is a single character wildcard. So "SVR??HDQ" would match "SVR01HDQ", "SVR02HDQ", all the way to "SVR99HDQ" (and even machines with non-numeric characters in those spots). But, it wouldn't match "SVR01HDD".

Anyhow, you get the idea... If you search around a bit about SQL, you can probably come up with some even more creative filters than I'm showing you...
MERB
Posts: 3
Joined: Fri Oct 08, 2010 12:01 am

Re: [HOWTO] Availability Reporting

Post by MERB »

Thanks again, I haven't had much to do with SQL but you explained it well. I have created the filters for all the important devices and it works perfectly. :)
MajorWoody
Posts: 4
Joined: Tue Nov 09, 2010 10:25 am

Re: [HOWTO] Availability Reporting

Post by MajorWoody »

First off, thanks for this script it works great!

A few enhancements I would love to see:

1. A static html page of the report on the Cacti website.
2. The duration and times of failed polls. So you could see that it was down twice on Tuesday, one time it was down for an hour the other time is was down for 30 minutes.
3. A link to that nodes graph in the e-mail.

I don't know if these are impossible requests or not (I am not much of a programmer) but I think these would greatly enhance there ability.


Thanks again for this awesome script,
Major
MajorWoody
Posts: 4
Joined: Tue Nov 09, 2010 10:25 am

Re: [HOWTO] Availability Reporting

Post by MajorWoody »

Having an issue receiving emails.

This worked perfectly for two weeks without issue then all of a sudden it stopped?

The job is shown as being executed in syslog but I do not receive any emails.

If I run the command manually it runs fine and I receive the email, yesterday while testing I had a success rate of about 1 out of every 5 times getting it to run the cron job. (Setting it for one minute in the future)

Can you provide any help?


Thanks,
Major
ptaylor874
Posts: 45
Joined: Fri Jan 04, 2008 11:45 am

Re: [HOWTO] Availability Reporting

Post by ptaylor874 »

About the only thing that comes to mind is perhaps it's crashing, so it never gets to the step where it would send the emails... If you can manually run it and it works every time, then I'm not sure what the issue is, as I would expect it to crash consistently if that's what is happening...

Have you tried taking a vanilla copy of the script and slowly adding your settings to it? (Before doing anything like this, you should really back up all the data files in your tmp directory, unless the data isn't that important.)
MajorWoody
Posts: 4
Joined: Tue Nov 09, 2010 10:25 am

Re: [HOWTO] Availability Reporting

Post by MajorWoody »

ptaylor874 wrote:About the only thing that comes to mind is perhaps it's crashing, so it never gets to the step where it would send the emails... If you can manually run it and it works every time, then I'm not sure what the issue is, as I would expect it to crash consistently if that's what is happening...

Have you tried taking a vanilla copy of the script and slowly adding your settings to it? (Before doing anything like this, you should really back up all the data files in your tmp directory, unless the data isn't that important.)
Thanks for the quick response.

I will try reverting back to a fresh install of the script. We haven't pushed this into 'production' yet so I can lose the data already there without problems.

I will let you know my results.


Major
mhouse43
Posts: 1
Joined: Mon Dec 13, 2010 2:39 pm

Re: [HOWTO] Availability Reporting

Post by mhouse43 »

Thanks for the script. It is very useful and working great. I would like to run a pair of scripts with different filters so that I can send one report for switches and hubs and one report for servers, with each report having different recipients. What will I have to modify in the script so the changes from one script don't overwrite the other?

Thanks,

Mike
MajorWoody
Posts: 4
Joined: Tue Nov 09, 2010 10:25 am

Re: [HOWTO] Availability Reporting

Post by MajorWoody »

MajorWoody wrote:
ptaylor874 wrote:About the only thing that comes to mind is perhaps it's crashing, so it never gets to the step where it would send the emails... If you can manually run it and it works every time, then I'm not sure what the issue is, as I would expect it to crash consistently if that's what is happening...

Have you tried taking a vanilla copy of the script and slowly adding your settings to it? (Before doing anything like this, you should really back up all the data files in your tmp directory, unless the data isn't that important.)
Thanks for the quick response.

I will try reverting back to a fresh install of the script. We haven't pushed this into 'production' yet so I can lose the data already there without problems.

I will let you know my results.


Major
Never did respond with my testing.

I went back to a fresh install but still had no luck. I got it to work by running it as a little shell script, I had to cd into the directory and use php's full path but it is now working.

I do have one more question, how hard would it be to add the data in the 'Notes' field as a column on the report?


Thanks again for this great script,
Major
heliopaixao
Posts: 1
Joined: Mon Feb 21, 2011 1:57 pm

Re: [HOWTO] Availability Reporting

Post by heliopaixao »

Dear guys,

I have dowloaded availibilityreport.zip and runned availibilityReport.php but have not received none mail. I have changed parameters of availibilityReport.php accordingly steps 1..5 of ptaylor874

If someone could send any tip I will appreciate.

Helio Paixao
User avatar
TFC
Cacti Pro User
Posts: 739
Joined: Wed Apr 09, 2003 2:17 am
Location: Izmir/Turkey

Re: [HOWTO] Availability Reporting

Post by TFC »

Hi,
I apply the step at the beginning of this topic. But I get weird error. Here is my history:
root@cacti:/usr/local/cacti_scripts# php /usr/local/cacti_scripts/availabilityReport.php

Parse error: syntax error, unexpected T_STRING, expecting ')' in /usr/local/cacti_scripts/availabilityReport.php on line 45
root@cacti:/usr/local/cacti_scripts# ls -la
total 48
drwxr-xr-x 2 root root 4096 2011-04-01 14:15 .
drwxr-xr-x 13 root root 4096 2011-04-01 14:14 ..
-rw-r--r-- 1 root root 16565 2011-04-01 14:24 availabilityReport.php
-rw-r--r-- 1 root root 17321 2011-04-01 14:15 smtp.class.php
and line 45 is a comment!
// This directory is where the "yesterday" data file can be written. This should
anybody help me why i get this error?
noname
Cacti Guru User
Posts: 1566
Joined: Thu Aug 05, 2010 2:04 am
Location: Japan

Re: [HOWTO] Availability Reporting

Post by noname »

Probably " is missing before line 45.
Maybe:
$monthlyRecipients = array("mgr1@yourdomain.com","mgr2@yourdomain.com);
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest