Changeset 436
- Timestamp:
- 05/12/08 17:58:48
- Arquivos:
-
- cacic/trunk/agente-linux/pycacic/src/cacic.py (modified) (7 diffs)
Legenda:
- Não modificado
- Adicionado
- Removido
- Modificado
- Copiado
- Movido
cacic/trunk/agente-linux/pycacic/src/cacic.py
r433 r436 15 15 def __init__(self): 16 16 try: 17 17 # adiciona o diretorio do pycacic ao sys.path 18 18 sys.path[0] = Globals.PATH 19 19 … … 37 37 self.udp_sock = socket.socket(AF_INET, SOCK_DGRAM) 38 38 self.udp_sock.bind(self.addr) 39 # executa thread para escutar o socket 40 thread.start_new_thread(self.checkSocket, ()) 39 41 while 1: 40 42 # verifica se o coletor nao esta parado … … 43 45 self.gc_stopped = 1 # True 44 46 # conecta ao servidor para pegar as informacoes 45 xml = self.gc.conecta(self.gc.cacic_url, self.gc.dicionario) 46 print(" Contato com o Gerente Web: %s" % strftime("%H:%M:%S")) 47 self.gc.readXML(xml) 47 self.conecta() 48 48 # com o coletor parado (dormindo) dispara timeout para iniciar a coleta 49 49 # apos o intervalo de tempo definido pelo servidor … … 58 58 # muda estado para nao habilitado 59 59 self.gc_ok = 0 # False 60 # conecta ao servidor para pegar as informacoes 61 # pode ter ocorrido alguma mudanca desde a ultima 62 self.conecta() 60 63 # inicia coletas 61 64 self.gc.coletas_forcadas = self.isforcada 62 thread.start_new_thread(self.start, ()) 63 # executa thread para escutar o socket 64 thread.start_new_thread(self.checkSocket, ()) 65 thread.start_new_thread(self.start, ()) 65 66 time.sleep(2) 66 67 # fechando conexao 67 68 self.udp_sock.close() 68 69 except Exception, e: 69 import traceback70 traceback.print_exc()71 70 print e 72 73 71 74 72 def isRoot(self): … … 76 74 if os.getuid() != 0: 77 75 return 0 # False 78 return 1 # True 79 76 return 1 # True 80 77 81 78 def start(self): 82 79 """Inicia as coletas""" 83 try: 84 self.gc_started = 1 # True 85 self.isforcada = [] 86 print(" --- INICIO DAS COLETAS ---") 87 print 'Total Coletas: %s' % len(self.gc.coletores) 88 print('\tColetas a serem feitas: \n\t(%s)' % ', '.join(self.gc.coletores.keys())) 89 self.gc.startColeta() 90 self.gc.createDat() 91 self.gc.sendColetas() 92 self.gc_started = 0 # False 93 print(" --- FIM DAS COLETAS ---") 94 except Exception, e: 95 print e 80 self.gc_started = 1 # True 81 self.isforcada = [] 82 print(" --- INICIO DAS COLETAS ---") 83 print 'Total Coletas: %s' % len(self.gc.coletores) 84 print('\tColetas a serem feitas: \n\t(%s)' % ', '.join(self.gc.coletores.keys())) 85 self.gc.startColeta() 86 self.gc.createDat() 87 self.gc.sendColetas() 88 self.gc_started = 0 # False 89 print(" --- FIM DAS COLETAS ---") 96 90 97 91 def timeout(self): … … 105 99 self.gc_stopped = 0 # False 106 100 self.gc_ok = 1 # True 101 102 def conecta(self): 103 """Conecta ao Gerente Web para pegar informacoes de configuracao""" 104 xml = self.gc.conecta(self.gc.cacic_url, self.gc.dicionario) 105 print(" Contato com o Gerente Web: %s" % strftime("%H:%M:%S")) 106 self.gc.readXML(xml) 107 107 108 108 def checkSocket(self): … … 110 110 data, self.addr = self.udp_sock.recvfrom(self.buf) 111 111 self.isforcada.append(data) 112 self.checkSocket() 112 113 113 114
