location: localhost
services:
  - type: org.apache.brooklyn.entity.stock.BasicApplication
    name: ServiceNow Incident Reporter Example
    brooklyn.policies:
      - type: cmdb-exporter-policy
        brooklyn.config:
          period: 10s
          command: cat - > $PUBLISH_FILE && amp-cmdb snow --profile amp-snow  --publish --input $PUBLISH_FILE
          env:
            PUBLISH_FILE: /tmp/snow.publish.json
      - type: itsm-incidents-policy
        brooklyn.config:
          sensor: incident
          sensor.producer: $brooklyn:entity("e1")
          # 'sensor.valueFilter' defaults to Strings::isNonEmpty - opens an incident if sensor value is not empty
          details.sensor: incident.details
          details.sensor.producer: $brooklyn:entity("e1")
          command: cat - > $INCIDENT_FILE && amp-cmdb snow --profile amp-snow  --publish_incident --input $INCIDENT_FILE
          env:
            INCIDENT_FILE: /tmp/snow.incident.e1.json
      - type: itsm-incidents-policy
        brooklyn.config:
          sensor: incident
          sensor.producer: $brooklyn:entity("e2")
          sensor.valueFilter: # Math predicate to open an incident if sensor value is '1234'
            $brooklyn:object:
              type: com.google.common.base.Predicates
              factoryMethod.name: equalTo
              factoryMethod.args:
                - '1234'
          details.sensor: incident.details
          details.sensor.producer: $brooklyn:entity("e1") # deliberately takes details from the entity 1
          command: cat - > $INCIDENT_FILE && amp-cmdb snow --profile amp-snow  --publish_incident --input $INCIDENT_FILE
          env:
            INCIDENT_FILE: /tmp/snow.incident.e2.json
    brooklyn.children:
      - type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
        id: e1
        name: Entity 1 (Incident Producer)
        launch.command: |
          # sleep for 3 days
          nohup sleep 259200 &
          echo $! > $PID_FILE
        brooklyn.initializers:
          - type: org.apache.brooklyn.core.effector.ssh.SshCommandEffector
            brooklyn.config:
              name: incident # use this effector to change the value of the incident sensor
              command: echo $condition > /tmp/problem1.txt && echo $details > /tmp/problem1.details.txt
              parameters:
                condition:
                  description: Incident condition
                details:
                  description: Incident details
                  defaultValue: 'Incident details at Entity 1!'
          - type: org.apache.brooklyn.core.sensor.ssh.SshCommandSensor
            brooklyn.config:
              name: incident
              command: cat /tmp/problem1.txt
              period: 5s
          - type: org.apache.brooklyn.core.sensor.ssh.SshCommandSensor
            brooklyn.config:
              name: incident.details
              command: cat /tmp/problem1.details.txt
              period: 5s
      - type: org.apache.brooklyn.entity.software.base.VanillaSoftwareProcess
        id: e2
        name: Entity 2 (Incident Producer)
        launch.command: |
          # sleep for 3 days
          nohup sleep 259200 &
          echo $! > $PID_FILE
        brooklyn.initializers:
          - type: org.apache.brooklyn.core.effector.ssh.SshCommandEffector
            brooklyn.config:
              name: incident # use this effector to change the value of the incident sensor
              command: echo $condition > /tmp/problem2.txt && echo $details > /tmp/problem2.details.txt
              parameters:
                condition:
                  description: Incident condition
          - type: org.apache.brooklyn.core.sensor.ssh.SshCommandSensor
            brooklyn.config:
              name: incident
              command: cat /tmp/problem2.txt
              period: 5s
