Changeset 854 for trunk/Monitoring/Watch
- Timestamp:
- 04/26/13 16:57:16 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/Watch/watch
r841 r854 1 #!/usr/bin/ python -u1 #!/usr/bin/env python 2 2 # -*- coding: ISO-8859-1 -*- 3 3 … … 13 13 ################################## 14 14 15 from smon import dao 15 #from smon import dao 16 import pika 17 import base64 18 import json 19 import sys 20 import traceback 21 import smtplib 22 from email.mime.text import MIMEText 16 23 17 24 class Watcher(): 25 message_code_action_mapping = {"0000":["log","mail"],"1000":["log"],"2000":["log"],"3000":["log"],"9000":["log"],"9999":["log","mail"]} 18 26 19 27 @classmethod … … 23 31 @classmethod 24 32 def start(cls): 25 dao.insert_progress_messages(cls.get_fake_progress_messages()) 33 #dao.insert_progress_messages(cls.get_fake_progress_messages()) 34 pass 26 35 27 36 @classmethod 28 37 def stop(cls): 29 38 pass 30 39 40 @classmethod 41 def add(cls,message): 42 pass 43 44 @classmethod 45 def mail_example(cls): 46 me="jripsl@ipsl.jussieu.fr" 47 you="jripsl@ipsl.jussieu.fr" 48 body="Alarm" 49 object="Supervisor" 50 51 cls.mail(me,you,object,body) 52 53 @classmethod 54 def mail(cls): 55 cls.mail_example() 56 57 @classmethod 58 def send_mail(cls,me,you,object,body): 59 msg = MIMEText(body) 60 msg['Subject'] = object 61 msg['From'] = me 62 msg['To'] = you 63 64 # Send the message via our own SMTP server, but don't include the # envelope header. 65 s = smtplib.SMTP('localhost') 66 s.sendmail(me,[you], msg.as_string()) 67 s.quit() 68 69 @classmethod 70 def log(cls,message): 71 72 with open("/home/jripsl/supervisor/log/supervisor.log", "a") as log_file: 73 log_file.write("%s %s\n"%(message["code"],message["jobid"])) 74 75 @classmethod 76 def execActions(cls,message): 77 78 message_code=message["code"] 79 80 for action in cls.message_code_action_mapping[message_code]: 81 proc_name=action 82 83 try: 84 getattr(cls, proc_name)(message) 85 except Exception,e: 86 traceback.print_exc() 87 88 raise Exception("WATCH-ERR002","procedure error (%s,%s)"%(proc_name,str(e))) 89 31 90 def main(): 32 91 92 """ 33 93 # parse args 34 94 parser = argparse.ArgumentParser(prog='watcher') … … 41 101 42 102 SMON.init_singleton() 103 """ 104 105 connection = pika.BlockingConnection(pika.ConnectionParameters( host='localhost')) 106 channel = connection.channel() 107 108 #channel.queue_declare(queue='myqueue') 109 110 print ' [*] Waiting for messages. To exit press CTRL+C' 111 112 def callback(ch, method, properties, raw_msg): 113 # 114 #return 115 116 base64_decoded_msg=base64.b64decode(raw_msg) 117 118 # debug 119 #print " [x] Received %s" % raw_msg 120 #print " [x] Received %s (uudecoded)" % base64_decoded_msg 121 122 try: 123 message=json.loads(base64_decoded_msg) 124 except Exception,e: 125 print base64_decoded_msg 126 127 # message code based action 128 Watcher.execActions(message) 129 130 channel.basic_consume(callback, queue='myqueue', no_ack=True) 131 132 channel.start_consuming() 43 133 44 134 45 135 """ 46 136 SMON.free_singleton() 137 """ 47 138 48 139 if __name__ == '__main__': … … 54 145 except Exception, e: 55 146 56 #traceback.print_exc()147 traceback.print_exc() 57 148 58 149 sys.exit(1)
Note: See TracChangeset
for help on using the changeset viewer.