Skip to content
Merged
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
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
This changelog format was introduced in NAV 5.4.0. Older changelogs can be
found in the [HISTORY](HISTORY) file.

## [Unreleased]



## bugfix/atomic-save-of-alerts-and-events

### Fixed

#### User-visible fixes
- Make save function in AlertHistory, EventHistory and AlertQueue atomic ([#2594](https://github.com/Uninett/nav/pull/2594))



## [5.6.0] - 2023-01-20

### Added
Expand Down
5 changes: 4 additions & 1 deletion python/nav/models/event.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import logging
import datetime as dt

from django.db import models
from django.db import models, transaction
from django.db.models import Q
from django.core.validators import MaxValueValidator, MinValueValidator

Expand Down Expand Up @@ -417,6 +417,7 @@ def __str__(self):
)
return string.format(self=self, state=dict(self.STATE_CHOICES)[self.state])

@transaction.atomic
def save(self, *args, **kwargs):
new_object = self.pk is None
super(EventQueue, self).save(*args, **kwargs)
Expand Down Expand Up @@ -550,6 +551,7 @@ def __str__(self):
self.severity,
)

@transaction.atomic
def save(self, *args, **kwargs):
new_object = self.pk is None
super(AlertQueue, self).save(*args, **kwargs)
Expand Down Expand Up @@ -756,6 +758,7 @@ def acknowledge(self, account, comment):

ack.save()

@transaction.atomic
def save(self, *args, **kwargs):
new_object = self.pk is None
super(AlertHistory, self).save(*args, **kwargs)
Expand Down
57 changes: 57 additions & 0 deletions tools/eventgenerators/devicenotice.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
#!/usr/bin/env python3
#
# Copyright (C) 2023 Sikt
#
# This file is part of Network Administration Visualized (NAV).
#
# NAV is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License version 3 as published by
# the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details. You should have received a copy of the GNU General Public
# License along with NAV. If not, see <http://www.gnu.org/licenses/>.
#
"""Module comment"""
from argparse import ArgumentParser

from nav.bootstrap import bootstrap_django

bootstrap_django()

from nav.event2 import EventFactory
from nav.models.manage import Device

from django.db import transaction


def main():
"""Main controller"""
args = parse_options()

device = Device.objects.get(serial=args.serial)
event = EventFactory('ipdevpoll', 'eventEngine', 'deviceNotice')
event.notify(
device=device,
alert_type=args.alerttype,
varmap={
"old_version": "old",
"new_version": "new",
},
).save()


def parse_options():
"""Parse command line options and args"""
parser = ArgumentParser()
parser.add_argument('-s', dest='serial', required=True, help='Serial of device')
parser.add_argument(
'-a', dest='alerttype', required=True, help='The name of the alert type'
)
return parser.parse_args()


if __name__ == '__main__':
main()