-
Notifications
You must be signed in to change notification settings - Fork 1
/
AOC.py
120 lines (97 loc) · 3.65 KB
/
AOC.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/usr/bin/env python
'''
Created on 29/10/2011
@author: Fernando
Agente de Obtencion de Cargas
'''
# importaciones
from threading import Thread
from modulo.Logger import setLOGFILE, setLOGLEVEL
from Config import Load
from modulo import AOCMR, AOCME
# definiciones
CONFIGFILE = 'aoc.conf'
AOCHOST = None
AOCPORT = None
SBCHOST = None
SBCPORT = None
# clases
class ThreadxAOCME(Thread):
def __init__(self, HOST, PORT):
Thread.__init__(self)
self.HOST = HOST
self.PORT = PORT
def run(self):
AOCME.run(self.HOST, self.PORT)
class ThreadxAgenteVivo(Thread):
def __init__(self, SBCHOST, SBCPORT, PORT):
Thread.__init__(self)
self.SBCHOST = SBCHOST
self.SBCPORT = SBCPORT
self.PORT = PORT
def run(self):
AOCME.AgenteVivo(self.SBCHOST, self.SBCPORT, self.PORT)
# funciones
def setAOCHOST(VALUE):
global AOCHOST; AOCHOST = VALUE
handler.log.debug('AOCHOST : ' + AOCHOST)
def setAOCPORT(VALUE):
global AOCPORT; AOCPORT = VALUE
handler.log.debug('AOCPORT : ' + str(AOCPORT))
def setSBCHOST(VALUE):
global SBCHOST; SBCHOST = VALUE
handler.log.debug('SBCHOST : ' + SBCHOST)
def setSBCPORT(VALUE):
global SBCPORT; SBCPORT = VALUE
handler.log.debug('SBCPORT : ' + str(SBCPORT))
# cargando configuraciones del agente
try:
cfg = Load(CONFIGFILE)
LOGFILE = cfg["LOGFILE"]; setLOGFILE(LOGFILE)
LOGLEVEL = cfg["LOGLEVEL"]; setLOGLEVEL(LOGLEVEL)
# se importa el Logger una ves instanciados los parametros necesarios para su ejecucion
from modulo.Logger import handler
handler.log.info('cargando configuraciones')
AOCHOST = cfg["AOCHOST"]; setAOCHOST(AOCHOST)
AOCPORT = int(cfg["AOCPORT"]); setAOCPORT(AOCPORT)
SBCHOST = cfg["SBCHOST"]; setSBCHOST(SBCHOST)
SBCPORT = int(cfg["SBCPORT"]); setSBCPORT(SBCPORT)
AOCMESLEEPTIME = cfg["AOCMESLEEPTIME"]; AOCME.setAOCMESLEEPTIME(AOCMESLEEPTIME)
SBCTIMEOUT = int(cfg["SBCTIMEOUT"]); AOCME.setSBCTIMEOUT(SBCTIMEOUT)
AOCMRSLEEPTIME = cfg["AOCMRSLEEPTIME"]; AOCMR.setAOCMRSLEEPTIME(AOCMRSLEEPTIME)
except KeyError as message:
handler.log.critical('no se ha podido encontrar una variable de configuracion necesaria: %s', message)
handler.log.exception(message)
exit(1);
except Exception as message:
handler.log.error('ha ocurrido un error al cargar el archivo de configuracion: ' + CONFIGFILE)
handler.log.exception(message)
exit(1);
else: handler.log.info('configuraciones cargadas correctamente')
# main
if __name__ == '__main__':
handler.log.info('iniciando el agente')
try: AOCMR.run()
except Exception as message:
handler.log.error('ha ocurrido un error al cargar el modulo AOCMR')
handler.log.exception(message)
exit(1);
# ejecutando el modulo AOCME como hilo
try: tAOCME = ThreadxAOCME(AOCHOST, AOCPORT).start()
except Exception as message:
handler.log.error('ha ocurrido un error al cargar el modulo AOCME')
handler.log.exception(message)
exit(1);
handler.log.info('el agente se ha iniciado correctamente')
# enviando keep alive a SBC
try: tAgenteVivo = ThreadxAgenteVivo(SBCHOST, SBCPORT, AOCPORT).start()
except Exception as message:
handler.log.error('ha ocurrido un error al enviar signo de vida a SBC')
handler.log.exception(message)
exit(1);
try:
AOCMR.ObtieneCarga()
except Exception as message:
handler.log.error('ha ocurrido un error al obtener la carga del sistema')
handler.log.exception(message)
exit(1);