Graphing a developed plugin

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
jdcassin33
Posts: 2
Joined: Tue Sep 25, 2018 1:00 pm

Graphing a developed plugin

Post by jdcassin33 »

Hi everybody.

Im traying to develope a nagios plugin using shell that gets Temperature and status information from a Fan Coil using SNMP oid, c. It works good. But when I click on the Graph button next to the service (pnp4nagios addon for nagios) it doesnt graph anything, when I try to graph using another plugin, such as check_snmp (Comes with the official nagios plugins pack) pnp4nagios graphs it.
Is there anything bad with my code? I think the information that my plugin sets to nagios isnt enough. Maybe an integer that im missing?

Ill appreciate your help

Code: Select all

#!/bin/sh

fc_return_temperature=`snmpwalk -v2c -c public $1 1.3.6.1.4.1.476.1.42.3.9.20.1.20.1.2.1.4291 /| awk '{print $4}' | bc -l | sed 's/[.].*//'` #Almacena valor obtenido de consulta SNMP, convierte en integer y sin decimales

fc_status=`snmpwalk -v2c -c public $1 1.3.6.1.4.1.476.1.42.3.9.20.1.20.1.2.1.4706 /| awk '{print $4}'` #Almacena valor obtenido de consulta SNMP y obtiene unicamente si esta encendido o apagado

fc_status_string=$(echo "${fc_status//'"'}")

if [ $fc_status_string = "on" ]; then

        if ((19<=$fc_return_temperature && $fc_return_temperature<=26)); then
                echo "OK - $fc_return_temperature"
                exit 0

                elif ((18<=$fc_return_temperature && $fc_return_temperature<=27)); then
                        echo "WARNING HIGH TEMP- $fc_return_temperature"
                        exit 1

                elif ((17<=$fc_return_temperature && $fc_return_temperature<=40)); then
                        echo "CRITICAL HIGH TEMP - $fc_return_temperature"
                        exit 2
        else
                echo "UNKNOWN - $fc_return_temperature"
                exit 3
fi

else
        echo "STANDBY - $fc_return_temperature"
        exit 0

fi
Attachments
pnp4nagios graph
pnp4nagios graph
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Graphing a developed plugin

Post by scottwilkerson »

You need to add to you plugin to contain the performance data
https://nagios-plugins.org/doc/guidelines.html#AEN200

[quote] Nagios 3 and newer will concatenate the parts following a "|" in a) the first line output by the plugin, and b) in the second to last line, into a string it passes to whatever performance data processing it has configured. (Note that it currently does not insert additional whitespace between both, so the plugin needs to provide some to prevent the last pair of a) and the first of b) getting run together.) Please refer to the Nagios documentation for information on how to configure such processing. However, it is the responsibility of the plugin writer to ensure the performance data is in a "Nagios Plugins" format.

This is the expected format:

Code: Select all

'label'=value[UOM];[warn];[crit];[min];[max][/quote]
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Graphing a developed plugin

Post by scottwilkerson »

something like this

Code: Select all

#!/bin/sh

fc_return_temperature=`snmpwalk -v2c -c public $1 1.3.6.1.4.1.476.1.42.3.9.20.1.20.1.2.1.4291 /| awk '{print $4}' | bc -l | sed 's/[.].*//'` #Almacena valor obtenido de consulta SNMP, convierte en integer y sin decimales

fc_status=`snmpwalk -v2c -c public $1 1.3.6.1.4.1.476.1.42.3.9.20.1.20.1.2.1.4706 /| awk '{print $4}'` #Almacena valor obtenido de consulta SNMP y obtiene unicamente si esta encendido o apagado

fc_status_string=$(echo "${fc_status//'"'}")

if [ $fc_status_string = "on" ]; then

        if ((19<=$fc_return_temperature && $fc_return_temperature<=26)); then
                echo "OK - $fc_return_temperature|temp=$fc_return_temperature"
                exit 0

                elif ((18<=$fc_return_temperature && $fc_return_temperature<=27)); then
                        echo "WARNING HIGH TEMP- $fc_return_temperature|temp=$fc_return_temperature"
                        exit 1

                elif ((17<=$fc_return_temperature && $fc_return_temperature<=40)); then
                        echo "CRITICAL HIGH TEMP - $fc_return_temperature|temp=$fc_return_temperature"
                        exit 2
        else
                echo "UNKNOWN - $fc_return_temperature"
                exit 3
fi

else
        echo "STANDBY - $fc_return_temperature"
        exit 0

fi
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
jdcassin33
Posts: 2
Joined: Tue Sep 25, 2018 1:00 pm

Re: Graphing a developed plugin

Post by jdcassin33 »

scottwilkerson wrote:something like this

Code: Select all

#!/bin/sh

fc_return_temperature=`snmpwalk -v2c -c public $1 1.3.6.1.4.1.476.1.42.3.9.20.1.20.1.2.1.4291 /| awk '{print $4}' | bc -l | sed 's/[.].*//'` #Almacena valor obtenido de consulta SNMP, convierte en integer y sin decimales

fc_status=`snmpwalk -v2c -c public $1 1.3.6.1.4.1.476.1.42.3.9.20.1.20.1.2.1.4706 /| awk '{print $4}'` #Almacena valor obtenido de consulta SNMP y obtiene unicamente si esta encendido o apagado

fc_status_string=$(echo "${fc_status//'"'}")

if [ $fc_status_string = "on" ]; then

        if ((19<=$fc_return_temperature && $fc_return_temperature<=26)); then
                echo "OK - $fc_return_temperature|temp=$fc_return_temperature"
                exit 0

                elif ((18<=$fc_return_temperature && $fc_return_temperature<=27)); then
                        echo "WARNING HIGH TEMP- $fc_return_temperature|temp=$fc_return_temperature"
                        exit 1

                elif ((17<=$fc_return_temperature && $fc_return_temperature<=40)); then
                        echo "CRITICAL HIGH TEMP - $fc_return_temperature|temp=$fc_return_temperature"
                        exit 2
        else
                echo "UNKNOWN - $fc_return_temperature"
                exit 3
fi

else
        echo "STANDBY - $fc_return_temperature"
        exit 0

fi

I followed your instructions and now pnp4nagios addon is graphing all my hosts and services.

I noticed that if I run scripts, for example check_snmp plugin, it echoes you the parameter of your OID and the extra numbers you gave me in the development guidelines: 'label'=value[UOM];[warn];[crit];[min];[max]

made the same for my plugin.

Thanks scottwilkerson for your support
Attachments
nagios plugin.jpg
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: Graphing a developed plugin

Post by scottwilkerson »

Awesome, glad to see you got it working!

Locking thread
Former Nagios employee
Creator:
ahumandesign.com
enneagrams.com
Locked