cisco-check.pl returns error when CPU usage is 0

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
DanSuper
Posts: 2
Joined: Wed May 12, 2021 1:30 am

cisco-check.pl returns error when CPU usage is 0

Post by DanSuper »

Cisco routers return an integer for CPU usage.

The Icinga check-cisco.pl script works well when CPU usage is between 1% to 99%, but sometimes the usage is legitimately 0%. It's only an integer, no float so guess 0.4% would be rounded down to 0.

I can test this with:

snmpget -v 2c -c public myciscorouter .1.3.6.1.4.1.9.2.1.56.0
SNMPv2-SMI::enterprises.9.2.1.56.0 = INTEGER: 0

I expect Icinga check to return OK and 0% CPU.

What I get instead is:
"Remote device does not return data for cpu"

This file with the problem is located here on my Debian machine:
/usr/lib/nagios/plugins/check-cisco.pl

I can see the problem in the perl code, but I don't understand perl and struggle to fix it:

sub check_oid_return {
        my ($oid_value, $parameter_name) = @_;

        if ( $oid_value == '' ) {
                print "Remote device does not return data for $parameter_name\n";
                exit(1);
        }
}


I changed if line to:
        if ( $oid_value eq '' and ( $parameter_name eq 'cpu'  and looks_like_number($oid_value) and $oid_value == 0 ) ) {

This fixes it for 0 checks, e.g.:

Cpu: OK - Cpu Load 0% 0% 0% | cpu_5s=0percent;80;90 cpu_1m=0percent cpu_5m=0percent

However, it I no longer get "Remote device does not return data" error when this is actually the case, e.g.:

/usr/bin/perl /usr/lib/nagios/plugins/check-cisco-test.pl -H nonciscohost -C public -t cpu -w 80 -c 90

Cpu: OK - Cpu Load noSuchObject% noSuchObject% noSuchObject% | cpu_5s=noSuchObjectpercent;80;90 cpu_1m=noSuchObjectpercent cpu_5m=noSuchObjectpercent

How can this be fixed?
User avatar
Rfferrao13
Posts: 12
Joined: Tue Aug 09, 2016 3:56 pm

Re: cisco-check.pl returns error when CPU usage is 0

Post by Rfferrao13 »

I don't get what you were trying to do with this modified expression, but I think you can just simplify the condition from this:

Code: Select all

if ( $oid_value eq '' and ( $parameter_name eq 'cpu'  and looks_like_number($oid_value) and $oid_value == 0 ) ) {
To this:

Code: Select all

if ( ! looks_like_number($oid_value) ) {
And it would most likely work for what you need.
DanSuper
Posts: 2
Joined: Wed May 12, 2021 1:30 am

Re: cisco-check.pl returns error when CPU usage is 0

Post by DanSuper »

Thanks for reply, but doesn't work.

I'm trying to make it report 0% CPU usage when this is the case, but I don't want it to return 0% CPU usage when actually no value is returned.
Locked