Page 1 of 1

Can I change a hostname used in the check?

Posted: Tue Jul 25, 2017 12:04 pm
by anepomn
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

Re: Can I change a hostname used in the check?

Posted: Tue Jul 25, 2017 1:08 pm
by mcapra
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$:

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
        }
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:

Code: Select all

define host{
        use                     linux-server
        host_name               kibprod00
        address                 kibprod00
        check_command           check_ping!100.0,20%!500.0,60%
    }
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):

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%
    }
Then the address, someothersite.domain.com, would be what gets pinged.

Re: Can I change a hostname used in the check?

Posted: Tue Jul 25, 2017 2:07 pm
by dwhitfield
anepomn wrote: Can I change a hostname ($HOSTNAME$) used in the check?
Do you mean as a one-time thing or permanently?

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?

Posted: Tue Jul 25, 2017 2:35 pm
by anepomn
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

Re: Can I change a hostname used in the check?

Posted: Tue Jul 25, 2017 3:14 pm
by dwhitfield
anepomn wrote:I'd like to avoid creating an extra host for abcILOdefgh in Nagios.
Why not make it a service on the host and hard code the ILO address?

Re: Can I change a hostname used in the check?

Posted: Tue Jul 25, 2017 3:27 pm
by anepomn
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

Re: Can I change a hostname used in the check?

Posted: Tue Jul 25, 2017 3:56 pm
by dwhitfield
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.

Re: Can I change a hostname used in the check?

Posted: Wed Jul 26, 2017 2:36 pm
by anepomn
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:

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


Re: Can I change a hostname used in the check?

Posted: Wed Jul 26, 2017 2:48 pm
by dwhitfield
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?

Posted: Thu Jul 27, 2017 3:09 pm
by anepomn
I think this solution is OK (I am going to use it :)), we can probably lock the thread.