Link to home
Start Free TrialLog in
Avatar of valheru_m
valheru_mFlag for United States of America

asked on

Nagios plugin output editing

Hi all!

So I've got nagios monitoring our ESXi hosts with the awesome op5 check_vmware_api.pl script and it's working well except for one (admittedly mostly cosmetic) thing.  The output string from that script is very messy because every check returns the entire name of the script before any of the results, which takes up a considerable amount of real estate in the status information column of the services monitor as shown here:

User generated image
The entire CHECK_VMWARE_API.PL string appears in EVERY result, unlike the output of most other plugins which is fairly clean.  In an effort to fix the problem myself I temporarily changed the command in the nagios config and added:

 | sed -e 's/CHECK_VMWARE_API.PL //'

to the end of the command, which seemed to work well at first:

User generated image
until I realized that it prevented nagios from seeing a warning output as an actionable warning for alerting purposes.  Notice the warning for the ESXi2 server memory usage that appears as a yellow warning in the first screenshot above still appears as a warning in the text output from the command in the second screenshot, but nagios sees it as a green "ok" in the status column, which means I would never get alerts based on the results from that check.

Does anyone know if there's a way to clean up the output from a plugin cleanly without editing the actual perl script?  I can spell 'perl' but other than that I'm pretty much useless with it.

Thanks in advance for your time!
Avatar of Kerem ERSOY
Kerem ERSOY

Hi,

The problem here is : the plugin does not just send a text but also returns a status code 0 being OK and so on.. But since you're filtering the output the return code from the sed is returning to nagios and it always returns 0.

To modify this you might like to invoke the plugin from another script and preserve the status and return it.
Avatar of valheru_m

ASKER

This is the output of the normal command when run from a command line:

check_vmware_api.pl -H esxi2 -f esxiauth -S esxisession -l mem
CHECK_VMWARE_API.PL OK - mem usage=34165.33 MB (69.52%), overhead=934.56 MB, swapped=0.00 MB, memctl=0.00 MB | mem_usagemb=34165.33MB;; mem_usage=69.52%;; mem_overhead=934.56MB;; mem_swap=0.00MB;; mem_memctl=0.00MB;;

You're saying that the sed command above removes more of the result than just the text I specified?  If that's the case, is there a different method of cleaning up the results?
No I don't say that.. When a process exits it sends a status code to the O/S. This is a numeric variable not to do with the output it prints.. Nagios Plugins return 0 if it is OK, 1 for a Warning 2 for a critical situation. But since you pipe the output to sed you get the status code form the sed command which is always 0 this is why even warnings are displayed as OK.

Here's a document about Nagios Plugin Exit Status Codes.
http://nagiosplug.sourceforge.net/developer-guidelines.html#AEN76

This a general documantation about exit status codes.:
http://www.cyberciti.biz/faq/shell-how-to-determine-the-exit-status-of-linux-and-unix-command/
So what I would do would write a wrapper script such  as this:

#!/bin/sh

/usr/local/libexec/check_vmware_api.pl -H $1 -f $2 -S $3 -l $4 > /tmp/vmout

VMSTATUS=$?

sed -e sed -e 's/CHECK_VMWARE_API.PL //' /tmp/vmout

exit $VMSATUS

Open in new window


An then call this script instead. Don't forget to modify the service to call your script instead of CHECK_VMWARE_API.PL

Cheers,
K.
ASKER CERTIFIED SOLUTION
Avatar of Kerem ERSOY
Kerem ERSOY

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Haven' gotten a chance to try this yet, but the tip sounds quite plausible.  Thanks.  Sorry for the delay but will get back to you as soon as I get a chance to put in play.