$HOSTADDRESS:Servername$

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
eltrasimaco
Posts: 75
Joined: Thu Aug 02, 2012 7:15 am

$HOSTADDRESS:Servername$

Post 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!
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: $HOSTADDRESS:Servername$

Post 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.
Former Nagios employee
https://www.mcapra.com/
kyang

Re: $HOSTADDRESS:Servername$

Post by kyang »

Thanks @mcapra!

@eltrasimaco, Take a look at what mcapra said, and let us know if you have any more questions.
eltrasimaco
Posts: 75
Joined: Thu Aug 02, 2012 7:15 am

Re: $HOSTADDRESS:Servername$

Post 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
User avatar
tacolover101
Posts: 432
Joined: Mon Apr 10, 2017 11:55 am

Re: $HOSTADDRESS:Servername$

Post 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.
eltrasimaco
Posts: 75
Joined: Thu Aug 02, 2012 7:15 am

Re: $HOSTADDRESS:Servername$

Post by eltrasimaco »

OK it's clear now; question has been resolved.
Thanks
User avatar
mcapra
Posts: 3739
Joined: Thu May 05, 2016 3:54 pm

Re: $HOSTADDRESS:Servername$

Post 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.
Former Nagios employee
https://www.mcapra.com/
dwhitfield
Former Nagios Staff
Posts: 4583
Joined: Wed Sep 21, 2016 10:29 am
Location: NoLo, Minneapolis, MN
Contact:

Re: $HOSTADDRESS:Servername$

Post by dwhitfield »

Thanks @mcapra! Locking, as OP said resolved.
Locked