Page 1 of 1

$HOSTNAME$ macro in check

Posted: Wed Oct 24, 2018 6:04 am
by AlexSavVl
Hello! I have nagios xi 5.5.5.

I'm trying to use the $HOSTNAME$ macro in the service check command. My service check command:

Code: Select all

$USER1$/my_script.sh $HOSTNAME$ 
The script (my_script.sh) simply writes the first argument to a file (for example: echo $1 >> /tmp/script.log).

The service has “manage host,” the host name is DS. But in /tmp/script.log I get

nagios.mydomain.local$

nagios.mydomain.local - is the linux hostname of the nagios machine. And '$' at the end of the hostname.

Is it a bug?

Re: $HOSTNAME$ macro in check

Posted: Wed Oct 24, 2018 4:20 pm
by scottwilkerson
Are you running this from the command line or are you letting nagios run it?

I ask because if you run it from the command line, (or simply test it in the CCM) the macro is not going to be replaced before the script is executed..

Being $HOSTNAME is actually a valid variable on any machine

Code: Select all

echo $HOSTNAME
you are getting this output plus the extra $

Re: $HOSTNAME$ macro in check

Posted: Thu Oct 25, 2018 7:09 am
by AlexSavVl
Thank for you answer.
I run it from nagios interface. If I replace $HOSTNAME$ with $HOSTADDRESS$ all works, but I get ip adress of checked machine in my log. I need hostname instead..

I suppose, macro $HOSTNAME$ is consist of OS variable $HOSTNAME so OS variable works first. In result, we have machine name and '$' at the end.
If macro name and OS variable are different, all works well.

Re: $HOSTNAME$ macro in check

Posted: Thu Oct 25, 2018 7:30 am
by scottwilkerson
AlexSavVl wrote:I run it from nagios interface.
Do you mean the "Test Command" button in the CCM?

If so this is the issue, it does not expand all macros, just $USERn$ and $HOSTADDRESS$

If you save the service when nagios actually executes it, the $HOSTNAME$ macro will be replaced before the command is executed by the shell

Re: $HOSTNAME$ macro in check

Posted: Thu Oct 25, 2018 7:44 am
by AlexSavVl
The macros doesnt work with "Run Check Command" btton, but work when nagios execute. If it will work with the button, it will be perfect (debugging is difficult without this).

Thank you!

Re: $HOSTNAME$ macro in check

Posted: Thu Oct 25, 2018 7:47 am
by scottwilkerson
AlexSavVl wrote:The macros doesnt work with "Run Check Command" btton, but work when nagios execute. If it will work with the button, it will be perfect (debugging is difficult without this).

Thank you!
I agree, the developers are working to get additional macros working with the test command.