Skip to content

Commit

Permalink
Merge pull request #61 from Uninett/add-event-is-down-property
Browse files Browse the repository at this point in the history
Add method to determine whether event is down
  • Loading branch information
podliashanyk authored Jun 10, 2024
2 parents 1ef9f59 + ddfbd8c commit 34e7faf
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/zinolib/event_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def create(cls, attrdict):
eventobj = subtype(**attrdict)
return eventobj

def is_down(self):
raise NotImplementedError("Abstract method was called, can not calculate is_down status without event type.")


EventType = TypeVar('EventType', bound=Event)
EventOrId = Union[EventType, int]
Expand All @@ -195,6 +198,9 @@ def op_state(self) -> str:
def description(self) -> Optional[str]:
return self.lastevent

def is_down(self) -> bool:
return self.alarm_count > 0


class BFDEvent(Event):
type: str = Event.Type.BFD
Expand All @@ -219,6 +225,9 @@ def description(self) -> str:
def op_state(self) -> str:
return f"BFD {self.bfd_state[:5]}"

def is_down(self) -> bool:
return self.bfd_state == BFDState.DOWN


class BGPEvent(Event):
type: str = Event.Type.BGP
Expand Down Expand Up @@ -247,6 +256,9 @@ def description(self) -> str:
def op_state(self) -> str:
return f"BGP {self.bgp_OS[:5]}"

def is_down(self) -> bool:
return self.bgp_OS == "down"


class ReachabilityEvent(Event):
type: str = Event.Type.REACHABILITY
Expand All @@ -260,6 +272,9 @@ class ReachabilityEvent(Event):
def op_state(self) -> str:
return self.reachability

def is_down(self) -> bool:
return self.reachability == ReachabilityState.NORESPONSE


class PortStateEvent(Event):
type: str = Event.Type.PORTSTATE
Expand Down Expand Up @@ -295,3 +310,6 @@ def get_downtime(self):
return accumulated + now - lasttrans
else:
return accumulated

def is_down(self) -> bool:
return self.port_state in [PortState.DOWN, PortState.LOWER_LAYER_DOWN]

0 comments on commit 34e7faf

Please sign in to comment.