The problem of sending a ping status

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.
tmcdonald
Posts: 9117
Joined: Mon Sep 23, 2013 8:40 am

Re: The problem of sending a ping status

Post by tmcdonald »

I'm having a hard time understanding what you want. Which script has been disabled?
Former Nagios employee
rumarcin11
Posts: 36
Joined: Thu Feb 25, 2016 7:42 am

Re: The problem of sending a ping status

Post by rumarcin11 »

Does anyone know the resp
rumarcin11
Posts: 36
Joined: Thu Feb 25, 2016 7:42 am

Re: The problem of sending a ping status

Post by rumarcin11 »

Does anyone know the resp
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: The problem of sending a ping status

Post by eloyd »

rumarcin11 wrote:This configuration only sends a status change, yet I would like to have it sends status as approximately every hour
Then you have two basic options: A custom check or Nagios Reactor. First, a little bit about how Nagios works (in general):

Nagios schedules checks internally. When it is time to run a check, it executes an external command called a plugin. These are things like /usr/local/nagios/libexec/check_http and /usr/local/nagios/libexec/check_ping. The plugin does the work and exits with a Unix status code of 0, 1, or 2. These mean OK, WARNING, or CRITICAL. If it returns with any other exit code, it will be interpreted as UNKNOWN. The last line of output printed by the plugin will also be captured as additional information to be displayed on the service check within Nagios.

Normally, Nagios only tells you if a state changes from OK to CRITICAL or from WARNING to OK. It is not designed to tell you that something is OK now when it was also OK the last time it checked. The idea is that you only want to know about problems and solutions to problems, not that you want to always know that something is working correctly. The assumption is that it is always working correctly and Nagios notifies you if it is not.

To accomplish what you want, you must do something Nagios is not designed for. So you must either write a custom plugin that checks what you want and notifies directly (so that Nagios itself does not have to) or you have to use an event handler and/or Nagios Reactor to do the notification for you (and maybe also the check, in the case of Reactor). You can also just use cron to execute the check and pipe the output to /bin/mail and send it to yourself without Nagios. It's all up to you. But in the end, you need to remember that you are trying to accomplish something that Nagios is not expecting to do - notify on every OK.

I hope that gives you some ideas. They have all been discussed in previous notes, but here's a quick plugin that would do what you want:

Code: Select all

#!/bin/sh
host="$1"
warning="$2"
critical="$3"
sendTo="$4"
status=3
statusText="UNKNOWN"
output=`/usr/local/nagios/libexec/check_ping -H "$host" -w "$warning" -c "$critical"`
case "$?" in
  0) status=0; statusText="OK";;
  1) status=1; statusText="WARNING";;
  2) status=2; statusText="CRITICAL";;
esac
echo "$output"
echo "$output" | /bin/mail -s "Nagios ping result for $host: $statusText" "$sendTo"
exit $status
Now go put that in cron to run every hour, or put that code in /usr/local/nagios/libexec and generate a Nagios service definition to do the same thing except turn off notifications.

EDIT: You'll need to pass hostname, warning, critical, and email address as parameters, in that order.
Last edited by eloyd on Mon Feb 29, 2016 10:59 am, edited 1 time in total.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: The problem of sending a ping status

Post by rkennedy »

Thanks @eloyd! That script should work well with CRON.

Let us know if you have any further questions @rumarcin11.
Former Nagios Employee
rumarcin11
Posts: 36
Joined: Thu Feb 25, 2016 7:42 am

Re: The problem of sending a ping status

Post by rumarcin11 »

One more thing I have to do to get email updates inf about nagios with the Works
rumarcin11
Posts: 36
Joined: Thu Feb 25, 2016 7:42 am

Re: The problem of sending a ping status

Post by rumarcin11 »

somehow I do not go out, and do not know how it is and how to send ping polling about the script. and yet, please explain how this skrytp, if you will all hosts send email as ping OK or separate
User avatar
nozlaf
Posts: 172
Joined: Sun Nov 09, 2014 9:50 pm
Location: Victoria, Australia

Re: The problem of sending a ping status

Post by nozlaf »

What eloyd has provided you is a cron script which will use one of the nagios plugs to check if a host is up and then send an e-mail, this is not going to use nagios to do the checks, there is some assumption that you understand how to setup jobs to run via cron


if that is confusing (which I would suspect it would be to most people) you should use nagios reactor

Nagios reactor is free and is able to do what you have requested



nagios core is not able to do what you want, it is not designed to send notifications for things which are working fine.
Looking forward to seeing you all at #NagiosCon2019?
-Dedicated Lover of Nconf,PNP4Nagios and Nagvis
User avatar
eloyd
Cool Title Here
Posts: 2190
Joined: Thu Sep 27, 2012 9:14 am
Location: Rochester, NY
Contact:

Re: The problem of sending a ping status

Post by eloyd »

A final suggestion is that if cron is beyond your skill level at this time, then you may want to consider outsourcing your Nagios configuration and management to a company more familiar with Nagios. If you are interested, PM me and we can discuss.
Image
Eric Loyd • http://everwatch.global • 844.240.EVER • @EricLoyd
I'm a Nagios Fanatic! • Join our public Nagios Discord Server!
rkennedy
Posts: 6579
Joined: Mon Oct 05, 2015 11:45 am

Re: The problem of sending a ping status

Post by rkennedy »

Thanks @eloyd and @nozlaf!

OP - let us know if you need any further help with Nagios.
Former Nagios Employee
Locked