Title: [opsview] [11686] SNMP threshold alerts' expanded syntax support.
Modified: trunk/CHANGES
===================================================================
--- trunk/CHANGES	2013-03-08 11:59:48 UTC (rev 11685)
+++ trunk/CHANGES	2013-03-08 12:11:21 UTC (rev 11686)
@@ -6,8 +6,10 @@
     PLATFORMS:
     ENHANCEMENTS:
     Allow tracing of individual hosts in check_snmp_interfaces_cascade
+    Allow specifying a throughput range for SNMP alerts
     Restore clicking on product name in footer to get build version information
     check_snmp_sysinfo now returns CRITICAL if it cannot connect to SNMP
+    SNMP throughput thresholds now have an expanded syntax to handle input and output throughput separately
     Updated NRPE to 2.14 due to potential security exposure
     Allow authtkt cookie to be set when logging into Opsview REST API
     NOTICES:

Modified: trunk/opsview-core/lib/Opsview/Utils/SnmpInterfaces.pm
===================================================================
--- trunk/opsview-core/lib/Opsview/Utils/SnmpInterfaces.pm	2013-03-08 11:59:48 UTC (rev 11685)
+++ trunk/opsview-core/lib/Opsview/Utils/SnmpInterfaces.pm	2013-03-08 12:11:21 UTC (rev 11686)
@@ -26,6 +26,7 @@
 use warnings;
 
 use Math::BigInt;
+use Nagios::Plugin;
 
 =head2 tidy_interface_ifdescr
 
@@ -40,8 +41,8 @@
 Should be used by query_host and check_snmp_linkstatus to keep in sync
 with name changes
 
-NOTE: the words to be removed are governed by the provided level which is 
-set on a per host basis.  This is to ensure upgraded systems are not 
+NOTE: the words to be removed are governed by the provided level which is
+set on a per host basis.  This is to ensure upgraded systems are not
 affected by adding new words here
 
 =cut
@@ -449,4 +450,153 @@
     return $interfaces;
 }
 
+sub throughput_state {
+
+    my (
+        $warning_syntax, $critical_syntax,   $throughput_in,
+        $throughput_out, $throughput_in_pct, $throughput_out_pct
+    ) = @_;
+
+    my $np = Nagios::Plugin->new;
+
+    my ( $warning_state, $warning_speed_is_zero ) =
+      _calculate_state( $np, 'warning', $warning_syntax,
+        $throughput_in_pct, $throughput_out_pct, $throughput_in,
+        $throughput_out );
+
+    my ( $critical_state, $critical_speed_is_zero ) =
+      _calculate_state( $np, 'critical', $critical_syntax,
+        $throughput_in_pct, $throughput_out_pct, $throughput_in,
+        $throughput_out );
+
+    if ( $warning_speed_is_zero or $critical_speed_is_zero ) {
+        return ( 1, 1 );
+    }
+
+    return
+        $critical_state ? ( $critical_state, 0 )
+      : $warning_state  ? ( $warning_state,  0 )
+      :                   ( 0, 0 );
+
+}
+
+sub _calculate_state {
+
+    my ( $np, $type, $criteria,
+        $throughput_in_pct, $throughput_out_pct, $throughput_in,
+        $throughput_out )
+      = @_;
+    $criteria = lc $criteria;
+
+    my ( $input, $conjunction, $output );
+    if ( $criteria =~ /^\s*in\s+([.\d:%]+)\s+(and|or)\s+out\s+([.\d:%]+)\s*$/ )
+    {
+        ( $input, $conjunction, $output ) = ( $1, $2, $3 );
+    }
+    elsif ( $criteria =~ /^\s*in\s+([.\d:%]+)\s*$/ ) {
+        $input       = $1;
+        $conjunction = 'or';
+    }
+    elsif ( $criteria =~ /^\s*out\s+([.\d:%]+)\s*$/ ) {
+        $output      = $1;
+        $conjunction = 'or';
+    }
+    elsif ( $criteria =~ /^\s*([.\d:%]+)\s*$/ ) {
+        $input = $output = $1;
+        $conjunction = 'or';
+    }
+    $input  =~ s/%+//g if defined $input;
+    $output =~ s/%+//g if defined $output;
+
+    my ( $max_state, $speed_is_zero ) = ( 0, 0 );
+
+    if ( $criteria =~ /%/ ) {
+        if (
+            $conjunction eq 'and'
+            and (   not defined $throughput_in_pct
+                and not defined $throughput_out_pct )
+          )
+        {
+            $speed_is_zero = 1;
+            return ( 1, 1 );
+        }
+        elsif (
+            $conjunction eq 'or'
+            and (  not defined $throughput_in_pct
+                or not defined $throughput_out_pct )
+          )
+        {
+            $speed_is_zero = 1;
+            return ( 1, 1 );
+        }
+    }
+
+    # If we're only checking input.
+    if ( not defined $output
+        or ( $criteria =~ /%/ and not defined $throughput_out_pct ) )
+    {
+        $max_state = $np->check_threshold(
+            check => ( $criteria =~ /%/ ? $throughput_in_pct : $throughput_in ),
+            warning  => ( $type eq 'warning'  ? $input : undef ),
+            critical => ( $type eq 'critical' ? $input : undef ),
+        );
+    }
+
+    # If we're only checking output.
+    elsif ( not defined $input
+        or ( $criteria =~ /%/ and not defined $throughput_in_pct ) )
+    {
+        $max_state = $np->check_threshold(
+            check =>
+              ( $criteria =~ /%/ ? $throughput_out_pct : $throughput_out ),
+            warning  => ( $type eq 'warning'  ? $output : undef ),
+            critical => ( $type eq 'critical' ? $output : undef ),
+        );
+    }
+
+    # We're checking everything.
+    elsif (
+        defined $input and defined $output
+        or (    defined $throughput_in_pct
+            and defined $throughput_out_pct )
+      )
+    {
+
+        my $max_state_input = $np->check_threshold(
+            check => ( $criteria =~ /%/ ? $throughput_in_pct : $throughput_in ),
+            warning  => ( $type eq 'warning'  ? $input : undef ),
+            critical => ( $type eq 'critical' ? $input : undef ),
+        );
+
+        my $max_state_output = $np->check_threshold(
+            check =>
+              ( $criteria =~ /%/ ? $throughput_out_pct : $throughput_out ),
+            warning  => ( $type eq 'warning'  ? $output : undef ),
+            critical => ( $type eq 'critical' ? $output : undef ),
+        );
+
+        if ( $conjunction eq 'and' ) {
+            if ( $max_state_input and $max_state_output ) {
+                $max_state =
+                    $max_state_input > $max_state_output
+                  ? $max_state_input
+                  : $max_state_output;
+            }
+        }
+        elsif ( $conjunction eq 'or' ) {
+            if ( $max_state_input or $max_state_output ) {
+                $max_state =
+                  $max_state_input ? $max_state_input : $max_state_output;
+            }
+        }
+
+    }
+    else {
+        # A catch-all. We shouldn't get here, but if Nagios returns no data...
+        $speed_is_zero = 1;
+    }
+
+    return ( $max_state, $speed_is_zero );
+}
+
 1;

Modified: trunk/opsview-core/nagios-plugins/check_snmp_interfaces_cascade
===================================================================
--- trunk/opsview-core/nagios-plugins/check_snmp_interfaces_cascade	2013-03-08 11:59:48 UTC (rev 11685)
+++ trunk/opsview-core/nagios-plugins/check_snmp_interfaces_cascade	2013-03-08 12:11:21 UTC (rev 11686)
@@ -799,59 +799,15 @@
           $intdata->{octetsOut};
     }
 
-    my $max_state     = 0;
-    my $extra_message = "";
-    my $speed_is_zero = 0;
-    if ( my $critical = $intdata->{throughput_critical} ) {
-        if ( $critical =~ s/%$//xsm ) {
+    my ( $max_state, $speed_is_zero ) =
+      Opsview::Utils::SnmpInterfaces::throughput_state(
+        $intdata->{throughput_warning},
+        $intdata->{throughput_critical},
+        $throughput_in, $throughput_out,
+        $throughput_in_pct, $throughput_out_pct
+      );
 
-            # Check throughput_in_pct and out_pct
-            if ( defined $throughput_in_pct && defined $throughput_out_pct ) {
-                $max_state = $np->check_threshold(
-                    check    => [ $throughput_in_pct, $throughput_out_pct ],
-                    warning  => undef,
-                    critical => $critical
-                );
-            }
-            else {
-                $speed_is_zero = 1;
-            }
-        }
-        else {
-            $max_state = $np->check_threshold(
-                check    => [ $throughput_in, $throughput_out ],
-                warning  => undef,
-                critical => $critical
-            );
-        }
-    }
-    if ( my $warning = $intdata->{throughput_warning} ) {
-        if ( $warning =~ s/%$//xsm ) {
-            if ( defined $throughput_in_pct && defined $throughput_out_pct ) {
-                $max_state = $np->max_state(
-                    $max_state,
-                    $np->check_threshold(
-                        check    => [ $throughput_in_pct, $throughput_out_pct ],
-                        warning  => $warning,
-                        critical => undef,
-                    )
-                );
-            }
-            else {
-                $speed_is_zero = 1;
-            }
-        }
-        else {
-            $max_state = $np->max_state(
-                $max_state,
-                $np->check_threshold(
-                    check    => [ $throughput_in, $throughput_out ],
-                    warning  => $warning,
-                    critical => undef,
-                )
-            );
-        }
-    }
+    my $extra_message = "";
     if ($speed_is_zero) {
         $extra_message =
           " but has an interface speed of 0, so cannot check a percentage threshold";

Modified: trunk/opsview-core/share/_javascript_/forms.js
===================================================================
--- trunk/opsview-core/share/_javascript_/forms.js	2013-03-08 11:59:48 UTC (rev 11685)
+++ trunk/opsview-core/share/_javascript_/forms.js	2013-03-08 12:11:21 UTC (rev 11686)
@@ -159,6 +159,7 @@
 var invalidTimeperiodChars = /[\[\]`~!$%^&*|'"<>?()=a-zA-Z ]/;     /* timeperiods */
 var invalidCharsIP = /[\[\]`~!$%^&*|'"<>?,()= ]/;
 var integer_percent = /[\[\]\/£,.@+:;\\{}_#`~!$^&*|'"<>?()=a-zA-Z ]/; /* whole numbers with a percent sign */
+var integer_percent_colon_space_ampersand_bar = /[\[\]\/£,@+;\\{}_#`~!$^*'"<>?()=]/;
 var integer = /[\[\]\/£,.@+:;\\{}_#`~!$%^&*|'"<>?()=a-zA-Z ]/; /* whole numbers only */
 
 function blockInvalidKeys(objEvent, chars) {
@@ -179,6 +180,8 @@
 		chars = invalidCharsIP;
 	} else if (chars == 9) {
 		chars = invalidCharsAllowParenthesis;
+	} else if (chars == 10) {
+		chars = integer_percent_colon_space_ampersand_bar;
 	} else {
 		chars = invalidChars;
 	}

Modified: trunk/opsview-web/lib/Opsview/Web/I18N/i_default.po
===================================================================
--- trunk/opsview-web/lib/Opsview/Web/I18N/i_default.po	2013-03-08 11:59:48 UTC (rev 11685)
+++ trunk/opsview-web/lib/Opsview/Web/I18N/i_default.po	2013-03-08 12:11:21 UTC (rev 11686)
@@ -10,10 +10,10 @@
 "PO-Revision-Date: 2009-06-09 14:10+0000\n"
 "Last-Translator: Ton Voon <ton.v...@opsview.com>\n"
 "Language-Team: English <e...@li.org>\n"
-"Language: en\n"
 "MIME-Version: 1.0\n"
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
+"Language: en\n"
 
 msgid "messages.access.noAuthToChangeService"
 msgstr "You are not authorised to change the state of this service"
@@ -146,8 +146,9 @@
 msgid "messages.auditlog.submitServiceCheck.failed %1"
 msgstr "Failed to submit service check result: %1"
 
+#. ($s->servicename,         $s->hostname,                    $states_by_id->{$state}, $comment,)
 #. ($c->stash->{object}->name,                    $c->stash->{object}->host_object_id->name,                    $states_by_id->{$state},                    $comment,)
-#. ($s->servicename,         $s->hostname,                    $states_by_id->{$state}, $comment,)
+#. ($c->stash->{object}->name,                    $c->stash->{object}->host_object_id->name,                    $states_by_id->{$state},                    $comment,)
 msgid "messages.auditlog.submittingServiceCheckResultOnAs %1 %2 %3 %4"
 msgstr "Submitting service check result: %1 on %2 as %3: %4"
 
@@ -871,7 +872,7 @@
 msgstr "> # per minute in one polling cycle"
 
 msgid "ui.admin.host.edit.interfaces.heading.help.throughput"
-msgstr "> % or bits per second"
+msgstr "max%, min:max%, or bits per second"
 
 msgid "ui.admin.host.edit.interfaces.heading.throughput"
 msgstr "Throughput"
@@ -1371,8 +1372,9 @@
 msgid "ui.admin.list.label.delete.confirm %1"
 msgstr "Are you sure you want to delete `%1`?"
 
+#. ($c->stash->{object}->name)
 #. ($o->name)
-#. ($c->stash->{object}->name)
+#. ($o->name)
 #. (object_name)
 msgid "ui.admin.list.label.edit %1"
 msgstr "Edit %1"
@@ -2516,9 +2518,9 @@
 msgid "ui.downtime.help.commentEmpty"
 msgstr "Comment is empty"
 
-#. (join( "::",                        $c->stash->{object}->hostname,                        $c->stash->{object}->name)
 #. ($c->stash->{object}->name)
 #. (join( "::",                $c->stash->{object}->hostname,                $c->stash->{object}->name)
+#. (join( "::",                        $c->stash->{object}->hostname,                        $c->stash->{object}->name)
 msgid "ui.downtime.help.downtimeDeletedFor %1"
 msgstr "Downtime delete for %1"
 

Modified: trunk/opsview-web/opsview_web.yml.in
===================================================================
--- trunk/opsview-web/opsview_web.yml.in	2013-03-08 11:59:48 UTC (rev 11685)
+++ trunk/opsview-web/opsview_web.yml.in	2013-03-08 12:11:21 UTC (rev 11686)
@@ -79,7 +79,7 @@
   ON_ERROR_SERVE: /usr/local/nagios/share/images/rrderror.png
 
 host_interfaces:
-  default_throughput_critical: 50%
+  default_throughput_critical: 0:50%
   default_errors_critical: 10
   default_discards_critical: 15
 

Modified: trunk/opsview-web/root/admin/host/interfaces
===================================================================
--- trunk/opsview-web/root/admin/host/interfaces	2013-03-08 11:59:48 UTC (rev 11685)
+++ trunk/opsview-web/root/admin/host/interfaces	2013-03-08 12:11:21 UTC (rev 11686)
@@ -73,7 +73,7 @@
 </div>
 <script type="text/_javascript_">
 Validation.add('validate-throughput','', {
-  pattern: new RegExp(/^[-\.\d]+%?$/)
+  pattern: new RegExp(/^[-.\d:%INADROUT ]+%?$/i)
 });
 Validation.add('validate-discards','', {
   pattern: new RegExp(/^[-\d]+$/)

Modified: trunk/opsview-web/root/admin/host/snmpinterfaces
===================================================================
--- trunk/opsview-web/root/admin/host/snmpinterfaces	2013-03-08 11:59:48 UTC (rev 11685)
+++ trunk/opsview-web/root/admin/host/snmpinterfaces	2013-03-08 12:11:21 UTC (rev 11686)
@@ -12,7 +12,7 @@
   ELSE;
     value = "-";
   END;
-  %]<td><input class="[% args.validation %]" type="text" name="[% threshold %]" value="[% value | html %]" size="6" _onkeypress_="return blockInvalidKeys(event,6)" /></td>[%
+  %]<td><input class="[% args.validation %]" type="text" name="[% threshold %]" value="[% value | html %]" size="6" _onkeypress_="return blockInvalidKeys(event,10)" /></td>[%
 END;
 
 %]

_______________________________________________
Opsview-checkins mailing list
Opsview-checkins@lists.opsview.org
http://lists.opsview.org/lists/listinfo/opsview-checkins

Reply via email to