[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

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

[HOWTO] Availability Reporting

Post by ptaylor874 »

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
Screenshot
Screenshot.png (15.46 KiB) Viewed 62307 times
availabilityReport.zip
availabilityReport.php and smtp.class.php. Place both in the same directory.
(9.22 KiB) Downloaded 6544 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

Post by sveno »

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

Post by ptaylor874 »

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

Post by torstentfk »

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 "test@de.com,l@l.com"
  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

Post by phakesley »

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

Post by ptaylor874 »

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

Post by phakesley »

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

Post by saya »

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

Post by sveno »

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

Post by big-timmy »

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

Post by ptaylor874 »

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

Post by ptaylor874 »

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

Post by niobe »

subscribing I will update this a little later
sumitohri
Posts: 11
Joined: Fri Jun 20, 2008 7:47 pm

Post by sumitohri »

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

Post by ptaylor874 »

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

Who is online

Users browsing this forum: No registered users and 1 guest