transition

Performs various actions based on a changed field

Field NameDescriptionTypeDefault
watchA field that is watched for changesfield-
elapsed-output-fieldA field that will be used to store elapsed time between state changesfield-
time-fieldA field containing a time valuedefault_iso-
markerGenerate a new event, depending on if a transition has happenedarray of strings-
value-at-last-change-output-fieldContains state value of before transition happenedfield-
time-at-last-change-output-fieldContains timestamp of before transition happenedfield-
threshold-countNumber of times a value must have been seen in a row, in order to consider a state change a transitioninteger1
group-byAllows tracking transitions individually in the case of aggregated datafield-
save-fileA file to persist state, so as to know where we left off in the case where the Pipe is restartedstring-

watch

A field that is watched for changes

the field value may be a string, number or boolean

Type: field

Example

input:

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

action:

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

output:

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

elapsed-output-field

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

Type: field

time-field

A field containing a time value

If not specified, system time is used instead.

Type: default_iso

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}

action:

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

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

Type: array of strings

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}

action:

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

Contains state value of before transition happened

This is useful for associating states with their duration

Type: field

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}

action:

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

Contains timestamp of before transition happened

Type: field

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}

action:

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}

action:

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}

threshold-count

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

Type: integer

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}

action:

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}

action:

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}

group-by

Allows tracking transitions individually in the case of aggregated data

Type: field

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}

action:

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}

action:

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

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

Type: string

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}

action:

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}