Can I change a hostname used in the check?
Can I change a hostname used in the check?
Apologies for the beginner's question.
Can I change a hostname ($HOSTNAME$) used in the check?
For example:
for host 'abcdefgh' I'd like to ping 'abcxyfgh'.
Thank you,
Aleksandr
Can I change a hostname ($HOSTNAME$) used in the check?
For example:
for host 'abcdefgh' I'd like to ping 'abcxyfgh'.
Thank you,
Aleksandr
Re: Can I change a hostname used in the check?
I think it might be more appropriate to change the address value of the host object unless you have modified your commands to use $HOSTNAME$ instead of $HOSTADDRESS$. The default check_ping command definition uses $HOSTADDRESS$:
Could you explain the use case a bit more? Also share the relevant host/service/command definitions in play for this scenario to help shed some light on exactly what you're trying to do?
Do you need to change the remote address for this host for all of your checks? Or just "Ping" checks specifically?
Strictly speaking, $HOSTNAME$ and $HOSTADDRESS$ should never resolve to anything other than a host object's host_name and address directives respectively.
https://assets.nagios.com/downloads/nag ... l#hostname
So if I have a host object defined like so:
Then the address, kibprod00, would be what gets pinged. But if I were to change my host object to use a different address (and restart the nagios process to apply the changes):
Then the address, someothersite.domain.com, would be what gets pinged.
Code: Select all
# 'check_ping' command definition
define command{
command_name check_ping
command_line $USER1$/check_ping -H $HOSTADDRESS$ -w $ARG1$ -c $ARG2$ -p 5
}
Do you need to change the remote address for this host for all of your checks? Or just "Ping" checks specifically?
Strictly speaking, $HOSTNAME$ and $HOSTADDRESS$ should never resolve to anything other than a host object's host_name and address directives respectively.
https://assets.nagios.com/downloads/nag ... l#hostname
So if I have a host object defined like so:
Code: Select all
define host{
use linux-server
host_name kibprod00
address kibprod00
check_command check_ping!100.0,20%!500.0,60%
}
Code: Select all
define host{
use linux-server
host_name kibprod00
address someothersite.domain.com
check_command check_ping!100.0,20%!500.0,60%
}
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: Can I change a hostname used in the check?
Do you mean as a one-time thing or permanently?anepomn wrote: Can I change a hostname ($HOSTNAME$) used in the check?
One-time: no, not really, unless you change and change back
Permanently: see @mcapra's response above.
Re: Can I change a hostname used in the check?
Thanks or response!
My use case - for every host abcSRVdefgh I would like to have 2 ping checks:
- ping_check for abcSRVdefgh (SRV in the name indicates a server), this would be standard
- ping_check_ILO for abcILOdefgh (ILO in the name indicates an ILO board)
I hope to be able to use sed in ping_check_ILO, but can't figure out how this could be done. I'd like to avoid creating an extra host for abcILOdefgh in Nagios.
Thank you,
Aleksandr
My use case - for every host abcSRVdefgh I would like to have 2 ping checks:
- ping_check for abcSRVdefgh (SRV in the name indicates a server), this would be standard
- ping_check_ILO for abcILOdefgh (ILO in the name indicates an ILO board)
I hope to be able to use sed in ping_check_ILO, but can't figure out how this could be done. I'd like to avoid creating an extra host for abcILOdefgh in Nagios.
Thank you,
Aleksandr
-
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: Can I change a hostname used in the check?
Why not make it a service on the host and hard code the ILO address?anepomn wrote:I'd like to avoid creating an extra host for abcILOdefgh in Nagios.
Re: Can I change a hostname used in the check?
Thanks for the answer!
We are using DHCP (please don't laugh ), I'd like to avoid hardcoding if I could come up with smart regex in the check.
Thank you,
Aleksandr
We are using DHCP (please don't laugh ), I'd like to avoid hardcoding if I could come up with smart regex in the check.
Thank you,
Aleksandr
-
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: Can I change a hostname used in the check?
I'm not sure how well it works with DHCP, but you might want to check out https://exchange.nagios.org//directory/ ... th/details
It seems to generally get good reviews.
It seems to generally get good reviews.
Re: Can I change a hostname used in the check?
In case anyone is interested in the subject - I have written the simple check check_ping_remote_mangmt.sh which gets $HOSTNAME$ as a parameter and manipulates the hostname before calling check_ping.
Something like this:
Something like this:
Code: Select all
define command{
command_name check-ping-remote-managment
command_line /usr/local/bin/check_ping_remote_mangmt.sh $HOSTNAME$
}
Code: Select all
#!/bin/bash
RemoteManagementName=$( sed 's/^abcSRV/abcILO/' <<< $1 )
/usr/lib64/nagios/plugins/check_ping ${RemoteManagementName} -w 3000.0,80% -c 5000.0,100% -p 5
-
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: Can I change a hostname used in the check?
Thanks so much for posting the solution! Did you have any other questions, or are we ready to lock things up? (people will still be able to view the thread to see the solution!)
Re: Can I change a hostname used in the check?
I think this solution is OK (I am going to use it ), we can probably lock the thread.