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