Merge ~peppepetra/charm-graylog:lp1805043 into ~graylog-charmers/charm-graylog:master

Proposed by Giuseppe Petralia
Status: Merged
Approved by: Xav Paice
Approved revision: c2f2554f9c9aa472819da2d0187e713feb54d7cc
Merge reported by: Xav Paice
Merged at revision: c2f2554f9c9aa472819da2d0187e713feb54d7cc
Proposed branch: ~peppepetra/charm-graylog:lp1805043
Merge into: ~graylog-charmers/charm-graylog:master
Diff against target: 114 lines (+35/-2)
5 files modified
actions.yaml (+4/-0)
actions/actions.py (+10/-0)
actions/ignore-indexer-failures (+1/-0)
files/check_graylog_health.py (+16/-2)
lib/charms/layer/graylog/api.py (+4/-0)
Reviewer Review Type Date Requested Status
Xav Paice (community) Approve
Jeremy Lounder Pending
Canonical IS Reviewers Pending
Review via email: mp+378329@code.launchpad.net

Commit message

Add ignore-indexer-failures action

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
Zachary Zehring (zzehring) wrote :

Added comments.

~peppepetra/charm-graylog:lp1805043 updated
83b85b0... by Giuseppe Petralia

Address review comments:

- use with open(file) instead of f = open()
- improve action descritpion and comments
- refactor variable names to be more explicit

Revision history for this message
Xav Paice (xavpaice) wrote :

This change fails lint with ./actions/actions.py:20:1: E402 module level import not at top of file

Unfortunately the coverage for unit tests doesn't include a lot of the files touched in this change, but fwiw, they pass OK.

review: Needs Fixing
~peppepetra/charm-graylog:lp1805043 updated
c2f2554... by Giuseppe Petralia

Fix linting

Revision history for this message
Xav Paice (xavpaice) wrote :

Tests work OK, LGTM

review: Approve

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
index 7528e95..c8d6f78 100644
--- a/actions.yaml
+++ b/actions.yaml
@@ -9,3 +9,7 @@ set-admin-password:
9 type: string9 type: string
10 required:10 required:
11 - password11 - password
12ignore-indexer-failures:
13 description: |
14 From NRPE check viewpoint, ignore all indexer failures that have occurred before the action is run.
15 Future indexer failure occurrences will still be checked.
diff --git a/actions/actions.py b/actions/actions.py
index eed1233..5b9808d 100755
--- a/actions/actions.py
+++ b/actions/actions.py
@@ -1,5 +1,6 @@
1#!/usr/local/sbin/charm-env python31#!/usr/local/sbin/charm-env python3
22
3import datetime
3import os4import os
4import sys5import sys
5import traceback6import traceback
@@ -16,6 +17,8 @@ if libs_dir not in sys.path:
16from charms import reactive # noqa E40217from charms import reactive # noqa E402
17from charmhelpers.core import hookenv, host, unitdata # noqa E40218from charmhelpers.core import hookenv, host, unitdata # noqa E402
1819
20from charms.layer.graylog.api import get_ignore_indexer_failures_file # noqa E402
21
1922
20def reactive_remove_state(state):23def reactive_remove_state(state):
21 reactive.remove_state(state)24 reactive.remove_state(state)
@@ -49,6 +52,11 @@ def set_admin_passwd(admin_password=None):
49 reactive_remove_state('graylog.configured')52 reactive_remove_state('graylog.configured')
5053
5154
55def ignore_indexer_failures():
56 with open(get_ignore_indexer_failures_file(), 'w') as f:
57 f.write(datetime.datetime.utcnow().isoformat())
58
59
52def main(argv):60def main(argv):
53 action = os.path.basename(argv[0])61 action = os.path.basename(argv[0])
54 params = hookenv.action_get()62 params = hookenv.action_get()
@@ -57,6 +65,8 @@ def main(argv):
57 get_admin_passwd()65 get_admin_passwd()
58 elif action == 'set-admin-password':66 elif action == 'set-admin-password':
59 set_admin_passwd(params['password'])67 set_admin_passwd(params['password'])
68 elif action == 'ignore-indexer-failures':
69 ignore_indexer_failures()
60 else:70 else:
61 hookenv.action_fail('Action {} not implemented'.format(action))71 hookenv.action_fail('Action {} not implemented'.format(action))
62 except Exception:72 except Exception:
diff --git a/actions/ignore-indexer-failures b/actions/ignore-indexer-failures
63new file mode 12000073new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/actions/ignore-indexer-failures
@@ -0,0 +1 @@
1actions.py
0\ No newline at end of file2\ No newline at end of file
diff --git a/files/check_graylog_health.py b/files/check_graylog_health.py
index 7fde420..2cbb597 100755
--- a/files/check_graylog_health.py
+++ b/files/check_graylog_health.py
@@ -13,10 +13,10 @@ if libs_dir not in sys.path:
1313
14try:14try:
15 # api will be under $CHARM_SOURCE_DIR/lib during unit tests15 # api will be under $CHARM_SOURCE_DIR/lib during unit tests
16 from charms.layer.graylog.api import GraylogApi16 from charms.layer.graylog.api import GraylogApi, get_ignore_indexer_failures_file
17except ImportError:17except ImportError:
18 # api will be under $NAGIOS_PLUGIN_DIR at runtime18 # api will be under $NAGIOS_PLUGIN_DIR at runtime
19 from api import GraylogApi19 from api import GraylogApi, get_ignore_indexer_failures_file
2020
21STATE_OK = 021STATE_OK = 0
22STATE_WARNING = 122STATE_WARNING = 1
@@ -87,6 +87,20 @@ def outstanding_notifications(gapi_con, args):
8787
88def indexer_failures(gapi_con, args):88def indexer_failures(gapi_con, args):
89 since = datetime.datetime.utcnow() - datetime.timedelta(days=1)89 since = datetime.datetime.utcnow() - datetime.timedelta(days=1)
90
91 # the variable "since" is equal to now() - 1 day or to ignore_indexer_failures action timestamp
92 # if ignore_indexer_failures action timestamp is more recent than 1 day.
93 try:
94 with open(get_ignore_indexer_failures_file(), 'r') as f:
95 file_content = f.read()
96 ignore_indexer_failures_since = datetime.datetime.strptime(file_content.strip(), "%Y-%m-%dT%H:%M:%S.%f")
97
98 if ignore_indexer_failures_since > since:
99 since = ignore_indexer_failures_since
100 except (FileNotFoundError, ValueError):
101 # Ignore actioned_since if file not exists or not contains valid ISO date
102 pass
103
90 failures = gapi_con.indexer_failures_count(since.isoformat())['count']104 failures = gapi_con.indexer_failures_count(since.isoformat())['count']
91 msg = 'Indexer failures: {}'.format(failures)105 msg = 'Indexer failures: {}'.format(failures)
92 if failures == 0:106 if failures == 0:
diff --git a/lib/charms/layer/graylog/api.py b/lib/charms/layer/graylog/api.py
index 87ded7f..b38c2cc 100644
--- a/lib/charms/layer/graylog/api.py
+++ b/lib/charms/layer/graylog/api.py
@@ -20,6 +20,10 @@ else:
20 charm = False20 charm = False
2121
2222
23def get_ignore_indexer_failures_file():
24 return "/usr/local/lib/nagios/plugins/ignore_indexer_failures.timestamp"
25
26
23class GraylogApi:27class GraylogApi:
2428
25 def __init__(self, base_url, username, password, token_name='graylog-api'):29 def __init__(self, base_url, username, password, token_name='graylog-api'):

Subscribers

People subscribed via source and target branches