Limbic~Region has asked for the wisdom of the Perl Monks concerning the following question:
One thing I needed to solve was a way of monitoring system health and reporting only what was relavent. Without discussing the merits of other programs that do the same thing, I needed it to be incredibly specific to my environment, I needed it to be fast, and I needed it to be expandable.
The last part is the one that intrigued me - was it possible to write a program that could grow and expand without modifying the code? The answer is yes if you standardize the "types" of things you are looking for. Now the question you may slam me for asking - is this the right approach? Here is a sample of some code to give you an idea of what I am talking about.
#!/usr/bin/perl -W use strict; use Config::IniFiles; delete @ENV{qw(IFS PATH CDPATH ENV BASH_ENV)}; my $cfg = new Config::IniFiles( -file => "default.ini" ); &processcheck if $cfg->val('PROCESS','ENABLED'); &displayresults; exit; sub processcheck { my @ptable = `/usr/bin/ps -ef`; my @alert = $cfg->val('PROCESS','ALERT'); my @message = $cfg->val('PROCESS','MESSAGE'); my @process = $cfg->val('PROCESS','PROCESS'); for ( my $i = 0; $i <= $#alert; $i++ ) { unless(grep /$process[$i]/ , @ptable) { $alerts{"$alert[$i]"} .= "\n$message[$i]"; } } } sub displayresults { print "REPORT TAKEN AT " . localtime(time) . "\n"; for my $alerttype ( sort keys %alerts ) { print "\n\U$alerttype\E ALERTS"; print "$alerts{$alerttype}\n"; } } #default.ini [PROCESS] ENABLED = 1 PROCESS = ldapd -p 389 PROCESS = sendmail: accepting PROCESS = /xntpd PROCESS = apache/bin/httpd MESSAGE = LDAP is not running MESSAGE = Sendmail daemon is not accepting connections MESSAGE = NTP daemon is not running MESSAGE = Apache web server is not running ALERT = medium ALERT = major ALERT = minor ALERT = minor
Again, most of the code is tailored for the environment I work in and I couldn't disclose it here if I wanted to. There is a way to set thresholds for disk space and the appropriate alert, ways to check if log files are being updated or are stagnant, etc.
My question is - is this a bad idea, are the security risks too great? The above section of code should work with Taint turned on for those of you who would like to use it. For me, it is a lot easier to go into the config file to adjust a parameter or add a new check then it is to go into the code - especially when what people want changes every day - I wanted the code to stay small and clean.
ok, fire away - my job is secure even if my XPs aren't.
|
|---|