[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: Moderators, Developers

Author
Message
ptaylor874
Posts: 45
Joined: Fri Jan 04, 2008 11:45 am

[HOWTO] Availability Reporting

#1 Post by ptaylor874 » Mon Jan 28, 2008 3:45 pm

Cacti is nice in that it calculates availability for you, but my management is interested in availability by month. The technical guys are more interested in the availability of the previous day. To accomplish both of these, I wrote a reporting script, attached to this post.

**** UPDATE ****
9/2/2008
Version 1.3 of the script has been uploaded. By popular demand, this version adds a weekly report.

Version 1.2 of the script has been uploaded. This version adds a $filter variable that lets you select which devices are shown in the report. Essentially, the $filter variable is inserted into the WHERE clause of the SQL statement when pulling the hosts. This version also has a fix for a minor issue that affected my system (and probably other very large installs) where the stats of seemingly random devices were not cleared every month. (I suspect this was a record locking issue)

****************

Unzip these files into a directory like /usr/local/cacti_scripts and give them appropriate permissions.

In your cron, set it to run one minute after midnight:

1 0 * * * php /usr/local/cacti_scripts/availabilityReport.php

Edit the availabilityReport.php:
1. Set your MySQL server settings (default is for CactiEZ)
2. Set your smtpServer and the "from Address" for emails
3. Set your daily and monthly recipients. (Each are arrays, so you can send the daily/monthly reports to two different sets of people)
4. Set a good temporary directory that will survive a reboot
5. Set the "topX" or "AvailPercent" sections appropriately. The TopX allows you to get a list of the top X worst availability devices. The AvailPercent shows you all devices with less than the availability percentage you specify. (Only one per report can be active.) 0 disables these features, resulting in a complete list of all devices.
Attachments
Screenshot.png
Screenshot
Screenshot.png (15.46 KiB) Viewed 55991 times
availabilityReport.zip
availabilityReport.php and smtp.class.php. Place both in the same directory.
(9.22 KiB) Downloaded 5179 times
Last edited by ptaylor874 on Tue Sep 02, 2008 11:47 am, edited 7 times in total.

sveno
Posts: 7
Joined: Thu Feb 14, 2008 9:36 am

#2 Post by sveno » Tue Feb 19, 2008 6:57 am

This is awesome!
Can't wait to try it out!
Will it work with the latest versions, yeah?

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

#3 Post by ptaylor874 » Tue Feb 19, 2008 8:16 am

I'm running 0.87a, so I can say it works with that version... Other than that one, I'm not sure. I don't know when the fields that I'm grabbing were put in place.

Paul

torstentfk
Cacti User
Posts: 367
Joined: Tue Apr 05, 2005 9:52 am
Location: Munich, Germany

#4 Post by torstentfk » Wed Feb 20, 2008 4:32 am

Hi,

here is our script for getting avail-report: the script is used for more than one cacti location so I must devide between the cities (bamberg....).
After reading the counters they will be reseted so the next time (every month) I get a new, clean statistic.

Code: Select all

#!/bin/bash

mailto="ADMIN-EMAIL"


if [ $# -lt 1 ]; then
  echo Das Script erwartet als Parameter eine/mehrere Email-Adressen
  echo z.b. avail-report.sh "[email protected],[email protected]"
  exit 1
fi
mailto=$1
 
if test -f  /tmp/avail-report.txt ; then
 rm -f /tmp/avail-report.txt
fi

hostn=`hostname`
echo \"Location\",\"Device\",\"Availability \(%\)\",\"Uptime \(d\)\" >  /tmp/avail-report.txt

case "$hostn" in
mgtm)
 host="Muenchen"
;;
*mgtd*)
 host="Duesseldorf"
;;
*mgtb*)
 host="Bielefeld"
esac

m="/usr/mysql/bin/mysql -u cacti --password=cacti"

echo "SELECT host.description,host.availability, uptime.uptime FROM host left join uptime on uptime.id=host.i
d ORDER by host.availability,host.description; UPDATE host SET total_polls = '0',failed_polls = '0';" |$m cacti | grep -v  desc | awk '{h="'$host'" ;print "\""h
 "\",\""$1"\",\""$2"\",\""$3/8640000"\"";}' >> /tmp/avail-report.txt


mail -s "Availability-Report Monitored Device from ${HOSTNAME}" ${mailto} < /tmp/avail-report.txt


if test -f  /tmp/avail-report.txt ; then
 rm -f /tmp/avail-report.txt
fi
Torsten

User avatar
phakesley
Posts: 39
Joined: Tue Nov 13, 2007 11:24 am

Availabilty report

#5 Post by phakesley » Tue Mar 11, 2008 5:10 am

Hi, I am using this function and think it is great however it reports the first server each day as Total Polls = Zero and Failed Polls = Zero. All the other are fine.


Devices with Availability Less Than 99.5%
Report Duration: March 10, 2008, 12:01 am - March 11, 2008, 12:01 am

Device Availability Total Polls Failed Polls
Server 1 0.00000 0 0
Server 2 93.33333 285 19
Server 3 99.30556 288 2


Any ideas?

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

#6 Post by ptaylor874 » Tue Mar 11, 2008 8:24 am

I'm not seeing this in my environment.

Is the Server1 device being polled?

I'm guessing that the math works out like that because Server1 has 0 successful polls..??

User avatar
phakesley
Posts: 39
Joined: Tue Nov 13, 2007 11:24 am

#7 Post by phakesley » Tue Mar 25, 2008 10:16 am

I have resolved the problem in that the problem was in the poller cache. I have rebuilt the cache and all is working fine now - Thanks.

saya
Cacti User
Posts: 58
Joined: Wed Jan 16, 2008 10:56 pm

#8 Post by saya » Fri Mar 28, 2008 3:37 am

Hello, I am working on similar issue but using a script that fetch remote host status(value 3 for up and 1 for down) from table host, and graph every host's status...then I can simply use reportit plugin to generate availability status report by using average((status-1)/2)*100%. but my problem is that if the remote device is down, it's impossible to write rrd file and update the graph. so for these device, they only have value when they are up, and as the result the value is 3. this makes the availability still equals 100%. (but if manually run in command line, it returns 1 which means device down) :(

I am now thinking of using cron to update those rrd file, but have no idea whether this way is possible or not..

can help me??
Thanks a lot!!!

saya

sveno
Posts: 7
Joined: Thu Feb 14, 2008 9:36 am

#9 Post by sveno » Fri Apr 04, 2008 4:02 am

Hey,

I realized that there must be a bug in it.

The daily availability is calculated by total polls vs failed polls, the problem is that the counters should be reset on a daily basis however (at least for me, 0.87b) the total seems to accumulate day by day so that the last daily report = monthly report.
First day you have 576 total polls, then you have 1152 total polls and so on. So for me the daily reports are actually 1st day to x day reports.


Otherwise its great!

big-timmy
Posts: 8
Joined: Thu Apr 03, 2008 9:47 am

#10 Post by big-timmy » Fri Apr 04, 2008 4:46 pm

Works perfekt on 0.8.7b with Windows Server 2003 and PHP5.

Many thanks!!! :D

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

#11 Post by ptaylor874 » Tue Apr 08, 2008 2:33 pm

sveno wrote:Hey,

I realized that there must be a bug in it.

The daily availability is calculated by total polls vs failed polls, the problem is that the counters should be reset on a daily basis however (at least for me, 0.87b) the total seems to accumulate day by day so that the last daily report = monthly report.
First day you have 576 total polls, then you have 1152 total polls and so on. So for me the daily reports are actually 1st day to x day reports.


Otherwise its great!
That is not how it is designed. The script writes temp files out each night when it runs. These temp files contain the information for the previous day. The next time it runs, it reads these temp files and subtracts the previous days totals out of the new total so you end up with just the total polls and failed polls per day.

Since it sounds like your temp files are the issue, make sure you've set the $tmpDir variable to a good directory that exists on your system. You may need to ensure that the user the daily report runs under is able to write to that location. If you have any job that cleans up that directory on a regular basis, you should disable that job.

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

#12 Post by ptaylor874 » Fri Apr 11, 2008 8:28 am

Helped sveno out via PMs. In his case, he kept the $tmpDir to the default of "/tmp/", having a /tmp directory on the root of his drive on his Windows system. In the case of Windows, you must specify the drive letter and full path, like C:/tmp/.

At any rate, he's working now! Just thought I would post this tip in case anyone else with a Windows system had this problem.

niobe
Cacti User
Posts: 228
Joined: Mon Mar 10, 2008 6:52 pm
Location: Australia

#13 Post by niobe » Mon Apr 21, 2008 1:35 pm

subscribing I will update this a little later

sumitohri
Posts: 11
Joined: Fri Jun 20, 2008 7:47 pm

#14 Post by sumitohri » Thu Jun 26, 2008 2:03 pm

ptaylor...

which table is it trying to read... i need to know this so i could assign a valid table to $mytable in the availabilityReport.php


I am unable to get this to work...

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

#15 Post by ptaylor874 » Thu Jun 26, 2008 3:33 pm

$myTable is defined in the top... It's trying to read the "host" table.

Post Reply