new-klecker is on buster
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-msa-eventlog
index dff9648..4416992 100755 (executable)
@@ -6,7 +6,7 @@
 # once an issue has been acknowledged/fixed, change the --startindex option
 
 
-# Copyright (C) 2009 Peter Palfrader <peter@palfrader.org>
+# Copyright (C) 2009,2012 Peter Palfrader <peter@palfrader.org>
 #
 # Permission is hereby granted, free of charge, to any person obtaining
 # a copy of this software and associated documentation files (the
@@ -34,13 +34,15 @@ use Net::SNMP;
 use Getopt::Long;
 
 
-my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--timeout=<timeout>] [--startindex=<idx>] <host> <community>\n";
+my $usage = "$PROGRAM_NAME: Usage: $PROGRAM_NAME [--help|--version] [--timeout=<timeout>] [--startindex=<idx>] [--verbose] <host> <community>\n";
 my $params;
+$params->{'verbosity'} = 0;
 Getopt::Long::config('bundling');
 if (!GetOptions (
        '--help'         => \$params->{'help'},
        '--timeout=i'    => \$params->{'timeout'},
        '--startindex=i' => \$params->{'startindex'},
+       '-verbose'       => \$params->{'verbosity'},
        )) {
        die ($usage);
 };
@@ -119,15 +121,18 @@ for my $key (keys %$r) {
 
 my $exit = 0;
 my $res = '';
-my %num = ('warn' => 0, 'error' => 0);
+my %num = ('warn' => 0, 'error' => 0, 'info' => 0, 'error-ignored' => 0, 'warn-ignored' => 0);
 
 for my $idx (sort {$a <=> $b} keys %{$data{'severity'}}) {
        my $sev = $snmp_severity{$data{'severity'}->{$idx}};
        die("Unexpected severity $data{'severity'}->{$idx}\n") unless $sev;
        my $sevint = $severity_int{$sev};
-       if ($sevint > 0) {
+       if ($sevint > -$params->{'verbosity'}) {
                my $msg = $data{'message'}->{$idx};
-               next if grep {$_ eq $msg} @ignores;
+               if (grep {$_ eq $msg} @ignores) {
+                       $num{$sev.'-ignored'}++;
+                       next;
+               };
 
                $exit = $sevint > $exit ? $sevint : $exit;
 
@@ -137,11 +142,18 @@ for my $idx (sort {$a <=> $b} keys %{$data{'severity'}}) {
                        $data{'timestamp'}->{$idx},
                        $msg;
 
+               $num{$sev}++;
+       } else {
                $num{$sev}++;
        };
 };
 
-printf "Event Log: %d warnings, %d errors\n", $num{'warn'}, $num{'error'};
+printf "Event Log: %d info, %d warnings%s, %d errors%s\n",
+       $num{'info'},
+       $num{'warn'},
+       ($num{'warn-ignored'} ? " (+$num{'warn-ignored'} ignored)" : ""),
+       $num{'error'},
+       ($num{'error-ignored'} ? " (+$num{'error-ignored'} ignored)" : "");
 print $res;
 exit $exit;