Ping without warning/critical possible (check if up/down)?

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.
jobst
Posts: 16
Joined: Mon Jul 22, 2013 6:33 pm

Ping without warning/critical possible (check if up/down)?

Post by jobst »

Hi.
Is it possible to have a ping that does not create warnings/critical?

I used to use a different monitoring solution but now switching over to Nagios.
There used to be a test called "dialup" that would indicated a greyed out button instead of red when it was not turned on.

Is it possible to do the same in Nagios?

Jobst
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Ping without warning/critical possible (check if up/down

Post by lmiltchev »

There is no such an option in nagios. I am not sure if I understand what is the reasoning behind this... If you exceed the warning/critical thresholds, you have a problem, and nagios will let you know. What's the difference if you see "a greyed out button instead of red" (or yellow)? Why do you need this functionality?
Be sure to check out our Knowledgebase for helpful articles and solutions!
jobst
Posts: 16
Joined: Mon Jul 22, 2013 6:33 pm

Re: Ping without warning/critical possible (check if up/down

Post by jobst »

Hi.

thanks for the reply lmiltchev.

It's for workstations,laptops,mobiles and tablets - this way I (and others) can see who's in, not in, already in and/or whether they have returned from an external meeting - so we know whether to redirect phone calls or not. The feature has been good in our other solution.

The thing with marking it as yellow raises alarm bells, having a fourth state "dialup" (or whatever one wants to call it) makes it possible to see "ok this service/host is down but - it's not important but good to know".

jobst
sreinhardt
-fno-stack-protector
Posts: 4366
Joined: Mon Nov 19, 2012 12:10 pm

Re: Ping without warning/critical possible (check if up/down

Post by sreinhardt »

Well, to avoid some things, you can disable notifications for these hosts\services. Alternatively, a simple script to run the ping check and if nothing is returned, set the service to unknown(grey) would not be terribly difficult. Would that work for you?
Nagios-Plugins maintainer exclusively, unless you have other C language bugs with open-source nagios projects, then I am happy to help! Please pm or use other communication to alert me to issues as I no longer track the forum.
jobst
Posts: 16
Joined: Mon Jul 22, 2013 6:33 pm

Re: Ping without warning/critical possible (check if up/down

Post by jobst »

Sorry, late reply ... been busy.

Thanks for the reply, sreinhardt, but that does not work.
If you set the script to return STATE_UNKNOWN (3) it will be flagged as down and red ... I am not sure whether this is a bug.

What I did is make a template that points to my own script for "check_command". If I return ok, its green, but i I return unknown its red.
The Status information does return "UNKNOWN" and my text, but the status is still red.

I even tried it with a dummy command, same result.

Good idea, though.

Jobst
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Ping without warning/critical possible (check if up/down

Post by lmiltchev »

If you set the script to return STATE_UNKNOWN (3) it will be flagged as down and red ...
Is the check returning "3"? Can you run it in the command line, then run:

Code: Select all

echo $?
Be sure to check out our Knowledgebase for helpful articles and solutions!
yancy
Posts: 523
Joined: Thu Oct 06, 2011 10:12 am

Re: Ping without warning/critical possible (check if up/down

Post by yancy »

jobst,

It's very easy to customize your own plugin to use instead of check_ping

This one should do the trick.

Code: Select all

#!/usr/bin/env python

from optparse import OptionParser
import sys
import os

#collect arguments
def parse_args():
    usage = "usage: %prog -h host [--help]"
    parser = OptionParser(usage=usage)
           
    parser.add_option("-t", "--target_host",
        action="store", type="string",
        help="target IP or hostname")

    (options, args) = parser.parse_args()

    if not options.target_host:
        parser.error("Must give a hostname.\n use --help for options")
    else:
        return (options, args)

(options, args) = parse_args()

#run ping check on host
response = os.system("ping -c 1 " + options.target_host + "> /dev/null 2>&1")

#and then check the response...
if response == 0:
  print options.target_host, 'is in the office!'
  sys.exit(0)
else:
  print options.target_host, 'is out of the office!'
  sys.exit(0)
here is an example run from the command line

Code: Select all

./check_in_office.py -t 192.168.5.90
192.168.5.90 is in the office!

./check_in_office.py -t 192.168.1.1
192.168.1.1 is out of the office!
the key to making sure it stays as a status of "OK" instead of warning is we always exit with 0 (sys.exit(0))


-Yancy
jobst
Posts: 16
Joined: Mon Jul 22, 2013 6:33 pm

Re: Ping without warning/critical possible (check if up/down

Post by jobst »

lmiltchev wrote:
If you set the script to return STATE_UNKNOWN (3) it will be flagged as down and red ...
Is the check returning "3"? Can you run it in the command line, then run:

Code: Select all

echo $?
Hi lmiltchev

This is the last part of the script:

Code: Select all

/bin/ping -c 1 -W 3  $ipaddress > /dev/null 2> /dev/null
if [ $? -eq 0 ]; then
                echo "OK: machine $name ($ipaddress) is alive."
                exit $STATE_OK
else
                echo "UNKNOWN: machine $name ($ipaddress) not turned on."
                exit $STATE_UNKNOWN
fi
This is the output of the commandline

Code: Select all

[root /src/nagios-plugins-1.4.16/plugins-scripts] #>./check_no_failure_ping.sh -i 192.168.0.249 -n blah
UNKNOWN: machine blah (192.168.0.249) not turned on.
[root /src/nagios-plugins-1.4.16/plugins-scripts] #>echo $?
3
[root /src/nagios-plugins-1.4.16/plugins-scripts] #>
But if I do that under the "hosts" section (host details for all host groups) the status turns red.
Now I did a little bit of research to find why (note I put all source code below /src, as I did for nagios-3.5.0.tar.gz)

Looking at /src/nagios/cgi/status.c, line 2198 "if(temp_status->status" there is no such thing as "unknown" only "pending,up,down and unreachable".

I gather, that it is not possible to to return a state of "unknown" for a host, because if you search for any define like "HOST_UNKNOWN" it does not exist, only HOST_DOWN,HOST_UP,HOST_PENDING and HOST_UNREACHABLE. Putting and HOST_UNREACHABLE value of 2 turns it red as it does if you return 3 out of the script.

It would be nice if a state of unknown would exist as lots of printers, laptops, mobile devices, workstations etc don't need to go red if they are not ping-able.
I know I could simply return a "STATUS_OK" as exit code and put something like "The machine is not turned on", but then you need to read 30 hosts ... not including the servers.

Not sure whether I can set "STATUS_PENDING" or "HOST_PENDING"?


jobst
yancy
Posts: 523
Joined: Thu Oct 06, 2011 10:12 am

Re: Ping without warning/critical possible (check if up/down

Post by yancy »

jobst,

http://nagiosplug.sourceforge.net/devel ... html#AEN76

plugin return codes do include unknown (exit with 3). This is usually reserved for handling exceptions however.

-Yancy
jobst
Posts: 16
Joined: Mon Jul 22, 2013 6:33 pm

Re: Ping without warning/critical possible (check if up/down

Post by jobst »

yancy wrote:jobst,

http://nagiosplug.sourceforge.net/devel ... html#AEN76

plugin return codes do include unknown (exit with 3). This is usually reserved for handling exceptions however.

-Yancy
Yancy, I know what the return codes are ... that is not my problem.
If you look at the code above you can see I return 3 and it is the value being returned properly (as shown by the debug echo $?).

Jobst
Locked