Custom Watchers - Templating

Custom watchers support templating which can be used to create new types of watchers with predefined characteristics for specific use-cases. A HTML template can be set for the watcher’s configuration panel, which includes the watcher’s basic settings. This template defaults to the standard configuration panel. A template can also be provided for an additional parameters panel, which can prompt the user creating the watcher to input additional parameters.

A template uses basic HTML, with injection and processing logic provided by AngularJS syntax. Styling can also be applied using the provided [Bootstrap 3](https://getbootstrap.com/docs/3.3/css/) classes.

Templating for the configuration panel

titlePanelWatcherWizard represents a root object, which contains the watcher data and methods to process input data. The following properties and methods are provided:

Property Type Description

titlePanelWatcherWizard.titleText

string

Returns the title of the watcher in the format Custom watcher: $CUSTOM_WATCHER_TYPE

titlePanelWatcherWizard.watcher

object

Access to the whole watcher object with the defined properties on it. An example of the watcher object can be found here

titlePanelWatcherWizard.onScheduleChange

({ mode: string, text: string }) => ƒ

Changes schedule property for the watcher

titlePanelWatcherWizard.hideSettings

boolean

Reads and returns hideSettings flag from the watcher script

titlePanelWatcherWizard.onPrivacyModeChange

(isPrivate: boolean, string[]) => ƒ

Sets the privacy control properties for the watcher and produced alarms/reports.

titlePanelWatcherWizard.hasSecurity

boolean

Returns true if security is enabled

titlePanelWatcherWizard.schedule.selected

string

Returns and sets the selected schedule mode

titlePanelWatcherWizard.schedule.options

string[]

Returns and sets the available schedule options

titlePanelWatcherWizard.schedule.handleChange

(mode: string, text: string) => ƒ

Sets the new schedule for the watcher

titlePanelWatcherWizard.form

object

AngularJS-object for the state of the form if it is used in the template

titlePanelWatcherWizard.showScheduleMode

(mode: string) => ƒ

Sets titlePanelWatcherWizard.schedule.selected

titlePanelWatcherWizard.isValidationMessageVisible

string

Returns the status of the message for the selected form’s input

titlePanelWatcherWizard.template

string

Returns id for the current template

titlePanelWatcherWizard.data.fields

string[]

Returns the available fields of selected saved search

titlePanelWatcherWizard.data.geoFields

string[]

Returns the available geo-fields of selected saved search

An example of a configuration template can be found here.

Templating for the parameters panel

The parameters panel has an access to two objects on scope of AngularJS controller: params and data.

The linked watcher custom parameters can be accessed through the params object. The newly created watcher requires all parameters to be defined. The template for the parameters panel should have default values for the hidden parameters on the template.

The data object represents the available fields of selected saved search. The data object has the following properties:

Property

Type

Description

data.fields

string[]

Returns the available fields of selected saved search

data.geoFields

string[]

Returns the available geo-fields of selected saved search

The parameters template allows you to customize one section in the watcher creation page (below the configuration panel). If more flexibility is required, the parameters, as well as the basic settings of a watcher create page, can be rendered using the configuration template. This template is given full access to the watcher object, the parameters specific to the custom watcher (as titlePanelWatcherWizard.watcher.custom.params), and the data object (as titlePanelWatcherWizard.data).

An example of a parameters template can be found here.

Defined components

For any of the templates, the following HTML components provide built-in forms for configuring watcher settings.

Component Attributes Description

<watcher-wizard-human-schedule />

watcher="$WATCHER_OBJECT" on-select="$CALLBACK"

Renders the form to set schedule through a single text value for the selected watcher and invokes calback on changes

<watcher-wizard-every-schedule />

watcher="$WATCHER_OBJECT" on-select="$CALLBACK"

Renders the form to set schedule through configurable interval and unit value for the selected watcher and invokes calback on changes

<watcher-wizard-privacy-control />

watcher="$WATCHER_OBJECT" on-select="$CALLBACK"

Renders the form to set the privacy settings for the selected watcher and invokes callback on changes

<watcher-wizard-priority />

Renders the form to set priority for the available watcher on the scope

Sanitizing

Templates do not support usage of insecure HTML tags, attributes, scripts or custom stylesheets using the <style> tag. Custom HTML tags, attributes, stylesheets can, however, be permitted by setting the following flags in the $INVESTIGATE_HOME/config/investigate.yml.

Flag

Type

Description

investigate_core.security.allow_css_watcher_template

boolean

Allows the use of custom stylesheets

investigate_core.security.allowed_attributes_watcher_template

string[]

Allows the use of specified custom attributes

investigate_core.security.allowed_tags_watcher_template

string[]

Allows the use of specified custom tags