Merge lp:~verterok/charms/trusty/elasticsearch/elasticsearch2_more-details-in-health-check into lp:~onlineservices-charmers/charms/trusty/elasticsearch/elasticsearch2

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Michael Nelson
Approved revision: 50
Merged at revision: 45
Proposed branch: lp:~verterok/charms/trusty/elasticsearch/elasticsearch2_more-details-in-health-check
Merge into: lp:~onlineservices-charmers/charms/trusty/elasticsearch/elasticsearch2
Diff against target: 84 lines (+58/-3)
2 files modified
files/nrpe/check_health (+41/-0)
playbook.yaml (+17/-3)
To merge this branch: bzr merge lp:~verterok/charms/trusty/elasticsearch/elasticsearch2_more-details-in-health-check
Reviewer Review Type Date Requested Status
Michael Nelson (community) Approve
Review via email: mp+285927@code.launchpad.net

Commit message

Replace check_http based health nrpe check with a custom script that understands the status values.

Description of the change

Replace check_http based health check with a custom script that understand the status values.

To post a comment you must log in.
Revision history for this message
Michael Nelson (michael.nelson) wrote :

21:41 < noodles> verterok: Is nagios_health_color currently a config option (defaulting to green)? From memory it was, because otherwise if you're developing and using only one unit, the health will always be yellow?
21:42 < noodles> If you think that's unnecessary, we can probably remove the option (as it should only be used in dev, and worst-case, anyone upgrading will see it's removed with a config error)
21:44 < caio1982> atomatt: nice! i will take a look!
21:44 < verterok> noodles: didn't know it is a config, assumed it was the way ES reported status
21:44 < verterok> let me check
21:45 < verterok> noodles: oh, I understand now
21:46 < verterok> noodles: I can tweak the script to accept a custom "OK" status if you think it's needed.
21:47 < noodles> verterok: If that's simple enough, it'll mean maintaining the ability to deploy just one unit in a devel spec without error, but it's not that important . Fine either way. The script is a great improvement :)
21:48 < verterok> noodles: will play with the script tomorrow and ping you back when it's done. thanks
21:48 < noodles> verterok: Ack - or if it's an issue, fine to just remove that config option. No need to check back - just land with either.

review: Approve
48. By Guillermo Gonzalez

add --override-green option to nrpe script and use nagios_health_color in nrpe check

49. By Guillermo Gonzalez

only use --override-green if nagios_health_color is != green

50. By Guillermo Gonzalez

fix conditional

Revision history for this message
Guillermo Gonzalez (verterok) wrote :

fixed and pushed.

I don't have perms to top-approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added directory 'files/nrpe'
2=== added file 'files/nrpe/check_health'
3--- files/nrpe/check_health 1970-01-01 00:00:00 +0000
4+++ files/nrpe/check_health 2016-02-16 16:43:37 +0000
5@@ -0,0 +1,41 @@
6+#!/usr/bin/env python
7+from __future__ import print_function
8+
9+import json
10+import urllib
11+import sys
12+
13+
14+def main(url, override_green):
15+ resp = urllib.urlopen(url)
16+ if resp.code == 200:
17+ info = json.loads(resp.read())
18+ status = info['status']
19+ if status == "green" or (override_green and override_green == status):
20+ print(info)
21+ sys.exit(0)
22+ elif status == "yellow":
23+ print(info)
24+ sys.exit(1)
25+ elif status == "red":
26+ print(info)
27+ sys.exit(2)
28+ else:
29+ print("UNKNOWN status: {} - {}".format(status, info))
30+ sys.exit(3)
31+ else:
32+ print('HTTP CODE: {} - BODY: {}'.format(resp.code, resp.read()))
33+ sys.exit(2)
34+
35+if __name__ == "__main__":
36+ import argparse
37+ parser = argparse.ArgumentParser()
38+ parser.add_argument("health_url")
39+ parser.add_argument("--override-green", dest="override_green",
40+ required=False, default="")
41+ args = parser.parse_args()
42+ try:
43+ main(args.health_url, args.override_green)
44+ except Exception as exc:
45+ print(exc)
46+ sys.exit(3)
47
48=== modified file 'playbook.yaml'
49--- playbook.yaml 2015-11-26 04:10:47 +0000
50+++ playbook.yaml 2016-02-16 16:43:37 +0000
51@@ -1,9 +1,9 @@
52 - hosts: localhost
53 roles:
54 - role: nrpe
55- check_name: check_http
56- check_params: -H localhost -u /_cluster/health -p 9200 -w 2 -c 3 -s {{ nagios_health_color }}
57- service_description: "Verify the cluster health is green."
58+ check_name: check_health
59+ check_params: http://localhost:9200/_cluster/health {{ '--override-green ' + nagios_health_color if nagios_health_color and nagios_health_color != 'green' else '' }}
60+ service_description: "Verify the cluster health"
61
62 handlers:
63
64@@ -14,6 +14,20 @@
65 - service_name: "{{ local_unit.split('/')[0] }}"
66
67 tasks:
68+ - name: Install nrpe plugins
69+ tags:
70+ - install
71+ - upgrade-charm
72+ copy: src="{{ charm_dir }}/files/nrpe/" dest="/usr/lib/nagios/plugins" mode=0755
73+
74+ - name: Remove old http nrpe check
75+ tags:
76+ - upgrade-charm
77+ file: path={{ item.path }} state=absent
78+ with_items:
79+ - { path: "/etc/nagios/nrpe.d/check_http.cfg" }
80+ - { path: "/var/lib/nagios/export/service__{{ relations['nrpe-external-master'][0]['nagios_hostname'] }}_check_http.cfg" }
81+ when: '"nrpe-external-master" in relations and relations["nrpe-external-master"]|length > 0 and relations["nrpe-external-master"][0].nagios_hostname is defined'
82
83 - include: tasks/install-elasticsearch.yml
84 - include: tasks/peer-relations.yml

Subscribers

People subscribed via source and target branches