Merge ~canonical-bootstack/charm-openstack-service-checks:bug#1818966 into ~canonical-bootstack/charm-openstack-service-checks:master

Proposed by Diko Parvanov
Status: Merged
Approved by: David O Neill
Approved revision: 5f8300c6dc893f658f21bdbd9cf29c15a23272f0
Merged at revision: f051594315a9e6678e473eb32dfb3edca3e8144e
Proposed branch: ~canonical-bootstack/charm-openstack-service-checks:bug#1818966
Merge into: ~canonical-bootstack/charm-openstack-service-checks:master
Diff against target: 76 lines (+27/-2)
3 files modified
config.yaml (+6/-0)
files/plugins/check_nova_services.py (+8/-0)
lib/lib_openstack_service_checks.py (+13/-2)
Reviewer Review Type Date Requested Status
David O Neill (community) Approve
Alvaro Uria (community) Needs Fixing
Andrew McLeod (community) Approve
Review via email: mp+367455@code.launchpad.net

Commit message

Added option to skip host aggregates from checks

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
Alvaro Uria (aluria) wrote :

Please see comment inline. I also understand that an empty value would call "--skip" instead of "--skip <str>", but since the default value is "", that should be ok.

review: Needs Fixing
Revision history for this message
Andrew McLeod (admcleod) wrote :

Lgtm +1

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

I think there is an error when building the check_command to be passed to nrpe. See comment inline.

review: Needs Fixing
Revision history for this message
Diko Parvanov (dparv) wrote :

> I think there is an error when building the check_command to be passed to
> nrpe. See comment inline.

True, have missed the 5th param, now should be fixed.

Revision history for this message
David O Neill (dmzoneill) wrote :

all feedback addressed, approved

review: Approve
Revision history for this message
🤖 Canonical IS Merge Bot (canonical-is-mergebot) wrote :

Change successfully merged at revision f051594315a9e6678e473eb32dfb3edca3e8144e

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/config.yaml b/config.yaml
2index 6f09823..461bfe1 100644
3--- a/config.yaml
4+++ b/config.yaml
5@@ -22,6 +22,12 @@ options:
6 type: int
7 description: |
8 Critical level for nova aggregate unit count check - setting this to -1 will effectively disable host aggregate checks.
9+ skipped_host_aggregates:
10+ type: string
11+ default: ""
12+ description: |
13+ Comma separated list of host aggregates that need to be skipped from checks. Example "Agg1,AGg2" or 'Aggregate3'.
14+ This is a case-insensitive option.
15 nagios_context:
16 default: "juju"
17 type: string
18diff --git a/files/plugins/check_nova_services.py b/files/plugins/check_nova_services.py
19index 8a3666d..5e73de9 100755
20--- a/files/plugins/check_nova_services.py
21+++ b/files/plugins/check_nova_services.py
22@@ -59,6 +59,12 @@ def check_nova_services(args, nova):
23 status = []
24 hosts_checked = []
25 for agg in aggregates:
26+ # skip the defined host aggregates to be skipped from the config
27+ # making it case-insensitive
28+ skipped_aggregates = [name.lower() for name in args.skip.split(',')]
29+ aggregate_name = agg['name'].lower()
30+ if aggregate_name in skipped_aggregates:
31+ continue
32 # get a list of hosts, pass to the function
33 hosts = agg['hosts']
34 hosts_checked.append(hosts)
35@@ -91,6 +97,8 @@ if __name__ == '__main__':
36 help="Warn at this many hosts running")
37 parser.add_argument('--crit', dest='crit', type=int, default=1,
38 help="Critical at this many hosts running or less")
39+ parser.add_argument('--skip', dest='skip', type=str, default="",
40+ help="Comma separated list of types of aggregates to skip.")
41 parser.add_argument('--env', dest='env',
42 default='/var/lib/nagios/nagios.novarc',
43 help="Novarc file to use for this check")
44diff --git a/lib/lib_openstack_service_checks.py b/lib/lib_openstack_service_checks.py
45index efdae7c..ca184a6 100644
46--- a/lib/lib_openstack_service_checks.py
47+++ b/lib/lib_openstack_service_checks.py
48@@ -84,6 +84,17 @@ class OSCHelper():
49 return self.charm_config.get('nova_crit')
50
51 @property
52+ def nova_skip(self):
53+ skipped_aggregates = self.charm_config.get('skipped_host_aggregates')
54+ # We have to make sure there are no malicious injections in the code
55+ # as this gets passed to a python script via bash
56+ regex = r'(\w+[,\w+]*)'
57+ sanitized = ",".join(re.findall(regex, skipped_aggregates))
58+ sanitized = [s for s in sanitized.split(',') if s != ""]
59+ sanitized = ",".join(sanitized)
60+ return sanitized
61+
62+ @property
63 def skip_disabled(self):
64 if self.charm_config.get('skip-disabled'):
65 return '--skip-disabled'
66@@ -111,8 +122,8 @@ class OSCHelper():
67
68 nova_check_command = os.path.join(self.plugins_dir,
69 'check_nova_services.py')
70- check_command = '{} --warn {} --crit {} {}'.format(
71- nova_check_command, self.nova_warn, self.nova_crit,
72+ check_command = '{} --warn {} --crit {} --skip {} {}'.format(
73+ nova_check_command, self.nova_warn, self.nova_crit, self.nova_skip,
74 self.skip_disabled).strip()
75 nrpe.add_check(shortname='nova_services',
76 description='Check that enabled Nova services are up',

Subscribers

People subscribed via source and target branches

to all changes: