Yes, this is called "data driven programming" and is generally agreed on as a Good Thing. :-)

There is room for improvement though. You are using functions that take no parameters, a single time each. There's no need to put that code in functions.

As suggested, a refined ps call will help a lot. If you have a GNU ps available, try ps xo command.

A suggestion for your configuration needs: use Config::General, makes for much nicer files, something like:

Enabled 1 <Process ldap> Name "ldapd -p 389" Message "LDAP is not running" Level medium </Process> <Process mta> Name "sendmail: accepting" Message "Sendmail daemon is not accepting connections" Level critical </Process> <Process ntp> Name /xntpd Message "NTP daemon is not running" Level minor </Process> <Process httpd> Name apache/bin/httpd Message "Apache web server is not running" Level minor </Process>
Overall it then looks like this:
#!/usr/bin/perl -w use strict; use Config::General; delete @ENV{qw(IFS PATH CDPATH ENV BASH_ENV)}; my %config = Config::General->new( -ConfigFile => ".processcheckrc", -LowerCaseNames => 1, )->getall; exit unless $config{enabled}; my $ptable = `/usr/bin/ps xo command`; my %alert; while(my($name,$option) = each %{$config{process}}) { my $re = quotemeta $option->{name}; push @{ $alert{ $option->{level} } }, $option->{message} unless $ptable =~ /$re/; } print "REPORT TAKEN AT " . localtime . "\n"; print map "$_\n", "\U$_\E ALERTS", @{%alert{$_}} for sort keys %alert;

Makeshifts last the longest.


In reply to Re: Anticipation of future needs and other musings from the crystal ball by Aristotle
in thread Anticipation of future needs and other musings from the crystal ball by Limbic~Region

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.