Skip to content

Commit

Permalink
Create events for modules deleted via devicehistory
Browse files Browse the repository at this point in the history
  • Loading branch information
stveit committed Sep 20, 2024
1 parent 0a7e6fd commit 10065b5
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion python/nav/web/devicehistory/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
from django.shortcuts import render, redirect
from django.urls import reverse

from nav.event2 import EventFactory
from nav.models.fields import INFINITY
from nav.models.manage import Netbox, Module
from nav.models.event import AlertHistory
Expand All @@ -37,6 +38,8 @@
from nav.web.devicehistory.utils.error import register_error_events
from nav.web.devicehistory.forms import DeviceHistoryViewFilter

device_event = EventFactory('ipdevpoll', 'eventEngine', 'deviceState')

DEVICEQUICKSELECT_VIEW_HISTORY_KWARGS = {
'button': 'View %s history',
'module': True,
Expand Down Expand Up @@ -289,12 +292,18 @@ def do_delete_module(request):
# AlertHistory entries will be closed by a database trigger.
cursor.execute("DELETE FROM module WHERE moduleid IN %s", (module_ids,))

# Delete the entities representing these modules
for hist in history:
# Delete the entity representing the module
cursor.execute(
"DELETE FROM netboxentity WHERE netboxid = %s and deviceid = %s",
[hist.module.netbox.id, hist.module.device.id],
)
# Create event for deleted module
device_event.notify(
device=hist.module.device,
netbox=hist.module.netbox,
alert_type="deviceDeletedModule",
)

return HttpResponseRedirect(reverse('devicehistory-module'))

Expand Down

0 comments on commit 10065b5

Please sign in to comment.