Transform your observation data

or click any element in the pipeline to jump to it.

In the transform stage, Sensu executes mutators.

The transform stage of the Sensu observability pipeline executes any mutators you have specified in your pipeline configuration to transform your observability data so other technologies can consume it. For example, if you’re sending metrics to Graphite using a TCP handler, Graphite expects data that follows the Graphite plaintext protocol. You can use Sensu’s built-in only_check_output mutator to transform the data into the format Graphite can accept.

Here’s how transform stage of the pipeline works: first, the Sensu backend receives an event and executes the filter stage of the observability pipeline. If the event data meets the conditions, triggers, or thresholds you specified in your event filters, Sensu checks the pipeline for a mutator. If the pipeline includes a mutator, the Sensu backend executes the mutator.

There are two types of mutators: pipe and JavaScript.

Pipe mutators

Pipe mutator definitions include executable commands that will be executed on a Sensu backend. Pipe mutators produce an exit status code to indicate state.

  • If the mutator executes successfully (that is, returns an exit status code of 0), Sensu applies the mutator to transform the event data, returns the transformed event data to the handler specified in the pipeline, and executes the handler.
  • If the mutator fails to execute (that is, returns a non-zero exit status code or fails to complete within its configured timeout), Sensu logs an error and does not execute the handler specified in the pipeline.

This example pipe mutator resource definition uses the Sensu Check Status Metric Mutator dynamic runtime asset:

---
type: Mutator
api_version: core/v2
metadata:
  name: sensu-check-status-metric-mutator
spec:
  command: sensu-check-status-metric-mutator
  runtime_assets:
  - nixwiz/sensu-check-status-metric-mutator
{
  "type": "Mutator",
  "api_version": "core/v2",
  "metadata": {
    "name": "sensu-check-status-metric-mutator"
  },
  "spec": {
    "command": "sensu-check-status-metric-mutator",
    "runtime_assets": [
      "nixwiz/sensu-check-status-metric-mutator"
    ]
  }
}

Most pipe mutator commands are provided by Sensu plugins, which you can deploy with dynamic runtime assets. Use Bonsai, the Sensu asset hub, to discover, download, and share dynamic runtime assets for Sensu pipe mutators. Read Use assets to install plugins to get started.

JavaScript mutators

JavaScript mutators allow you to write your own evaluation expressions and do not require an executable command attribute. Each Sensu JavaScript mutator definition includes the eval attribute, whose value must be an ECMAScript 5 expression.

This example uses a JavaScript mutator to remove event attributes (in this case, the check name and entity app_id label):

---
type: Mutator
api_version: core/v2
metadata:
  name: remove_checkname_entitylabel
spec:
  eval: >-
    data = JSON.parse(JSON.stringify(event)); delete data.check.metadata.name;
    delete data.entity.metadata.labels.app_id; return JSON.stringify(data)    
  type: javascript
{
  "type": "Mutator",
  "api_version": "core/v2",
  "metadata": {
    "name": "remove_checkname_entitylabel"
  },
  "spec": {
    "eval": "data = JSON.parse(JSON.stringify(event)); delete data.check.metadata.name; delete data.entity.metadata.labels.app_id; return JSON.stringify(data)",
    "type": "javascript"
  }
}