alarms package

Submodules

alarms.admin module

Admin settings for alarm app.

Generated by ‘django-admin startproject’ using Django 1.11.6.

For more information on this file, see https://docs.djangoproject.com/en/1.11/topics/settings/

For the full list of settings and their values, see https://docs.djangoproject.com/en/1.11/ref/settings/

alarms.apps module

class alarms.apps.AlarmConfig(app_name, app_module)

Bases: django.apps.config.AppConfig

Configuration of the application Alarm

name = 'alarms'

Name of the application

ready()

Initializes AlarmCollection on application start

alarms.auth module

class alarms.auth.TokenAuthMiddleware(inner)

Bases: object

Custom middleware to use a token for user authentication

alarms.collections module

class alarms.collections.AlarmCollection

Bases: object

This class defines the data structure that will store and handle the Alarms in memory. Allows observers to subscribe to changes on the Alarm objects

classmethod acknowledge(core_ids)

Acknowledges an alarm or a list of Alarms

Args:
core_ids (list or string): list of core_ids (or a single core_id) of the Alarms to acknowledge
Return:
(list of string): list of core_ids of the acknowledged alarms including dependent alarms
classmethod add(alarm)

Adds the alarm to the AlarmCollection dictionary

Args:
alarm (Alarm): the Alarm object to add
Returns:
tickets_to_create: a list of IDS to create tickets
classmethod add_or_update_alarm(iasio)

Adds the alarm if it isn’t in the AlarmCollection already or updates the alarm in the other case. It also initializes the Collection if it has been not initialized before.

Records the changes to be notified if it is the case

Args:
iasio (dict): the dict correpsonding to the Alarm to add or update
Returns:
message (string): a string message sumarizing what happened
classmethod add_or_update_value(iasio)

Adds the ias value if it isn’t in the values collection already or updates the ias value in the other case.

It does not notify the observers on change. It only mantains updated the collection to respond to user requests.

Args:
iasio (dict): the IASValue object to add or update
Returns:
message (string): a string message sumarizing what happened
alarm_changes = []

List of IDs of Alarms that have changed and must be notified

alarms_views_dict = None

Dictionary to store the related view names by alarm, indexed by core_id

classmethod broadcast_observers()

Notify to all observers the alarms list with its current status

broadcast_task = None

Reference to the Task that sends all alarms periodically

classmethod clear_tickets(alarm_ids)

Clear the open tickets for a list of specified Alarm IDs

Args:
alarm_ids (string[]): List of Core ID of the Alarms associated to the Tickets to clear
classmethod create_tickets(alarm_ids)

Creates a ticket for a list of specified Alarm IDs

Args:
alarm_ids (string[]): List of Core ID of the Alarms to create tickets
classmethod get(core_id)

Returns the Alarm object in the AlarmCollection dictionary with that core_id value. It also initializes the Collection if it has been not initialized before.

Args:
core_id (string): the core_id of the Alarm to get
Returns:
dict: A dictionary of Alarm objects
classmethod get_all_as_dict()

Returns all the Alarms as a dictionary indexed by core_id

Returns:
dict: A dictionary of Alarms indexed by core_id
classmethod get_all_as_list()

Returns all the Alarms as a list

classmethod get_ancestors_recursively(core_id)

Return the list of parents and grandparents recursively of the specified alarm

Args:
core_id (string): the ID of the Alarm object to get its ancestors
Returns:
list: List with the IDs of the ancestors
classmethod get_dependencies_recursively(core_id)

Returns a list of alarm ids of all the dependencies of the specified alarm

Returns:
list: A list of alarm ids dependencies of the alarm with core_id
classmethod get_value(core_id)

Returns the value indexed by core_id in the values collection dict

Args:
core_id (string): The core core_id of the value
init_state = 'pending'

Status of initialization, cand be either ‘pending’, ‘in-progress’ or ‘done’

classmethod initialize(iasios=None)

Initializes the alarms collection with default alarms. If a list of iasios is passed, it initializes Alarms only for those iasios. If not, it initializes Alarms based on the alarm_ids used in AlarmConfig objects of the Panels app, getting their description and documentation urls from the CDB.

Args:
iasios (list): An optional list of iasio objects
Returns:
dict: A dictionary of Alarm objects
mode_options = {'CLOSING': 2, 'DEGRADED': 6, 'INITIALIZATION': 1, 'MAINTENANCE': 4, 'MALFUNCTIONING': 8, 'OPERATIONAL': 5, 'SHUTTEDDOWN': 3, 'STARTUP': 0, 'UNKNOWN': 7}

Dictionary to transform Alarm OperationalMode from string to the corresponding numbers

notification_task = None

Reference to the Task that notifies changes periodically

classmethod notify_observers()

Notify to all observers an action over Alarms

num_pattern = re.compile('\\d+')

Pattern used to find the number in a templated id from a CDB IASIO

observers = []

List to store references to the observers subscribed to changes in the collection

parents_collection = None

Dictionary to store the parents of each alarm

pattern = re.compile('\\[!#\\d+!\\]')

Pattern used to find templated ids from CDB IASIOS

classmethod periodic_broadcast_coroutine(rate)

Coroutine that notifies of changes to all the observers periodically

Args:
rate (int): time in seconds
classmethod periodic_notification_coroutine()

Coroutine that notifies of changes to all the observers periodically The notifications rate is defined in the variable ias_webserver.settings.NOTIFICATIONS_RATE

classmethod receive_iasios(iasios)
classmethod record_alarm_changes(alarms)

Register given Alarm(s) in order to notify its(their) change(s)

Args:
alarms (list or Alarm): list of Alarms (or a single Alarm) whose changes must be notified
classmethod register_observer(observer)

Add an observer to the observers list

classmethod reset(iasios=None)

Resets the AlarmCollection dictionary initializing it again. Go to initialize() to see the initialization specification.

Args:
iasios (list): A list of iasio objects
classmethod shelve(core_id)

Shelves an alarm

Args:
core_id (string): core_ids of the Alarm to shelve
Returns:
int: 1 if it was shelved, 0 if not, -1 if shelving is not allowed
singleton_collection = None

Dictionary to store the Alarm objects, indexed by core_id

classmethod start_initialization()

Starts the initialization of the AlarmCollection. It is an async m ethod that can be awaited

classmethod start_periodic_tasks()

Starts the coroutine that notifies changes to all the observers as a task.

Checks if the task (notification_task) has started and starts it if not, or if it has been cancelled or has finished

classmethod unshelve(core_ids)

Unshelves an alarm or a list of Alarms

Args:
core_ids (list or string): list of core_ids (or a single core_id) of the Alarms to unshelve
Returns:
boolean: True if it was unshelved, False if not
classmethod update_alarm(stored_alarm, alarm)

Updates an already existing Alarm in the AlarmCollection. Records the changes to be notified if it is the case

Args:
alarm (Alarm): the dict correpsonding to the Alarm to add or update
Returns:
message (string), tickets_to_create, tickets_to_clear: a string message sumarizing what happened, a list of IDS to create tickets and a list of IDs to clear tickets
classmethod update_all_alarms_validity()

Update the validity of each alarm in the AlarmCollection dictionary. Go to alarms.models.Alarm.update_validity() to see the validation specification.

Returns:
dict: the AlarmCollection as a dictionary after the validity update
validity_options = {'RELIABLE': 1, 'UNRELIABLE': 0}

Dictionary to transform Alarm Validity from string to the corresponding numbers

value_options = {'CLEARED': 0, 'SET_CRITICAL': 4, 'SET_HIGH': 3, 'SET_LOW': 1, 'SET_MEDIUM': 2}

Dictionary to transform Alarm Value from string to the corresponding numbers

values_collection = None

Dictionary to store other type of values, indexed by core_id

class alarms.collections.AlarmCollectionObserver

Bases: abc.ABC

This class defines an interface that all the observers must implement

update(stream)

Method that will be called on Observers when there is a new action to notifiy

Args:
data (dict): Dictionary that contains the ‘alarms’ and ‘counters’ stream (string): Stream to send the data through

alarms.connectors module

class alarms.connectors.CdbConnector

Bases: object

This class defines methods to communicate the Alarm app with the CDB app

classmethod get_iasios(type=None)

Return a list of iasios filtered by type formatted as dict

classmethod initialize_ias(pk=0)

Return the ias if exist or None if it is not.

refresh_rate = 3000

refreshrate in milliseconds defined to be used to calculate the validity of alarms

validity_threshold = 10000

Validity threshold in milliseconds defines to be used to calculate the validity of alarms

class alarms.connectors.PanelsConnector

Bases: object

This class defines methods to communicate the Alarm app with the Panels app

classmethod get_alarm_ids_of_alarm_configs()

Returns a list with the ids (alarm_id) of all the AlarmConfigs

Returns:
(list): the list of alarm ids
classmethod get_alarms_views_dict_of_alarm_configs()

Returns a dict with the names of the views related to an alarm from all the AlarmConfigs

Returns:
(dict): dictionary of views names with alarm_ids as keys
class alarms.connectors.TicketConnector

Bases: object

This class defines methods to communicate the Alarm app with the Ticket app

classmethod check_acknowledgement(alarm_id)

Check if the alarm has pending acknowledgements.

Args:
alarm_id (string): ID of the Alarm
Returns:
(bolean): true if the alarm is acknowledged otherwise false
classmethod check_shelve(alarm_id)

Check if the alarm is shelved.

Args:
alarm_id (string): ID of the Alarm
Returns:
(bolean): true if the alarm is shelved otherwise false
classmethod clear_tickets(alarm_ids)

Closes a list of ticket for a given list of Alarm IDs

Args:
alarm_ids (string[]): List of IDs of the Alarms associated to the tickets
classmethod create_tickets(alarm_ids)

Create a list of ticket for a given list of Alarm IDs

Args:
alarm_ids (string[]): List of ID of Alarms to create tickets
unack_statuses = [0, 2]

alarms.consumers module

class alarms.consumers.ClientConsumer(*args, **kwargs)

Bases: channels.generic.websocket.AsyncJsonWebsocketConsumer, alarms.collections.AlarmCollectionObserver

Consumer to notify clients and listen their requests

connect()

Called upon connection, rejects connection if no authenticated user or password. Start the periodic notifications in the AlarmCollection

disconnect(close_code)

Called when the socket closes

groups = []
receive_json(content, **kwargs)

Handles the messages received by this consumer

If the message contains the ‘action’ ‘list’, responds with the list of all the current Alarms.

update(payload, stream)

Notifies the client of changes in an Alarm. Implements the AlarmCollectionObserver.update method

Args:
data (dict): Dictionary that contains the ‘alarms’ and ‘counters’ stream (string): Stream to send the data through
class alarms.consumers.CoreConsumer(*args, **kwargs)

Bases: channels.generic.websocket.AsyncJsonWebsocketConsumer

Consumer for messages from the core system

connect()

Called upon connection, rejects connection if no authenticated user or password

receive_json(content, **kwargs)

Handles the messages received by this consumer. It delegates handling of the alarms received in the messages to add_or_update_alarm()

Responds with a message indicating the action taken (created, updated, ignored)

alarms.interfaces module

class alarms.interfaces.IAlarms

Bases: object

This class defines the methods that the Alarms app provides to be used by other apps

classmethod acknowledge_alarms(alarm_ids)

Akcnowledge Alarms based on a list of Alarm IDs

Args:
alarms_ids (list): List of IDs of the Alarms to acknowledge
classmethod get_alarm_ancestors(alarm_id)

Get the ancestors of the specified alarm

Args: alarm_id (string): The id of the alarm to get the ancestors

classmethod get_alarm_dependencies(alarm_id)

Get the dependencies of the specified alarm

Args:
alarm_id (string): The id of the alarm to get the dependencies
classmethod get_value(value_id)

Get a selected IASValue from the values_collection

Args: value_id (string): The core_id of the value

classmethod shelve_alarm(alarm_id)

Shelve an Alarm based on an Alarm ID

Args:
alarm_id (string): ID of the Alarms to shelve
classmethod unshelve_alarms(alarm_ids)

Unshelve Alarms based on a list of Alarm IDs

Args:
alarms_ids (list): List of IDs of the Alarms to unshelve

alarms.models module

class alarms.models.Alarm(core_timestamp, core_id, running_id, value=0, mode=0, validity=0, dependencies=[], properties={}, timestamps={}, ack=False, shelved=False, state_change_timestamp=0, description='', url='', sound='', can_shelve=False, views=[], stored=False, value_change_timestamp=0, value_change_transition=[0, 0])

Bases: object

Alarm generated by some device in the observatory.

ack = None

True if the alarm is acknowledged, False if not

acknowledge(ack=True)

Acknowledges the Alarm if its value is SET

Args:
ack (optional boolean): acknowledge status to update, True by default
Returns:
boolean: the final ack status
can_shelve = None

Flag that defines weteher or not the alarm can be shelved

core_id = None

Core ID of the alarm

core_timestamp = None

Core timestamp of the alarm

dependencies = None

Children Alarms, alarms on which this Alarm depends

description = None

Description of the alarm

is_not_set()

Method to check is the alarm is not set

is_set()

Method to check is the alarm is set

is_stored()

Method to check is the alarm was stored in the collection

mode = None

Operational mode of the alarm

objects = <alarms.models.AlarmManager object>
properties = None

Properties of the core

running_id = None

Running ID of the alarm

shelve()

Shelves the Alarm

Returns:
int: 1 if it was shelved, 0 if not, -1 if shelving is not allowed
shelved = None

True if the alarm is shelved, False if not

sound = None

Sound associated to the alarm

state_change_timestamp = None

Timestamp of the last important (notified) change in the alarm

stored = None

Flag that defines weteher or not the alarm is stored

timestamps = None

Timestamps of the core

to_dict()

Returns a dict with all the values of the different attributes

unacknowledge()

Unacknowledge the Alarm

Returns:
boolean: the final ack status
unshelve()

Unshelves the Alarm

Returns:
boolean: True if it was unshelved, False if not
update(alarm)

Updates the alarm with attributes from another given alarm if the timestamp of the given alarm is greater than the stored alarm.

Args:
alarm (Alarm): The new alarm object
Returns:
(string, string, boolean): A tuple with the state of the update (not-updated, updated-equal, updated-different), the transition of the alarm value (clear-set, set-clear or None) and wether or not the dependencies of the alarm have been updated
update_validity()

Calculate the validity of the alarm considering the current time, the refresh rate and a previously defined delta time

url = None

URL to go for documentation of the alarm

validity = None

Validity of the alarm

value = None

Value of the alarm

value_change_timestamp = None

Timestamp of the last change in the alarm value

value_change_transition = None

Transition of the last change in the alarm value Stored as a list with 2 elements in order: [previous_value, new_value]

views = None

List of views for which the alarm must be considered for counting

class alarms.models.AlarmCountManager

Bases: object

Class to manage the counter by view.

counter_by_view = {}
reset_counter_by_view()

Method to clear the counter by view

update_counter_by_view_if_alarm_has_value_update(alarm, initial_ack_state, transition)

Update counter after value (set or cleared) update

update_counter_by_view_if_alarm_is_acknowledged(after_ack_alarm, initial_ack_state)

Update counter after acknowledgment action

update_counter_by_view_if_alarm_is_unacknowledged(after_ack_alarm, initial_ack_state)

Update counter after unacknowledgment action

update_counter_by_view_if_new_alarm_in_collection(alarm)

Increase counter for a new SET UNACK alarm Note: This method is used in the AlarmCollection

class alarms.models.AlarmManager

Bases: alarms.models.AlarmCountManager

Set of auxiliary methods for the alarm model.

class alarms.models.IASValue(core_timestamp, core_id, running_id, value, mode=0, validity=0, timestamps={}, state_change_timestamp=0)

Bases: alarms.models.Alarm

IASValue from some device in the observatory.

to_dict()

Returns a dict with all the values of the different attributes

update(ias_value)

Updates the ias_value with attributes from another given ias_value if the timestamp of the given ias_value is greater than the stored ias value.

Args:
ias_value (dict): The new ias_value object
Returns:
string: the state of the update (not-updated, updated-equal, updated-different)
class alarms.models.OperationalMode

Bases: utils.choice_enum.ChoiceEnum

Operational Mode of a monitor point value.

CLOSING = 2
DEGRADED = 6
INITIALIZATION = 1
MAINTENANCE = 4
MALFUNCTIONING = 8
OPERATIONAL = 5
SHUTTEDDOWN = 3
STARTUP = 0
UNKNOWN = 7
class alarms.models.Validity

Bases: utils.choice_enum.ChoiceEnum

Possible validity states of an Alarm

RELIABLE = 1

The value has been provided in time and the operator can trust what the IAS shows

UNRELIABLE = 0

The values has not been produced in time either by the IAS Core or due to network problems or any other reason.

class alarms.models.Value

Bases: utils.choice_enum.ChoiceEnum

Value of the Alarm.

CLEARED = 0
SET_CRITICAL = 4
SET_HIGH = 3
SET_LOW = 1
SET_MEDIUM = 2

alarms.views module

alarms.views.test_core(request)

Basic view used mostly for debuging purposes

Module contents