--- /dev/null
+# Register this routine with the plugin reqistry
+$CHECKFUNCS{'cpu'} = \&check_cpu;
+
+# This routine checks the 5min CPU load avg from the uptime comand. This
+# check also return a status of warning if the uptime is less then 1 hour.
+
+sub check_cpu {
+ my $color = "green";
+ my $uptime = `$UPTIME`;
+ my( $message, $jobs );
+
+ my $s = 'up\s+([^\,]+)\,.*\s(\d+) user.+?' .
+ '[0-9\.]+\,\s*([0-9\.]+)\,\s*([0-9\.]+)\s*$';
+ my( $up, $users, $load ) = ( $uptime =~ /$s/ );
+
+ open( PIPE, "$PS |" );
+ while( <PIPE> ) { if( $jobs++ < 11 ) { $message .= $_; } }
+ close( PIPE );
+
+ # Check to see if the system has only been up a short time, and if it has
+ # only been less then an hour, send a page
+
+ if( $up =~ /min/ ) { $color = "yellow"; }
+ if( $load > $CPUWARN ) { $color = "yellow"; }
+ if( $load > $CPUCRIT ) { $color = "red"; }
+
+ my $summary = "up $up, load = $load, $users users, $jobs jobs";
+
+ &debug( "cpu - $color, $summary" );
+ &status( $SPONGSERVER, $HOST, "cpu", $color, $summary, $message );
+}
+
+# I'm include perl code, I need this.
+1;
--- /dev/null
+# Register the routine with the plugin registry
+$CHECKFUNCS{'disk'} = \&check_disk;
+
+# This check check the amount of free diskspace for all of the mounted disk
+# partitions and the the amount of free swapspace.
+
+sub check_disk {
+ my $color = "green";
+ my( $summary, $message, $check, @problems, $large, $lpercent, $page );
+
+ open( PIPE, "$DF |" );
+
+ DFPIPE:
+ while( <PIPE> ) {
+ if( m!^(\S+)\s.*?\s(\d+)\%\s+[^/]*(/.*)$! ) {
+ my( $rawfs, $percent, $name ) = ( $1, $2, $3 );
+ my $skip;
+
+ my $panic = $DFCRIT{$name} || $DFCRIT{$rawfs} || $DFCRIT{"ALL"};
+ my $warn = $DFWARN{$name} || $DFWARN{$rawfs} || $DFWARN{"ALL"};
+
+ foreach $check ( @DFIGNORE ) {
+ next DFPIPE if $rawfs =~ /$check/;
+ next DFPIPE if $name =~ /$check/;
+ }
+
+ if( $percent > $lpercent ) { $lpercent = $percent; $large = $name; }
+
+ $message .= $_;
+ if( $percent >= $panic ) {
+ $color = "red";
+ push( @problems, "$name $percent" );
+ } elsif( $percent >= $warn ) {
+ $color = "yellow" unless $color eq "red";
+ push( @problems, "$name $percent" );
+ }
+ }
+ }
+ close( PIPE );
+
+ # This checks the paging space as well.
+
+ if( $LSPS ) {
+ my $panic = $DFCRIT{"page"} || $DFCRIT{"ALL"};
+ my $warn = $DFWARN{"page"} || $DFWARN{"ALL"};
+
+ $page = `$LSPS 2>&1`;
+ $message .= "\n$page";
+ $page =~ s/.*\s(\d+)%.*/$1/s;
+
+ if( $page >= $panic ) {
+ $color = "red";
+ push( @problems, "page $page" );
+ } elsif( $page >= $warn ) {
+ $color = "yellow" unless $color eq "red";
+ push( @problems, "page $page" );
+ }
+ }
+
+ if (defined &get_swap) {
+ my $panic = $DFCRIT{"page"} || $DFCRIT{"ALL"};
+ my $warn = $DFWARN{"page"} || $DFWARN{"ALL"};
+
+ ($msg, $page) = &get_swap;
+ $message .= "\nSwap Space\n$msg";
+ $page =~ s/.*\s(\d+)%.*/$1/s;
+
+ if( $page >= $panic ) {
+ $color = "red";
+ push( @problems, "page $page" );
+ } elsif( $page >= $warn ) {
+ $color = "yellow" unless $color eq "red";
+ push( @problems, "page $page" );
+ }
+ }
+
+ # Collect the problems, and print a single message describing the problem(s)
+
+ if( $#problems < 0 ) {
+ $summary = "largest filesystem $large at $lpercent%";
+ } elsif( $#problems == 0 ) {
+ my( $disk, $percent) = (split( /\s+/, $problems[0] ));
+ $summary = "$disk is $percent% full";
+ } else {
+ my( $gstr, $sstr );
+
+ $summary = "multiple problems: ";
+ foreach( @problems ) {
+ my( $disk, $percent) = (split( /\s+/, $_ ));
+ $summary .= "$disk ($percent%), ";
+ }
+ chop $summary; chop $summary;
+ }
+
+ &debug( "disk - $color, $summary" );
+ &status( $SPONGSERVER, $HOST, "disk", $color, $summary, $message );
+}
+
+# I'm include perl code, so I need this
+1;
--- /dev/null
+# Register this routine with the plugin registry
+$CHECKFUNCS{'logs'} = \&check_logs;
+
+# Load the logmon modules
+use Spong::Client::logmon;
+
+# Scan through the log files and flag any messages.
+
+sub check_logs {
+ my $color = "green";
+ my( $message, $summary, $word, $ret, $hit, @hit, $time, $critical );
+ my( $lm, @logs, $stat, $key, $numprob, $status, $text, $file, $chk, $lc);
+
+ # If @LOGMON is not defined, load the log monitoring checks
+ if (! defined @LOGMON) {
+ foreach $lc (@$LOGCHECKS) {
+ $lm = Spong::Client::logmon->new($lc->{'logfile'});
+
+ foreach $chk ( @{$lc->{'checks'}} ) {
+ $lm->add_check($chk);
+ }
+ push @LOGMON, $lm
+ }
+ }
+
+ # Run the checks for all of the log files
+ foreach $lm (@LOGMON) { $lm->check(); }
+
+ # Scan each log monitor stati, build the message and calculate summary
+ $message = "";
+ foreach $lm (@LOGMON) {
+ $message .= $lm->logfile() . "\n";
+ $stat = $lm->stati(); $numprob = 0;
+ foreach $key (%$stat) {
+ $numprob++;
+ $status = $stat->{$key}->{'status'};
+ $text = $stat->{$key}->{'text'};
+ if ( $text or $status ) {
+ $message .= "$status : $text\n";
+ }
+ $color = "yellow" if $status eq "yellow" and $color eq "green";
+ $color = "red" if $status eq "red";
+ }
+ if ($numprob == 0) {$message .= "No bad messages\n"; }
+ else { push @logs,$lm->logfile(); }
+ }
+
+ $summary = "All logs ok." if $color eq "green";
+ $summary = "log problems: @logs" if $color ne "green";
+
+ &debug( "logs - $color, $summary" );
+ &status( $SPONGSERVER, $HOST, "logs", $color, $summary, $message );
+}
+
+# I'm included perl code, I need this line.
+1;
--- /dev/null
+# Register this routine with the plugin registery
+
+$CHECKFUNCS{'processes'} = \&check_processes;
+
+
+# This routine checks processes running on the host and makes sure that
+# the important ones are running
+
+sub check_processes {
+ my $color = "green";
+ my( $message, $summary, $check, $ret, $down, @down, $time, $critical );
+
+ system( "$PS > $SPONGTMP/PS.$$" );
+ foreach $check ( @JOBSWARN, @PROCSWARN ) {
+ $ret = `$GREP '$check' $SPONGTMP/PS.$$`;
+ if( $ret =~ /^\s*$/ ) { $color = "yellow"; push( @down, $check ); }
+ else { $message .= $ret; }
+ }
+ foreach $check ( @JOBSCRIT, @PROCSCRIT ) {
+ $ret = `$GREP '$check' $SPONGTMP/PS.$$`;
+ if( $ret =~ /^\s*$/ ) { $color = "red"; push( @down, $check ); }
+ else { $message .= $ret; }
+ }
+ unlink "$SPONGTMP/PS.$$";
+
+ $summary = "processes ok" if $color eq "green";
+ $summary = "(@down) not running" if $color ne "green";
+
+ &debug( "jobs - $color, $summary" );
+ &status( $SPONGSERVER, $HOST, "jobs", $color, $summary, $message );
+}
+
+# I'm include perl code, I need this line.
+1;