Skip to content
This repository has been archived by the owner on Oct 18, 2024. It is now read-only.

Commit

Permalink
Merge pull request Uninett#2611 from stveit/device_removed_events
Browse files Browse the repository at this point in the history
Create events when PowerSupplyOrFans are deleted
  • Loading branch information
stveit authored Sep 24, 2024
2 parents 2dda1eb + e3dd9a6 commit 6407c86
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions changelog.d/2982.added.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Post event when a PowerSupplyOrFan is deleted
4 changes: 4 additions & 0 deletions doc/reference/alerttypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,10 @@ Registers the state of a device
- The device has been found as a power supply.
* - ``deviceNewFan``
- The device has been found as a fan.
* - ``deviceDeletedFan``
- The device has been removed as a fan.
* - ``deviceDeletedPsu``
- The device has been removed as a power supply.



Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Subject: Device has been removed as a fan
Device {{device}} has been removed from {{netbox}} as a fan
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Device {{device}} has been removed from {{netbox}} as a fan
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Subject: Device has been removed as a power supply
Device {{device}} has been removed from {{netbox}} as a power supply
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Device {{device}} has been removed from {{netbox}} as a power supply
18 changes: 18 additions & 0 deletions python/nav/ipdevpoll/shadows/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,7 @@ def _delete_missing_psus_and_fans(cls, containers):
netbox.sysname,
", ".join(psu_and_fan_names),
)
cls._alert_missing_devices_are_deleted(missing_psus_and_fans)
missing_psus_and_fans.delete()

@classmethod
Expand All @@ -838,6 +839,23 @@ def _get_missing_psus_and_fans(cls, containers):
).exclude(pk__in=found_psus_and_fans_pks)
return missing_psus_and_fans

@classmethod
def _alert_missing_devices_are_deleted(cls, deleted_psus_and_fans):
for psufan in deleted_psus_and_fans:
try:
if psufan.device.serial:
device_event.notify(
device=psufan.device,
netbox=psufan.netbox,
alert_type=(
"deviceDeletedPsu"
if psufan.is_psu()
else "deviceDeletedFan"
),
).save()
except manage.Device.DoesNotExist:
pass


class POEPort(Shadow):
__shadowclass__ = manage.POEPort
Expand Down
5 changes: 5 additions & 0 deletions python/nav/models/sql/changes/sc.05.05.0002.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- Add new deviceState alert
INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES
('deviceState','deviceDeletedFan','The device has been removed as a fan.');
INSERT INTO alerttype (eventtypeid,alerttype,alerttypedesc) VALUES
('deviceState','deviceDeletedPsu','The device has been removed as a power supply.');

0 comments on commit 6407c86

Please sign in to comment.