Business service monitoring SDK

COMMERCIAL FEATURE: Access business service monitoring (BSM) in the packaged Sensu Go distribution. For more information, read Get started with commercial features.

NOTE: Business service monitoring (BSM) is in public preview and is subject to change.

Sensu’s business service monitoring (BSM) feature uses a dedicated SDK of JavaScript-based expressions that provide additional functionality. Use the BSM SDK to create custom JavaScript expressions with complex logic.

BSM SDK expressions are defined in rule templates, so they act in the context of determining whether aggregate data derived from a service component’s selection of Sensu Go events should trigger a rule-based event. They always receive a single event and some information about that event, like event.timestamp or event.check.interval, and always return either true or false.

BSM SDK expressions are evaluated by the Otto JavaScript VM as JavaScript programs.

NOTE: Sensu query expressions also provide JavaScript functions for using nested parameters and custom functions to retrieve events from the event store.

Syntax quick reference

operator description
=== Identity
!== Nonidentity
== Equality
!= Inequality
&& Logical AND
|| Logical OR
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to

Specification

BSM SDK expressions are valid ECMAScript 5 (JavaScript) expressions that return either true or false. Other values are not allowed. If an expression returns a value besides true or false, the Sensu backend log will record an error and the filter will evaluate to false.

The BSM SDK allows you to to express rules for the number or percentage of events with critical, warning, OK, and unknown statuses. You can also configure expressions to ignore silenced events.

Custom functions

The Sensu BSM SDK includes two custom functions: sensu.Count() and sensu.Percentage().

sensu.Count()

The custom function sensu.Count() returns the number of events with the specified status. For example, to return the number of events with ok status:

sensu.Count("ok")

sensu.Percentage()

The custom function sensu.Percentage() returns the percentage of events with the specified status. For example, to return the percentage of events with critical status:

sensu.Percentage("critical")

Example BSM SDK expression

The following BSM SDK expression creates a critical event if at least 35% of events generated by the service component have critical status or creates a warning event if the service component generates one or more events with warning status:

if (sensu.Percentage("critical") >= 35) {
  event.check = {status: 2, output: "critical event"}
} else if (sensu.Count("warning") >= 1) {
  event.check = {status: 1, output: "warning event"}
}