State change mappings insert a field in the message that indicates whether the state of that message has changed since the last time it got the message. To define a state change mapping the type attribute needs to be set to "statechange". The attributes that need to be set in a state change mapping are:

Attribute

Required

Description

from

Y

Defines the field id (needs to be unique).

to

Y

Defines the field name after mapping.

precedence

N

Defines the precedence used when mapping.

Function typeYDefines the function type of the mapping. Needs to be "Enrichment/lookup table functions"

Function

Y

Defines the type of mapping. Needs to be "state changes".

statefield

Y

Defines the state field.

initialValue

Y

Defines the starting value when the first message for a particular is is received. An * means "any value", or never interpret the first message as a state change.

In the following example, the field status_raw is tracked. If the value of the field changes from one metric to another (for the same ci), a field with "statehaschanged": "true" is added and "statehaschanged": "false" otherwise.

Image 1. State change mapping.

In this message the state didn't change because the previous metric of the same device had the same value as the current one.

Image 2. Message mapped with the state change mapping.

Optionally, the state information can be persisted to disk by writing in the initial value field "persist" or "<value>;persist".