BaseRule

class lsst.ts.watcher.BaseRule(config, name, remote_info_list)

Bases: abc.ABC

Base class for watcher rules.

Parameters:
config : types.SimpleNamespace

Rule configuration, as validated by the schema.

name : str

Name of alarm. This must be unique among all alarms and should be of the form system.[subsystem….]_name so that groups of related alarms can be acknowledged.

remote_info_list : list [RemoteInfo]

Information about the remotes used by this rule.

Notes

Model.add_rule adds an attribute lowerremotename_index to the rule for each remote in remote_info_list. The value of the attribute is the appropriate RemoteWrapper. lowerremotename is the name of the remote converted to lowercase and the index is the integer index of the remote, e.g. “atptg_0”.

Attributes Summary

name Get the rule name.

Methods Summary

__call__(topic_callback) Run the rule and return the severity and reason.
get_schema() Return a jsonschema to validate configuration, as a dict.
is_usable(disabled_sal_components) Return True if rule can be used, despite disabled SAL components.
start() Start any background tasks, such as a polling loop.
stop() Stop all background tasks.

Attributes Documentation

name

Get the rule name.

Methods Documentation

__call__(topic_callback)

Run the rule and return the severity and reason.

Parameters:
topic_callback : TopicCallback

Topic callback wrapper.

Returns:
A tuple of two values:
severity: `lsst.ts.idl.enums.Watcher.AlarmSeverity`

The new alarm severity.

reason : str

Detailed reason for the severity, e.g. a string describing what value is out of range, and what the range is. If severity is NONE then this value is ignored (but still required) and the old reason is retained until the alarm is reset to nominal state.

Notes

You may return NoneNoReason if the alarm states is NONE.

To defer setting the alarm state, start a task that calls self.alarm.set_severity later. For example the heartbeat rule’s __call__ method is called when the heartbeat event is seen, and this restarts a timer and returns NoneNoReason. If the timer finishes, meaning the next heartbeat event was not seen in time, the timer sets alarm severity > NONE.

classmethod get_schema()

Return a jsonschema to validate configuration, as a dict.

Notes

Please provide default values for all fields for which defaults make sense. This makes watcher configuration files easier to write.

If your rule has no configuration then return None.

We recommend that you write the schema as yaml, for compactness, then use yaml.safe_load to convert it to a dict. For example:

schema_yaml = """
    $schema: http://json-schema.org/draft-07/schema#
    $id: https://github.com/lsst-ts/ts_watcher/MyRule.yaml
    description: Configuration for MyRule
    type: object
    properties:
    ...
    required: [...]
    additionalProperties: false
"""
return yaml.safe_load(schema_yaml)
is_usable(disabled_sal_components)

Return True if rule can be used, despite disabled SAL components.

The attributes config, name and remote_info_list will all be available when this is called:

Parameters:
disabled_sal_components : list [tuple [str, int]]

List of disabled SAL components. Each element is a tuple of:

  • SAL component name (e.g. “ATPtg”)
  • SAL index
start()

Start any background tasks, such as a polling loop.

This is called when the watcher goes into the enabled state.

Notes

Do not assume that start is called before stop; the order depends on the initial state of the Watcher.

Immediate subclasses need not call super().start()

stop()

Stop all background tasks.

This is called when the watcher goes out of the enabled state, and must stop any tasks that might trigger an alarm state change.

Notes

Do not assume that start is called before stop; the order depends on the initial state of the Watcher.

This base implementation does nothing, so immediate subclasses need not call super().stop().