Page 1 of 1

$HOSTADDRESS:Servername$

Posted: Thu Nov 02, 2017 7:31 am
by eltrasimaco
When calling commands, can I have the addresses of other hosts, by something like:
$HOSTADDRESS:Servername$
?
Can I have access to this variables/macros inside a shell script or command?
Thanks!

Re: $HOSTADDRESS:Servername$

Posted: Thu Nov 02, 2017 9:22 am
by mcapra
From:
https://assets.nagios.com/downloads/nag ... acros.html
Macros as Environment Variables

Most macros are made available as environment variables for easy reference by scripts or commands that are executed by Nagios Core. For purposes of security and sanity, $USERn$ and "on-demand" host and service macros are not made available as environment variables.

Environment variables that contain standard macros are named the same as their corresponding macro names (listed here), with "NAGIOS_" prepended to their names. For example, the $HOSTNAME$ macro would be available as an environment variable named "NAGIOS_HOSTNAME".
Also from:
https://assets.nagios.com/downloads/nag ... gmain.html

Environment Macros Option

Format: enable_environment_macros=<0/1>
Example: enable_environment_macros=0
This option determines whether or not the Nagios daemon will make all standard macros available as environment variables to your check, notification, event hander, etc. commands. In large Nagios installations this can be problematic because it takes additional memory and (more importantly) CPU to compute the values of all macros and make them available to the environment.

0 = Don't make macros available as environment variables
1 = Make macros available as environment variables (default)
But your specific question:
Can I have access to this variables/macros inside a shell script or command?
Depends on the context of this script/command. Where it's executed, how it's executed, what you want to do with it, etc.

Re: $HOSTADDRESS:Servername$

Posted: Thu Nov 02, 2017 9:48 am
by kyang
Thanks @mcapra!

@eltrasimaco, Take a look at what mcapra said, and let us know if you have any more questions.

Re: $HOSTADDRESS:Servername$

Posted: Fri Nov 03, 2017 2:23 am
by eltrasimaco
Thanks for your immediate response; I only miss the solution for my first question:

When calling commands, can I have the addresses of other hosts, by something like:
$HOSTADDRESS:Servername$ ?

$HOSTADDRESS$, as you now well, refers to the IP address of the "current" host.
But sometimes I need, in the called script, other IP addresses of other hosts.
How can I get those addresses, if I only know their display names?
I was thinking about something like "$HOSTADDRESS:hostname$", but this doesn't work for me

Re: $HOSTADDRESS:Servername$

Posted: Fri Nov 03, 2017 5:37 am
by tacolover101
eltrasimaco wrote:Thanks for your immediate response; I only miss the solution for my first question:

When calling commands, can I have the addresses of other hosts, by something like:
$HOSTADDRESS:Servername$ ?

$HOSTADDRESS$, as you now well, refers to the IP address of the "current" host.
But sometimes I need, in the called script, other IP addresses of other hosts.
How can I get those addresses, if I only know their display names?
I was thinking about something like "$HOSTADDRESS:hostname$", but this doesn't work for me
your question is already answered by @mcapra here - https://assets.nagios.com/downloads/nag ... acros.html - define custom variables at a host or service level, and you can then call them.

to answer the second part - i'm not following your logic. "But sometimes I need, in the called script, other IP addresses of other hosts." - this sounds custom of some sort which you need to work with. the above option will work, but it won't be dynamic.

Re: $HOSTADDRESS:Servername$

Posted: Fri Nov 03, 2017 6:11 am
by eltrasimaco
OK it's clear now; question has been resolved.
Thanks

Re: $HOSTADDRESS:Servername$

Posted: Fri Nov 03, 2017 7:08 am
by mcapra
eltrasimaco wrote: But sometimes I need, in the called script, other IP addresses of other hosts.
How can I get those addresses, if I only know their display names?
In Nagios XI, you could use the REST API. See the "Help" section of the Nagios XI GUI for usage instructions.

In Nagios Core, you could use the back-end JSON CGIs.

Re: $HOSTADDRESS:Servername$

Posted: Fri Nov 03, 2017 3:01 pm
by dwhitfield
Thanks @mcapra! Locking, as OP said resolved.