def from_action(self, action: str, text: str = '', timeout: int = None) -> 'Alert': self.timeout = timeout or current_app.config['ALERT_TIMEOUT'] previous_status = db.get_status(self) severity, status = alarm_model.transition( previous_severity=self.previous_severity, current_severity=self.severity, previous_status=previous_status, current_status=self.status, action=action) history = History(id=self.id, event=self.event, severity=self.severity if self.previous_severity != self.severity else None, status=self.status, text=text, change_type='action', update_time=datetime.utcnow()) return Alert.from_db( db.set_alert(self.id, severity, status, self.tags, self.attributes, timeout, history))
def update(self) -> 'Alert': now = datetime.utcnow() self.previous_severity = db.get_severity(self) previous_status = db.get_status(self) self.trend_indication = alarm_model.trend(self.previous_severity, self.severity) _, new_status = alarm_model.transition( previous_severity=self.previous_severity, current_severity=self.severity, previous_status=previous_status, current_status=self.status) self.duplicate_count = 0 self.repeat = False self.receive_time = now self.last_receive_id = self.id self.last_receive_time = now 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 new_status != previous_status: history_text = 'correlated alert status change' history.append( History(id=self.id, event=self.event, status=new_status, text=history_text, change_type='status', update_time=self.create_time)) status_change_hook.send(self, status=new_status, text=history_text) self.status = new_status return Alert.from_db(db.correlate_alert(self, history))
def update(self): now = datetime.utcnow() self.previous_severity = db.get_severity(self) previous_status = db.get_status(self) self.trend_indication = severity.trend(self.previous_severity, self.severity) self.status = status_code.status_from_severity( previous_severity=self.previous_severity, current_severity=self.severity, previous_status=previous_status, current_status=self.status ) self.duplicate_count = 0 self.repeat = False self.receive_time = now self.last_receive_id = self.id self.last_receive_time = now 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 self.status != previous_status: history.append(History( id=self.id, event=self.event, status=self.status, text="correlated alert status change", change_type="status", update_time=self.create_time )) return Alert.from_db(db.correlate_alert(self, history))
def deduplicate(self): now = datetime.utcnow() previous_status = db.get_status(self) if self.status == status_code.UNKNOWN or self.status == previous_status: self.status = status_code.status_from_severity( self.severity, self.severity, previous_status) self.repeat = True self.last_receive_id = self.id self.last_receive_time = now if self.status != previous_status: history = History(id=self.id, event=self.event, status=self.status, text="duplicate alert status change", change_type="status", update_time=now) else: history = None return Alert.from_db(db.dedup_alert(self, history))
def from_action(self, action: str, text: str = '', timeout: int = None) -> 'Alert': self.timeout = timeout or current_app.config['ALERT_TIMEOUT'] previous_status = db.get_status(self) new_severity, new_status = alarm_model.transition( previous_severity=self.previous_severity, current_severity=self.severity, previous_status=previous_status, current_status=self.status, action=action) history = [] if new_severity != self.previous_severity: history.append( History(id=self.id, event=self.event, severity=new_severity, text=text, change_type='action', update_time=datetime.utcnow())) if new_status != previous_status: history_text = 'alert status change from action' history.append( History(id=self.id, event=self.event, status=new_status, text=history_text, change_type='action', update_time=datetime.utcnow())) status_change_hook.send(self, status=new_status, text=history_text) return Alert.from_db( db.set_alert(self.id, new_severity, new_status, self.tags, self.attributes, timeout, history))
def deduplicate(self): now = datetime.utcnow() previous_status = db.get_status(self) if self.status == status_code.UNKNOWN or self.status == previous_status: self.status = status_code.status_from_severity(self.severity, self.severity, previous_status) self.repeat = True self.last_receive_id = self.id self.last_receive_time = now if self.status != previous_status: history = History( id=self.id, event=self.event, status=self.status, text="duplicate alert status change", change_type="status", update_time=now ) else: history = None return Alert.from_db(db.dedup_alert(self, history))
def update(self): now = datetime.utcnow() self.previous_severity = db.get_severity(self) previous_status = db.get_status(self) self.trend_indication = severity.trend(self.previous_severity, self.severity) if self.status == status_code.UNKNOWN: self.status = status_code.status_from_severity(self.previous_severity, self.severity, previous_status) self.duplicate_count = 0 self.repeat = False self.receive_time = now self.last_receive_id = self.id self.last_receive_time = now history = [History( id=self.id, event=self.event, severity=self.severity, value=self.value, text=self.text, change_type="severity", update_time=now )] if self.status != previous_status: history.append(History( id=self.id, event=self.event, status=self.status, text="correlated alert status change", change_type="status", update_time=now )) return Alert.from_db(db.correlate_alert(self, history))