def process_alert(incomingAlert): for plugin in plugins: try: incomingAlert = plugin.pre_receive(incomingAlert) except RejectException: raise except Exception as e: raise RuntimeError('Error while running pre-receive plug-in: %s', e) if not incomingAlert: raise SyntaxError('Plug-in pre-receive hook did not return modified alert') try: if db.is_duplicate(incomingAlert): started = duplicate_timer.start_timer() alert = db.save_duplicate(incomingAlert) duplicate_timer.stop_timer(started) elif db.is_correlated(incomingAlert): started = correlate_timer.start_timer() alert = db.save_correlated(incomingAlert) correlate_timer.stop_timer(started) else: started = create_timer.start_timer() alert = db.create_alert(incomingAlert) create_timer.stop_timer(started) except Exception as e: raise RuntimeError(e) for plugin in plugins: try: plugin.post_receive(alert) except Exception as e: raise RuntimeError('Error while running post-receive plug-in: %s', e) return alert
def create(self) -> 'Alert': trend_indication = alarm_model.trend( alarm_model.DEFAULT_PREVIOUS_SEVERITY, self.severity) _, self.status = alarm_model.transition(alert=self) self.duplicate_count = 0 self.repeat = False self.previous_severity = alarm_model.DEFAULT_PREVIOUS_SEVERITY self.trend_indication = trend_indication self.receive_time = datetime.utcnow() self.last_receive_id = self.id self.last_receive_time = self.receive_time self.history = [ History(id=self.id, event=self.event, severity=self.severity, status=self.status, value=self.value, text='new alert', change_type='new', update_time=self.create_time) ] return Alert.from_db(db.create_alert(self))
def create(self) -> 'Alert': now = datetime.utcnow() trend_indication = alarm_model.trend(alarm_model.DEFAULT_PREVIOUS_SEVERITY, self.severity) _, self.status = alarm_model.transition( alert=self ) self.duplicate_count = 0 self.repeat = False self.previous_severity = alarm_model.DEFAULT_PREVIOUS_SEVERITY self.trend_indication = trend_indication self.receive_time = now self.last_receive_id = self.id self.last_receive_time = now self.update_time = now self.history = [History( id=self.id, event=self.event, severity=self.severity, status=self.status, value=self.value, text='new alert', change_type='new', update_time=self.create_time, user=g.login )] return Alert.from_db(db.create_alert(self))
def process_alert(alert): for plugin in plugins.routing(alert): started = pre_plugin_timer.start_timer() try: alert = plugin.pre_receive(alert) except (RejectException, RateLimit): reject_counter.inc() pre_plugin_timer.stop_timer(started) raise except Exception as e: error_counter.inc() pre_plugin_timer.stop_timer(started) raise RuntimeError( "Error while running pre-receive plug-in '%s': %s" % (plugin.name, str(e))) if not alert: error_counter.inc() pre_plugin_timer.stop_timer(started) raise SyntaxError( "Plug-in '%s' pre-receive hook did not return modified alert" % plugin.name) pre_plugin_timer.stop_timer(started) if db.is_blackout_period(alert): raise BlackoutPeriod("Suppressed alert during blackout period") try: if db.is_duplicate(alert): started = duplicate_timer.start_timer() alert = db.save_duplicate(alert) duplicate_timer.stop_timer(started) elif db.is_correlated(alert): started = correlate_timer.start_timer() alert = db.save_correlated(alert) correlate_timer.stop_timer(started) else: started = create_timer.start_timer() alert = db.create_alert(alert) create_timer.stop_timer(started) except Exception as e: error_counter.inc() raise RuntimeError(e) for plugin in plugins.routing(alert): started = post_plugin_timer.start_timer() try: plugin.post_receive(alert) except Exception as e: error_counter.inc() post_plugin_timer.stop_timer(started) raise RuntimeError( "Error while running post-receive plug-in '%s': %s" % (plugin.name, str(e))) post_plugin_timer.stop_timer(started) return alert
def process_alert(incomingAlert): for plugin in plugins: started = pre_plugin_timer.start_timer() try: incomingAlert = plugin.pre_receive(incomingAlert) except RejectException: reject_counter.inc() pre_plugin_timer.stop_timer(started) raise except Exception as e: error_counter.inc() pre_plugin_timer.stop_timer(started) raise RuntimeError('Error while running pre-receive plug-in: %s' % str(e)) if not incomingAlert: error_counter.inc() pre_plugin_timer.stop_timer(started) raise SyntaxError( 'Plug-in pre-receive hook did not return modified alert') pre_plugin_timer.stop_timer(started) if db.is_blackout_period(incomingAlert): raise RuntimeWarning('Suppressed during blackout period') try: if db.is_duplicate(incomingAlert): started = duplicate_timer.start_timer() alert = db.save_duplicate(incomingAlert) duplicate_timer.stop_timer(started) elif db.is_correlated(incomingAlert): started = correlate_timer.start_timer() alert = db.save_correlated(incomingAlert) correlate_timer.stop_timer(started) else: started = create_timer.start_timer() alert = db.create_alert(incomingAlert) create_timer.stop_timer(started) except Exception as e: error_counter.inc() raise RuntimeError(e) for plugin in plugins: started = post_plugin_timer.start_timer() try: plugin.post_receive(alert) except Exception as e: error_counter.inc() post_plugin_timer.stop_timer(started) raise RuntimeError('Error while running post-receive plug-in: %s' % str(e)) post_plugin_timer.stop_timer(started) return alert
def process_alert(incomingAlert): for plugin in plugins: started = pre_plugin_timer.start_timer() try: incomingAlert = plugin.pre_receive(incomingAlert) except RejectException: reject_counter.inc() pre_plugin_timer.stop_timer(started) raise except Exception as e: error_counter.inc() pre_plugin_timer.stop_timer(started) raise RuntimeError('Error while running pre-receive plug-in: %s' % str(e)) if not incomingAlert: error_counter.inc() pre_plugin_timer.stop_timer(started) raise SyntaxError('Plug-in pre-receive hook did not return modified alert') pre_plugin_timer.stop_timer(started) if db.is_blackout_period(incomingAlert): raise RuntimeWarning('Suppressed during blackout period') try: if db.is_duplicate(incomingAlert): started = duplicate_timer.start_timer() alert = db.save_duplicate(incomingAlert) duplicate_timer.stop_timer(started) elif db.is_correlated(incomingAlert): started = correlate_timer.start_timer() alert = db.save_correlated(incomingAlert) correlate_timer.stop_timer(started) else: started = create_timer.start_timer() alert = db.create_alert(incomingAlert) create_timer.stop_timer(started) except Exception as e: error_counter.inc() raise RuntimeError(e) for plugin in plugins: started = post_plugin_timer.start_timer() try: plugin.post_receive(alert) except Exception as e: error_counter.inc() post_plugin_timer.stop_timer(started) raise RuntimeError('Error while running post-receive plug-in: %s' % str(e)) post_plugin_timer.stop_timer(started) return alert
def process_alert(alert): for plugin in plugins.routing(alert): started = pre_plugin_timer.start_timer() try: alert = plugin.pre_receive(alert) except (RejectException, RateLimit): reject_counter.inc() pre_plugin_timer.stop_timer(started) raise except Exception as e: error_counter.inc() pre_plugin_timer.stop_timer(started) raise RuntimeError("Error while running pre-receive plug-in '%s': %s" % (plugin.name, str(e))) if not alert: error_counter.inc() pre_plugin_timer.stop_timer(started) raise SyntaxError("Plug-in '%s' pre-receive hook did not return modified alert" % plugin.name) pre_plugin_timer.stop_timer(started) if db.is_blackout_period(alert): raise BlackoutPeriod("Suppressed alert during blackout period") try: if db.is_duplicate(alert): started = duplicate_timer.start_timer() alert = db.save_duplicate(alert) duplicate_timer.stop_timer(started) elif db.is_correlated(alert): started = correlate_timer.start_timer() alert = db.save_correlated(alert) correlate_timer.stop_timer(started) else: started = create_timer.start_timer() alert = db.create_alert(alert) create_timer.stop_timer(started) except Exception as e: error_counter.inc() raise RuntimeError(e) for plugin in plugins.routing(alert): started = post_plugin_timer.start_timer() try: plugin.post_receive(alert) except Exception as e: error_counter.inc() post_plugin_timer.stop_timer(started) raise RuntimeError("Error while running post-receive plug-in '%s': %s" % (plugin.name, str(e))) post_plugin_timer.stop_timer(started) return alert
def create(self): if self.status == status_code.UNKNOWN: status = status_code.status_from_severity( current_app.config['DEFAULT_PREVIOUS_SEVERITY'], self.severity) else: status = self.status trend_indication = severity.trend( current_app.config['DEFAULT_PREVIOUS_SEVERITY'], self.severity) self.status = status self.duplicate_count = 0 self.repeat = False self.previous_severity = current_app.config[ 'DEFAULT_PREVIOUS_SEVERITY'] self.trend_indication = trend_indication self.receive_time = datetime.utcnow() self.last_receive_id = self.id self.last_receive_time = self.receive_time self.history = [ History(id=self.id, event=self.event, severity=self.severity, value=self.value, text=self.text, change_type='severity', update_time=self.create_time) ] if status != self.status: self.history.append( History(id=self.id, event=self.event, status=status, text="new alert status change", change_type='status', update_time=self.last_receive_time)) return Alert.from_db(db.create_alert(self))
def process_alert(incomingAlert): for plugin in plugins: try: incomingAlert = plugin.pre_receive(incomingAlert) except RejectException: raise except Exception as e: raise RuntimeError('Error while running pre-receive plug-in: %s', e) if not incomingAlert: raise SyntaxError( 'Plug-in pre-receive hook did not return modified alert') try: if db.is_duplicate(incomingAlert): started = duplicate_timer.start_timer() alert = db.save_duplicate(incomingAlert) duplicate_timer.stop_timer(started) elif db.is_correlated(incomingAlert): started = correlate_timer.start_timer() alert = db.save_correlated(incomingAlert) correlate_timer.stop_timer(started) else: started = create_timer.start_timer() alert = db.create_alert(incomingAlert) create_timer.stop_timer(started) except Exception as e: raise RuntimeError(e) for plugin in plugins: try: plugin.post_receive(alert) except Exception as e: raise RuntimeError('Error while running post-receive plug-in: %s', e) return alert
def create(self): if self.status == status_code.UNKNOWN: status = status_code.status_from_severity(current_app.config['DEFAULT_PREVIOUS_SEVERITY'], self.severity) else: status = self.status trend_indication = severity.trend(current_app.config['DEFAULT_PREVIOUS_SEVERITY'], self.severity) self.status = status self.duplicate_count = 0 self.repeat = False self.previous_severity = current_app.config['DEFAULT_PREVIOUS_SEVERITY'] self.trend_indication = trend_indication self.receive_time = datetime.utcnow() self.last_receive_id = self.id self.last_receive_time = self.receive_time self.history = [History( id=self.id, event=self.event, severity=self.severity, value=self.value, text=self.text, change_type='severity', update_time=self.create_time )] if status != self.status: self.history.append(History( id=self.id, event=self.event, status=status, text="new alert status change", change_type='status', update_time=self.last_receive_time )) return Alert.from_db(db.create_alert(self))