From: Peter Palfrader Date: Tue, 1 Mar 2011 17:10:23 +0000 (+0100) Subject: Add dsa-check-resolver X-Git-Url: https://git.adam-barratt.org.uk/?a=commitdiff_plain;h=53c7efbd7914e572e8e4223de010732e4b929194;p=mirror%2Fdsa-nagios.git Add dsa-check-resolver --- diff --git a/dsa-nagios-checks/checks/dsa-check-resolver b/dsa-nagios-checks/checks/dsa-check-resolver new file mode 100755 index 0000000..f05d6a6 --- /dev/null +++ b/dsa-nagios-checks/checks/dsa-check-resolver @@ -0,0 +1,77 @@ +#!/usr/bin/python + +# Copyright 2011 Peter Palfrader +# +# Permission is hereby granted, free of charge, to any person obtaining +# a copy of this software and associated documentation files (the +# "Software"), to deal in the Software without restriction, including +# without limitation the rights to use, copy, modify, merge, publish, +# distribute, sublicense, and/or sell copies of the Software, and to +# permit persons to whom the Software is furnished to do so, subject to +# the following conditions: +# +# The above copyright notice and this permission notice shall be +# included in all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +import datetime +import socket +import optparse +import sys + +parser = optparse.OptionParser() +parser.set_usage("%prog [ ..]") +parser.add_option("-t", "--timeout", dest="timeout", metavar="TIMEOUT", + type="int", default=500, + help="Resolve timeout in msecs [500].") +(options, args) = parser.parse_args() + +if len(args) == 0: + parser.print_help() + sys.exit(4) + +def check(hostname): + now = datetime.datetime.now() + try: + socket.gethostbyname(hostname) + except: + return None + then = datetime.datetime.now() + + td = then - now + msecs = td.microseconds/1000 + (td.seconds + td.days * 24 * 3600) * 1000 + return msecs + +msg = [] +ret = 0 +oklist = [] +slowlist = [] +faillist = [] +for hostname in args: + time = check(hostname) + if time is None: + faillist.append(hostname) + ret = 2 + elif time > options.timeout: + slowlist.append(hostname) + ret = max(ret, 1) + else: + oklist.append(hostname) + +if len(faillist) > 0: msg.append("FAILED: %s"%(', '.join(faillist))) +if len(slowlist) > 0: msg.append("SLOW: %s"%(', '.join(slowlist))) +if len(oklist) > 0: msg.append("OK: %s"%(', '.join(oklist))) + +print '; '.join(msg) +sys.exit(ret) + +# vim:set et: +# vim:set ts=4: +# vim:set shiftwidth=4: diff --git a/dsa-nagios-checks/debian/changelog b/dsa-nagios-checks/debian/changelog index c0c55f9..d89e848 100644 --- a/dsa-nagios-checks/debian/changelog +++ b/dsa-nagios-checks/debian/changelog @@ -21,8 +21,9 @@ dsa-nagios-checks (8x) xnstable; urgency=low that do not say 'Yes' in the present-line. * dsa-check-udldap-freshness: Also check age of /var/lib/misc/passwd.db in addition to /var/lib/misc/thishost/passwd.tdb. + * Add dsa-check-resolver. - -- Peter Palfrader Mon, 24 Jan 2011 16:26:44 +0100 + -- Peter Palfrader Tue, 01 Mar 2011 18:09:57 +0100 dsa-nagios-checks (87) unstable; urgency=low diff --git a/dsa-nagios-checks/debian/copyright b/dsa-nagios-checks/debian/copyright index b6f8bdd..9e11e5f 100644 --- a/dsa-nagios-checks/debian/copyright +++ b/dsa-nagios-checks/debian/copyright @@ -105,3 +105,8 @@ dsa-check-raid-megaraid: dsa-check-backuppg: Copyright: 2010 Peter Palfrader License: MIT + +######################################################################## +dsa-check-resolver: + Copyright: 2011 Peter Palfrader + License: MIT