Different event handlers can be configured for each AlertNode.
Some handlers like Email, HipChat, Sensu, Slack, OpsGenie, VictorOps, PagerDuty and Talk have a configuration
option 'global' that indicates that all alerts implicitly use the handler.

Available event handlers:

log – log alert data to file.

post – HTTP POST data to a specified URL.

email – Send and email with alert data.

exec – Execute a command passing alert data over STDIN.

HipChat – Post alert message to HipChat room.

Alerta – Post alert message to Alerta.

Sensu – Post alert message to Sensu client.

Slack – Post alert message to Slack channel.

OpsGenie – Send alert to OpsGenie.

VictorOps – Send alert to VictorOps.

PagerDuty – Send alert to PagerDuty.

Talk – Post alert message to Talk client.

See below for more details on configuring each handler.

Each event that gets sent to a handler contains the following alert data:

ID – the ID of the alert, user defined.

Message – the alert message, user defined.

Details – the alert details, user defined HTML content.

Time – the time the alert occurred.

Level – one of OK, INFO, WARNING or CRITICAL.

Data – influxql.Result containing the data that triggered the alert.

Events are sent to handlers if the alert is in a state other than 'OK'
or the alert just changed to the 'OK' state from a non 'OK' state (a.k.a. the alert recovered).
Using the AlertNode.StateChangesOnly property events will only be sent to handlers
if the alert changed state.

It is valid to configure multiple alert handlers, even with the same type.

It is assumed that each successive level filters a subset
of the previous level. As a result, the filter will only be applied if
a data point passed the previous level.
In the above example, if value = 15 then the INFO and
WARNING expressions would be evaluated, but not the
CRITICAL expression.
Each expression maintains its own state.

Alerta

In order to not post a message every alert interval
use AlertNode.StateChangesOnly so that only events
where the alert changed state are sent to Alerta.

Send alerts to Alerta. The resource and event properties are required.

Example:

stream....alert().alerta().resource('Hostname or service').event('Something went wrong')

Alerta also accepts optional alert information.

Example:

stream....alert().alerta().resource('Hostname or service').event('Something went wrong').environment('Development').group('Dev. Servers')

NOTE: Alerta cannot be configured globally because of its required properties.

node.alerta()

Alerta Environment

Alerta environment.
Can be a template and has access to the same data as the AlertNode.Details property.
Defaut is set from the configuration.

node.alerta().environment(valuestring)

Alerta Group

Alerta group.
Can be a template and has access to the same data as the AlertNode.Details property.
Default: {{ .Group }}

node.alerta().group(valuestring)

Alerta Origin

Alerta origin.
If empty uses the origin from the configuration.

node.alerta().origin(valuestring)

Alerta Resource

Alerta resource.
Can be a template and has access to the same data as the AlertNode.Details property.
Default: {{ .Name }}

node.alerta().resource(valuestring)

Alerta Token

Alerta authentication token.
If empty uses the token from the configuration.

node.alerta().token(valuestring)

Alerta Value

Alerta value.
Can be a template and has access to the same data as the AlertNode.Details property.
Default is an empty string.

node.alerta().value(valuestring)

Crit

Filter expression for the CRITICAL alert level.
An empty value indicates the level is invalid and is skipped.

node.crit(valuetick.Node)

Details

Template for constructing a detailed HTML message for the alert.
The same template data is available as the AlertNode.Message property,
in addition to a Message field that contains the rendered Message value.

The intent is that the Message property be a single line summary while the
Details property is a more detailed message possibly spanning multiple lines,
and containing HTML formatting.

This template is rendered using the html/template package in Go so that
safe and valid HTML can be generated.

The json method is available within the template to convert any variable to a valid
JSON string.

Email

Email the alert data.

If the To list is empty, the To addresses from the configuration are used.
The email subject is the AlertNode.Message property.
The email body is the AlertNode.Details property.
The emails are sent as HTML emails and so the body can contain html markup.

If the 'smtp' section in the configuration has the option: global = true
then all alerts are sent via email without the need to explicitly state it
in the TICKscript.

Flapping

Each different alerting level is considered a different state.
The low and high thresholds are inverted thresholds of a percentage of state changes.
Meaning that if the percentage of state changes goes above the high
threshold, the alert enters a flapping state. The alert remains in the flapping state
until the percentage of state changes goes below the low threshold.
Typical values are low: 0.25 and high: 0.5. The percentage values represent the number state changes
over the total possible number of state changes. A percentage change of 0.5 means that the alert changed
state in half of the recorded history, and remained the same in the other half of the history.

node.flapping(lowfloat64,highfloat64)

HipChat

If the 'hipchat' section in the configuration has the option: global = true
then all alerts are sent to HipChat without the need to explicitly state it
in the TICKscript.

OpsGenie

Send alert to OpsGenie.
To use OpsGenie alerting you must first enable the 'Alert Ingestion API'
in the 'Integrations' section of OpsGenie.
Then place the API key from the URL into the 'opsgenie' section of the Kapacitor configuration.

If the "value" is greater than 10 for a total of 60s, then
only two events will be sent. First, when the value crosses
the threshold, and second, when it falls back into an OK state.
Without stateChangesOnly, the alert would have triggered 7 times:
6 times for each 10s period where the condition was met and once more
for the recovery.

node.stateChangesOnly()

Talk

Send the alert to Talk.
To use Talk alerting you must first follow the steps to create a new incoming webhook.

Go to the URL https:/account.jianliao.com/signin.

Sign in with you account. under the Team tab, click "Integrations".

Select "Customize service", click incoming Webhook "Add" button.

After choose the topic to connect with "xxx", click "Confirm Add" button.

Once the service is created, you'll see the "Generate Webhook url".

Place the 'Generate Webhook url' into the 'Talk' section of the Kapacitor configuration as the option 'url'.

VictorOps

Send alert to VictorOps.
To use VictorOps alerting you must first enable the 'Alert Ingestion API'
in the 'Integrations' section of VictorOps.
Then place the API key from the URL into the 'victorops' section of the Kapacitor configuration.

Example:

[victorops]enabled=trueapi-key="xxxxx"routing-key="everyone"

With the correct configuration you can now use VictorOps in TICKscripts.

Example:

stream....alert().victorOps()

Send alerts to VictorOps using the routing key in the configuration file.

Example:

stream....alert().victorOps().routingKey('team_rocket')

Send alerts to VictorOps with routing key 'team_rocket'

If the 'victorops' section in the configuration has the option: global = true
then all alerts are sent to VictorOps without the need to explicitly state it
in the TICKscript.

You can specify additional lambda expressions to further constrain when the deadman's switch is triggered.
Example:

vardata=stream.from()...// Trigger critical alert if the throughput drops below 100 points per 10s and checked every 10s.
// Only trigger the alert if the time of day is between 8am-5pm.
data.deadman(100.0,10s,lambda:hour("time")>=8ANDhour("time")<=17)//Do normal processing of data
data....

Stats

Create a new stream of data that contains the internal statistics of the node.
The interval represents how often to emit the statistics based on real time.
This means the interval time is independent of the times of the data points the source node is receiving.