ARG fields in service checks

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
TethiS
Posts: 32
Joined: Tue Aug 04, 2020 9:37 am
Location: Bucharest

ARG fields in service checks

Post 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!
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: ARG fields in service checks

Post 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!
TethiS
Posts: 32
Joined: Tue Aug 04, 2020 9:37 am
Location: Bucharest

Re: ARG fields in service checks

Post 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.
ssax
Dreams In Code
Posts: 7682
Joined: Wed Feb 11, 2015 12:54 pm

Re: ARG fields in service checks

Post 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?
TethiS
Posts: 32
Joined: Tue Aug 04, 2020 9:37 am
Location: Bucharest

Re: ARG fields in service checks

Post 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 ?? ;) )
You do not have the required permissions to view the files attached to this post.
User avatar
vtrac
Posts: 903
Joined: Tue Oct 27, 2020 1:35 pm

Re: ARG fields in service checks

Post 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
TethiS
Posts: 32
Joined: Tue Aug 04, 2020 9:37 am
Location: Bucharest

Re: ARG fields in service checks

Post by TethiS »

Thank you, Vinh!.

I will take that into consideration.


This topic can be closed.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: ARG fields in service checks

Post by scottwilkerson »

TethiS wrote:Thank you, Vinh!.

I will take that into consideration.


This topic can be closed.
Locking thread
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked