Merge lp:~verterok/charms/trusty/logstash/logstash2_fix-e2e-cron into lp:~canonical-is-sa/charms/trusty/logstash/logstash2

Proposed by Guillermo Gonzalez
Status: Merged
Merged at revision: 61
Proposed branch: lp:~verterok/charms/trusty/logstash/logstash2_fix-e2e-cron
Merge into: lp:~canonical-is-sa/charms/trusty/logstash/logstash2
Diff against target: 75 lines (+12/-11)
2 files modified
files/nrpe/check_lumberjack_e2e.py (+10/-10)
templates/e2e-cron.tmpl (+2/-1)
To merge this branch: bzr merge lp:~verterok/charms/trusty/logstash/logstash2_fix-e2e-cron
Reviewer Review Type Date Requested Status
Chris Stratford (community) Approve
Review via email: mp+284609@code.launchpad.net

Commit message

Fix cron script: add new line and use run-this-one instead of run-one, to kill any previous stalled run.
Also, use python3 and add timeout for the ES http request in the lumberjack e2e script

Description of the change

Fix cron script: add new line and use run-this-one instead of run-one, to kill any previous stalled run.
Also, use python3 and add timeout for the ES http request in the lumberjack e2e script

To post a comment you must log in.
Revision history for this message
Chris Stratford (chris-gondolin) wrote :

approve

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'files/nrpe/check_lumberjack_e2e.py'
2--- files/nrpe/check_lumberjack_e2e.py 2016-01-22 21:34:37 +0000
3+++ files/nrpe/check_lumberjack_e2e.py 2016-02-01 13:59:37 +0000
4@@ -1,12 +1,9 @@
5-#!/usr/bin/env python2
6+#!/usr/bin/env python3
7 """
8 This is very simple lumbjerjack client to run a e2e check against logstash+elasticsearch.
9
10 All the lumberjack protocol code was adapted from Matt Johnson: https://pypi.python.org/pypi/stashward/0.1.4
11 """
12-from __future__ import unicode_literals
13-from __future__ import print_function
14-from __future__ import division
15
16 import traceback
17 import datetime
18@@ -14,13 +11,12 @@
19 import errno
20 import socket
21 import sys
22-import urllib
23+import urllib.request
24 import json
25 import time
26 import uuid
27 import random
28
29-
30 from logging import INFO
31
32 from ssl import wrap_socket, CERT_NONE, CERT_REQUIRED, SSLError
33@@ -215,11 +211,13 @@
34 while not ok or elapsed >= args.critical:
35 es_host = es_hosts[random.randint(0, len(es_hosts)-1)]
36 try:
37- resp = urllib.urlopen("http://%s/%s/_search?size=1" % (es_host, index), data=json.dumps(get_body))
38- except Exception, e:
39+ resp = urllib.request.urlopen("http://%s/%s/_search?size=1" % (es_host, index),
40+ data=json.dumps(get_body).encode('utf-8'),
41+ timeout=args.es_timeout)
42+ except Exception as e:
43 print("Elasticsearch unreachable: %s" % str(e))
44 return 2
45- results = json.loads(resp.read())
46+ results = json.loads(resp.read().decode('utf-8'))
47 elapsed = time.time()-ts
48 for result in results['hits']['hits']:
49 if 'request_id' in result['_source'] and req_id == result['_source']['request_id']:
50@@ -252,12 +250,14 @@
51 parser.add_argument('--es', dest="es_host_port", required=True,
52 help="Comma separated list of elasticsearch " + \
53 "host:port, e.g: host:port,host1:port1..")
54+ parser.add_argument('-t', dest="es_timeout", type=int, default=5,
55+ help="timeout for ES http request")
56 parser.add_argument('-f', dest="e2e_file", required=True,
57 help="path to the output file")
58 args = parser.parse_args()
59 try:
60 sys.exit(main(args))
61- except Exception, e:
62+ except Exception as e:
63 with open(args.e2e_file, 'w') as fd:
64 fd.write("ERROR: Unhandled error: %s\n" % (str(e),))
65 fd.flush()
66
67=== modified file 'templates/e2e-cron.tmpl'
68--- templates/e2e-cron.tmpl 2016-01-25 13:09:45 +0000
69+++ templates/e2e-cron.tmpl 2016-02-01 13:59:37 +0000
70@@ -1,3 +1,4 @@
71 # Cron job to run e2e check
72 MAILTO=""
73-{{ cron_expression }} nagios run-one python {{ charm_dir }}/files/nrpe/check_lumberjack_e2e.py --es {{ es_ips }} -f {{ e2e_file }} {{ e2e_params }}
74+{{ cron_expression }} nagios run-this-one python3 {{ charm_dir }}/files/nrpe/check_lumberjack_e2e.py --es {{ es_ips }} -f {{ e2e_file }} {{ e2e_params }}
75+

Subscribers

People subscribed via source and target branches