Follow me!

LinkedIn Twitter

Who's Online

We have 151 guests online

Python News



  

Daily Nagios Report Python Script Part One
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.

UPDATE!!!
Cambid, fixed the regex in the script. It  should now match correctly in all environments!

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

 Download Daily Nagios Report
File Title:Daily Nagios Report (Details)
File Type:py
File Version:1.0
File Size:4.21 Kb
License:Copyright (C) 2008 Allen Sanabria This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
File Author:
File HomePage:http://www.linuxdynasty.org/
Downloads:459
Rating: ( Votes)
Your Vote:

alt



Add this page to your favorite Social Bookmarking websites
Reddit! Del.icio.us! Mixx! Free and Open Source Software News Google! Live! Facebook! StumbleUpon! Yahoo! Free Joomla PHP extensions, software, information and tutorials.
Comments
Search RSS
dynasty   |SAdministrator |2009-06-26 06:12:46
Cambid, thanks for the regex fix! I uploaded the new revision to the site.
cambid     |Author |2009-06-29 08:15:40
Hi dynasty

sorry for not replying, but there was much work here.

I have added
my info into the script. I will maintain it on
www.faderweb.de/downloads/nagios_report.py or can I upload it right here?

Kind
regards
dynasty   |SAdministrator |2009-06-29 09:16:15
You can definitely upload it here.

As I appreciate the fact that you took the
time to post it here.
Only registered users can write comments!

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

Last Updated on Wednesday, 02 September 2009 08:57