This repository has been archived by the owner on May 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
haagent.py
54 lines (40 loc) · 1.45 KB
/
haagent.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import time, halib, subprocess as proc
active_vifip = "ipaddress"
active_vifif = "bond0"
master_eventsa = "tcp://ipaddr:port"
master_statea = "tcp://ipcaddr:port"
local_eventsa = "ipc://path"
local_statea = "ipc://path"
local_cmda = "ipc://path"
timeout = 180000
class haagent(halib.haloop):
def become_passive(self):
vifcmd = "/sbin/ip addr del {0} dev {1}".format(active_vifip, active_vifif)
if proc.call(vifcmd) != 0:
return False
if proc.call("/sbin/service nagios status") == 1:
if subprocess.call("/sbin/service nagios start") != 0:
return False
if proc.call("/sbin/service mqbroker restart") != 0:
return False
self.send_nagios_commands('disable_all_notifications',
'stop_executing_host_checks', 'stop_executing_service_checks',
'stop_using_event_handlers')
return True
def become_active(self):
vifcmd = "/sbin/ip addr add {0} dev {1}".format(active_vifip, active_vifif)
if proc.call(vifcmd) != 0:
return False
if proc.call("/sbin/service nagios status") == 1:
if proc.call("/sbin/service nagios start") != 0:
return False
if proc.call("/sbin/service mqbroker restart") != 0:
return False
self.send_nagios_commands('enable_all_notifications',
'start_executing_host_checks', 'start_executing_service_checks',
'start_using_event_handlers')
return True
run = haagent(master_eventsa, master_statea, local_eventsa, local_cmda, local_statea)
#while True:
# run.passive_loop(timeout)
# run.active_loop(timeout)