Skip to main content
Version: Next

Action: transition

Performs various actions based on a changed field

Field Summary

Field NameTypeDescriptionDefault
conditionexpressionOnly run this action if the condition the specified condition is met-
watch-fieldfieldA field that is watched for changes-
elapsed-output-fieldfieldA field that will be used to store elapsed time between state changes-
time-fieldiso time fieldA field containing a time value-
markerarray of stringsGenerate a new event, depending on if a transition has happened-
value-at-last-change-output-fieldfieldContains state value of before transition happened-
time-at-last-change-output-fieldfieldContains timestamp of before transition happened-
time-at-last-change-output-formattime formatThe time format to be used for the time-at-last-change-output-field-
candidate-time-at-transition-output-fieldfieldThe time field of the record that caused the transition-
threshold-countintegerNumber of times a value must have been seen in a row, to consider a state change a transition1
threshold-count-output-fieldfieldA field to record the action threshold count at the time of change-
group-byfieldAllows tracking transitions individually in the case of aggregated data-
save-filepathA file to persist state, to know where we left off in the case where the Pipe is restarted-
maximum-agestringThe maximum age of any recorded history-
maximum-age-markerstringThe marker in the event stream to watch for to trigger a maximum age record sweep-

Fields

condition

Type: expression

Only run this action if the condition the specified condition is met

watch-field

Type: field
Alias: watch

A field that is watched for changes

The field value may be a string, number or boolean

Example

Input:

input:
exec:
command:
echo '{"state":0}';
sleep 1;
echo '{"state":1}';
sleep 1;
echo '{"state":1}';
raw: true
no-strip-linefeeds: true

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed

Output:

{"state":0,"elapsed":0}
{"state":1,"elapsed":0}
{"state":1,"elapsed":1002}

elapsed-output-field

Type: field

A field that will be used to store elapsed time between state changes

time-field

Type: iso time field
Alias: input-time

A field containing a time value

If not specified, system time is used instead.

Example

Input:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time

Output:

{"time":"2020-02-03T15:34:55.149Z","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:56.149Z","state":1,"elapsed":0}
{"time":"2020-02-03T15:34:57.149Z","state":1,"elapsed":1000}

marker

Type: array of strings

Generate a new event, depending on if a transition has happened

Example

Input:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}
{"time":"2020-02-03T15:34:58.149Z","state":0}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time
marker:
- marker

Output:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"_marker":"marker","state":1,"elapsed":1000}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}
{"_marker":"marker","state":0,"elapsed":2000}
{"time":"2020-02-03T15:34:58.149Z","state":0}

value-at-last-change-output-field

Type: field

Contains state value of before transition happened

This is useful for associating states with their duration

Example

Input:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}
{"time":"2020-02-03T15:34:58.149Z","state":0}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time
marker:
- marker
value-at-last-change-output-field: previous

Output:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"_marker":"marker","state":1,"elapsed":1000,"previous":0}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}
{"_marker":"marker","state":0,"elapsed":2000,"previous":1}
{"time":"2020-02-03T15:34:58.149Z","state":0}

time-at-last-change-output-field

Type: field

Contains timestamp of before transition happened

Example

Input:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}
{"time":"2020-02-03T15:34:58.149Z","state":0}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time
time-at-last-change-output-field: previous

Output:

{"time":"2020-02-03T15:34:55.149Z","state":0,"elapsed":0,"previous":"2020-02-03T15:34:55.149Z"}
{"time":"2020-02-03T15:34:56.149Z","state":1,"elapsed":0,"previous":"2020-02-03T15:34:56.149Z"}
{"time":"2020-02-03T15:34:57.149Z","state":1,"elapsed":1000,"previous":"2020-02-03T15:34:56.149Z"}
{"time":"2020-02-03T15:34:58.149Z","state":0,"elapsed":0,"previous":"2020-02-03T15:34:58.149Z"}

Example: With a marker

Input:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}
{"time":"2020-02-03T15:34:58.149Z","state":0}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time
marker:
- marker
time-at-last-change-output-field: previous

Output:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"_marker":"marker","state":1,"elapsed":1000,"previous":"2020-02-03T15:34:56.149Z"}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}
{"_marker":"marker","state":0,"elapsed":2000,"previous":"2020-02-03T15:34:58.149Z"}
{"time":"2020-02-03T15:34:58.149Z","state":0}

time-at-last-change-output-format

Type: time format

The time format to be used for the time-at-last-change-output-field

candidate-time-at-transition-output-field

Type: field

The time field of the record that caused the transition

threshold-count

Type: integer

Default: 1

Number of times a value must have been seen in a row, to consider a state change a transition

Example

Input:

{"time":"2020-02-03T15:34:45.149Z","state":0}
{"time":"2020-02-03T15:34:46.149Z","state":1}
{"time":"2020-02-03T15:34:47.149Z","state":1}
{"time":"2020-02-03T15:34:48.149Z","state":1}
{"time":"2020-02-03T15:34:49.149Z","state":0}
{"time":"2020-02-03T15:34:50.149Z","state":1}
{"time":"2020-02-03T15:34:51.149Z","state":0}
{"time":"2020-02-03T15:34:52.149Z","state":1}
{"time":"2020-02-03T15:34:53.149Z","state":0}
{"time":"2020-02-03T15:34:54.149Z","state":0}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time
threshold-count: 2

Output:

{"time":"2020-02-03T15:34:45.149Z","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:46.149Z","state":1,"elapsed":1000}
{"time":"2020-02-03T15:34:47.149Z","state":1,"elapsed":2000}
{"time":"2020-02-03T15:34:48.149Z","state":1,"elapsed":3000}
{"time":"2020-02-03T15:34:49.149Z","state":1,"elapsed":4000}
{"time":"2020-02-03T15:34:50.149Z","state":1,"elapsed":5000}
{"time":"2020-02-03T15:34:51.149Z","state":1,"elapsed":6000}
{"time":"2020-02-03T15:34:52.149Z","state":1,"elapsed":7000}
{"time":"2020-02-03T15:34:53.149Z","state":1,"elapsed":8000}
{"time":"2020-02-03T15:34:54.149Z","state":0,"elapsed":1000}

Example

Input:

{"time":"2020-02-03T15:34:45.149Z","state":0}
{"time":"2020-02-03T15:34:46.149Z","state":1}
{"time":"2020-02-03T15:34:47.149Z","state":1}
{"time":"2020-02-03T15:34:48.149Z","state":1}
{"time":"2020-02-03T15:34:49.149Z","state":0}
{"time":"2020-02-03T15:34:50.149Z","state":1}
{"time":"2020-02-03T15:34:51.149Z","state":0}
{"time":"2020-02-03T15:34:52.149Z","state":1}
{"time":"2020-02-03T15:34:53.149Z","state":0}
{"time":"2020-02-03T15:34:54.149Z","state":0}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time
threshold-count: 1

Output:

{"time":"2020-02-03T15:34:45.149Z","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:46.149Z","state":1,"elapsed":0}
{"time":"2020-02-03T15:34:47.149Z","state":1,"elapsed":1000}
{"time":"2020-02-03T15:34:48.149Z","state":1,"elapsed":2000}
{"time":"2020-02-03T15:34:49.149Z","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:50.149Z","state":1,"elapsed":0}
{"time":"2020-02-03T15:34:51.149Z","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:52.149Z","state":1,"elapsed":0}
{"time":"2020-02-03T15:34:53.149Z","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:54.149Z","state":0,"elapsed":1000}

threshold-count-output-field

Type: field

A field to record the action threshold count at the time of change

group-by

Type: field

Allows tracking transitions individually in the case of aggregated data

Example

Input:

{"time":"2020-02-03T15:34:45.149Z","name":"john","state":0}
{"time":"2020-02-03T15:34:46.149Z","name":"jane","state":0}
{"time":"2020-02-03T15:34:47.149Z","name":"john","state":1}
{"time":"2020-02-03T15:34:48.149Z","name":"jane","state":1}
{"time":"2020-02-03T15:34:49.149Z","name":"john","state":1}
{"time":"2020-02-03T15:34:50.149Z","name":"jane","state":1}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time
group-by: name

Output:

{"time":"2020-02-03T15:34:45.149Z","name":"john","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:46.149Z","name":"jane","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:47.149Z","name":"john","state":1,"elapsed":0}
{"time":"2020-02-03T15:34:48.149Z","name":"jane","state":1,"elapsed":0}
{"time":"2020-02-03T15:34:49.149Z","name":"john","state":1,"elapsed":2000}
{"time":"2020-02-03T15:34:50.149Z","name":"jane","state":1,"elapsed":2000}

Example: Without group-by usage

Input:

{"time":"2020-02-03T15:34:45.149Z","name":"john","state":0}
{"time":"2020-02-03T15:34:46.149Z","name":"jane","state":0}
{"time":"2020-02-03T15:34:47.149Z","name":"john","state":1}
{"time":"2020-02-03T15:34:48.149Z","name":"jane","state":1}
{"time":"2020-02-03T15:34:49.149Z","name":"john","state":1}
{"time":"2020-02-03T15:34:50.149Z","name":"jane","state":1}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time

Output:

{"time":"2020-02-03T15:34:45.149Z","name":"john","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:46.149Z","name":"jane","state":0,"elapsed":1000}
{"time":"2020-02-03T15:34:47.149Z","name":"john","state":1,"elapsed":0}
{"time":"2020-02-03T15:34:48.149Z","name":"jane","state":1,"elapsed":1000}
{"time":"2020-02-03T15:34:49.149Z","name":"john","state":1,"elapsed":2000}
{"time":"2020-02-03T15:34:50.149Z","name":"jane","state":1,"elapsed":3000}

save-file

Type: path

A file to persist state, to know where we left off in the case where the Pipe is restarted

Example

Input:

{"time":"2020-02-03T15:34:55.149Z","state":0}
{"time":"2020-02-03T15:34:56.149Z","state":1}
{"time":"2020-02-03T15:34:57.149Z","state":1}

Pipe Language Snippet:

transition:
watch: state
elapsed-output-field: elapsed
time-field: time
save-file: transition-state.yml

Output:

{"time":"2020-02-03T15:34:55.149Z","state":0,"elapsed":0}
{"time":"2020-02-03T15:34:56.149Z","state":1,"elapsed":0}
{"time":"2020-02-03T15:34:57.149Z","state":1,"elapsed":1000}

maximum-age

Type: string

The maximum age of any recorded history

maximum-age-marker

Type: string

The marker in the event stream to watch for to trigger a maximum age record sweep