Changeset 966 for trunk/Monitoring
- Timestamp:
- 11/11/13 20:19:13 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Monitoring/Watch/watch
r940 r966 18 18 import sys 19 19 import signal 20 import traceback21 20 import smtplib 22 21 from email.mime.text import MIMEText … … 37 36 CSTE_LOG_FILENAME_MSG='message.log' # log AMQP msgs 38 37 CSTE_LOG_FILE_MAIN="%s/%s"%(CSTE_LOG_DIR,CSTE_LOG_FILENAME_MAIN) 39 40 # logger init. 41 logging.basicConfig(filename=CSTE_LOG_FILE_MAIN,level=logging.INFO,) 42 38 CSTE_LOG_FILE_MSG="%s/%s"%(CSTE_LOG_DIR,CSTE_LOG_FILENAME_MSG) 39 40 def create_logger(name,fullpath_filename): 41 42 # new logger instance 43 logger = logging.getLogger(name) 44 logger.setLevel(logging.DEBUG) 45 46 # create associated file 47 fh = logging.FileHandler(fullpath_filename) 48 fh.setLevel(logging.DEBUG) 49 50 # create formatter 51 formatter = logging.Formatter('%(asctime)-15s - %(message)s') 52 fh.setFormatter(formatter) 53 54 # binding 55 logger.addHandler(fh) 56 57 return logger 58 59 60 61 62 # loggers init. 63 logger=create_logger(CSTE_LOG_FILENAME_MAIN,CSTE_LOG_FILE_MAIN) 64 msg_logger=create_logger(CSTE_LOG_FILENAME_MSG,CSTE_LOG_FILE_MSG) 43 65 44 66 class Mail(): … … 81 103 82 104 except: 83 traceback.print_exc()84 105 raise 85 106 … … 100 121 101 122 except: 102 traceback.print_exc()103 123 raise 104 124 … … 144 164 def log_msg(cls,message): 145 165 line="%s %s %s %s"%(message.code,message.jobid,message.timestamp,message.command) 146 cls.log(CSTE_LOG_FILENAME_MSG,line)166 msg_logger.info(line) 147 167 148 168 """ … … 164 184 getattr(Actions, proc_name)(message) 165 185 except Exception,e: 166 traceback.print_exc()167 168 raise Exception("WATCH-ERR002","procedure error (%s ,%s)"%(proc_name,str(e)))186 logger.exception("ERR909 - exception occurs") 187 188 raise Exception("WATCH-ERR002","procedure error (%s)"%(proc_name,)) 169 189 170 190 class MessageActionsMapping(): 171 191 172 # debug173 #174 192 # TAG0001: note that crea_sim must be BEFORE store_msg in the list (because when we insert the msg, we need the simu_id) 175 193 # … … 180 198 "2000":["log_msg", "store_msg"], 181 199 "3000":["log_msg", "store_msg"], 200 "7000":["log_msg"], 182 201 "8888":["cleanup"], 183 202 "9000":["log_msg", "store_msg"], 184 203 "9999":["log_msg", "store_msg", "set_sim_status_to_error"] } 185 204 186 # prod 187 # 188 # TAG0001: note that crea_sim must be BEFORE store_msg in the list (because when we insert the msg, we need the simu_id) 189 # 205 # prod (mail added for some action) 190 206 """ 191 mapping = { "0000":["crea_sim", "log_msg", "store_msg"],192 "0100":["log_msg", "store_msg", "set_sim_status_to_complete"],193 "1000":["log_msg", "store_msg"],194 "1100":["log_msg", "store_msg"],195 "2000":["log_msg", "store_msg"],196 "3000":["log_msg", "store_msg"],197 "8888":["cleanup"],198 207 "9000":["log_msg", "store_msg", "mail"], 199 208 "9999":["log_msg", "store_msg", "set_sim_status_to_error", "mail"] } … … 229 238 self.channel = connection.channel() 230 239 231 logg ing.info("[*] Waiting for messages")240 logger.info("[*] Waiting for messages") 232 241 233 242 def callback(ch, method, properties, raw_msg): … … 247 256 248 257 # debug 249 #logg ing.debug(" [x] Received %s"%field)258 #logger.debug(" [x] Received %s"%field) 250 259 251 260 splitted_field=field.split(":") … … 258 267 259 268 # debug 260 #logg ing.debug(" [x] Received %s (encoded)" % l__tmp_dic["body"])269 #logger.debug(" [x] Received %s (encoded)" % l__tmp_dic["body"]) 261 270 262 271 … … 266 275 267 276 # debug 268 #logg ing.debug(" [x] Received %s" % raw_msg)269 #logg ing.debug(" [x] Received %s (uudecoded)" % base64_decoded_msg )270 #logg ing.debug(" [x] Received %s (uudecoded)" % base64_decoded_msg )277 #logger.debug(" [x] Received %s" % raw_msg) 278 #logger.debug(" [x] Received %s (uudecoded)" % base64_decoded_msg ) 279 #logger.debug(" [x] Received %s (uudecoded)" % base64_decoded_msg ) 271 280 272 281 … … 278 287 279 288 # non working 280 #logg ing.debug("DEB003 - %s"%message.type)289 #logger.debug("DEB003 - %s"%message.type) 281 290 282 291 # working 283 #logg ing.debug("DEB009 - %s"%message.code)292 #logger.debug("DEB009 - %s"%message.code) 284 293 285 294 … … 287 296 except Exception,e: 288 297 289 logg ing.exception("ERR009 - exception occurs (exception=%s)"%(str(e),))298 logger.exception("ERR009 - exception occurs") 290 299 291 300 Actions.log_debug("DEB021 - %s"%base64_decoded_msg) … … 313 322 314 323 except Exception,e: 315 logg ing.exception("ERR019 - exception occurs (exception=%s)"%(str(e),))324 logger.exception("ERR019 - exception occurs") 316 325 317 326 Actions.log_debug("DEB020 - %s"%base64_decoded_msg) … … 323 332 #time.sleep(0.5) 324 333 325 self.channel.queue_declare(queue='myqueue' )334 self.channel.queue_declare(queue='myqueue',durable=True) 326 335 327 336 self.channel.basic_consume(callback, queue='myqueue', no_ack=True) … … 335 344 336 345 def signal_handler(signal, frame): 337 logg ing.info("TERM signal received: exiting.")346 logger.info("TERM signal received: exiting.") 338 347 Watcher.channel.stop_consuming() 339 348 Watcher.stop() … … 357 366 except Exception, e: 358 367 359 traceback.print_exc()368 logger.exception("ERR904 - exception occurred") 360 369 361 370 sys.exit(1)
Note: See TracChangeset
for help on using the changeset viewer.