cloudsoft.io

Implementing Sensors and Effectors

Containers are an excellent way to define sophisticated behavior that Cloudsoft AMP should do to retrieve sensors or to offer actions through effectors. This is done through brooklyn.initializers which are documented in the reference guide:

A sample sensor definition which runs the common jq container (to extract JSON path values) whenever the sensor list-of-maps-containing-value is published, and extracts the key called value from the first map in the list, then publishes it as json-value-of-first-element, is as follows:

brooklyn.initializers:
- type: container-sensor
  brooklyn.config:
    name: json-value-of-first-element
    targetType: integer
    image: stedolan/jq
    triggers:
      - list-of-maps-containing-value
    shell.env:
      INPUT: $brooklyn:attributeWhenReady("list-of-maps-containing-value")
    bashScript: echo $INPUT | jq '.[0].value'

A sample effector called get-json-value-of-first-element which runs the same command whenever an operator invokes it is as follows:

brooklyn.initializers:
- type: container-effector
  brooklyn.config:
    name: get-json-value-of-first-element
    image: stedolan/jq
    shell.env:
      INPUT: $brooklyn:attributeWhenReady("list-of-maps-containing-value")
    bashScript: echo $INPUT | jq '.[0].value'

These techniques can be used for a vast range of functionality, from running aws commands (passing AWS_... environment variables based on the location) to integrating with monitoring and ITSM tools. You can also of course write sensors and effectors in any language you choose, save it as a container, and use it from Cloudsoft AMP.