View health state configuration functions
StackState Self-hosted v4.5.x

Overview

A view health state configuration function is a user defined script that takes user parameters and has access to a viewSummary variable that can be used to get summary information on the (states of) the components and relations in the view.

Create a custom view health state configuration function

To create, update or delete a view state configuration, go to Settings -> Functions -> View Health State Configuration Functions.
A view health state configuration function receives a viewSummary as well as any User parameters named in the function. It needs to return value from the viewHealthStates enum - one of UNKNOWN, CLEAR, DEVIATING or CRITICAL.

Available properties and methods

The viewSummary is available to all view health state configuration functions and gives access to the following methods:
Method
Returns
countHealthState
A count of all components with a specified state. See countHealthState and countPropagatedHealthState.
countPropagatedHealthState
A count of all elements with a specified propagated state. See countHealthState and countPropagatedHealthState.
viewSummary
A list of the states of all elements in the view. See ElementState.

countHealthState and countPropagatedHealthState

The methods countHealthState and countPropagatedHealthState return a count of all components in the view with a specified state. For example:
1
viewSummary.countPropagatedHealthState(propagatedHealthStates.DEVIATING)
Copied!
Note that countPropagatedHealthState will return a count of all elements with a specified propagated state. As both the originating component and all relations have a propagated health state these will be included in the returned count. This means that a DEVIATING propagated health state count of a view with one deviating component will be three. Two for the components (originating and propagated) and one for the relation.
In the script example below, minCriticalHealthStates and minDeviatingHealthStates are user parameters. These are named in the view health state configuration function and set by the user when the view health state is configured.
1
if (viewSummary.countHealthState(healthStates.CRITICAL) >= minCriticalHealthStates) {
2
return viewHealthStates.CRITICAL;
3
} else if (viewSummary.countHealthState(healthStates.DEVIATING) >= minDeviatingHealthStates) {
4
return viewHealthStates.DEVIATING;
5
} else {
6
return viewHealthStates.CLEAR;
7
}
Copied!

ElementState

The states of all components and relations in the view can be accessed as a list from viewSummary using ElementState. ElementState has the following properties:
  • elementId
  • stateId
  • name
  • layer
  • domain
  • A list of environments
  • A list of labels
  • Element type
  • healthState
  • propagatedHealthState
This can be used to query particular elements in the view. In the example below, a CRITICAL state will be returned if any component of type DB reports a DEVIATING state. In all other cases a CLEAR state will be returned:
1
if (viewSummary.getStates().any{elementState -> (elementState.type == "DB") && (elementState.healthState >= healthStates.DEVIATING ) } ) {
2
return viewHealthStates.CRITICAL;
3
} else {
4
return viewHealthStates.CLEAR;
5
}
Copied!

See also

Last modified 20d ago