Skip to content

Commit

Permalink
Schedule verification for links that change state
Browse files Browse the repository at this point in the history
As per the original Zino code, whenever a port state change is detected,
an extra job to poll that single interface is scheduled.
  • Loading branch information
lunkwill42 committed Oct 20, 2023
1 parent 404d9d9 commit f2c856c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/zino/tasks/linkstatetask.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from typing import Any

from zino.oid import OID
from zino.scheduler import get_scheduler
from zino.snmp import SNMP, SparseWalkResponse
from zino.statemodels import EventState, InterfaceState, Port, PortStateEvent
from zino.tasks.task import Task
Expand Down Expand Up @@ -43,6 +44,10 @@ class LinkStateTask(Task):

sysuptime: int = 0

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._scheduler = get_scheduler()

async def run(self):
snmp = SNMP(self.device)
poll_list = [("IF-MIB", column) for column in BASE_POLL_LIST]
Expand Down Expand Up @@ -125,7 +130,19 @@ def _make_or_update_state_event(self, port: Port, new_state: InterfaceState, las
_logger.info(log)
event.add_log(log)

# at this point we should re-schedule a new job in 2 minutes to verify the state change
self._schedule_verification_of_single_port(port.ifindex)

def _schedule_verification_of_single_port(self, ifindex: int):
in_two_minutes = datetime.datetime.now() + datetime.timedelta(minutes=2)
job_name = f"{self.device.name}-verify-{ifindex}-state"
self._scheduler.add_job(
func=self.poll_single_interface,
args=(ifindex,),
trigger="date",
run_date=in_two_minutes,
name=job_name,
id=job_name,
)

def _get_or_create_port(self, ifindex: int):
ports = self.state.devices.get(self.device.name).ports
Expand Down

0 comments on commit f2c856c

Please sign in to comment.