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 AsyncPing import PingJob 
15  from twisted.internet import reactor 
16  import os.path 
17  import time 
18   
19 -class Ping(object):
20 - def __init__(self, *args):
21 self.count = 0
22
23 - def jobCount(self):
24 return self.count
25
26 - def sendPacket(self, pj):
27 self.count += 1 28 pj.reset() 29 pj.start = time.time() 30 if not os.path.exists('/tmp/testping'): 31 reactor.callLater(0, self.bad, pj) 32 else: 33 for line in file('/tmp/testping'): 34 if line.strip() == pj.ipaddr: 35 reactor.callLater(0, self.good, pj) 36 break 37 else: 38 reactor.callLater(0, self.bad, pj)
39
40 - def good(self, pj):
41 self.count -= 1 42 pj.deferred.callback(pj)
43
44 - def bad(self, pj):
45 self.count -= 1 46 pj.deferred.errback(pj)
47