No Account Yet?

You are not logged in.

Add to: JBookmarks Add to: Facebook Add to: Windows Live Add to: Digg Add to: Del.icoi.us Add to: Reddit Add to: StumbleUpon Add to: Slashdot Add to: Netscape Add to: Furl Add to: Yahoo Add to: Blogmarks Add to: Technorati Add to: Newsvine Add to: Google Information
Daily Nagios Report Python Script Part One E-mail
Programming HowTo's - Python HowTo's
Written by Allen Sanabria   
Wednesday, 01 October 2008 13:11

I had to create a script that will output every host that has went down in the past day and how many times that host went down and at what times did that host go down and when it came back up in a nice readable format ( Executives who do not know what they are looking at ). Now this is the first release of my script and I do mean first release as I really want to expand it to not just do daily reports from nagios.log but as well as get the archives and any to pass it dates.

I hope you Nagios users who have to send reports to your executives find this script useful but check back soon as I'm going to be adding more to it or even changing it into its own class. As of right now it consist of three functions. The only draw back of the script is that it takes a while to parse the log file since it has to find all the uniq hosts in nagios.log and find only the hard down and hard up events compared to the uniq hosts.

For now I run this script in cron at 6AM and have the txt file that it creates sent to a list of users at 7AM on a daily basis.  Again this is my first revision it will go through alot more and if you have suggestions or you have expanded on this script by all means let me know so I can post it up here or you can become a member and post it yourself. Also if you have request please become a member and ask in the forums section.

The output looks like this

Host host1 Status Report
-----------------------------------------------------------------
Total Times Down = 1
host1 went DOWN at Thu Oct 2 01:34:31 2008
-----------------------------------------------------------------

Host host2 Status Report
-----------------------------------------------------------------
Total Times Down = 1
host2 went DOWN at Thu Oct 2 03:16:11 2008
host2 went UP at Thu Oct 2 03:26:51 2008
-----------------------------------------------------------------

Host host3 Status Report
-----------------------------------------------------------------
Total Times Down = 1
host3 went DOWN at Thu Oct 2 04:16:31 2008
-----------------------------------------------------------------

Host host4 Status Report
-----------------------------------------------------------------
Total Times Down = 3
host4 went DOWN at Tue Oct 2 04:13:58 2008
host4 went DOWN at Tue Oct 2 08:50:28 2008
host4 went DOWN at Tue Oct 2 12:17:08 2008
host4 went UP at Tue Oct 2 07:28:38 2008
host4 went UP at Tue Oct 2 10:53:08 2008
host4 went UP at Tue Oct 2 12:43:48 2008

You can download the script here. To download the script you must become a member first

Comments
Search RSS
dynasty   |SAdministrator |2008-10-14 10:27:39
Quick update this script has been updated and now runs in seconds instead of
minutes.. Thank you for your patience.
nynix  - cant get the code--   |Registered |2008-11-22 07:12:12
Hey Allen!

I am trying to dl the code for this script, but cant for some
reason-

I would like to check it out if possible.

Thanks!

Nynix
dynasty  - re: cant get the code--   |SAdministrator |2008-11-22 08:45:41
nynix wrote:
Hey Allen!

I am trying to dl the code for this script, but cant for some
reason-

I would like to check it out if possible.

Thanks!

Nynix

Yo buddy, I just tested the link it works. All you need to do is go to the
downloads sections and download it from there.
Only registered users can write comments!

3.22 Copyright (C) 2007 Alain Georgette / Copyright (C) 2006 Frantisek Hliva. All rights reserved."

Last Updated ( Tuesday, 07 October 2008 09:49 )
 

 

Python News