$HOSTNAME$ macro in check

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
AlexSavVl
Posts: 38
Joined: Wed Oct 24, 2018 5:50 am

$HOSTNAME$ macro in check

Post 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?
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: $HOSTNAME$ macro in check

Post 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 $
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
AlexSavVl
Posts: 38
Joined: Wed Oct 24, 2018 5:50 am

Re: $HOSTNAME$ macro in check

Post 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.
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: $HOSTNAME$ macro in check

Post 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
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
AlexSavVl
Posts: 38
Joined: Wed Oct 24, 2018 5:50 am

Re: $HOSTNAME$ macro in check

Post 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!
scottwilkerson
DevOps Engineer
Posts: 19396
Joined: Tue Nov 15, 2011 3:11 pm
Location: Nagios Enterprises
Contact:

Re: $HOSTNAME$ macro in check

Post 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.
Former Nagios employee
Creator:
Human Design Website
Get Your Human Design Chart
Locked