| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172 |
- import logging
- from urllib3 import request,PoolManager
- from urllib3.util.timeout import Timeout
- from adm.constants import CTS as cts
- import os,sys
- import json
- import logging
- class HandlerUtil():
- def sendMsgHandler(self,strMsg,strCanal):
- data = {
- "blocks": [
- {
- "type": "section",
- "text": {
- "type": "mrkdwn",
- "text": strMsg
- }
- }
- ]
- }
- http = PoolManager()
- try:
- http.request('POST', strCanal,
- headers={'Content-Type': 'application/json'},
- body=json.dumps(data), timeout=Timeout(5))
- except BaseException as error:
- try:
- exc_type, exc_obj, exc_tb = sys.exc_info()
- fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
- strErro = "ERRO: %s | %s | %s | %s" % (error, exc_type, fname, exc_tb.tb_lineno)
- print(strErro)
- pass
- except:
- pass
- class MsgOperacaoHandler(logging.Handler):
- def emit(self, record):
- strCanal = cts.SLACK_HOOK_OPERACOES
- strAux = cts.GIT_PREF_USER
- if strAux!="":
- strAux = " (" + strAux.replace("-u ","") + ")"
- tipoMsg = cts.AMBIENTE_EC2 + strAux + " - Monitor"
- arrAssunto = self.format(record).split("|")
- self.formatter=None
- strMensagem = self.format(record)
- if len(arrAssunto)>1:
- strMensagem = arrAssunto[1] + "\n" + strMensagem
- icone="rotating_light"
- if arrAssunto[0].replace("\n","").replace(" ","")=="INFO":
- icone="clipboard"
- strMsg = ":" + icone + ": *" + tipoMsg + " " + arrAssunto[0] + "*\n" + strMensagem
- HandlerUtil().sendMsgHandler(strMsg,strCanal)
- class MsgServiceHandler(logging.Handler):
- def emit(self, record):
- strCanal = cts.SLACK_HOOK_LOG_BACKEND
- strAux = cts.GIT_PREF_USER
- if strAux!="":
- strAux = " (" + strAux.replace("-u ","") + ")"
- tipoMsg = cts.AMBIENTE_EC2 + strAux + " - LOG"
- arrAssunto = self.format(record).split("|")
- self.formatter=None
- strMensagem = self.format(record)
- if len(arrAssunto)>1:
- strMensagem = arrAssunto[1] + "\n" + strMensagem
- icone="rotating_light"
- if arrAssunto[0].replace("\n","").replace(" ","")=="INFO":
- icone="clipboard"
- #strMensagem = "Arquivo:%s\nLinha:%s\nMensagem:%s\nArgs:%s\n" % (record.filename, record.lineno,record.msg, record.args)
- strMsg = ":" + icone + ": *" + tipoMsg + " " + arrAssunto[0] + "*\n" + strMensagem
- HandlerUtil().sendMsgHandler(strMsg,strCanal)
|