1
2
3
4
5
6
7
8
9 """
10 Agent zephir pour la surveillance de services via tcpcheck
11 """
12
13 from twisted.python import log
14 from twisted.internet import defer
15 from twisted.internet.utils import getProcessOutput, getProcessValue
16
17 from zephir.monitor.agentmanager.agent import Agent
18 from zephir.monitor.agentmanager.data import HTMLData, TableData
19 from zephir.monitor.agentmanager.util import status_to_img, boolean_to_onoff
20 from zephir.monitor.agentmanager import status
21
22 TCPCHECK = '/usr/bin/tcpcheck'
23
25 h1, p1 = hp1.split(':')
26 h2, p2 = hp2.split(':')
27 result = cmp(h1, h2)
28 if result != 0:
29 return result
30 else:
31 return cmp(int(p1), int(p2))
32
34
35
36 - def __init__(self, name,
37 tcp_services,
38 module,
39 **params):
40 Agent.__init__(self, name, **params)
41 self.tcp_services = tcp_services
42 self.module = module
43 self.table = TableData([
44 ('status', "état", {'align':'center'}, status_to_img),
45 ('description', "Description", {'align':'left'}, None),
46 ('host', "Hôte", {'align':'left'}, None),
47 ('port', "Port", {'align':'left'}, None) ])
48 self.data = [self.table]
49
50
57
59 lines = tcpcheck_result.splitlines()
60 hostports_status = [l.split(' ', 1) for l in lines]
61 hostports_status.sort(lambda (hp1, s1), (hp2, s2):
62 compare_hostports(hp1, hp2))
63 for hostport, status in hostports_status:
64 status = boolean_to_onoff(status.endswith('alive'))
65 mesures=[{ 'description': self.tcp_services[hostport],
66 'host': hostport.split(':')[0],
67 'port': hostport.split(':')[1],
68 'status': status }]
69 self.measure_data['status'] = status
70 return {'services': mesures}
71
73 Agent.write_data(self)
74 if self.last_measure is not None:
75 self.table.table_data = self.last_measure.value['services']
76
78 """remonte une erreur si un des services est tombé"""
79 if self.last_measure is not None:
80 for service in self.last_measure.value['services']:
81 if service['status'] != 'On':
82 return status.Error()
83 else:
84
85 return status.Unknown()
86 return status.OK()
87
88
90
91 - def __init__(self, name,
92 tcp_services,
93 module,
94 **params):
95 Agent.__init__(self, name, **params)
96 self.tcp_services = tcp_services
97 self.module = module
98 self.table = TableData([
99 ('status', "Etat", {'align':'center'}, status_to_img),
100 ('description', "Description", {'align':'left'}, None),
101 ('host', "Hôte", {'align':'left'}, None),
102 ('port', "Port", {'align':'left'}, None) ])
103 self.data = [self.table]
104
105
107 cmd = "/usr/sbin/service"
108 vpncheck = getProcessOutput(cmd,
109 args=['ipsec','status'],
110 env = {'LC_ALL': 'C'})
111 vpncheck.addCallbacks(self.measure_vpn,self.service_error)
112 return vpncheck
113
115 """status a remonté une erreur
116 """
117 log.msg("erreur status : %s" % str(data))
118 status = 'Off'
119 mesures=[{ 'description': "Service Réseau Virtuel Privé (IpSec)",
120 'host': 'localhost',
121 'port': '',
122 'status': status }]
123 return {'services': mesures}
124
126 status = 'Off'
127
128 data = data.split('\n')
129 end = 5
130 if len(data) < 5:
131 end = len(data)
132 first_lines = "".join(data[0:end])
133 if first_lines.count('not running') == 0:
134 status = 'On'
135
136 mesures=[{ 'description': "Service Réseau Virtuel Privé (IpSec)",
137 'host': 'localhost',
138 'port': '',
139 'status': status }]
140 return {'services': mesures}
141
143 Agent.write_data(self)
144 if self.last_measure is not None:
145 self.table.table_data = self.last_measure.value['services']
146
148 """remonte une erreur si un des services est tombé"""
149 if self.last_measure is not None:
150 for service in self.last_measure.value['services']:
151 if service['status'] != 'On':
152 return status.Error()
153 else:
154
155 return status.Unknown()
156 return status.OK()
157