Plugin output works from CLI but errors within Nagios XI

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
TylerTX
Posts: 13
Joined: Wed Oct 07, 2015 12:56 pm

Plugin output works from CLI but errors within Nagios XI

Post by TylerTX »

Nagios XI Installed Version: 5.2.2

I have a device that I can pull runtime from:

Code: Select all

# ./check_snmp -H 0.0.0.0 -C public -o 1.3.6.1.4.1.318.1.1.1.2.2.3.0
SNMP OK - Timeticks: (126000) 0:21:00.00 |
But I only want minutes:

Code: Select all

# ./check_snmp -H 0.0.0.0 -C public -o 1.3.6.1.4.1.318.1.1.1.2.2.3.0 -P 1 | awk '{print substr($6,3,2)}'
21
Works great from command line, and even displays the value I want using the Test Check Command Button. But when I create a command and make a service out of it:

Code: Select all

$USER1$/check_snmp -H $HOSTADDRESS$ -C $ARG1$ -o $ARG2$ | awk '{print substr($6,3,2)}'
I get this:

Code: Select all

(No output on stdout) stderr: awk: cmd. line:1: {print substr($6,3,2)}$
awk: cmd. line:1: ^ unexpected newline or end of string
Are there characters in my command that Nagios doesn't like? I guess I don't understand how it can work from CLI but not through the Nagios interface. If I'm doing something wrong it isn't obvious to me. Please lend me your eyes!

Thank you.
bwallace
Posts: 1145
Joined: Tue Nov 17, 2015 1:57 pm

Re: Plugin output works from CLI but errors within Nagios XI

Post by bwallace »

Yeah, the "Test Check Command" option in the CCM has been known to have escaping issues with certain checks. Have you tried just configuring the check, and then applying configuration and allowing XI to perform the check normally?
Be sure to check out the Knowledgebase for helpful articles and solutions!
TylerTX
Posts: 13
Joined: Wed Oct 07, 2015 12:56 pm

Re: Plugin output works from CLI but errors within Nagios XI

Post by TylerTX »

Yes, the error message is the result of doing that.

Runtime 1h 2m 58s 3/3 2016-04-05 10:36:03 (No output on stdout) stderr: awk: cmd. line:1: {print substr($6,3,2)}$

I even tried substituting every variable with $ARGx$:

Code: Select all

$USER1$/check_snmp -H $HOSTADDRESS$ -C $ARG1$ -o $ARG2$ -P $ARG3$ | $ARG4$
The check works fine without altering the output. As soon as I add awk to the check, it errors out. That's why I thought maybe I was just formatting it incorrectly. It is strange that it works fine on CLI.
TylerTX
Posts: 13
Joined: Wed Oct 07, 2015 12:56 pm

Re: Plugin output works from CLI but errors within Nagios XI

Post by TylerTX »

I see what you mean about the Test Check Command. I didn't notice before that it totally ignored my attempt to alter the output:

Code: Select all

COMMAND: /usr/local/nagios/libexec/check_snmp -H 0.0.0.0 -C public -o 1.3.6.1.4.1.318.1.1.1.2.2.3.0 \| awk '\{print substr\(\$6,3,2\)\}'
OUTPUT: SNMP OK - Timeticks: (217900) 0:36:19.00 |
Looks like it nuked my attempt with invalid escape characters/sequences. I think I'll just see if there is another way I can grab those numbers. I appreciate you taking a look at it.

Thanks!
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Plugin output works from CLI but errors within Nagios XI

Post by lmiltchev »

Looks like it nuked my attempt with invalid escape characters/sequences. I think I'll just see if there is another way I can grab those numbers. I appreciate you taking a look at it.

Thanks!
Test you mods from the command line, apply changes in XI, then schedule an immediate check to make sure you are getting the expected output. Use testing under the CCM only for simple checks where escaping wouldn't be a problem.

Is it all right if we lock this topic?
Be sure to check out our Knowledgebase for helpful articles and solutions!
TylerTX
Posts: 13
Joined: Wed Oct 07, 2015 12:56 pm

Re: Plugin output works from CLI but errors within Nagios XI

Post by TylerTX »

Code: Select all

./check_snmp -H 0.0.0.0 -C public -o 1.3.6.1.4.1.318.1.1.1.2.2.3.0 | awk '{print substr($6,3,2)}'
21
Here is my check from the CLI along with the value it returns '21'. Works great. When I have time, I'll dig around the cfg files and find out what's butchering it.

Feel free to lock it.
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: Plugin output works from CLI but errors within Nagios XI

Post by rkennedy »

COMMAND: /usr/local/nagios/libexec/check_snmp -H 0.0.0.0 -C public -o 1.3.6.1.4.1.318.1.1.1.2.2.3.0 \| awk '\{print substr\(\$6,3,2\)\}'
You'll need to create a wrapper script to do this, rather then trying to push the | awk directly through to Nagios. For example (this would pass no variables, feel free to use $1, $2, $3 to easily create your wrapper as needed) -

Code: Select all

#!/bin/bash
/check_snmp -H 0.0.0.0 -C public -o 1.3.6.1.4.1.318.1.1.1.2.2.3.0 | awk '{print substr($6,3,2)}'
Then, create a custom command in Nagios to reference this bash script.
Former Nagios Employee
TylerTX
Posts: 13
Joined: Wed Oct 07, 2015 12:56 pm

Re: Plugin output works from CLI but errors within Nagios XI

Post by TylerTX »

You'll need to create a wrapper script to do this, rather then trying to push the | awk directly through to Nagios. For example (this would pass no variables, feel free to use $1, $2, $3 to easily create your wrapper as needed) -
Thanks, I'll give that a try. That makes sense.

Command:
$USER1$/check_snmp -H $HOSTADDRESS$ -C $ARG1$ -o $ARG2$ | awk '{print substr($6,3,2)}'

Service arguments:
$ARG1$ = public
$ARG2$ = 1.3.6.1.4.1.318.1.1.1.2.2.3.0

Test Check Command:
COMMAND: /usr/local/nagios/libexec/check_snmp -H 0.0.0.0 -C public -o 1.3.6.1.4.1.318.1.1.1.2.2.3.0 | awk '{print substr($6,3,2)}'
OUTPUT: 36

I changed it slightly and now it gives me the output I wanted from the CLI and TCC. I'm still getting the error after an immediate check.

But, you can still lock it. I'm sure this works fine from pure CLI Nagios. I'll try out the bash script.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Plugin output works from CLI but errors within Nagios XI

Post by lmiltchev »

But, you can still lock it. I'm sure this works fine from pure CLI Nagios. I'll try out the bash script.
Noted.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Locked