$USERn$ Macros in Commands

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
Smark
Posts: 32
Joined: Tue Jan 08, 2013 6:12 pm

$USERn$ Macros in Commands

Post by Smark »

Hello everyone,

I'm attempting to store my WMI login information in $USERn$ variables so they can be easily changed globally. It doesn't seem to be working properly as (more likely I'm just not configuring properly) as the variables are not being replaced. I am using the Nagios XI VM during the full feature evaluation phase.

Nagios.cfg:

Code: Select all

...
resource_file=/usr/local/nagios/etc/resource.cfg
...
resource.cfg:

Code: Select all

# Path to the plugins
$USER3$=domain\\user
$USER4$=pass\&word
$USER1$=/usr/local/nagios/libexec

# Path to event handlers
#$USER2$=/usr/local/nagios/libexec/eventhandlers


# Port for NSClient++
$USER7$=12489
# Password for NSClient++
$USER8$=secret
commands.cfg:

Code: Select all

...
define command {
       command_name                  		check_wmi_cpu_usage
       command_line                  		$USER1$/check_wmi_plus.pl -H $HOSTADDRESS$ -m checkcpu -u $USER3$ -p $USER4$ -w $ARG1$ -c $ARG2$ $ARG3$
}
...
When I run the command from the XI Test Command button, it returns the following:

Code: Select all

COMMAND: /usr/local/nagios/libexec/check_wmi_plus.pl -H REMOVEDHOSTNAME -m checkcpu -u $USER3$ -p $USER4$ -w 50 -c 75 
OUTPUT: UNKNOWN - The WMI query had problems. You might have your username/password wrong or the user's access level is too low. Wmic error text on the next line.
[librpc/rpc/dcerpc_util.c:1290:dcerpc_pipe_auth_recv()] Failed to bind to uuid 4d9f4ab8-7d1c-11cf-861e-0020af6e7c57 - NT_STATUS_NET_WRITE_FAULT
[librpc/rpc/dcerpc_connect.c:790:dcerpc_pipe_connect_b_recv()] failed NT status (c0000022) in dcerpc_pipe_connect_b_recv
[wmi/wmic.c:196:main()] ERROR: Login to remote object.
NTSTATUS: NT_STATUS_ACCESS_DENIED - Access denied
The interesting thing to note is that $USER1$ is replaced, but not $USER3$ or $USER4$. I've also tried changing $USER1$ and rerunning the command (after a restart) and the command doesn't change. I was able to get the command to work if I set it as a Host Check Command. It doesn't seem to work via the Test Check Command either as a host check or a service check. It does seem to work if initiated by the nagios process itself as host check, but not a service check.

I've turned on debug logging and can tell it replaces them correctly as host checks, but doesn't say anything when marked as a service check. Not sure how to proceed.

What gives? Am I doing something wrong here? It there a different way I should be doing this? I tried setting the username and password as host variables in my "Generic Host" Host Template. This seemed to sort of work but was flakey and unreliable due to the slashes in the username (for the domain) and escape slashes for special characters in the password.

Any suggestions. We're definitely grateful for anything you could send our way!

Thank you for your time,
Smark
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: $USERn$ Macros in Commands

Post by slansing »

I am going to send this over to the General > Nagios XI forum.

In the command definition try adding quotes around:

Code: Select all

-u $USER3$ -p $USER4$ 
Like so:

Code: Select all

-u "$USER3$" -p "$USER4$"
An easy way to test this is to run:

Code: Select all

echo $USER3$
and

Code: Select all

echo $USER4$
Do they return how they should to correctly run the check?
Smark
Posts: 32
Joined: Tue Jan 08, 2013 6:12 pm

Re: $USERn$ Macros in Commands

Post by Smark »

Thanks for moving it, I realized after I had posted that theres a non-support public XI forum.

I changed the macros from USER3/4 to 20/21 so they're more easily rememberable.

Code: Select all

COMMAND: echo $USER20$ - $USER21$
OUTPUT: $ - $
And with quotes:

Code: Select all

COMMAND: echo "$USER20$" - "$USER21$"
OUTPUT: $ - $
I've done some poking around and it looks like the CGIs don't get access to the $USER$ macros for security reasons. Is there a way around this besides hard coding the login information into the command? If you want to add them into the resource.cfg is there a way to test commands or are you limited to testing when the host checks by itself?

Thanks for all your help!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: $USERn$ Macros in Commands

Post by scottwilkerson »

Ok, this looks like you are testing this with the "Test Commands" button in the CCM.

This is a limitation with this "test" it will read them in and use them in actual practice.

So if you saved this service and applied configuration you would see in the service detail page the values for $USER20$ - $USER21$
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked