SteScho / manubulon-snmp

Set of Icinga/Nagios plugins to check hosts and hardware with the SNMP protocol.
GNU General Public License v2.0
73 stars 71 forks source link

Allow output for NagVis "weathermap" lines #22

Closed miken32 closed 7 years ago

miken32 commented 7 years ago

More info on the expected format is available here. It's a very poor format (would be nice if we could tell it how to parse standard plugin output) but it's very useful for visualizing bandwidth. I made the following changes which should merge nicely without affecting existing users. Of course, Icinga's command-plugins-manubulon.conf file would need to be updated to support this as well.

diff --git a/plugins/check_snmp_int.pl b/plugins/check_snmp_int.pl
index 7bebf10..f612741 100755
--- a/plugins/check_snmp_int.pl
+++ b/plugins/check_snmp_int.pl
@@ -73,6 +73,7 @@ my $o_version = undef;    # print version
 my $o_noreg   = undef;    # Do not use Regexp for name
 my $o_short   = undef;    # set maximum of n chars to be displayed
 my $o_label   = undef;    # add label before speed (in, out, etc...).
+my $o_weather = undef;    # output "weathermap" data for NagVis

 # Performance data options
 my $o_perf  = undef;      # Output performance data
@@ -257,6 +258,8 @@ sub help {
    warning level for input / output bandwidth (0 for no warning)
      unit depends on B,M,G,u options
    warning for error & discard input / output in error/min (need -q)
+-W, --weather
+   Output data for "weathermap" lines in NagVis with performance data
 -c, --critical=input,output[,error in,error out,discard in,discard out]
    critical level for input / output bandwidth (0 for no critical)
      unit depends on B,M,G,u options
@@ -353,7 +356,9 @@ sub check_options {
         'delta:i'       => \$o_delta,
         'D'             => \$o_dormant,
         'dormant'       => \$o_dormant,
-        'down'          => \$o_down
+        'down'          => \$o_down,
+        'W'             => \$o_weather,
+        'weather'       => \$o_weather
     );
     if (defined($o_help))    { help();      exit $ERRORS{"UNKNOWN"} }
     if (defined($o_version)) { p_version(); exit $ERRORS{"UNKNOWN"} }
@@ -418,6 +423,11 @@ sub check_options {
         print_usage();
         exit $ERRORS{"UNKNOWN"};
     }
+    if (defined($o_weather) && !defined($o_perf)) {
+        print "Cannot output weathermap line data without -f option!\n";
+        print_usage();
+        exit $ERRORS{"UNKNOWN"};
+    }
     if (defined($o_perfr) && defined($o_perfp)) {
         print "-Y and -y options are exclusives\n";
         print_usage();
@@ -963,7 +973,11 @@ for (my $i = 0; $i < $num_int; $i++) {
             $perf_out .= "'" . $descr[$i] . "_out_discard'=" . $$result{ $oid_perf_outdisc[$i] } . "c ";
         }
         if (defined($o_perfs)) {
-            $perf_out .= "'" . $descr[$i] . "_speed_bps'=" . $speed_real;
+            $perf_out .= "'" . $descr[$i] . "_speed_bps'=" . $speed_real . " ";
+        }
+        if (defined($o_weather) && $usable_data == 1) {
+            $perf_out .= "in=" . sprintf("%.0f", $checkperf_out_raw[0]) . ";;;0;" . sprintf("%.0f", $speed_real / 8) . " ";
+            $perf_out .= "out=" . sprintf("%.0f", $checkperf_out_raw[1]) . ";;;0;" . sprintf("%.0f", $speed_real / 8) . " ";
         }
     }
 }
dnsmichi commented 7 years ago

Send a PR please 👍