<commit_before>heat_template_version: queens

description: >
  Containerized Sensu client service

parameters:
  DockerSensuClientImage:
    description: image
    type: string
  DockerSensuConfigImage:
    description: The container image to use for the sensu config_volume
    type: string
  EndpointMap:
    default: {}
    description: Mapping of service endpoint -> protocol. Typically set
                 via parameter_defaults in the resource registry.
    type: json
  ServiceData:
    default: {}
    description: Dictionary packing service data
    type: json
  ServiceNetMap:
    default: {}
    description: Mapping of service_name -> network name. Typically set
                 via parameter_defaults in the resource registry.  This
                 mapping overrides those in ServiceNetMapDefaults.
    type: json
  DefaultPasswords:
    default: {}
    type: json
  RoleName:
    default: ''
    description: Role name on which the service is applied
    type: string
  RoleParameters:
    default: {}
    description: Parameters specific to the role
    type: json
  SensuDockerCheckCommand:
    type: string
    default: |
      output=''
      for i in $(docker ps --format '{{.ID}}'); do
        if result=$(docker inspect --format='{{.State.Health.Status}}' $i 2>/dev/null); then
          if [ "$result" != 'healthy' ]; then
            output="${output} ; $(docker inspect --format='{{.Name}}' $i) ($i): $(docker inspect --format='{{(index .State.Health.Log 0).Output}}' $i)";
          fi
        fi
      done
      if [ ! -z "${output}" ]; then
        echo ${output:3} && exit 2;
      fi
  SensuDockerCheckInterval:
    type: number
    description: The frequency in seconds the docker health check is executed.
    default: 10
  SensuDockerCheckHandlers:
    default: []
    description: The Sensu event handler to use for events
                 created by the docker health check.
    type: comma_delimited_list
  SensuDockerCheckOccurrences:
    type: number
    description: The number of event occurrences before sensu-plugin-aware handler should take action.
    default: 3
  SensuDockerCheckRefresh:
    type: number
    description: The number of seconds sensu-plugin-aware handlers should wait before taking second action.
    default: 90

resources:

  ContainersCommon:
    type: ./containers-common.yaml

  SensuClientBase:
    type: ../../puppet/services/monitoring/sensu-client.yaml
    properties:
      EndpointMap: {get_param: EndpointMap}
      ServiceData: {get_param: ServiceData}
      ServiceNetMap: {get_param: ServiceNetMap}
      DefaultPasswords: {get_param: DefaultPasswords}

outputs:
  role_data:
    description: Role data for the Sensu client role.
    value:
      service_name: {get_attr: [SensuClientBase, role_data, service_name]}
      config_settings:
        map_merge:
          - get_attr: [SensuClientBase, role_data, config_settings]
          - sensu::checks:
              check-docker-health:
                standalone: true
                command: {get_param: SensuDockerCheckCommand}
                interval: {get_param: SensuDockerCheckInterval}
                handlers: {get_param: SensuDockerCheckHandlers}
                occurrences: {get_param: SensuDockerCheckOccurrences}
                refresh: {get_param: SensuDockerCheckRefresh}
      service_config_settings: {get_attr: [SensuClientBase, role_data, service_config_settings]}
      # BEGIN DOCKER SETTINGS
      puppet_config:
        config_volume: sensu
        puppet_tags:  sensu_rabbitmq_config,sensu_client_config,sensu_check_config,sensu_check
        step_config:
          get_attr: [SensuClientBase, role_data, step_config]
        config_image: {get_param: DockerSensuConfigImage}
      kolla_config:
        /var/lib/kolla/config_files/sensu-client.json:
          command: /usr/bin/sensu-client -d /etc/sensu/conf.d/ -l /var/log/sensu/sensu-client.log
          config_files:
            - source: "/var/lib/kolla/config_files/src/*"
              dest: "/"
              merge: true
              preserve_properties: true
          permissions:
            - path: /var/log/sensu
              owner: sensu:sensu
              recurse: true
      docker_config:
        step_3:
          sensu_client:
            image: {get_param: DockerSensuClientImage}
            net: host
            privileged: true
            # NOTE(mmagr) kolla image changes the user to 'sensu', we need it
            # to be root have rw permission to docker.sock to run successfully
            # "docker inspect" command
            user: root
            restart: always
            healthcheck:
              test: /openstack/healthcheck
            volumes:
              list_concat:
                - {get_attr: [ContainersCommon, volumes]}
                -
                  - /var/run/docker.sock:/var/run/docker.sock:rw
                  - /var/lib/kolla/config_files/sensu-client.json:/var/lib/kolla/config_files/config.json:ro
                  - /var/lib/config-data/puppet-generated/sensu/:/var/lib/kolla/config_files/src:ro
                  - /var/log/containers/sensu:/var/log/sensu:rw
            environment:
              - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS<commit_msg>Use sensu-client healthcheck parameter<commit_after>heat_template_version: queens

description: >
  Containerized Sensu client service

parameters:
  DockerSensuClientImage:
    description: image
    type: string
  DockerSensuConfigImage:
    description: The container image to use for the sensu config_volume
    type: string
  EndpointMap:
    default: {}
    description: Mapping of service endpoint -> protocol. Typically set
                 via parameter_defaults in the resource registry.
    type: json
  ServiceData:
    default: {}
    description: Dictionary packing service data
    type: json
  ServiceNetMap:
    default: {}
    description: Mapping of service_name -> network name. Typically set
                 via parameter_defaults in the resource registry.  This
                 mapping overrides those in ServiceNetMapDefaults.
    type: json
  DefaultPasswords:
    default: {}
    type: json
  RoleName:
    default: ''
    description: Role name on which the service is applied
    type: string
  RoleParameters:
    default: {}
    description: Parameters specific to the role
    type: json
  SensuDockerCheckCommand:
    type: string
    default: |
      output=''
      for i in $(docker ps --format '{{.ID}}'); do
        if result=$(docker inspect --format='{{.State.Health.Status}}' $i 2>/dev/null); then
          if [ "$result" != 'healthy' ]; then
            output="${output} ; $(docker inspect --format='{{.Name}}' $i) ($i): $(docker inspect --format='{{(index .State.Health.Log 0).Output}}' $i)";
          fi
        fi
      done
      if [ ! -z "${output}" ]; then
        echo ${output:3} && exit 2;
      fi
  SensuDockerCheckInterval:
    type: number
    description: The frequency in seconds the docker health check is executed.
    default: 10
  SensuDockerCheckHandlers:
    default: []
    description: The Sensu event handler to use for events
                 created by the docker health check.
    type: comma_delimited_list
  SensuDockerCheckOccurrences:
    type: number
    description: The number of event occurrences before sensu-plugin-aware handler should take action.
    default: 3
  SensuDockerCheckRefresh:
    type: number
    description: The number of seconds sensu-plugin-aware handlers should wait before taking second action.
    default: 90


resources:
  ContainersCommon:
    type: ./containers-common.yaml

  SensuClientBase:
    type: ../../puppet/services/monitoring/sensu-client.yaml
    properties:
      EndpointMap: {get_param: EndpointMap}
      ServiceData: {get_param: ServiceData}
      ServiceNetMap: {get_param: ServiceNetMap}
      DefaultPasswords: {get_param: DefaultPasswords}


outputs:
  role_data:
    description: Role data for the Sensu client role.
    value:
      service_name: {get_attr: [SensuClientBase, role_data, service_name]}
      config_settings:
        map_merge:
          - get_attr: [SensuClientBase, role_data, config_settings]
          - sensu::checks:
              check-docker-health:
                standalone: true
                command: {get_param: SensuDockerCheckCommand}
                interval: {get_param: SensuDockerCheckInterval}
                handlers: {get_param: SensuDockerCheckHandlers}
                occurrences: {get_param: SensuDockerCheckOccurrences}
                refresh: {get_param: SensuDockerCheckRefresh}
      service_config_settings: {get_attr: [SensuClientBase, role_data, service_config_settings]}
      # BEGIN DOCKER SETTINGS
      puppet_config:
        config_volume: sensu
        puppet_tags:  sensu_rabbitmq_config,sensu_client_config,sensu_check_config,sensu_check
        step_config:
          get_attr: [SensuClientBase, role_data, step_config]
        config_image: {get_param: DockerSensuConfigImage}
      kolla_config:
        /var/lib/kolla/config_files/sensu-client.json:
          command: /usr/bin/sensu-client -d /etc/sensu/conf.d/ -l /var/log/sensu/sensu-client.log
          config_files:
            - source: "/var/lib/kolla/config_files/src/*"
              dest: "/"
              merge: true
              preserve_properties: true
          permissions:
            - path: /var/log/sensu
              owner: sensu:sensu
              recurse: true
      docker_config:
        step_3:
          sensu_client:
            image: {get_param: DockerSensuClientImage}
            net: host
            privileged: true
            # NOTE(mmagr) kolla image changes the user to 'sensu', we need it
            # to be root have rw permission to docker.sock to run successfully
            # "docker inspect" command
            user: root
            restart: always
            healthcheck:
              test:
                list_join:
                  - ' '
                  - - '/openstack/healthcheck'
                    - yaql:
                        expression: >
                          switch(bool($.data.cluster) => $.data.cluster, bool($.data.single_node) => $.data.single_node).select($.port).distinct().join(' ')
                        data:
                          cluster: {get_attr: [SensuClientBase, role_data, config_settings, 'sensu::rabbitmq_cluster']}
                          single_node: [{port: {get_attr: [SensuClientBase, role_data, config_settings, 'sensu::rabbitmq_port']}}]
            volumes:
              list_concat:
                - {get_attr: [ContainersCommon, volumes]}
                -
                  - /var/run/docker.sock:/var/run/docker.sock:rw
                  - /var/lib/kolla/config_files/sensu-client.json:/var/lib/kolla/config_files/config.json:ro
                  - /var/lib/config-data/puppet-generated/sensu/:/var/lib/kolla/config_files/src:ro
                  - /var/log/containers/sensu:/var/log/sensu:rw
            environment:
              - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
{'fraction_non_alphanumeric': 0.08920018075011298, 'fraction_numerical': 0.0018075011296882061, 'mean_word_length': 2.2328366929593924, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6254075', 'n_tokens_mistral': 3300, 'n_tokens_neox': 3132, 'n_words': 783}