Writing my own SNMP plugin - problem

Hi there,

We’re running Nagios 1.3 on a Proliant ML350, RHEL4. Normal service checks work fine, but I’m having some difficulty getting Nagios to display the results of an SNMP plugin I have written in shell script.

The plugin is quite simple, and is currently only checking against the local Nagios server itself. When I execute the plugin from the command line, I get back the required string, which looks something like

“Memory: 643MB Free OK”

However when Nagios executes the plugin, in the display I only get the following;

“Memory: Free OK”

Very strange. Has anyone else come across this problem at all?

I wonder if I made the right decision going with Nagios 1.3 when 2.0 is now available. Would I be better off cutting my losses now and upgrading before my config becomes too complex (as if it isn’t already, lol).


If you are comfortable with nagios 1.x, then sure, upgrade now before you get to many checks.
Try running your script as user nagios in the command line. Sounds like user nagios doesn’t have access to some command used in your script. If it comes down to it, define a nagios command that starts with sudo.
For example in checkcommands.cfg
command_line sudo /usr/local/nagios2/libexec/ -H $HOSTADDRESS$ -S $ARG1$ -U $USER3$ -P $USER4$ -A $ARG2$ -w $ARG3$ -c $ARG4$

I’ve already tried running the plugin script as user ‘nagios’ and it worked fine. I’ll try the sudo addition as suggested though, and will report back here =)

Hmm. No dice I’m afraid.

Here’s the corresponding line in my checkcommands.cfg;

“command_line sudo /usr/local/nagios/libexec/cpq/check_cpq_freeram”

I have added the user Nagios to sudoers using visudo and granting user Nagios the ALL rights same as root.

Now the check just displays “(No output!)” in the cgi.

I have tried executing the above sudo-enabled command from the command line while logged in as user “nagios” and it worked fine.

Hm. I altered the checkcommands.cfg back to
"command_line /usr/local/nagios/libexec/cpq/check_cpq_freeram"

And got

“OKMB Free” as before.

What is the variable string name that stores the number? It looks like your script is the culprit. The script should have $OUTPUT=Memory: 643MB Free OK in it somewhere, and since the intergers are a variable also, it might be like $OUTPUT=Memory: $value MB Free $SERVICESTATE


Finally got this working - it was indeed my script that was at fault. Nagios wouldn’t return the result of snmpwalk until I specified the exact path of the snmpwalk binary in my script.

Strange as the nagios user was able to execute the plugin fine on it’s own. Perhaps there is some Linux intricacy that I’ve not picked up yet, I’m still pretty new.

Thanks for your help Jakkedup, I’ll continue to lurk here as my journeys into Nagios are far from over. Perhaps I’ll be able to help someone else as you have done :slight_smile:

Hello, would like to know why my check_mem is not working… I’m getting this error message “no output returned from plugin”. I got the “check_mem” from /root/nagios-plugins/plugins-script, just transfered it into /usr/local/nagios/libexec folder. What am I missing?? pls help…tnx

omlex, is this a thread highjacking? hehe.
Anyway, many memory check plugins have been written with a particular OS for use. You would have to look at the plugin code itself and find out what it is using, For example, it might use vmstat with some options/switches that are not available in MY version of linux, but they where valid to another linux version. So simply modify the script to fit your OS.