1
2
3
4
5
6
7
8
9 """
10 Agent zephir pour les services distants
11 """
12
13 import socket
14 from creole.parsedico import parse_dico
15
16 from zephir.monitor.agentmanager.agent import Agent
17 from zephir.monitor.agentmanager.data import HTMLData, TableData
18 from zephir.monitor.agentmanager import status
19 from zephir.monitor.agentmanager.util import status_to_img, boolean_to_onoff
20 from twisted.internet.utils import getProcessOutput
21
22 -def tcpcheck(mesures, label, address, port=80, timeout=3, fallback = None):
23 """tentative de connexion sur un port donné d'un serveur distant"""
24 tcpcheck = getProcessOutput('/usr/bin/tcpcheck',
25 args = [str(timeout), address+':'+str(port)],
26 env = {'LC_ALL': 'C'})
27 tcpcheck.addCallback(process_tcp, mesures, label, fallback)
28 return tcpcheck
29
31
32 if 'alive' in tcp_result:
33 status = "On"
34 else:
35
36 if fallback != None:
37 return tcpcheck(mesures, 'Accès Distant', fallback)
38 status = "Off"
39 mesures.append({'status':status, 'service':label})
40 return mesures
41
43 """résolution d'adresse"""
44 try:
45 socket.gethostbyname(address)
46 except socket.error:
47 return False
48 return True
49
50
52
53 - def __init__(self, name, module,
54 **params):
55 Agent.__init__(self, name, **params)
56 self.module = module
57 self.table = TableData([
58 ('status', "État", {'align':'center'}, status_to_img),
59 ('service', "Service", {'align':'left'}, None),
60 ])
61 self.dns = 1
62 self.data = [self.table]
63
65 mesures = []
66
67 conf_eole = parse_dico()
68 try:
69 status = tcpcheck(mesures, 'DNS distant 1', conf_eole['adresse_ip_dns_primaire'], 53)
70 if conf_eole['adresse_ip_dns_secondaire'] != "":
71 self.dns = 2
72 status = tcpcheck(mesures, 'DNS distant 2', conf_eole['adresse_ip_dns_secondaire'], 53)
73 except KeyError:
74
75 pass
76
77 status = resolve('eole.orion.education.fr')
78 mesures.append({'status':boolean_to_onoff(status), 'service':'Résolution'})
79
80 return tcpcheck(mesures, 'Accès Distant', 'eole.orion.education.fr', fallback='www.cru.fr')
81
83 Agent.write_data(self)
84 if self.last_measure is not None:
85 self.table.table_data = self.last_measure.value
86
88 """remonte une erreur si un des services est tombé"""
89 if self.last_measure is not None:
90 err_dns = 0
91 for service in self.last_measure.value:
92 self.measure_data[service['service']]=service['status']
93
94 if service['service'].startswith('DNS'):
95 if service['status'] != 'On':
96 err_dns += 1
97
98 if err_dns == self.dns:
99 return status.Error()
100 else:
101 if service['status'] != 'On':
102 return status.Error()
103 if err_dns > 0:
104 return status.Warn()
105 else:
106
107 return status.Unknown()
108 return status.OK()
109