Skip to content

Commit

Permalink
[plugin] report DOWN port status as warning (#183)
Browse files Browse the repository at this point in the history
This switches port status to WARNING from CRITICAL if their instances were shutdown.

Closes: #179

Signed-off-by: Ponnuvel Palaniyappan <[email protected]>
  • Loading branch information
pponnuvel authored Oct 10, 2024
1 parent fd606d5 commit 6f681fd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/files/plugins/check_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,23 @@ def mechanism_warning_ids(connection, resource_type) -> Dict[str, str]:
]
for ip in not_assigned_ips:
warn_ids[ip] = "unassigned"

if resource_type == "port":
# Move DOWN ports from CRITICAL to warning if the instance was shutoff
all_ports = RESOURCES[resource_type](connection)
for port in all_ports:
try:
if port.status == "DOWN":
server = connection.compute.get_server(port.device_id)
if server.power_state == 4: # 4 is SHUTOFF state
warn_ids[port.id] = "SHUTOFF"
except openstack.exceptions.ResourceNotFound:
# device_id won't be available for internal ports, and we don't
# expect them to be shutdown deliberately either. Basically,
# for any reason, if power_state can't be determined, we ignore
# them, and they'll be reported as CRITICAL as before.
pass

return warn_ids


Expand Down
1 change: 1 addition & 0 deletions src/tests/unit/test_check_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def __init__(self, type_, id_, status=None, **kwargs):
self._type = type_
self._id = id_
self.status = status
self.device_id = "fake_device_id"
for key, value in kwargs.items():
setattr(self, key, value)

Expand Down

0 comments on commit 6f681fd

Please sign in to comment.