Thursday, August 27, 2009

Nagios Downtime Scheduler in Ruby

It's been a while since I worked with anything in Ruby. I was getting into the groove when the whole DDS/MO layoffs happened. Since I got right back on my feet, I really didn't have time to dedicate any time to it.

So now 6+ months later, I had an opportunity to get back in the groove. It didn't go as smooth as I would have liked. I had to look up stuff that I knew by heart previously. That's just like any skill though. It atrophies with disuse.

In this case, none of the recuring downtime schedulers for Nagios were really cutting it. One of them had you add the downtime directly to the script. Others didn't work with Nagios 3. After a night of false alarms that escalated to my boss' boss, I decided to fix the damn problem.

So here's the first iteration of my ruby downtime scheduling script for Nagios 3. It's very rough. There's fuckall for input validation, for instance. It doesn't support anything more than daily recurrance. I'm going to be cleaning it up but I'm pretty happy with how it's shaping up. It has a setup mode and you can interactively add downtimes (as long as you don't fuck up the input - heh)

http://dev.lusis.org/nagios/downtime/

It's not yet approved on exchange.nagios.org. I'm looking for any feedback or feature requests. I want to keep it at its core a downtime scheduler and nothing more but I'd like to revisit my ruby Nagios config parser for the validation.

Like I said, it's been a while since I've done anything in Ruby so I know there are some major 'wtf' moments in there. Be gentle.

2 comments:

Kevin - TheHick said...

Man I wish I could get back into ruby. I'm working with an interface architecture here that has 2 java jars and a c program duct taped together with perl. *blah* I just wish the whole thing was in perl or ruby.

They say there is a ruby solution, but how soon I will get my hands on it is unknown at this point.

Thanks for the script. I don't do alot with NAGios but it is a good example of how to do command line options. I hadn't even tried to do that yet with ruby.

--kevin lester

lusis said...

Hey man! LTNS. Yeah the 'optparse' being included in base ruby is VERY nice. It's also really nice to work with.

I don't know that Ruby is the solution in your case but you COULD do it in ruby using JRuby in the VM and have direct access to the Java methods there.

http://www.linux-mag.com/cache/7470/1.html

There's some examples of using Rails with JRuby in the first part of the showdown with some notes on how the java interaction works. Pretty neat series of articles.