pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

Advertising: Credit Card Consolidation - Remortgaging - Bad Credit Loan - 3 mobile
Python paste-bin - collaborative debugging tool View Help

Posted by rpuga on Sun 4th Nov 04:58 (modification of post by view diff)
download | new post

  1. #!/usr/bin/python
  2. # -----------------------------------------------------------------------
  3. # - Feito por: Rafael Augusto Dornelas Puga
  4. # - E-mail/MSN/Jabber: [email protected]
  5. # - Programa: E1_Monitor
  6. # - Versao: 0.1
  7. # -
  8. # - Este script pode ser alterado e distribuido por qualquer pessoa,
  9. # - desde que este quadro se mantenha inalterado!         -
  10. # -
  11. # - Obs.: Trecho de envio de e-mail baseado e disponivel em:
  12. # - http://www.yak.net/fqa/84.html
  13. # -----------------------------------------------------------------------
  14.  
  15. def mon_log():
  16.  
  17.     from time import localtime
  18.  
  19.     log = open("/root/alarm_monitor/monitor.log","a")
  20.     x = time.localtime()
  21.     msg = "[" + str(x[0]) + "-" + str(x[1]) + "-" + str(x[2]) + " | " + str(x[3]) + ":" + str(x[4]) + ":" + str(x[5]) + "] "
  22.     msg = msg + "Erro no envio de e-mail.\n"
  23.     log.write(msg)
  24.     log.flush()
  25.     log.close()
  26.  
  27. def mon_mail(saida):
  28.  
  29.     x = time.localtime()
  30.     data = "[" + str(x[0]) + "-" + str(x[1]) + "-" + str(x[2]) + " | " + str(x[3]) + ":" + str(x[4]) + ":" + str(x[5]) + "] "
  31.     SENDMAIL = "/usr/sbin/sendmail"
  32.     p = os.popen("%s -t" % SENDMAIL, "w")
  33.     p.write("To: [email protected]\n")
  34.     p.write("Subject: ALARME: RENK ZANINI\n")
  35.     p.write("\n")
  36.     p.write(data + "Houve indicacao de ALARME no link de E1.\n\n")
  37.     p.write(saida)
  38.     sts = p.close()
  39.     if sts != None:
  40.         mon_log()
  41.  
  42. import os
  43. import time
  44.  
  45. while(os.system("asterisk -rx 'dgv show alarms 1' | grep -v  - | grep 'ALARM'  > /root/alarm_monitor/saida") != 0):
  46.     time.sleep(5)
  47.  
  48. base = open("/root/alarm_monitor/base","r")
  49. basestr = base.read()
  50. base.close()
  51.  
  52. saida = open("/root/alarm_monitor/saida","r")
  53. saidastr = saida.read()
  54. saida.close()
  55.  
  56. if basestr != saidastr:
  57.     mon_mail(saidastr)
  58.  
  59. 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.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me
: