Merge ~canonical-bootstack/charm-openstack-service-checks:check-loadbalancers into ~canonical-bootstack/charm-openstack-service-checks:master

Proposed by Joe Guo
Status: Superseded
Proposed branch: ~canonical-bootstack/charm-openstack-service-checks:check-loadbalancers
Merge into: ~canonical-bootstack/charm-openstack-service-checks:master
Diff against target: 515 lines (+386/-9)
9 files modified
actions.yaml (+3/-0)
actions/actions.py (+75/-0)
actions/refresh-endpoint-checks (+1/-0)
config.yaml (+18/-0)
files/plugins/check_octavia.py (+227/-0)
layer.yaml (+2/-0)
lib/lib_openstack_service_checks.py (+55/-8)
metadata.yaml (+1/-1)
tests/functional/test_deploy.py (+4/-0)
Reviewer Review Type Date Requested Status
Jose Guedez (community) Approve
Jeremy Lounder Pending
James Hebden Pending
Joe Guo Pending
Review via email: mp+377016@code.launchpad.net

This proposal has been superseded by a proposal from 2020-03-18.

Commit message

Add checks for loadbalancers.

To post a comment you must log in.
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

This merge proposal is being monitored by mergebot. Change the status to Approved to merge.

Revision history for this message
James Hebden (ec0) wrote :

Please see comments inline.
Overall, looks really cool!

One other check I would suggest, is verifying that the image exists in glance for booting new Amphorae if possible. The tag used by Octavia should be available as the amp-image-tag setting on Octavia, so we should either provide a setting on this charm to configure the tag we will monitor (i.e. a string setting called octavia-image-tag with default of 'amp-image-tag') or get this information from Octavia. We can then check that there is an image with this tag present in Glance, as if the image is deleted, we have a problem, because new amphora can not be booted.

I'd be happy to approve this with the below changes, even without the glance check, and we can handle the glance check as a follow up activity.

18472a4... by Joe Guo

add octavia checks

Signed-off-by: Joe Guo <email address hidden>

Revision history for this message
Alvaro Uria (aluria) wrote :

I've added a comment on a minor typo. OTOH, the best practice suggested for charms is to have as many things autoconfigured as possible (ie. reduce config parameters). So, I would suggest a new interface between charm-octavia and charm-openstack-service-checks which:
1) It would make "check-loadbalancer" be "True", which would create the nrpe check (as James mentioned, an extra config param could exist in charm-openstack-service-checks to disable certain "modules" (lb, amphorae, pools...)
2) The relation would share the amp-image-tag value automatically (if not set, charm-openstack-service-checks would only check for any image with the "octavia-amphora" tag.
3) Possibly do the same for the flavor id, which is a config param in Octavia (however, I don't know the way to guess if a flavor that will be used by the Amphorae exists - the default is that charm-octavia handles it, so an internal value probably exists)

Thank you for the change. Is there a bug we can link this MP to?

Revision history for this message
Joe Guo (guoqiao) wrote :

Hi,
Thanks for the review and feedback.
I've fixed all, and refactored the code to make it more flexible/reasonable.

Could you please review again when you get the time?

NOTE: for image check, it hardcoded `amp_img_tag` to `octavia-amphora` at the moment, and it's disabled by default. Work in progress to find a proper/minimal way to set it.

Revision history for this message
James Hebden (ec0) wrote :

Just a couple more comments, around config.yaml and default checks.

Revision history for this message
Joe Guo (guoqiao) wrote :

> Just a couple more comments, around config.yaml and default checks.

Hi James,
I've made the changes, please review again when you get the time. Thanks:)

0bfc801... by Jeremy Lounder

Updated maintainers in metadata.yaml

bd33e8e... by Xav Paice

Add ability to remove NRPE endpoint checks

When a service is removed from the Keystone catalog, this adds a
mechanism to remove that service from the list of NRPE checks so it
doesn't alert CRITICAL for services that aren't there any more.

Closes-Bug: LP: #1836385

Revision history for this message
Jose Guedez (jfguedez) wrote :

comments inline...

Revision history for this message
Joe Guo (guoqiao) wrote :

Hi Jose,
Thanks for the great review, they are all good advice. I will make those changes in my new Engineer rotation. Thanks.

Revision history for this message
Joe Guo (guoqiao) wrote :

Hi Jose,
I've made following changes:
1. split octavia nagios check into 4(loadbalancers|amphorae|pools|image), so I don't need to handle the complex logic of which ERROR to return
2. remove the image tag and days default on check_image function. But I still have them on both cli option and config.yaml since they are different levels.

I didn't import nagios3_plugin module for the status codes, so I can keep this script standalone, and run it from any location.

Another review appreciated:)

Revision history for this message
Jose Guedez (jfguedez) wrote :

Hi Joe - Good stuff, much cleaner now. Comments inline. Just one real comment with the functional test and the new filenames of the checks.

Revision history for this message
Joe Guo (guoqiao) wrote :

Hi Jose,
Changed and replied, see my inline replies.

BTW: I've verified the new octavia checks are added correctly with openstack-on-lxd env: https://pastebin.canonical.com/p/D26hdX3KDH/

Revision history for this message
Jose Guedez (jfguedez) wrote :

+1 LGTM

review: Approve

Unmerged commits

18472a4... by Joe Guo

add octavia checks

Signed-off-by: Joe Guo <email address hidden>

bd33e8e... by Xav Paice

Add ability to remove NRPE endpoint checks

When a service is removed from the Keystone catalog, this adds a
mechanism to remove that service from the list of NRPE checks so it
doesn't alert CRITICAL for services that aren't there any more.

Closes-Bug: LP: #1836385

0bfc801... by Jeremy Lounder

Updated maintainers in metadata.yaml

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
diff --git a/actions.yaml b/actions.yaml
0new file mode 1006440new file mode 100644
index 0000000..9e5a96a
--- /dev/null
+++ b/actions.yaml
@@ -0,0 +1,3 @@
1refresh-endpoint-checks:
2 description: >-
3 Trigger the Keystone endpoints to be reloaded on next update-status hook.
diff --git a/actions/actions.py b/actions/actions.py
0new file mode 1007554new file mode 100755
index 0000000..1e679b6
--- /dev/null
+++ b/actions/actions.py
@@ -0,0 +1,75 @@
1#!/usr/local/sbin/charm-env python3
2# Copyright 2020 Canonical Ltd
3#
4# Licensed under the Apache License, Version 2.0 (the "License");
5# you may not use this file except in compliance with the License.
6# You may obtain a copy of the License at
7#
8# http://www.apache.org/licenses/LICENSE-2.0
9#
10# Unless required by applicable law or agreed to in writing, software
11# distributed under the License is distributed on an "AS IS" BASIS,
12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13# See the License for the specific language governing permissions and
14# limitations under the License.
15
16import os
17import sys
18import charmhelpers.core.hookenv as hookenv
19import charmhelpers.core.unitdata as unitdata
20from traceback import format_exc
21
22# Load modules from $CHARM_DIR/lib
23sys.path.append("lib")
24
25import charms.reactive # NOQA: E402
26from charms.layer import basic # NOQA: E402
27
28basic.bootstrap_charm_deps()
29basic.init_config_states()
30
31from charms.reactive.flags import clear_flag # NOQA: E402
32
33
34def refresh_endpoint_checks(*args):
35 """Clear the openstack-service-checks.endpoints.configured flag
36 so that next time update-status runs, the Keystone catalog is re-read
37 and nrpe checks refreshed.
38 """
39 clear_flag("openstack-service-checks.endpoints.configured")
40
41
42# Actions to function mapping, to allow for illegal python action names that
43# can map to a python function.
44ACTIONS = {
45 "refresh-endpoint-checks": refresh_endpoint_checks,
46}
47
48
49def main(args):
50 action_name = os.path.basename(args[0])
51 try:
52 action = ACTIONS[action_name]
53 except KeyError:
54 return "Action %s undefined" % action_name
55 else:
56 try:
57 action(args)
58 except Exception:
59 exc = format_exc()
60 hookenv.log(exc, hookenv.ERROR)
61 hookenv.action_fail(exc.splitlines()[-1])
62 else:
63 # we were successful, so commit changes from the action
64 unitdata.kv().flush()
65 # try running handlers based on new state
66 try:
67 charms.reactive.main()
68 except Exception:
69 exc = format_exc()
70 hookenv.log(exc, hookenv.ERROR)
71 hookenv.action_fail(exc.splitlines()[-1])
72
73
74if __name__ == "__main__":
75 sys.exit(main(sys.argv))
diff --git a/actions/refresh-endpoint-checks b/actions/refresh-endpoint-checks
0new file mode 12000076new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/actions/refresh-endpoint-checks
@@ -0,0 +1 @@
1actions.py
0\ No newline at end of file2\ No newline at end of file
diff --git a/config.yaml b/config.yaml
index 073ba9b..edfda51 100644
--- a/config.yaml
+++ b/config.yaml
@@ -10,6 +10,24 @@ options:
10 description: |10 description: |
11 Switch to turn on or off neutron agents checks. By default, neutron_agents nrpe check is enabled.11 Switch to turn on or off neutron agents checks. By default, neutron_agents nrpe check is enabled.
12 If a different SDN (ie. Contrail) is in use, you may want to disable this check.12 If a different SDN (ie. Contrail) is in use, you may want to disable this check.
13 check-octavia:
14 default: True
15 type: boolean
16 description: |
17 Switch to turn on or off check for octavia services.
18 octavia-amp-image-tag:
19 default: "octavia-amphora"
20 type: string
21 description: |
22 The glance image tag octavia will use to create amphora.
23 octavia-amp-image-days:
24 default: 365
25 type: int
26 description: |
27 If latest glance image tagged with above octavia-amp-image-tag is updated more than these days ago,
28 a Nagios warning will be raised. The version of octavia agent builtin in amphora image must match
29 version of octavia controller, otherwise octavia will fail to communicate with new amphora,
30 failover will also fail.
13 check-rally:31 check-rally:
14 default: False32 default: False
15 type: boolean33 type: boolean
diff --git a/files/plugins/check_octavia.py b/files/plugins/check_octavia.py
16new file mode 10075534new file mode 100755
index 0000000..09fb6b1
--- /dev/null
+++ b/files/plugins/check_octavia.py
@@ -0,0 +1,227 @@
1#!/usr/bin/env python3
2
3import os
4import sys
5import json
6import argparse
7import subprocess
8from datetime import datetime, timedelta
9import openstack
10
11NAGIOS_STATUS_OK = 0
12NAGIOS_STATUS_WARNING = 1
13NAGIOS_STATUS_CRITICAL = 2
14NAGIOS_STATUS_UNKNOWN = 3
15
16NAGIOS_STATUS = {
17 NAGIOS_STATUS_OK: 'OK',
18 NAGIOS_STATUS_WARNING: 'WARNING',
19 NAGIOS_STATUS_CRITICAL: 'CRITICAL',
20 NAGIOS_STATUS_UNKNOWN: 'UNKNOWN',
21}
22
23
24def nagios_exit(status, message):
25 assert status in NAGIOS_STATUS, "Invalid Nagios status code"
26 # prefix status name to message
27 output = '{}: {}'.format(NAGIOS_STATUS[status], message)
28 print(output) # nagios requires print to stdout, no stderr
29 sys.exit(status)
30
31
32def check_loadbalancers(connection):
33 """check loadbalancers status."""
34
35 lb_mgr = connection.load_balancer
36 lb_all = lb_mgr.load_balancers()
37
38 # only check enabled lbs
39 lb_enabled = [lb for lb in lb_all if lb.is_admin_state_up]
40
41 # check provisioning_status is ACTIVE for each lb
42 bad_lbs = [lb for lb in lb_enabled if lb.provisioning_status != 'ACTIVE']
43 if bad_lbs:
44 parts = ['loadbalancer {} provisioning_status is {}'.format(
45 lb.id, lb.provisioning_status) for lb in bad_lbs]
46 message = ', '.join(parts)
47 return NAGIOS_STATUS_CRITICAL, message
48
49 # raise WARNING if operating_status is not ONLINE
50 bad_lbs = [lb for lb in lb_enabled if lb.operating_status != 'ONLINE']
51 if bad_lbs:
52 parts = ['loadbalancer {} operating_status is {}'.format(
53 lb.id, lb.operating_status) for lb in bad_lbs]
54 message = ', '.join(parts)
55 return NAGIOS_STATUS_CRITICAL, message
56
57 net_mgr = connection.network
58 # check vip port exists for each lb
59 bad_lbs = []
60 for lb in lb_enabled:
61 try:
62 net_mgr.get_port(lb.vip_port_id)
63 except openstack.exceptions.NotFoundException:
64 bad_lbs.append(lb)
65 if bad_lbs:
66 parts = ['vip port {} for loadbalancer {} not found'.format(
67 lb.vip_port_id, lb.id) for lb in bad_lbs]
68 message = ', '.join(parts)
69 return NAGIOS_STATUS_CRITICAL, message
70
71 # warn about disabled lbs if no other error found
72 lb_disabled = [lb for lb in lb_all if not lb.is_admin_state_up]
73 if lb_disabled:
74 parts = ['loadbalancer {} admin_state_up is False'.format(lb.id)
75 for lb in lb_disabled]
76 message = ', '.join(parts)
77 return NAGIOS_STATUS_WARNING, message
78
79 return NAGIOS_STATUS_OK, 'loadbalancers are happy'
80
81
82def check_pools(connection):
83 """check pools status."""
84 lb_mgr = connection.load_balancer
85 pools_all = lb_mgr.pools()
86 pools_enabled = [pool for pool in pools_all if pool.is_admin_state_up]
87
88 # check provisioning_status is ACTIVE for each pool
89 bad_pools = [pool for pool in pools_enabled if pool.provisioning_status != 'ACTIVE']
90 if bad_pools:
91 parts = ['pool {} provisioning_status is {}'.format(
92 pool.id, pool.provisioning_status) for pool in bad_pools]
93 message = ', '.join(parts)
94 return NAGIOS_STATUS_CRITICAL, message
95
96 # raise CRITICAL if operating_status is ERROR
97 bad_pools = [pool for pool in pools_enabled if pool.operating_status == 'ERROR']
98 if bad_pools:
99 parts = ['pool {} operating_status is {}'.format(
100 pool.id, pool.operating_status) for pool in bad_pools]
101 message = ', '.join(parts)
102 return NAGIOS_STATUS_CRITICAL, message
103
104 # raise WARNING if operating_status is NO_MONITOR
105 bad_pools = [pool for pool in pools_enabled if pool.operating_status == 'NO_MONITOR']
106 if bad_pools:
107 parts = ['pool {} operating_status is {}'.format(
108 pool.id, pool.operating_status) for pool in bad_pools]
109 message = ', '.join(parts)
110 return NAGIOS_STATUS_WARNING, message
111
112 return NAGIOS_STATUS_OK, 'pools are happy'
113
114
115def check_amphorae(connection):
116 """check amphorae status."""
117
118 lb_mgr = connection.load_balancer
119
120 resp = lb_mgr.get('/v2/octavia/amphorae')
121 # python api is not available yet, use url
122 if resp.status_code != 200:
123 return NAGIOS_STATUS_WARNING, 'amphorae api not working'
124
125 data = json.loads(resp.content)
126 # ouput is like {"amphorae": [{...}, {...}, ...]}
127 items = data.get('amphorae', [])
128
129 # raise CRITICAL for ERROR status
130 bad_status_list = ('ERROR',)
131 bad_items = [item for item in items if item['status'] in bad_status_list]
132 if bad_items:
133 parts = [
134 'amphora {} status is {}'.format(item['id'], item['status'])
135 for item in bad_items]
136 message = ', '.join(parts)
137 return NAGIOS_STATUS_CRITICAL, message
138
139 # raise WARNING for these status
140 bad_status_list = (
141 'PENDING_CREATE', 'PENDING_UPDATE', 'PENDING_DELETE', 'BOOTING')
142 bad_items = [item for item in items if item['status'] in bad_status_list]
143 if bad_items:
144 parts = [
145 'amphora {} status is {}'.format(item['id'], item['status'])
146 for item in bad_items]
147 message = ', '.join(parts)
148 return NAGIOS_STATUS_WARNING, message
149
150 return NAGIOS_STATUS_OK, 'amphorae are happy'
151
152
153def check_image(connection, tag, days):
154 img_mgr = connection.image
155 images = list(img_mgr.images(tag=tag))
156
157 if not images:
158 message = ('Octavia requires image with tag {} to create amphora, '
159 'but none exist').format(tag)
160 return NAGIOS_STATUS_CRITICAL, message
161
162 active_images = [image for image in images if image.status == 'active']
163 if not active_images:
164 parts = ['{}({})'.format(image.name, image.id) for image in images]
165 message = ('Octavia requires image with tag {} to create amphora, '
166 'but none is active: {}').format(tag, ', '.join(parts))
167 return NAGIOS_STATUS_CRITICAL, message
168
169 # raise WARNING if image is too old
170 when = (datetime.now() - timedelta(days=days)).isoformat()
171 # updated_at str format: '2019-12-05T18:21:25Z'
172 fresh_images = [image for image in active_images if image.updated_at > when]
173 if not fresh_images:
174 message = ('Octavia requires image with tag {} to create amphora, '
175 'but it is older than {} days').format(tag, days)
176 return NAGIOS_STATUS_WARNING, message
177
178 return NAGIOS_STATUS_OK, 'image is ready'
179
180
181if __name__ == '__main__':
182 parser = argparse.ArgumentParser(
183 description='Check Octavia status',
184 formatter_class=argparse.ArgumentDefaultsHelpFormatter,
185 )
186 parser.add_argument(
187 '--env', dest='env', default='/var/lib/nagios/nagios.novarc',
188 help='Novarc file to use for this check')
189
190 check_choices = ['loadbalancers', 'amphorae', 'pools', 'image']
191 parser.add_argument(
192 '--check', dest='check', metavar='|'.join(check_choices),
193 type=str, choices=check_choices,
194 default=check_choices[0],
195 help='which check to run')
196
197 parser.add_argument(
198 '--amp-image-tag', dest='amp_image_tag', default='octavia-amphora',
199 help='amphora image tag for image check')
200
201 parser.add_argument(
202 '--amp-image-days', dest='amp_image_days', type=int, default=365,
203 help='raise warning if amphora image is older than these days')
204
205 args = parser.parse_args()
206 # source environment vars
207 command = ['/bin/bash', '-c', 'source {} && env'.format(args.env)]
208 proc = subprocess.Popen(command, stdout=subprocess.PIPE)
209 for line in proc.stdout:
210 (key, _, value) = line.partition(b'=')
211 os.environ[key.decode('utf-8')] = value.rstrip().decode('utf-8')
212 proc.communicate()
213
214 # use closure to make all checks have same signature
215 # so we can handle them in same way
216 def _check_image(connection):
217 return check_image(connection, args.amp_image_tag, args.amp_image_days)
218
219 checks = {
220 'loadbalancers': check_loadbalancers,
221 'amphorae': check_amphorae,
222 'pools': check_pools,
223 'image': _check_image,
224 }
225
226 connection = openstack.connect(cloud='envvars')
227 nagios_exit(*checks[args.check](connection))
diff --git a/layer.yaml b/layer.yaml
index 4053919..0606d45 100644
--- a/layer.yaml
+++ b/layer.yaml
@@ -20,6 +20,8 @@ options:
20 - python3-keystoneclient20 - python3-keystoneclient
21 - python3-openstackclient21 - python3-openstackclient
22 - python-openstackclient22 - python-openstackclient
23 - python3-octaviaclient
24 - python-octaviaclient
23 snap:25 snap:
24 fcbtest:26 fcbtest:
25 channel: stable27 channel: stable
diff --git a/lib/lib_openstack_service_checks.py b/lib/lib_openstack_service_checks.py
index 9d123fb..38e5f0f 100644
--- a/lib/lib_openstack_service_checks.py
+++ b/lib/lib_openstack_service_checks.py
@@ -65,6 +65,18 @@ class OSCHelper():
65 return self.charm_config['check-neutron-agents']65 return self.charm_config['check-neutron-agents']
6666
67 @property67 @property
68 def is_octavia_check_enabled(self):
69 return self.charm_config['check-octavia']
70
71 @property
72 def octavia_amp_image_tag(self):
73 return self.charm_config['octavia-amp-image-tag']
74
75 @property
76 def octavia_amp_image_days(self):
77 return self.charm_config['octavia-amp-image-days']
78
79 @property
68 def skipped_rally_checks(self):80 def skipped_rally_checks(self):
69 skipped_os_components = self.charm_config['skip-rally'].strip()81 skipped_os_components = self.charm_config['skip-rally'].strip()
70 if not skipped_os_components:82 if not skipped_os_components:
@@ -186,6 +198,28 @@ class OSCHelper():
186 else:198 else:
187 nrpe.remove_check(shortname='neutron_agents')199 nrpe.remove_check(shortname='neutron_agents')
188200
201 if self.is_octavia_check_enabled:
202 script = os.path.join(self.plugins_dir, 'check_octavia.py')
203
204 for check in ('loadbalancers', 'amphorae', 'pools'):
205 nrpe.add_check(
206 shortname='octavia_{}'.format(check),
207 description='Check octavia {} status'.format(check),
208 check_cmd='{} --check {}'.format(script, check),
209 )
210
211 # image check has extra args, add it separately
212 check = 'image'
213 nrpe.add_check(
214 shortname='octavia_{}'.format(check),
215 description='Check octavia {} status'.format(check),
216 check_cmd='{} --check {} --amp-image-tag {} --amp-image-days {}'.format(
217 script, check, self.octavia_amp_image_tag, self.octavia_amp_image_days),
218 )
219 else:
220 for check in ('loadbalancers', 'amphorae', 'pools', 'image'):
221 nrpe.remove_check(shortname='octavia_{}'.format(check))
222
189 if self.contrail_analytics_vip:223 if self.contrail_analytics_vip:
190 contrail_check_command = '{} --host {}'.format(224 contrail_check_command = '{} --host {}'.format(
191 os.path.join(self.plugins_dir, 'check_contrail_analytics_alarms.py'),225 os.path.join(self.plugins_dir, 'check_contrail_analytics_alarms.py'),
@@ -272,7 +306,7 @@ class OSCHelper():
272 endpoints = self.keystone_endpoints306 endpoints = self.keystone_endpoints
273 services = [svc for svc in self.keystone_services if svc.enabled]307 services = [svc for svc in self.keystone_services if svc.enabled]
274 nrpe = NRPE()308 nrpe = NRPE()
275 skip_service = set()309 configured_endpoint_checks = dict()
276 for endpoint in endpoints:310 for endpoint in endpoints:
277 endpoint.service_names = [x.name311 endpoint.service_names = [x.name
278 for x in services312 for x in services
@@ -281,21 +315,18 @@ class OSCHelper():
281 endpoint.healthcheck_url = health_check_params.get(service_name, '/')315 endpoint.healthcheck_url = health_check_params.get(service_name, '/')
282316
283 # Note(aluria): glance-simplestreams-sync does not provide an API to check317 # Note(aluria): glance-simplestreams-sync does not provide an API to check
284 if service_name == 'image-stream':318 # Note(aluria): filter:healthcheck is not configured in Keystone v2
319 # https://docs.openstack.org/keystone/pike/configuration.html#health-check-middleware
320 if service_name == 'image-stream' or service_name == 'keystone':
285 continue321 continue
286322
287 if not hasattr(endpoint, 'interface'):323 if not hasattr(endpoint, 'interface'):
288 if service_name == 'keystone':
289 # Note(aluria): filter:healthcheck is not configured in v2
290 # https://docs.openstack.org/keystone/pike/configuration.html#health-check-middleware
291 continue
292 for interface in 'admin internal public'.split():324 for interface in 'admin internal public'.split():
293 old_interface_name = '{}url'.format(interface)325 old_interface_name = '{}url'.format(interface)
294 if not hasattr(endpoint, old_interface_name):326 if not hasattr(endpoint, old_interface_name):
295 continue327 continue
296 endpoint.interface = interface328 endpoint.interface = interface
297 endpoint.url = getattr(endpoint, old_interface_name)329 endpoint.url = getattr(endpoint, old_interface_name)
298 skip_service.add(service_name)
299 break330 break
300331
301 check_url = urlparse(endpoint.url)332 check_url = urlparse(endpoint.url)
@@ -324,10 +355,26 @@ class OSCHelper():
324 check_cmd=' '.join(cmd_params_cert))355 check_cmd=' '.join(cmd_params_cert))
325356
326 # Add the actual health check for the URL357 # Add the actual health check for the URL
327 nrpe.add_check(shortname='{}_{}'.format(service_name, endpoint.interface),358 nrpe_shortname = '{}_{}'.format(service_name, endpoint.interface)
359 nrpe.add_check(shortname=nrpe_shortname,
328 description='Endpoint url check for {} {}'.format(service_name, endpoint.interface),360 description='Endpoint url check for {} {}'.format(service_name, endpoint.interface),
329 check_cmd=' '.join(cmd_params))361 check_cmd=' '.join(cmd_params))
362 configured_endpoint_checks[nrpe_shortname] = True
363 nrpe.write()
364 self._remove_old_nrpe_endpoint_checks(nrpe, configured_endpoint_checks)
330365
366 def _remove_old_nrpe_endpoint_checks(self, nrpe, configured_endpoint_checks):
367 """Loop through the old and new endpoint checks, if there are checks that aren't needed any more,
368 remove them.
369 """
370 kv = unitdata.kv()
371 endpoint_delta = kv.delta(configured_endpoint_checks, 'endpoint_checks')
372 kv.update(configured_endpoint_checks, 'endpoint_checks')
373 for nrpe_shortname in endpoint_delta.items():
374 # generates tuples of the format ('heat_public', Delta(previous=None, current=True))
375 # remove any that are not current
376 if not nrpe_shortname[1].current:
377 nrpe.remove_check(shortname=nrpe_shortname[0])
331 nrpe.write()378 nrpe.write()
332379
333 def get_keystone_client(self, creds):380 def get_keystone_client(self, creds):
diff --git a/metadata.yaml b/metadata.yaml
index d4b7e87..94a7db8 100644
--- a/metadata.yaml
+++ b/metadata.yaml
@@ -1,7 +1,7 @@
1name: openstack-service-checks1name: openstack-service-checks
2summary: OpenStack Services NRPE Checks2summary: OpenStack Services NRPE Checks
3description: OpenStack Services NRPE Checks3description: OpenStack Services NRPE Checks
4maintainer: LMA Charmers <llama-charmers@lists.ubuntu.com>4maintainer: Llama (LMA) Charmers <llama-charmers@lists.ubuntu.com>
5subordinate: false5subordinate: false
6tags:6tags:
7 - openstack7 - openstack
diff --git a/tests/functional/test_deploy.py b/tests/functional/test_deploy.py
index d0eea26..1716339 100644
--- a/tests/functional/test_deploy.py
+++ b/tests/functional/test_deploy.py
@@ -128,6 +128,10 @@ async def test_openstackservicechecks_verify_default_nrpe_checks(deploy_app, mod
128 filenames.extend([128 filenames.extend([
129 '/etc/nagios/nrpe.d/check_nova_services.cfg',129 '/etc/nagios/nrpe.d/check_nova_services.cfg',
130 '/etc/nagios/nrpe.d/check_neutron_agents.cfg',130 '/etc/nagios/nrpe.d/check_neutron_agents.cfg',
131 '/etc/nagios/nrpe.d/check_octavia_loadbalancers.cfg',
132 '/etc/nagios/nrpe.d/check_octavia_amphorae.cfg',
133 '/etc/nagios/nrpe.d/check_octavia_pools.cfg',
134 '/etc/nagios/nrpe.d/check_octavia_image.cfg',
131 ])135 ])
132 for filename in filenames:136 for filename in filenames:
133 test_stat = await file_stat(filename, unit)137 test_stat = await file_stat(filename, unit)

Subscribers

People subscribed via source and target branches

to all changes: