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:
Overall it then looks like this: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>
#!/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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |