Can I change a hostname used in the check?

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
anepomn
Posts: 5
Joined: Mon Jul 24, 2017 3:44 pm

Can I change a hostname used in the check?

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

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

Post 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.
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: Can I change a hostname used in the check?

Post 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.
anepomn
Posts: 5
Joined: Mon Jul 24, 2017 3:44 pm

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

Post 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
dwhitfield
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?

Post 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?
anepomn
Posts: 5
Joined: Mon Jul 24, 2017 3:44 pm

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

Post 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
dwhitfield
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?

Post 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.
anepomn
Posts: 5
Joined: Mon Jul 24, 2017 3:44 pm

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

Post 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

dwhitfield
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?

Post 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!)
anepomn
Posts: 5
Joined: Mon Jul 24, 2017 3:44 pm

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

Post by anepomn »

I think this solution is OK (I am going to use it :)), we can probably lock the thread.
Locked