Merge "Support for Satellite Capsule in rhel-registration" into stable/pike
[apex-tripleo-heat-templates.git] / docker / services / sensu-client.yaml
1 heat_template_version: pike
2
3 description: >
4   Containerized Sensu client service
5
6 parameters:
7   DockerSensuClientImage:
8     description: image
9     type: string
10   DockerSensuConfigImage:
11     description: The container image to use for the sensu config_volume
12     type: string
13   EndpointMap:
14     default: {}
15     description: Mapping of service endpoint -> protocol. Typically set
16                  via parameter_defaults in the resource registry.
17     type: json
18   ServiceData:
19     default: {}
20     description: Dictionary packing service data
21     type: json
22   ServiceNetMap:
23     default: {}
24     description: Mapping of service_name -> network name. Typically set
25                  via parameter_defaults in the resource registry.  This
26                  mapping overrides those in ServiceNetMapDefaults.
27     type: json
28   DefaultPasswords:
29     default: {}
30     type: json
31   RoleName:
32     default: ''
33     description: Role name on which the service is applied
34     type: string
35   RoleParameters:
36     default: {}
37     description: Parameters specific to the role
38     type: json
39   SensuDockerCheckCommand:
40     type: string
41     default: |
42       output=''
43       for i in $(docker ps --format '{{.ID}}'); do
44         if result=$(docker inspect --format='{{.State.Health.Status}}' $i 2>/dev/null); then
45           if [ "$result" != 'healthy' ]; then
46             output="${output} ; $(docker inspect --format='{{.Name}}' $i) ($i): $(docker inspect --format='{{(index .State.Health.Log 0).Output}}' $i)";
47           fi
48         fi
49       done
50       if [ ! -z "${output}" ]; then
51         echo ${output:3} && exit 2;
52       fi
53   SensuDockerCheckInterval:
54     type: number
55     description: The frequency in seconds the docker health check is executed.
56     default: 10
57   SensuDockerCheckHandlers:
58     default: []
59     description: The Sensu event handler to use for events
60                  created by the docker health check.
61     type: comma_delimited_list
62   SensuDockerCheckOccurrences:
63     type: number
64     description: The number of event occurrences before sensu-plugin-aware handler should take action.
65     default: 3
66   SensuDockerCheckRefresh:
67     type: number
68     description: The number of seconds sensu-plugin-aware handlers should wait before taking second action.
69     default: 90
70
71 resources:
72
73   ContainersCommon:
74     type: ./containers-common.yaml
75
76   SensuClientBase:
77     type: ../../puppet/services/monitoring/sensu-client.yaml
78     properties:
79       EndpointMap: {get_param: EndpointMap}
80       ServiceData: {get_param: ServiceData}
81       ServiceNetMap: {get_param: ServiceNetMap}
82       DefaultPasswords: {get_param: DefaultPasswords}
83
84 outputs:
85   role_data:
86     description: Role data for the Sensu client role.
87     value:
88       service_name: {get_attr: [SensuClientBase, role_data, service_name]}
89       config_settings:
90         map_merge:
91           - get_attr: [SensuClientBase, role_data, config_settings]
92           - sensu::checks:
93               check-docker-health:
94                 standalone: true
95                 command: {get_param: SensuDockerCheckCommand}
96                 interval: {get_param: SensuDockerCheckInterval}
97                 handlers: {get_param: SensuDockerCheckHandlers}
98                 occurrences: {get_param: SensuDockerCheckOccurrences}
99                 refresh: {get_param: SensuDockerCheckRefresh}
100       step_config: &step_config
101         get_attr: [SensuClientBase, role_data, step_config]
102       service_config_settings: {get_attr: [SensuClientBase, role_data, service_config_settings]}
103       # BEGIN DOCKER SETTINGS
104       puppet_config:
105         config_volume: sensu
106         puppet_tags:  sensu_rabbitmq_config,sensu_client_config,sensu_check_config,sensu_check
107         step_config: *step_config
108         config_image: {get_param: DockerSensuConfigImage}
109       kolla_config:
110         /var/lib/kolla/config_files/sensu-client.json:
111           command: /usr/bin/sensu-client -d /etc/sensu/conf.d/ -l /var/log/sensu/sensu-client.log
112           config_files:
113             - source: "/var/lib/kolla/config_files/src/*"
114               dest: "/"
115               merge: true
116               preserve_properties: true
117           permissions:
118             - path: /var/log/sensu
119               owner: sensu:sensu
120               recurse: true
121       docker_config:
122         step_3:
123           sensu_client:
124             image: {get_param: DockerSensuClientImage}
125             net: host
126             privileged: true
127             # NOTE(mmagr) kolla image changes the user to 'sensu', we need it
128             # to be root have rw permission to docker.sock to run successfully
129             # "docker inspect" command
130             user: root
131             restart: always
132             volumes:
133               list_concat:
134                 - {get_attr: [ContainersCommon, volumes]}
135                 -
136                   - /var/run/docker.sock:/var/run/docker.sock:rw
137                   - /var/lib/kolla/config_files/sensu-client.json:/var/lib/kolla/config_files/config.json:ro
138                   - /var/lib/config-data/puppet-generated/sensu/:/var/lib/kolla/config_files/src:ro
139                   - /var/log/containers/sensu:/var/log/sensu:rw
140             environment:
141               - KOLLA_CONFIG_STRATEGY=COPY_ALWAYS
142       host_prep_tasks:
143         - name: create persistent logs directory
144           file:
145             path: /var/log/containers/sensu
146             state: directory
147       upgrade_tasks:
148         - name: Stop and disable sensu-client service
149           tags: step2
150           service: name=sensu-client.service state=stopped enabled=no