Merge ~dmzoneill/charm-hw-health:bug/1901735 into charm-hw-health:master

Proposed by David O Neill
Status: Rejected
Rejected by: Xav Paice
Proposed branch: ~dmzoneill/charm-hw-health:bug/1901735
Merge into: charm-hw-health:master
Diff against target: 213 lines (+100/-12)
5 files modified
src/README.md (+14/-0)
src/actions.yaml (+7/-0)
src/actions/ack-sel (+1/-0)
src/actions/actions.py (+69/-11)
src/lib/hwhealth/tools.py (+9/-1)
Reviewer Review Type Date Requested Status
James Troup (community) Needs Fixing
Review via email: mp+397487@code.launchpad.net
To post a comment you must log in.
Revision history for this message
James Troup (elmo) wrote :

Please use ISO 8601 format for the data, i.e. YYYY-MM-DD as that is universal and unambiguous

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

root@JFA1-0502-Compute-4:/home/ubuntu# ipmi-sel --help | grep date-range
      --date-range=MM/DD/YYYY-MM/DD/YYYY
      --exclude-date-range=MM/DD/YYYY-MM/DD/YYYY

Revision history for this message
Linda Guo (lihuiguo) wrote :

see the inline comments, needs to check if '--seloptions' already exists in cron job command line options.

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

Unmerged commits

3b2dfc2... by David O Neill

LP1901735 - data filtering

The ipmi-sel log can be filtered by date.
You must first acknowledge the previous ipmi sel entries by either specifying a date
or no date.
When specifying no date, that will default to the current date.

juju run-action hw-health/8 ack-sel --wait
juju run-action hw-health/8 ack-sel date=02/23/2019 --wait
juju run-action hw-health/8 show-sel --wait

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/src/README.md b/src/README.md
2index e367400..fdba28c 100644
3--- a/src/README.md
4+++ b/src/README.md
5@@ -54,6 +54,20 @@ zip /tmp/zipfile.zip megacli
6 etc.
7 ```
8
9+# Usage continued
10+
11+The ipmi-sel log can be filtered by date.
12+You must first acknowledge the previous ipmi sel entries by either specifying a date
13+or no date.
14+When specifying no date, that will default to the current date.
15+```
16+juju run-action hw-health/8 ack-sel --wait
17+# or
18+juju run-action hw-health/8 ack-sel date=02/23/2019 --wait
19+# view
20+juju run-action hw-health/8 show-sel --wait
21+```
22+
23 ## Known Limitations and Issues
24
25 Charm only install method is via Juju resources. There are plans to support
26diff --git a/src/actions.yaml b/src/actions.yaml
27index 2e691b8..dbc4553 100644
28--- a/src/actions.yaml
29+++ b/src/actions.yaml
30@@ -10,3 +10,10 @@ show-sel:
31 show-all:
32 type: boolean
33 description: Show all events, not just the non-nominal ones.
34+ack-sel:
35+ description: |
36+ Set date filter for ipmi-sel to filter out old logs from ongoing reports.
37+ params:
38+ date:
39+ type: string
40+ description: From what date to filter (default now if unspecified)
41diff --git a/src/actions/ack-sel b/src/actions/ack-sel
42new file mode 120000
43index 0000000..405a394
44--- /dev/null
45+++ b/src/actions/ack-sel
46@@ -0,0 +1 @@
47+actions.py
48\ No newline at end of file
49diff --git a/src/actions/actions.py b/src/actions/actions.py
50index 9a84c5f..e4b2b65 100755
51--- a/src/actions/actions.py
52+++ b/src/actions/actions.py
53@@ -14,13 +14,24 @@
54 # See the License for the specific language governing permissions and
55 # limitations under the License.
56 """Define hw-health charm actions."""
57-
58 import os
59 import subprocess
60 import sys
61+from datetime import datetime, timedelta
62+from traceback import format_exc
63+
64+# Load modules from $CHARM_DIR/lib
65+sys.path.append("lib")
66+
67+import charmhelpers.core.hookenv as hookenv # noqa: E402
68+import charmhelpers.core.unitdata as unitdata # noqa: E402
69
70-from charmhelpers.core.hookenv import action_fail, action_get, action_set, log
71+import charms.reactive # noqa: E402
72+from charms.layer import basic # noqa: E402
73+from charms.reactive.flags import clear_flag # noqa: E402
74
75+basic.bootstrap_charm_deps()
76+basic.init_config_states()
77
78 IPMI_SEL = "/usr/sbin/ipmi-sel"
79
80@@ -34,10 +45,10 @@ def clear_sel():
81 command = [IPMI_SEL, "--post-clear"]
82 try:
83 output = subprocess.check_output(command)
84- log("Action clear-sel completed, sel log cleared: {}".format(output))
85- action_set({"message": output.decode("UTF-8")})
86+ hookenv.log("Action clear-sel completed, sel log cleared: {}".format(output))
87+ hookenv.action_set({"message": output.decode("UTF-8")})
88 except subprocess.CalledProcessError as e:
89- action_fail("Action failed with {}".format(e))
90+ hookenv.action_fail("Action failed with {}".format(e))
91
92
93 def show_sel():
94@@ -46,8 +57,20 @@ def show_sel():
95 By default, this will show all non-nominal events.
96 If you specify show-all, it will show all events.
97 """
98- show_all = action_get("show-all")
99- command = [IPMI_SEL, "--output-event-state"]
100+ command = None
101+ show_all = hookenv.action_get("show-all")
102+ date_f = unitdata.kv().get("date_filter")
103+ if not date_f:
104+ command = [IPMI_SEL, "--output-event-state"]
105+ else:
106+ # if you ack-sel without specifying a date
107+ # the ack-sel default to now()
108+ # current date -> now is invalid date range
109+ # now -> tomorrow
110+ tomorrow = datetime.now() + timedelta(days=1)
111+ drange = str(date_f) + "-" + tomorrow.strftime("%m/%d/%Y")
112+ command = [IPMI_SEL, "--output-event-state", "--date-range", drange]
113+
114 try:
115 header, body = None, None
116 output = subprocess.check_output(command).decode("UTF-8")
117@@ -59,12 +82,36 @@ def show_sel():
118 body = [line for line in body if "Nominal" not in line]
119 if body:
120 final_output = "\n".join([header] + body)
121+ if date_f:
122+ final_output += "Has been date filtered: {}".format(date_f)
123 else:
124 final_output = "No matching entries found"
125- log("Action show-sel completed:\n{}".format(final_output))
126- action_set({"message": final_output})
127+ hookenv.log("Action show-sel completed:\n{}".format(final_output))
128+ hookenv.action_set({"message": final_output})
129 except subprocess.CalledProcessError as e:
130- action_fail("Action failed with {}".format(e))
131+ hookenv.action_fail("Action failed with {}".format(e))
132+
133+
134+def ack_sel():
135+ """Set the acknowledgement date filter."""
136+ clear_flag("hw-health.configured")
137+
138+ date_filter = hookenv.action_get("date")
139+ if not date_filter:
140+ unitdata.kv().set("date_filter", datetime.now().strftime("%m/%d/%Y"))
141+ unitdata.kv().flush()
142+ message = "Filtering from now: " + datetime.now().strftime("%m/%d/%Y")
143+ hookenv.action_set({"message": message})
144+ return
145+
146+ try:
147+ date_time_obj = datetime.strptime(date_filter, "%m/%d/%Y")
148+ unitdata.kv().set("date_filter", date_time_obj.strftime("%m/%d/%Y"))
149+ unitdata.kv().flush()
150+ message = "Filtering from now: " + date_time_obj.strftime("%m/%d/%Y")
151+ hookenv.action_set({"message": message})
152+ except ValueError:
153+ hookenv.action_fail("Action failed with date={} is invalid".format(date_filter))
154
155
156 # A dictionary of all the defined actions to callables (which take
157@@ -72,16 +119,27 @@ def show_sel():
158 ACTIONS = {
159 "clear-sel": clear_sel,
160 "show-sel": show_sel,
161+ "ack-sel": ack_sel,
162 }
163
164
165 def main(args):
166 """Define main subroutine."""
167 action_name = os.path.basename(args[0])
168+
169 try:
170 ACTIONS[action_name]()
171 except Exception as e:
172- action_fail(str(e))
173+ hookenv.action_fail(str(e))
174+ else:
175+ # try running handlers based on new state
176+ unitdata.kv().flush()
177+ try:
178+ charms.reactive.main()
179+ except Exception:
180+ exc = format_exc()
181+ hookenv.log(exc, hookenv.ERROR)
182+ hookenv.action_fail(exc.splitlines()[-1])
183
184
185 if __name__ == "__main__":
186diff --git a/src/lib/hwhealth/tools.py b/src/lib/hwhealth/tools.py
187index a3a92fa..ecc42ef 100644
188--- a/src/lib/hwhealth/tools.py
189+++ b/src/lib/hwhealth/tools.py
190@@ -14,7 +14,7 @@ from zipfile import BadZipFile, ZipFile
191
192 from charmhelpers import fetch
193 from charmhelpers.contrib.charmsupport import nrpe
194-from charmhelpers.core import hookenv
195+from charmhelpers.core import hookenv, unitdata
196 from charmhelpers.core.host import lsb_release, write_file
197 from charmhelpers.core.templating import render
198
199@@ -233,6 +233,14 @@ class Tool:
200 minutes=",".join(minutes_offsets), user=cron_user, cmd=" ".join(cmdline)
201 )
202
203+ db = unitdata.kv()
204+ if db.get("date_filter") and self._cron_script == "cron_ipmi_sensors.py":
205+ hookenv.log("Added date filter to ipmi sensors cmdline", hookenv.DEBUG)
206+ cronjob_line = cronjob_line.rstrip()
207+ cronjob_line += (
208+ ' --seloptions " --date-range ' + db.get("date_filter") + '-now"'
209+ )
210+
211 crond_file = os.path.join(self.CROND_DIR, "hwhealth_{}".format(self._shortname))
212 with open(crond_file, "w") as crond_fd:
213 crond_fd.write(cronjob_line)

Subscribers

People subscribed via source and target branches

to all changes: