LogoLogo
StackState.comDownloadSupportExplore playground
StackState v5.1
StackState v5.1
  • Welcome to the StackState docs!
  • StackState self-hosted v5.1 docs
  • Getting Started
  • 🚀Setup
    • Install StackState
      • Requirements
      • Kubernetes / OpenShift
        • Kubernetes install
        • OpenShift install
        • Required Permissions
        • Non-high availability setup
        • Override default configuration
        • Configure storage
        • Configure Ingress
        • Install from custom image registry
        • Migrate from Linux install
      • Linux
        • Before you install
        • Download
        • Install StackState
        • Install with production configuration
        • Install with development configuration
        • Install with POC configuration
        • Set up a reverse proxy
        • Set up TLS without reverse proxy
      • Initial run guide
      • Troubleshooting
    • Upgrade StackState
      • Steps to upgrade
      • Version specific upgrade instructions
      • StackPack versions
      • StackState release notes
    • StackState Agent
      • About StackState Agent V3
      • Docker
      • Kubernetes / OpenShift
      • Linux
      • Windows
      • Advanced Agent configuration
      • Use an HTTP/HTTPS proxy
      • Agent V1 (legacy)
      • Migrate Agent V1 to Agent V2
        • Linux
        • Docker
    • StackState CLI
      • CLI: sts
      • CLI: stac (deprecated)
      • Comparison between CLIs
    • Data management
      • Backup and Restore
        • Kubernetes backup
        • Linux backup
        • Configuration backup
      • Data retention
      • Clear stored data
  • 👤Use
    • Concepts
      • The 4T data model
      • Components
      • Relations
      • Health state
      • Layers, Domains and Environments
      • Perspectives
      • Anomaly detection
      • StackState architecture
    • StackState UI
      • Explore mode
      • Filters
      • Views
        • About views
        • Configure the view health
        • Create and edit views
        • Visualization settings
      • Perspectives
        • Topology Perspective
        • Events Perspective
        • Traces Perspective
        • Metrics Perspective
      • Timeline and time travel
      • Analytics
      • Keyboard shortcuts
    • Checks and monitors
      • Checks
      • Add a health check
      • Anomaly health checks
      • Monitors
      • Manage monitors
    • Problem analysis
      • About problems
      • Problem lifecycle
      • Investigate a problem
      • Problem notifications
    • Metrics
      • Telemetry streams
      • Golden signals
      • Top metrics
      • Add a telemetry stream
      • Browse telemetry
      • Set telemetry stream priority
    • Events
      • About events
      • Event notifications
      • Manage event handlers
    • Glossary
  • 🧩StackPacks
    • About StackPacks
    • Add-ons
      • Autonomous Anomaly Detector
      • Health Forecast
    • Integrations
      • About integrations
      • 💠StackState Agent V2
      • 💠AWS
        • AWS
        • AWS ECS
        • AWS X-ray
        • StackState/Agent IAM role: EC2
        • StackState/Agent IAM role: EKS
        • Policies for AWS
        • AWS (legacy)
        • Migrate AWS (legacy) to AWS
      • 💠Dynatrace
      • 💠Kubernetes
      • 💠OpenShift
      • 💠OpenTelemetry
        • About instrumentations
        • AWS NodeJS Instrumentation
        • Manual Instrumentation
          • Prerequisites
          • Tracer and span mappings
          • Relations between components
          • Span health state
          • Merging components
          • Code examples
      • 💠ServiceNow
      • 💠Slack
      • 💠Splunk
        • Splunk
        • Splunk Events
        • Splunk Health
        • Splunk Metrics
        • Splunk Topology
      • 💠VMWare vSphere
      • Apache Tomcat
      • Azure
      • Cloudera
      • Custom Synchronization
      • DotNet APM
      • Elasticsearch
      • Humio
      • Java APM
      • JMX
      • Logz.io
      • MySQL
      • Nagios
      • OpenMetrics
      • PostgreSQL
      • Prometheus
      • SAP
      • SCOM
      • SolarWinds
      • Static Health
      • Static Topology
      • Traefik
      • WMI
      • Zabbix
    • Develop your own StackPacks
  • 🔧Configure
    • Topology
      • Component actions
      • Identifiers
      • Topology naming guide
      • Topology sources
      • Create a topology manually
      • Configure topology synchronizations
      • Enable email event notifications
      • Send topology data over HTTP
      • Set the topology filtering limit
      • Use a proxy for event handlers
      • Use tags
      • Tune topology synchronization
      • Debug topology synchronization
    • Telemetry
      • Add telemetry during topology synchronization
      • Data sources
        • Elasticsearch
        • Prometheus mirror
      • Send events over HTTP
      • Send metrics data over HTTP
      • Set the default telemetry interval
      • Debug telemetry synchronization
    • Traces
      • Set up traces
      • Advanced configuration for traces
    • Health
      • Health synchronization
      • Send health data over HTTP
        • Send health data
        • Repeat Snapshots JSON
        • Repeat States JSON
        • Transactional Increments JSON
      • Debug health synchronization
    • Anomaly Detection
      • Export anomaly feedback
      • Scale the AAD up and down
      • The AAD status UI
    • Security
      • Authentication
        • Authentication options
        • File based
        • LDAP
        • Open ID Connect (OIDC)
        • KeyCloak
        • Service tokens
      • RBAC
        • Role-based Access Control
        • Permissions
        • Roles
        • Scopes
        • Subjects
      • Secrets management
      • Self-signed certificates
      • Set up a security backend for Linux
      • Set up a security backend for Windows
    • Logging
      • Kubernetes logs
      • Linux logs
      • Enable logging for functions
  • 📖Develop
    • Developer guides
      • Agent checks
        • About Agent checks
        • Agent check API
        • Agent check state
        • How to develop Agent checks
        • Connect an Agent check to StackState
      • Custom functions and scripts
        • StackState functions
        • Check functions
        • Component actions
        • Event handler functions
        • ID extractor functions
        • Mapping functions
        • Monitor functions
        • Propagation functions
        • Template functions
        • View health state configuration functions
      • Custom Synchronization StackPack
        • About the Custom Synchronization StackPack
        • How to customize elements created by the Custom Synchronization StackPack
        • How to configure a custom synchronization
      • Integrate external services
      • Mirroring Telemetry
      • Monitors
        • Create monitors
        • Monitor STJ file format
      • StackPack development
        • How to create a StackPack
        • Packaging
        • How to get a template file
        • How to make a multi-instance StackPack
        • Prepare a multi-instance provisioning script
        • Upload a StackPack file
        • Prepare a shared template
        • Customize a StackPack
        • Prepare instance template files
        • Prepare a StackPack provisioning script
        • Resources in a StackPack
        • StackState Common Layer
      • Synchronizations and templated files
    • Reference
      • StackState OpenAPI docs
      • StackState Template JSON (STJ)
        • Using STJ
        • Template functions
      • StackState Markup Language (STML)
        • Using STML
        • STML Tags
      • StackState Query Language (STQL)
      • StackState Scripting Language (STSL)
        • Scripting in StackState
        • Script result: Async
        • Script result: Streaming
        • Time in scripts
        • Script APIs
          • Async - script API
          • Component - script API
          • HTTP - script API
          • Prediction - script API
          • StackPack - script API
          • Telemetry - script API
          • Time - script API
          • Topology - script API
          • UI - script API
          • View - script API
    • Tutorials
      • Create a simple StackPack
      • Push data to StackState from an external system
      • Send events to StackState from an external system
      • Set up a mirror to pull telemetry data from an external system
Powered by GitBook
LogoLogo

Legal notices

  • Privacy
  • Cookies
  • Responsible disclosure
  • SOC 2/SOC 3
On this page
  • Overview
  • Create a custom event handler function
  • Parameters
  • Supported event types
  • Logging
  • Asynchronous execution (default)
  • Properties for asynchronous functions
  • Synchronous execution
  • Properties for synchronous functions
  • Plugins for synchronous functions
  • See also
  1. Develop
  2. Developer guides
  3. Custom functions and scripts

Event handler functions

StackState Self-hosted v5.1.x

PreviousComponent actionsNextID extractor functions

Last updated 2 years ago

Overview

Event handlers listen to events generated within a view. When the configured event type is generated, the event handler function is run to send an or trigger an action in a system outside of StackState. For example, an event handler function could send an email or make a POST to a webhook URL. A number of default event handler functions are included out of the box with StackState, or you can create your own custom event handler functions.

Create a custom event handler function

Advanced StackState users can write their own custom event handler functions that react to state change events or problem events. Event handler functions can use the StackState HTTP script API or a plugin to send an event notification to a system outside of StackState. To add a custom event handler function:

  1. In the StackState UI, go to Settings > Functions > Event Handler Functions.

  2. Click ADD EVENT HANDLER FUNCTION.

  3. Enter the required settings:

    • Name - A name to identify the event handler function.

    • Description - Optional. A description of the event handler function. This will be displayed on the page Settings > Functions > Event Handler Functions.

    • System parameters - predefined parameters that are passed automatically to the event handler function script. For details, see the section on below.

    • User parameters - parameters that must be entered by the user when an event handler is added to a view. Event handler functions also include the predefined user parameter event. For details, see the section on below.

    • Supported Event Types - The type of event(s) that the event handler can respond to. For details, see the section on below.

    • Execution - Event handler functions can be run as either Asynchronous (default) or Synchronous:

      • Asynchronous - use for Slack, SMS or HTTP webhook event handlers. The function script will have access to all functionality from the StackState script APIs and more functions will be allowed to run in parallel.

      • Synchronous - required for event handlers that generate email event notifications. The function will use a plugin to send notifications to external systems.

    • Script - The script run by the function. For details, see the sections below on:

      • .

      • .

      • How to .

    • Identifier - Optional. A unique identifier (URN) for the event handler function.

  4. Click CREATE to save the event handler function.

    • The new event handler function will be listed on the page Settings > Functions > Event Handler Functions.

    • The event handler will be available in the Run event handler drop-down when you that listens to one of the configured Supported Event Types.

Parameters

An event handler function includes predefined system and user parameters that are passed automatically to the event handler function script.

  • The view system parameter provides details of the view that the event handler has been added to.

  • The event user parameter provides the events that the event handler function will listen to.

You can also add your own user parameters, these can then be entered in the Add event handler dialogue when you add an event handler to a view.

Supported event types

One or more of the following events can be selected:

  • State change of entire view - For functions that will react to a ViewHealthStateChangedEvent. These events are generated when the health state of the entire view changes.

  • State change of an element - For functions that will react to a HealthStateChangedEvent. These events are generated when an element's own health state changes.

  • Propagated state change of an element - For functions that will react to a PropagatedHealthStateChangedEvent. These events are generated when the propagated health state of an element changes.

Logging

Only available for Linux installations of StackState.

Asynchronous execution (default)

When execution is set to Asynchronous, the event handler function will run as an asynchronous function.

The Slack event handler function shipped with StackState will run as an asynchronous function. This allows the event notifications sent to Slack to include extensive details about the event that triggered it, such as links to relevant data and a possible root cause. You could also use the HTTP script API to send an SMS or webhook post.

Properties for asynchronous functions

The properties described below can be retrieved from the default view and event parameters in an event handler function with asynchronous execution.

View properties return details of the view that the event handler is configured for. Note that parameter name view or scope can be used, or an alias.

  • view.name - returns the view name.

  • view.description - returns the view description.

  • view.query - returns an STQL query of the view.

  • view.identifier - returns the globally unique URN value that identifies the view.

Event properties return details of a received event and vary for the different event types:

  • Health state change events:

  • Problem events:

HealthStateChangedEvent properties (Asynchronous)

The properties listed below return details of a HealthStateChangedEvent in functions with asynchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the state change occurred.

  • event.causeId - returns the UUID of the event that triggered the health state change.

  • event.newState - returns the current state of the element.

  • event.oldState - returns the previous state of the element.

  • event.stackElement - returns the node ID of the element that has changed its state.

ViewHealthStateChangedEvent properties (Asynchronous)

The properties listed below return details of a ViewHealthStateChangedEvent in functions with asynchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the state change occurred.

  • event.causeId - returns the UUID of the event that triggered the health state change.

  • event.newState - returns the current state of the element.

  • event.oldState - returns the previous state of the element.

  • event.viewHealthState - returns the node ID of the health state object for the view that changed its state.

PropagatedHealthStateChangedEvent properties (Asynchronous)

The properties listed below return details of a PropagatedHealthStateChangedEvent in functions with asynchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the state change occurred.

  • event.causeId - returns the UUID of the event that triggered the health state change.

  • event.stateChanges -returns the chain of elements through which the health state change propagated.

ProblemCreatedEvent properties (Asynchronous)

The properties listed below return details of a ProblemCreatedEvent in functions with asynchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event._type - returns the event type (ProblemCreatedEvent).

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the event was generated.

  • event.identifier - returns the unique event identifier.

  • event.problemId - returns the (node) ID of the problem.

  • event.rootCause - returns the node ID of the root cause component.

  • event.nodes - returns the list of node IDs of all the components that were related to the problem when it was created.

ProblemUpdatedEvent properties (Asynchronous)

The properties listed below return details of a ProblemUpdatedEvent in functions with asynchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event._type - returns the event type (ProblemUpdatedEvent).

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the event was generated.

  • event.identifier - returns the unique event identifier.

  • event.problemId - returns the (node) ID of the problem.

  • event.rootCause - returns the node ID of the root cause component.

  • event.nodes - returns the list of node IDs of all the components that were related to the problem after it was updated.

ProblemSubsumedEvent properties (Asynchronous)

The properties listed below return details of a ProblemSubsumedEvent in functions with asynchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event._type - returns the event type (ProblemSubsumedEvent).

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the event was generated.

  • event.identifier - returns the unique event identifier.

  • event.problemId - returns the (node) ID of the problem.

  • event.rootCause - returns the node ID of the root cause component.

  • event.superProblemIds - returns the list of problem IDs that now contain the subsumed problem.

  • event.nodes - returns the list of node IDs of all the components that were related to the problem before it was subsumed.

ProblemResolvedEvent properties (Asynchronous)

The properties listed below return details of a ProblemResolvedEvent in functions with asynchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event._type - returns the event type (ProblemResolvedEvent).

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the event was generated.

  • event.identifier - returns the unique event identifier.

  • event.problemId - returns the (node) ID of the problem.

  • event.rootCause - returns the node ID of the root cause component.

  • event.nodes - returns the list of node IDs of all the components that were related to the problem before it was resolved.

Synchronous execution

When execution is set to Synchronous, the event handler function will run as a synchronous function.

Event handler functions developed prior to StackState v4.2 and email event handler functions run as synchronous functions. Compared to asynchronous functions, synchronous functions are limited in both the capability of what they can achieve and the number of functions that can run in parallel.

Properties for synchronous functions

The properties described below can be retrieved from the default synchronous event handler function parameters.

View properties return details of the view the event handler is in. Note that parameter name view or scope can be used, or an alias.

  • view.getName - returns the name of the view.

  • view.getDescription - returns the view description.

  • view.getQuery - returns an STQL query of the view.

  • view.getIdentifier - returns the globally unique URN value that identifies the view.

Event properties return details of a received event and vary for the different event types:

  • Health state change events:

  • Problem events:

HealthStateChangedEvent properties (Synchronous)

The properties listed below return details of a HealthStateChangedEvent in functions with synchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event.getTriggeredTimestamp - returns the time (epoch in ms) at which the state change occurred.

  • event.getCauseId - returns the UUID of the event that triggered the health state change.

  • event.getNewStateRef - returns the current state of the element.

  • event.getOldStateRef - returns the previous state of the element.

ViewHealthStateChangedEvent properties (Synchronous)

The properties listed below return details of a ViewHealthStateChangedEvent in functions with synchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event.getTriggeredTimestamp - returns the time (epoch in ms) at which the state change occurred.

  • event.getCauseId - returns the UUID of the event that triggered the health state change.

  • event.getNewStateRef - returns the current state of the element.

  • event.getOldStateRef - returns the previous state of the element.

PropagatedHealthStateChangedEvent properties (Synchronous)

The properties listed below return details of a PropagatedHealthStateChangedEvent in functions with synchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event.getTriggeredTimestamp - returns the time (epoch in ms) at which the state change occurred.

  • event.getCauseId - returns the UUID of the event that triggered the health state change.

  • event.getStateChanges -returns the chain of elements through which the health state change propagated.

ProblemCreated properties (Synchronous)

The properties listed below return details of a ProblemCreated event in functions with synchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event._type - returns the event type (ProblemCreated).

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the event was generated.

  • event.identifier - returns the unique event identifier.

  • event.problemId - returns the (node) ID of the problem.

  • event.rootCauseNodeId - returns the node ID of the root cause component.

  • event.nodes - returns the list of node IDs of all the components that were related to the problem when it was created.

ProblemUpdated properties (Synchronous)

The properties listed below return details of a ProblemUpdated event in functions with synchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event._type - returns the event type (ProblemUpdated).

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the event was generated.

  • event.identifier - returns the unique event identifier.

  • event.problemId - returns the (node) ID of the problem.

  • event.rootCauseNodeId - returns the node ID of the root cause component.

  • event.nodes - returns the list of node IDs of all the components that were related to the problem after it was updated.

ProblemSubsumed properties (Synchronous)

The properties listed below return details of a ProblemSubsumed event in functions with synchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event._type - returns the event type (ProblemSubsumed).

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the event was generated.

  • event.identifier - returns the unique event identifier.

  • event.problemId - returns the (node) ID of the problem.

  • event.rootCauseNodeId - returns the node ID of the root cause component.

  • event.superProblemIds - returns the list of problem IDs that now contain the subsumed problem.

  • event.nodes - returns the list of node IDs of all the components that were related to the problem before it was subsumed.

ProblemResolved properties (Synchronous)

The properties listed below return details of a ProblemResolved event in functions with synchronous execution. Note that the default parameter name isevent, this can be modified if you choose.

  • event._type - returns the event type (ProblemResolved).

  • event.triggeredTimestamp - returns the time (epoch in ms) at which the event was generated.

  • event.identifier - returns the unique event identifier.

  • event.problemId - returns the (node) ID of the problem.

  • event.rootCauseNodeId - returns the node ID of the root cause component.

  • event.nodes - returns the list of node IDs of all the components that were related to the problem before it was resolved.

Plugins for synchronous functions

Synchronous event handler functions use plugins to send notifications to external systems. The following plugins are available for use in custom event handler functions:

Plugin
Description

email

HTTP webhook

Sends an HTTP POST request with the specified content to a URL. webhookPlugin.sendMessage(url, "json")

SMS

Sends an SMS using MessageBird with the specified token. smsPlugin.sendSMSMessage(token, "to", "message")

See also

For details of the properties that can be retrieved from the default view and event parameters, see and below.

One or more supported event types can be added for each event handler function. The supported event types determine which event handler functions can be selected for each trigger event type when you to a view. For example, an event handler function with no supported event types won't be included in the Run event handler list of the Add event handler dialogue for any trigger event type.

Problem changed events - For functions that will react to ProblemCreated, ProblemUpdated, ProblemSubsumed or ProblemResolved. These events are generated for changes to in the view.

You can add logging statements to an event handler function for debug purposes, for example, with log.info("message"). Logs will appear in stackstate.log. Read how to .

An asynchronous event handler function has access to the . This allows the function to make an HTTP request with a custom header using the and gives access to the whole topology/telemetry.

Synchronous functions will be deprecated in a future release of StackState. It's advised to choose the type when writing a new event handler function.

Synchronous event handler functions use plugins to interact with external systems, see below for further details.

Sends an email using the . emailPlugin.sendEmail(to, subject, "body")

📖
problems
enable logging for functions
StackState script APIs
HTTP script API
Enable logging for functions
Configure an SMTP server to send email event notifications
StackState script APIs
How to create a Slack webhook (slack.com)
properties for asynchronous functions
properties for synchronous functions
HealthStateChangedEvent
ViewHealthStateChangedEvent
PropagatedHealthStateChangedEvent
ProblemCreatedEvent
ProblemUpdatedEvent
ProblemSubsumedEvent
ProblemResolvedEvent
default asynchronous execution
plugins
HealthStateChangedEvent
ViewHealthStateChangedEvent
PropagatedHealthStateChangedEvent
ProblemCreated
ProblemUpdated
ProblemSubsumed
ProblemResolved
configured SMTP server
event notification
parameters
parameters
supported event types
Functions with Asynchronous execution
Functions with Synchronous execution
add logging to a function
add an event handler
add an event handler
Send event notifications using an event handler function
Add a custom event handler function