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

Subscribers

People subscribed via source and target branches