Package ZenStatus :: Module TestPing
[hide private]
[frames] | no frames]

Source Code for Module ZenStatus.TestPing

 1  ########################################################################### 
 2  # 
 3  # This program is part of Zenoss Core, an open source monitoring platform. 
 4  # Copyright (C) 2007, Zenoss Inc. 
 5  # 
 6  # This program is free software; you can redistribute it and/or modify it 
 7  # under the terms of the GNU General Public License version 2 as published by 
 8  # the Free Software Foundation. 
 9  # 
10  # For complete information please visit: http://www.zenoss.com/oss/ 
11  # 
12  ########################################################################### 
13   
14  from twisted.internet import reactor 
15  import os.path 
16  import time 
17   
18  from Products.ZenUtils.Utils import unused 
19   
20 -class Ping(object):
21 - def __init__(self, *args):
22 unused(args) 23 self.count = 0
24
25 - def jobCount(self):
26 return self.count
27
28 - def sendPacket(self, pj):
29 self.count += 1 30 pj.reset() 31 pj.start = time.time() 32 if not os.path.exists('/tmp/testping'): 33 reactor.callLater(0, self.bad, pj) 34 else: 35 for line in file('/tmp/testping'): 36 if line.strip() == pj.ipaddr: 37 reactor.callLater(0, self.good, pj) 38 break 39 else: 40 reactor.callLater(0, self.bad, pj)
41
42 - def good(self, pj):
43 self.count -= 1 44 pj.deferred.callback(pj)
45
46 - def bad(self, pj):
47 self.count -= 1 48 pj.deferred.errback(pj)
49