Exemplo n.º 1
0
 def running(self) -> None:
     for number_line, line in enumerate(self.reading()):
         try:
             self.turn = 0
             alert = Alert.create_alert(self.host, line)
             if AlertModel.add(alert.alert()):
                 # condição para envio de mensagem no Telegram
                 if int(alert.alert_priority) <= 1:
                     num_alerts = len(AlertModel.select().where(
                         AlertModel.msg == alert.msg))
                     self.bot.sendMessage(
                         alert.telegram_alert(self.host, num_alerts))
         except Exception as err:
             logging.error(' error in running function: %s' % err)
Exemplo n.º 2
0
    def save(path, ip, conn):
        time.sleep(10)

        if not os.path.isfile(path):
            logging.error(' - path file "%s" not found' % path)
            return False

        f = open(path, 'r')
        lines = list(map(lambda x: x.replace('\n', ''), f.readlines()))
        for line in lines:
            alert = Alert.create_alert(ip, line)
            if not conn.insert(alert.alert()):
                logging.warning(
                    ' - could not add alert, maybe it already exists in the database'
                )