Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Suppress initial interface down alarms with config option #367

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/257.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add config option to suppress initial interface down events
1 change: 1 addition & 0 deletions src/zino/config/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ class Polling(BaseModel):

file: ExistingFileName = POLLFILE
period: int = 1
suppress_initial_down_alarms: bool = False


class Configuration(BaseModel):
Expand Down
5 changes: 5 additions & 0 deletions src/zino/tasks/linkstatetask.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from zino.oid import OID
from zino.scheduler import get_scheduler
from zino.snmp import SparseWalkResponse
from zino.state import config
from zino.statemodels import InterfaceState, Port, PortStateEvent
from zino.tasks.task import Task

Expand Down Expand Up @@ -117,6 +118,10 @@ def _update_state(self, data: BaseInterfaceRow, port: Port, row: dict[str, Any])
def _make_or_update_state_event(self, port: Port, new_state: InterfaceState, last_change: int):
event = self.state.events.get_or_create_event(self.device.name, port.ifindex, PortStateEvent)

if config.polling.suppress_initial_down_alarms and not event.id and new_state == InterfaceState.DOWN:
self.schedule_verification_of_single_port(port.ifindex)
return

event.portstate = new_state
event.port = port.ifdescr
event.ifindex = port.ifindex
Expand Down
8 changes: 8 additions & 0 deletions tests/tasks/test_linkstatetask.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ async def test_run_should_create_event_if_at_least_one_link_is_down(self, linkst
assert (await task.run()) is None
assert len(task.state.events) == 1

async def test_run_should_not_create_event_if_suppress_initial_down_alarms_config_is_true(
self, linkstatetask_with_one_link_down
):
task = linkstatetask_with_one_link_down
with patch("zino.state.config.polling.suppress_initial_down_alarms", True):
assert (await task.run()) is None
assert len(task.state.events) == 0

def test_when_patterns_are_empty_interface_should_not_be_ignored(self, task_with_dummy_device):
data = BaseInterfaceRow(
index=2, descr="GigabitEthernet1/2", alias="uplink", admin_status="up", oper_status="up", last_change=0
Expand Down
4 changes: 4 additions & 0 deletions zino.toml.example
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ file = "polldevs.cf"
# default 1 min
period = 1

# If on the first start of Zino interface-down alarms should be created
# default False
suppress_initial_down_alarms = False

# Logging configuration is optional, but if specified, it will override the
# default logging config of Zino. This is a TOML representation of the default
# logging configuration dictionary, whose full documentation is available at
Expand Down
Loading