Cacti (home)ForumsRepositoryDocumentation
Cacti: offical forums and support  

 FAQFAQ   SearchSearch   MemberlistMemberlist    RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in    


[HOWTO] Availability Reporting
Goto page 1, 2  Next
 
Post new topic   Reply to topic    Cacti Forum Index -> Informational/HOWTO's
Author Message
ptaylor874



Joined: 04 Jan 2008
Posts: 23

PostPosted: Mon Jan 28, 2008 3:45 pm    Post subject: [HOWTO] Availability Reporting Reply with quote

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.



Screenshot.png
 Description:
Screenshot
 Filesize:  15.46 KB
 Viewed:  4081 Time(s)

Screenshot.png



availabilityReport.zip
 Description:
availabilityReport.php and smtp.class.php. Place both in the same directory.

Download
 Filename:  availabilityReport.zip
 Filesize:  9.22 KB
 Downloaded:  493 Time(s)



Last edited by ptaylor874 on Tue Sep 02, 2008 11:47 am; edited 7 times in total
Back to top
sveno



Joined: 14 Feb 2008
Posts: 7

PostPosted: Tue Feb 19, 2008 6:57 am    Post subject: Reply with quote

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



Joined: 04 Jan 2008
Posts: 23

PostPosted: Tue Feb 19, 2008 8:16 am    Post subject: Reply with quote

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
Back to top
torstentfk
Cacti User


Joined: 05 Apr 2005
Posts: 182
Location: Munich, Germany

PostPosted: Wed Feb 20, 2008 4:32 am    Post subject: Reply with quote

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:
#!/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
Back to top
phakesley



Joined: 13 Nov 2007
Posts: 24

PostPosted: Tue Mar 11, 2008 5:10 am    Post subject: Availabilty report Reply with quote

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?
Back to top
ptaylor874



Joined: 04 Jan 2008
Posts: 23

PostPosted: Tue Mar 11, 2008 8:24 am    Post subject: Reply with quote

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..??
Back to top
phakesley



Joined: 13 Nov 2007
Posts: 24

PostPosted: Tue Mar 25, 2008 10:16 am    Post subject: Reply with quote

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.
Back to top
saya
Cacti User


Joined: 16 Jan 2008
Posts: 58

PostPosted: Fri Mar 28, 2008 3:37 am    Post subject: Reply with quote

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
Back to top
sveno



Joined: 14 Feb 2008
Posts: 7

PostPosted: Fri Apr 04, 2008 4:02 am    Post subject: Reply with quote

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!
Back to top
big-timmy



Joined: 03 Apr 2008
Posts: 8

PostPosted: Fri Apr 04, 2008 4:46 pm    Post subject: Reply with quote

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

Many thanks!!!
Back to top
ptaylor874



Joined: 04 Jan 2008
Posts: 23

PostPosted: Tue Apr 08, 2008 2:33 pm    Post subject: Reply with quote

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.
Back to top
ptaylor874



Joined: 04 Jan 2008
Posts: 23

PostPosted: Fri Apr 11, 2008 8:28 am    Post subject: Reply with quote

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.
Back to top
niobe
Cacti User


Joined: 10 Mar 2008
Posts: 125
Location: Australia

PostPosted: Mon Apr 21, 2008 1:35 pm    Post subject: Reply with quote

subscribing I will update this a little later
Back to top
sumitohri



Joined: 20 Jun 2008
Posts: 11

PostPosted: Thu Jun 26, 2008 2:03 pm    Post subject: Reply with quote

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...
Back to top
ptaylor874



Joined: 04 Jan 2008
Posts: 23

PostPosted: Thu Jun 26, 2008 3:33 pm    Post subject: Reply with quote

$myTable is defined in the top... It's trying to read the "host" table.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Cacti Forum Index -> Informational/HOWTO's All times are GMT - 5 Hours
Goto page 1, 2  Next
Page 1 of 2

 



Powered by phpBB © 2001, 2005 phpBB Group