3 # Copyright 2011 Peter Palfrader
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be
14 # included in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19 # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20 # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21 # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22 # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 parser = optparse.OptionParser()
30 parser.set_usage("%prog <hostname> [<hostname> ..]")
31 parser.add_option("-t", "--timeout", dest="timeout", metavar="TIMEOUT",
32 type="int", default=500,
33 help="Resolve timeout in msecs [500].")
34 (options, args) = parser.parse_args()
41 now = datetime.datetime.now()
43 socket.gethostbyname(hostname)
46 then = datetime.datetime.now()
49 msecs = td.microseconds/1000 + (td.seconds + td.days * 24 * 3600) * 1000
58 time = check(hostname)
60 faillist.append(hostname)
62 elif time > options.timeout:
63 slowlist.append(hostname)
66 oklist.append(hostname)
68 if len(faillist) > 0: msg.append("FAILED: %s"%(', '.join(faillist)))
69 if len(slowlist) > 0: msg.append("SLOW: %s"%(', '.join(slowlist)))
70 if len(oklist) > 0: msg.append("OK: %s"%(', '.join(oklist)))
77 # vim:set shiftwidth=4: