Skip to content

Create a calc rule

POST
/calc-rules
curl --request POST \
--url https://example.com/api/v1/calc-rules \
--header 'Content-Type: application/json' \
--data '{ "description": "example", "enabled": true, "inputs": [ { "alias": "example", "key": "example" } ], "label": "example", "name": "example", "output_key": "example", "owner_kind": "component", "reduce": { "expr": "example" }, "selector": { "component_types": [ "example" ], "components": [ "example" ], "system_types": [ "example" ], "systems": [ "example" ] } }'

Authors a rule that derives its output key on each owner (each component its selector picks, or each system) from its aliased inputs, reduced by an expression over the aliases, each bound as the list of its current values (one per instance on a component, every member’s on a system, with members records beside it). Every input key must be registered (by name or uuid; the rule holds it by uuid) and health may not be one; each alias is an identifier of at most 64, not a keyword, a builtin or list function’s name, or a site binding (component, has, members, system, value), and unique; the reduce must compile and yield the output key’s type (a 422 placed at body.reduce.expr with its line and column, and the name when it is one no alias binds); the output must be a registered key that is not health and that no collection writes (a native probe’s key, or one a driver declares among its emits); an enabled rule may not close a cycle in the graph from every enabled rule’s input keys to its output key (a 422 naming the chain of keys), nor write a key another enabled rule writes (a 422 naming that rule). A list or get carries calc_error when a stored reduce no longer compiles. A name already taken is a 409. Returns the rule with its uuid. Audited. Gated by rule:create, with an all-scope grant.

Media type application/json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
description

What the rule derives and why

string
enabled

Defaults to true

boolean
inputs
required

The keys the rule reads, each by a unique alias its reduce uses; health may not be one

Array<object> | null
>= 1 items <= 16 items
object
alias
required

The name the reduce’s expression binds the input by: an identifier of at most 64, not a keyword, a builtin or list function’s name, or one of the calc site’s own bindings (component, has, members, system, value); unique in the rule

string
>= 1 characters <= 64 characters /^[A-Za-z_][A-Za-z0-9_]*$/
key
required

The property or metric the input reads, by name or uuid; the rule holds it by uuid, so a rename changes nothing

string
>= 1 characters
label

A human label

string
name
required

The rule’s name (lowercase letters, digits, hyphens)

string
>= 1 characters <= 100 characters /^[a-z0-9][a-z0-9-]*$/
output_key
required

The property or metric the rule writes: its type pins the reduce’s result. Not a reserved key (a native probe key, health), not a key a driver’s emits or a command type write, and not one another enabled rule writes

string
>= 1 characters
owner_kind
required

What the rule derives a value on: each component its selector picks, or each system its selector picks (read from the system’s role-bound members). Fixed at create

string
Allowed values: component system
reduce
required

An expression over the inputs by alias

object
expr
required

An expression over the inputs by alias, each bound as the list of its current values (one per instance on a component, every member’s on a system), yielding the output key’s type: max(tcp), avg(temp), any(call) || max(people) > 0

string
>= 1 characters
selector

The owners the rule derives for: a component rule’s component_types and components, or a system rule’s system_types and systems; absent is every owner of its kind

object
component_types

A component rule: derive on components whose type falls within one of these component types

Array<string> | null
components

A component rule: derive on these components (by name or id on write; ids on read)

Array<string> | null
system_types

A system rule: derive on systems whose type falls within one of these system types (subtypes included)

Array<string> | null
systems

A system rule: derive on these systems (by name or id on write; ids on read)

Array<string> | null

Created

Media type application/json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
calc_error

Why the stored reduce does not compile against the registries as they are now (an input key deleted or retyped, or an expression a newer diagnostic refuses); absent when it compiles. While present the rule cannot be enabled

object
code

The registered diagnostic that gave it, when one did (documented on the expressions page)

string
column

The 1-based column of the fault, when it has a line

integer format: int64
field
required

The field at fault: an input’s key (inputs[0].key), reduce.expr or output_key

string
line

The 1-based line of the fault, when the reduce’s expression is what failed

integer format: int64
message
required

Why it does not compile, or what it warns of

string
calc_warnings

The warnings the stored reduce compiles with (a likely mistake, such as an input it never names), each with its code; notes only, never a fault: the rule computes all the same

Array<object> | null
object
code

The registered diagnostic that gave it, when one did (documented on the expressions page)

string
column

The 1-based column of the fault, when it has a line

integer format: int64
field
required

The field at fault: an input’s key (inputs[0].key), reduce.expr or output_key

string
line

The 1-based line of the fault, when the reduce’s expression is what failed

integer format: int64
message
required

Why it does not compile, or what it warns of

string
created_at
required

When the rule was created

string format: date-time
description

What the rule derives and why

string
enabled
required

Whether the rule runs; an enabled rule is part of the key graph

boolean
id
required

The rule’s uuid, the stable form of name

string
inputs
required

The keys the rule reads, each by the alias its reduce uses

Array<object> | null
object
alias
required

The name the reduce’s expression binds the input by

string
key
required

The key’s name now

string
key_id
required

The key’s uuid, which the rule holds it by

string
lane
required

Which registry the key is in

string
Allowed values: property metric
label

A human label

string
name
required

The rule’s name, the address an operator types; renameable

string
official
required

Shipped with the platform and read-only

boolean
output_key
required

The property or metric the rule writes

string
output_lane
required

Which lane the output key is on, derived from the registries

string
Allowed values: property metric
owner_kind
required

What the rule derives a value on: each component its selector picks, or each system its selector picks (read from the system’s role-bound members)

string
Allowed values: component system
owners_computed
required

How many owners the caller may read hold a value the rule computed (on the list; 0 on a single read)

integer format: int64
owners_failed
required

How many owners the caller may read the rule last failed on (on the list)

integer format: int64
owners_pending
required

How many owners the caller may read are marked for the next tick (on the list)

integer format: int64
owners_unsupported
required

How many owners the caller may read the rule last wrote nothing for: an input missing, a system with no members (on the list)

integer format: int64
reduce
required

How the inputs reduce into the output: an expression over their aliases

object
expr
required

An expression over the inputs by alias, each bound as the list of its current values (one per instance on a component, every member’s on a system), yielding the output key’s type: max(tcp), avg(temp), any(call) || max(people) > 0

string
>= 1 characters
selector
required

The owners the rule derives for: a component rule’s components or a system rule’s systems; empty is every owner of its kind

object
component_types

A component rule: derive on components whose type falls within one of these component types

Array<string> | null
components

A component rule: derive on these components (by name or id on write; ids on read)

Array<string> | null
system_types

A system rule: derive on systems whose type falls within one of these system types (subtypes included)

Array<string> | null
systems

A system rule: derive on these systems (by name or id on write; ids on read)

Array<string> | null
updated_at
required

When the rule was last written

string format: date-time
version
required

Bumps on every update

integer format: int64
Example
{
"$schema": "/api/v1/schemas/CalcRuleBody.json",
"inputs": [
{
"lane": "property"
}
],
"output_lane": "property",
"owner_kind": "component"
}

Error

Media type application/problem+json
object
$schema

A URL to the JSON Schema for this object.

string format: uri
detail

A human-readable explanation specific to this occurrence of the problem.

string
errors

Optional list of individual error details

Array<object> | null
object
location

Where the error occurred, e.g. ‘body.items[3].tags’ or ‘path.thing-id’

string
message

Error message text

string
value

The value at the given location

instance

A URI reference that identifies the specific occurrence of the problem.

string format: uri
status

HTTP status code

integer format: int64
title

A short, human-readable summary of the problem type. This value should not change between occurrences of the error.

string
type

A URI reference to human-readable documentation for the error.

string format: uri
default: about:blank
Example
{
"$schema": "/api/v1/schemas/ErrorModel.json",
"detail": "Property foo is required but is missing.",
"instance": "https://example.com/error-log/abc123",
"status": 400,
"title": "Bad Request",
"type": "about:blank"
}