Posted by rpuga on Sun 4th Nov 04:58 (modification of post by view diff)
download | new post
- #!/usr/bin/python
- # -----------------------------------------------------------------------
- # - Feito por: Rafael Augusto Dornelas Puga
- # - E-mail/MSN/Jabber: [email protected]
- # - Programa: E1_Monitor
- # - Versao: 0.1
- # -
- # - Este script pode ser alterado e distribuido por qualquer pessoa,
- # - desde que este quadro se mantenha inalterado! -
- # -
- # - Obs.: Trecho de envio de e-mail baseado e disponivel em:
- # - http://www.yak.net/fqa/84.html
- # -----------------------------------------------------------------------
- def mon_log():
- from time import localtime
- log = open("/root/alarm_monitor/monitor.log","a")
- x = time.localtime()
- msg = "[" + str(x[0]) + "-" + str(x[1]) + "-" + str(x[2]) + " | " + str(x[3]) + ":" + str(x[4]) + ":" + str(x[5]) + "] "
- msg = msg + "Erro no envio de e-mail.\n"
- log.write(msg)
- log.flush()
- log.close()
- def mon_mail(saida):
- x = time.localtime()
- data = "[" + str(x[0]) + "-" + str(x[1]) + "-" + str(x[2]) + " | " + str(x[3]) + ":" + str(x[4]) + ":" + str(x[5]) + "] "
- SENDMAIL = "/usr/sbin/sendmail"
- p = os.popen("%s -t" % SENDMAIL, "w")
- p.write("Subject: ALARME: RENK ZANINI\n")
- p.write("\n")
- p.write(data + "Houve indicacao de ALARME no link de E1.\n\n")
- p.write(saida)
- sts = p.close()
- if sts != None:
- mon_log()
- import os
- import time
- while(os.system("asterisk -rx 'dgv show alarms 1' | grep -v - | grep 'ALARM' > /root/alarm_monitor/saida") != 0):
- time.sleep(5)
- base = open("/root/alarm_monitor/base","r")
- basestr = base.read()
- base.close()
- saida = open("/root/alarm_monitor/saida","r")
- saidastr = saida.read()
- saida.close()
- if basestr != saidastr:
- mon_mail(saidastr)
- exit
Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.