Page 1 of 1

ARG fields in service checks

Posted: Mon Apr 05, 2021 9:57 am
by TethiS
Hi,

I am currently looking to see if there a way of using a NAGIOS variable (like $HOSTADDRESS$) in the content of an $ARGx$ field. Already tried it but at the runtime is it used literally, not expanded ("$HOSTADDRESS$" instead the actual hostname interpretation).

Is there a hint/trick to make use of these in the $ARG$ (without having to write another command..)?

Thanks!

Re: ARG fields in service checks

Posted: Mon Apr 05, 2021 12:30 pm
by ssax
You should be able to use them in any command/$ARGn$ input and it should be expanded properly.

If it's not working with the Run Check Command button, try applying configuration and forcing a check to see if that works.

You can see the macros and what context they are available in here (which shows $HOSTADDRESS$ available in all contexts):

https://assets.nagios.com/downloads/nag ... olist.html

Can you post your service definition so I can see how you have it setup? Or you can PM me a copy of your profile.zip from Admin > System Profile > Download Profile button.

Thank you!

Re: ARG fields in service checks

Posted: Wed Apr 07, 2021 4:22 am
by TethiS
well, let's say I used another way to avoid the need for that. But for the sake of knowledge, the $ARG1$ string for a snmp check service was containing data like :

$ARG1$ = -v3 -u '$HOSTADDRESS$_user' -A 'secret1' -x 'AES' -X 'secret1' -a 'SHA' -l 'authPriv'

where the snmpv3 username would have been something like switch1_user.
Using a template for the service would have required variabilizing the user form like $HOSTADDRESS$_user. It didn't happen and the $HOSTADDRESS$_user was sent literally while using the Run Check Command with any host.

Re: ARG fields in service checks

Posted: Wed Apr 07, 2021 5:12 pm
by ssax
I'm still not able to reproduce:

I added this:

Code: Select all

define command {
    command_name    atest
    command_line    $USER1$/check_output.sh $ARG1$
}

Code: Select all

[root@xid tmp]# cat /usr/local/nagios/libexec/check_output.sh
#!/bin/bash
echo "$@" >> /usr/local/nagiosxi/tmp/test.txt
exit 0

Code: Select all

define service {
    host_name                XXXXXXXXXXX
    service_description      atest
    check_command            atest!-v3 -u '$HOSTADDRESS$_user' -A 'secret1' -x 'AES' -X 'secret1' -a 'SHA' -l 'authPriv'!!!!!!!
Which resulted in:

Code: Select all

[root@xid tmp]# cat /usr/local/nagiosxi/tmp/test.txt
-v3 -u 192.168.X.X_user -A secret1 -x AES -X secret1 -a SHA -l authPriv
What was your command definition? What XI version are you running?

Re: ARG fields in service checks

Posted: Fri Apr 09, 2021 5:41 am
by TethiS
oh,

indeed that seems to be working from the example you gave (as I expected also on my side).

Well, the command is a modified version of /usr/local/nagios/libexec/check_ifoperstatnag to allow checking fopr other things than ifOperStatus (like ifInErrors)

Code: Select all

define command {
    command_name    check_xi_service_ifgenstat
    command_line    $USER1$/check_ifgenstat $ARG1$ $ARG2$ $HOSTADDRESS$ $ARG3$
}
Definition of the serrvice (in GUI) is like

Code: Select all

$USER1$/check_ifgenstat $ARG1$ $ARG2$ $HOSTADDRESS$ $ARG3$

Code: Select all

$ARG1$ = 1
$ARG2$ = -v3 -u '$HOSTADDRESS$_polling' -A 'secret1' -x 'AES' -X 'secret1' -a 'SHA' -l 'authPriv'
$ARG3$ = ifInErrors
Capture.JPG
Then using the Run Check Command (in GUI, for localhost, for the sake of example) gives:

Code: Select all

 /usr/local/nagios/libexec/check_ifgenstat 1 -v3 -u '$HOSTADDRESS$_polling' -A 'secret1' -x 'AES' -X 'secret1' -a 'SHA' -l 'authPriv' 127.0.0.1 ifInErrors
Capture2.JPG
I was expecting 127.0.0.1 to be expanded also on $HOSTADDRESS$


NagiosXi is something between version 5.7.2 - 5.7.4 (how do i check for the exact version ?? ;) )

Re: ARG fields in service checks

Posted: Fri Apr 09, 2021 4:32 pm
by vtrac
Hi,
The "$HOSTADDRESS$" or "$HOSTADDRESS$_polling" will not be expended if it is defined inside any $ARG#$ value .... like $ARG1$, $ARG2$ ... etc.

Those must be defined on the "command_line" (below) only.
For this to works, please try the followings:

Code: Select all

define command {
    command_name    check_xi_service_ifgenstat
    command_line    $USER1$/check_ifgenstat 1 -v3 -u "$HOSTADDRESS$_polling" $ARG1$ $HOSTADDRESS$ $ARG2$
}
Definition of the serrvice (in GUI) is like:

Code: Select all

$USER1$/check_ifgenstat 1 -v3 -u "$HOSTADDRESS$_polling" $ARG1$ $HOSTADDRESS$ $ARG2$

Code: Select all

$ARG1$ = -A 'secret1' -x 'AES' -X 'secret1' -a 'SHA' -l 'authPriv'
$ARG2$ = ifInErrors

Best Regards,
Vinh

Re: ARG fields in service checks

Posted: Mon Apr 12, 2021 5:02 am
by TethiS
Thank you, Vinh!.

I will take that into consideration.


This topic can be closed.

Re: ARG fields in service checks

Posted: Mon Apr 12, 2021 9:32 am
by scottwilkerson
TethiS wrote:Thank you, Vinh!.

I will take that into consideration.


This topic can be closed.
Locking thread