How make nagios alert if a host is present

1

I want a nagios alert that comes up when an IP number is present and goes away if it's absent. I can't google for this as mostly what people want is the opposite.

I wonder if there is a simple way to do this or I would have to write a plugin?

k-h

Posted 2015-02-25T03:01:09.157

Reputation: 67

Answers

2

I would recommend using the "negate" plugin that is included in the newest packages of monitoring plugins. The man page for the plugin is: https://www.monitoring-plugins.org/doc/man/negate.html

Then create a customer command and custom host such as:

define command{
        command_name    check-host-dead
        command_line    /usr/local/libexec/negate -s /usr/lib/nagios/plugins/check_ping -H '$HOSTADDRESS$' -w 5000,100% -c 5000,100% -p 1
        }

and host plus stupid service:

define host {
       host_name    hostname.domain.tld
       alias        Verbose Description Server
       address      192.168.1.50
       parents      parent.host_name
       notifications_enabled           1       ; Host notifications are enabled
       event_handler_enabled           1       ; Host event handler is enabled
       flap_detection_enabled          1       ; Flap detection is enabled
       failure_prediction_enabled      1       ; Failure prediction is enabled
       process_perf_data               1       ; Process performance data
       retain_status_information       1       ; Retain status information across program restarts
       retain_nonstatus_information    1       ; Retain non-status information across program restarts
       check_command                   check-host-dead
       max_check_attempts              10
       notification_interval           1440
       notification_period             wakehours
       notification_options            d,u,r
       contact_groups                  noticeadmins
       }
define service {
        host_name                       hostname.domain.tld
        service_description             Return OK
        check_command                   return-ok
        use                             generic-service
        contact_groups                  noticeadmins
        normal_check_interval           10
        notification_interval           60 ; set > 0 if you want to be renotified
}

A couple of notes, we use Check_MK as our graphical frontend to Nagios, and aesthetically a service is required for each host or we get an empty/useless page. So this is a service that is always ok. In my application, I only wanted to be alerted once a day during the day, hence 1440/wakehours. You would need to define or change things like wakehours/noticeadmins.

Corvar

Posted 2015-02-25T03:01:09.157

Reputation: 36

1

If you already have a working check but it does the exact opposite of what you want, have you tried changing the exit values around so that it doesn't alert for "failure" and does alert for "success"? In your scenario, exit 0 would be for the failure and exit 1 or exit 2 would be for success. If you are confused about what I am referring to by exit values, see this link.

David

Posted 2015-02-25T03:01:09.157

Reputation: 6 975

This is good but nagios automatically uses ping to check every host so I'll have to somehow disable this with a special template. – k-h – 2015-02-26T20:59:39.843