Event Templates
Event Templates are introduced to be able to display more detailed information
about a specific event. This template is included in the status details and on
the event details page.
Creating a template
To create a template for an event you need to know what the event type and optionally the
alert type is.
File structure
To start using custom event templates create a directory called templates in
NAV’s etc-directory, and inside that directory you create the alertmsg
directory. And finally inside this directory you can add event templates using
the following structure:
base.html
<event-type>
..base.html
..<alert-type>.html
<event-type>
..base.html
..<alert-type>.html
For a boxDown template it would look like this:
templates
..alertmsg
..boxState
..boxDown.html
Common template for all events
To create a template common for all events, create the base.html and add html
there.
Common template for an event-type
To create a template common for for instance boxState-events, create the
directory boxState and the file base.html inside the directory and add html
there.
Single template for an alert-type
To create a template for all boxDown-events, you create the directory boxState
because that is the event-type of boxDown and then you create the file
boxDown.html and add html there.
Template context
The template has all the variables from the API as well as the alert-object
available. See /api/1/alert and the class AlertHistory in the file
python/nav/models/event.py for more details.
nav.models.event.AlertHistory
-
class
nav.models.event.
AlertHistory
(*args, **kwargs)
From NAV Wiki: The alert history. Simular to the alert queue with one
important distinction; alert history stores stateful events as one row,
with the start and end time of the event.
-
exception
DoesNotExist
-
exception
MultipleObjectsReturned
-
acknowledge
(account, comment)
Acknowledges this alert using a given account and comment.
Any pre-existing acknowledgement will be overwritten.
-
acknowledgement
Accessor to the related object on the reverse side of a one-to-one
relation.
In the example:
class Restaurant(Model):
place = OneToOneField(Place, related_name='restaurant')
Place.restaurant
is a ReverseOneToOneDescriptor
instance.
-
alert_type
Accessor to the related object on the forward side of a many-to-one or
one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent
is a ForwardManyToOneDescriptor
instance.
-
alert_type_id
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
alertqueue_set
Accessor to the related objects manager on the reverse side of a
many-to-one relation.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children
is a ReverseManyToOneDescriptor
instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager()
defined below.
-
device
Accessor to the related object on the forward side of a many-to-one or
one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent
is a ForwardManyToOneDescriptor
instance.
-
device_id
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
end_time
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
event_type
Accessor to the related object on the forward side of a many-to-one or
one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent
is a ForwardManyToOneDescriptor
instance.
-
event_type_id
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
get_downtime
()
Returns the difference between start_time and end_time, the current
downtime if the alert is still open, and None if the alert is
stateless.
-
get_next_by_start_time
(*, field=<django.db.models.fields.DateTimeField: start_time>, is_next=True, **kwargs)
-
get_previous_by_start_time
(*, field=<django.db.models.fields.DateTimeField: start_time>, is_next=False, **kwargs)
-
id
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
is_acknowledged
()
Returns an Acknowledgement instance if this alert has been
acknowledged, otherwise None.
-
is_open
()
Returns true if stateful and open.
-
is_stateful
()
Returns true if the alert is stateful.
-
messages
Accessor to the related objects manager on the reverse side of a
many-to-one relation.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children
is a ReverseManyToOneDescriptor
instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager()
defined below.
-
netbox
Accessor to the related object on the forward side of a many-to-one or
one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent
is a ForwardManyToOneDescriptor
instance.
-
netbox_id
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
objects
= <django.db.models.manager.ManagerFromAlertHistoryQuerySet object>
-
save
(*args, **kwargs)
Save the current instance. Override this in a subclass if you want to
control the saving process.
The ‘force_insert’ and ‘force_update’ parameters can be used to insist
that the “save” must be an SQL insert or update (or equivalent for
non-SQL backends), respectively. Normally, they should not be set.
-
severity
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
source
Accessor to the related object on the forward side of a many-to-one or
one-to-one (via ForwardOneToOneDescriptor subclass) relation.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Child.parent
is a ForwardManyToOneDescriptor
instance.
-
source_id
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
start_time
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
subid
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
value
A wrapper for a deferred-loading field. When the value is read from this
object the first time, the query is executed.
-
variables
Accessor to the related objects manager on the reverse side of a
many-to-one relation.
In the example:
class Child(Model):
parent = ForeignKey(Parent, related_name='children')
Parent.children
is a ReverseManyToOneDescriptor
instance.
Most of the implementation is delegated to a dynamically defined manager
class built by create_forward_many_to_many_manager()
defined below.
-
varmap
Descriptor for simplified dict-like access to the AlertHistory
stateful variable map.
NOTE: Updating the dictionary will not save it, the attribute must be
assigned a dict value for a db update to take place.