29
27
print "No Password or Passfile in client config file"
30
28
# raise RuntimeError XXX
31
29
self.password = "gazonk"
32
self.fqdn = fqdn # string
33
31
self.created = datetime.datetime.now()
34
self.last_seen = None # datetime.datetime()
35
33
if timeout is None:
36
34
timeout = options.timeout
37
self.timeout = timeout # datetime.timedelta()
35
self.timeout = timeout
39
37
interval = options.interval
40
self.interval = interval # datetime.timedelta()
41
self.next_check = datetime.datetime.now() # datetime.datetime()
42
self.checker = None # or a subprocess.Popen()
43
def check_action(self, now=None):
44
"""The checker said something and might have completed.
45
Check if is has, and take appropriate actions."""
46
if self.checker.poll() is None:
47
# False alarm, no result yet
51
now = datetime.datetime.now()
52
if self.checker.returncode == 0:
54
while self.next_check <= now:
55
self.next_check += self.interval
56
handle_request = check_action
57
def start_checker(self):
60
self.checker = subprocess.Popen("sleep 1; fping -q -- %s"
61
% re.escape(self.fqdn),
62
stdout=subprocess.PIPE,
65
except subprocess.OSError, e:
66
print "Failed to start subprocess:", e
67
def stop_checker(self):
68
if self.checker is None:
70
os.kill(self.checker.pid, signal.SIGTERM)
71
if self.checker.poll() is None:
72
os.kill(self.checker.pid, signal.SIGKILL)
74
__del__ = stop_checker
76
if self.checker is None:
78
return self.checker.stdout.fileno()
80
"""The time when something must be done about this client"""
81
return min(self.last_seen + self.timeout, self.next_check)
82
def still_valid(self, now=None):
83
"""Has this client's timeout not passed?"""
85
now = datetime.datetime.now()
86
return now < (self.last_seen + timeout)
87
def it_is_time_to_check(self, now=None):
89
now = datetime.datetime.now()
90
return self.next_check <= now
38
self.interval = interval
39
self.next_check = datetime.datetime.now()
93
42
class server_metaclass(type):
280
230
credentials=cred)
284
input, out, err = select.select((udp_server,
291
except KeyboardInterrupt:
295
for client in clients:
296
client.stop_checker()
233
in_, out, err = select.select((udp_server,
236
server.handle_request()
299
239
if __name__ == "__main__":