[Tutor] implementing config files

Tracy R Reed treed at ultraviolet.org
Fri Jun 2 03:00:38 CEST 2006


Hello all!

I am writing some code to implement a bunch of passive checks for the 
nagios network monitoring system. It runs some checks on the local 
machine and reports the results back to the nagios server using rpc 
calls via Perspective Broker from the Twisted module. This code and 
associated config file is distributed to all of the machines in my 
infrastructure by cfengine. This part all works quite well. Now I need 
to refactor my code into a more general and flexible infrastructure and 
provide a way to configure the services being checked instead of hard 
coding them (as they currently are).

I need to implement a config file which will provide hostnames, the 
names of checks to run on those hosts, and the options to those checks. 
These things are sets which are nested inside each other which we can 
think of like nested objects. I could make a dictionary containing the 
host names each of which is a dictionary containing the services to be 
checked etc.

But rather than just make dictionaries of dictionaries (which could get 
confusing) I was wondering if I could make it more robust by somehow 
defining objects nested inside of other objects in the config file with 
certain attributes. For example I would like to be able to have a 
check_tcp object which would have two attributes: hostname and port. If 
you try to assign it anything else you get an error. If port isn't a 
number between 0 and 2^16 you get an error. Etc. Basically I don't want 
errors in the config file to propagate all the way to the client machine 
on which the code is going to be executed and have wrong arguments 
passed to the program which we os.popen() and read the results from.

Anyone have suggestions on how to proceed? I'm sure the problem of 
parsing config files into useful objects must be a solved one...

I will eventually be posting a link to my code for others to use and 
critique. It has been a neat project so far.

-- 
Tracy R Reed                  http://ultraviolet.org 
A: Because we read from top to bottom, left to right
Q: Why should I start my reply below the quoted text



More information about the Tutor mailing list