Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

More than just a config file

by Mur (Pilgrim)
on Mar 05, 2003 at 19:20 UTC ( #240670=perlquestion: print w/replies, xml ) Need Help??
Mur has asked for the wisdom of the Perl Monks concerning the following question:

I'm tasked with developing a system that monitors the rest of our application, and issues alert messages when certain measurements exceed predefined limits. I have a design in mind for how to do this, but what I still need is a way to supply the limits in the form of an external config file.

I know there are all sorts of .INI file parsers, but what I need is a bit stronger. I envision the configuration looking something like the following:

ALERT1 green 0 - 20 yellow 21 - 40 red > 40 ALERT2 green IN ('a','b','c') yellow IN ('d','e') red OTHERWISE ALERT3 yellow < 12 red >= 12
Each alert would correspond to an external script that would measure something (say, load average), and return a single value. That value might be a number on a scale, or it might be a discrete value (like a string). The alert levels might be scaled so that "high" values are "redder", or it might be the other way around. Some alert levels might be undefined (as the "green" level is in ALERT3, above).

What I'm hoping to find is a parser for a format like this. It's a long shot, but I figure it couldn't hurt to ask here. I poked around at CPAN for a bit, but I don't have a good "search" term that will filter out the various *.INI-type modules.
Jeff Boes
Database Engineer
Nexcerpt, Inc.
vox 269.226.9550 ext 24
fax 269.349.9076
...Nexcerpt...Connecting People With Expertise

Replies are listed 'Best First'.
Re: More than just a config file
by Elian (Parson) on Mar 05, 2003 at 19:33 UTC
    Looks like you're gearing your config file to be easily parseable by people. I think you may find that's not as wise as you might like, since the programs need to unambiguously parse the thing.

    You'd be better off with a compromise format that's parseable by both machines and (with some work) people. If you don't want that, then toss the thought of making the format parseable at all by people, and build yourself a maintenance tool instead. Make the file easy for programs to parse, and the tool easy for people to ues, and have the tool do the config file generation instead.

Re: More than just a config file
by zengargoyle (Deacon) on Mar 05, 2003 at 20:01 UTC

    how about Config::General?

    # myconfig <ALERT1> source = /var/etc/ green = 0 - 20 yellow = 21 - 40 red = > 40 </ALERT1> <ALERT2> source = /var/etc/ green = IN ('a','b','c') yellow = IN ('d', 'e') red = OTHERWISE </ALERT2> ...

    you still have to parse the values of your settings (like IN and OTHERWISE). but it's quite readable and parseable by Config::General.

Re: More than just a config file
by fruiture (Curate) on Mar 05, 2003 at 19:39 UTC

    There's probably no module for that particular format available, because it is your very invention ;). You'll have to parse on your own, but that needn't be too hard. If you can simplify the format so that regular expressions suffice, they'll do it. If you don't want to simplify, keep stuff extensible and maintainable, use Parse::RecDescent, it will do the parsing for you according to an easy-to-write grammar (you can also create very complicated things, but you don't want to).

Re: More than just a config file
by perrin (Chancellor) on Mar 05, 2003 at 20:35 UTC
    Have you considered just using mon? It's built for this.
      Hmm. That looks to be a bit more system-ish. My needs are for things like "widgets per fortnight", which would be tested by counting things in a database table.

      I didn't make it all the way through the dox, but would "mon" accept external tester scripts?
      Jeff Boes
      Database Engineer
      Nexcerpt, Inc.
      vox 269.226.9550 ext 24
      fax 269.349.9076
      ...Nexcerpt...Connecting People With Expertise

        The tests are just Perl modules that you write to implement a certain API. You could do anything in them. However, you're right that it's oriented toward system-level monitoring. I thought that was what you were looking for.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://240670]
Approved by Paladin
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2018-05-26 18:12 GMT
Find Nodes?
    Voting Booth?