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
diff --git a/src/README.md b/src/README.md
index e367400..fdba28c 100644
--- a/src/README.md
+++ b/src/README.md
@@ -54,6 +54,20 @@ zip /tmp/zipfile.zip megacli
54etc.54etc.
55```55```
5656
57# Usage continued
58
59The ipmi-sel log can be filtered by date.
60You must first acknowledge the previous ipmi sel entries by either specifying a date
61or no date.
62When specifying no date, that will default to the current date.
63```
64juju run-action hw-health/8 ack-sel --wait
65# or
66juju run-action hw-health/8 ack-sel date=02/23/2019 --wait
67# view
68juju run-action hw-health/8 show-sel --wait
69```
70
57## Known Limitations and Issues71## Known Limitations and Issues
5872
59Charm only install method is via Juju resources. There are plans to support73Charm only install method is via Juju resources. There are plans to support
diff --git a/src/actions.yaml b/src/actions.yaml
index 2e691b8..dbc4553 100644
--- a/src/actions.yaml
+++ b/src/actions.yaml
@@ -10,3 +10,10 @@ show-sel:
10 show-all:10 show-all:
11 type: boolean11 type: boolean
12 description: Show all events, not just the non-nominal ones.12 description: Show all events, not just the non-nominal ones.
13ack-sel:
14 description: |
15 Set date filter for ipmi-sel to filter out old logs from ongoing reports.
16 params:
17 date:
18 type: string
19 description: From what date to filter (default now if unspecified)
diff --git a/src/actions/ack-sel b/src/actions/ack-sel
13new file mode 12000020new file mode 120000
index 0000000..405a394
--- /dev/null
+++ b/src/actions/ack-sel
@@ -0,0 +1 @@
1actions.py
0\ No newline at end of file2\ No newline at end of file
diff --git a/src/actions/actions.py b/src/actions/actions.py
index 9a84c5f..e4b2b65 100755
--- a/src/actions/actions.py
+++ b/src/actions/actions.py
@@ -14,13 +14,24 @@
14# See the License for the specific language governing permissions and14# See the License for the specific language governing permissions and
15# limitations under the License.15# limitations under the License.
16"""Define hw-health charm actions."""16"""Define hw-health charm actions."""
17
18import os17import os
19import subprocess18import subprocess
20import sys19import sys
20from datetime import datetime, timedelta
21from traceback import format_exc
22
23# Load modules from $CHARM_DIR/lib
24sys.path.append("lib")
25
26import charmhelpers.core.hookenv as hookenv # noqa: E402
27import charmhelpers.core.unitdata as unitdata # noqa: E402
2128
22from charmhelpers.core.hookenv import action_fail, action_get, action_set, log29import charms.reactive # noqa: E402
30from charms.layer import basic # noqa: E402
31from charms.reactive.flags import clear_flag # noqa: E402
2332
33basic.bootstrap_charm_deps()
34basic.init_config_states()
2435
25IPMI_SEL = "/usr/sbin/ipmi-sel"36IPMI_SEL = "/usr/sbin/ipmi-sel"
2637
@@ -34,10 +45,10 @@ def clear_sel():
34 command = [IPMI_SEL, "--post-clear"]45 command = [IPMI_SEL, "--post-clear"]
35 try:46 try:
36 output = subprocess.check_output(command)47 output = subprocess.check_output(command)
37 log("Action clear-sel completed, sel log cleared: {}".format(output))48 hookenv.log("Action clear-sel completed, sel log cleared: {}".format(output))
38 action_set({"message": output.decode("UTF-8")})49 hookenv.action_set({"message": output.decode("UTF-8")})
39 except subprocess.CalledProcessError as e:50 except subprocess.CalledProcessError as e:
40 action_fail("Action failed with {}".format(e))51 hookenv.action_fail("Action failed with {}".format(e))
4152
4253
43def show_sel():54def show_sel():
@@ -46,8 +57,20 @@ def show_sel():
46 By default, this will show all non-nominal events.57 By default, this will show all non-nominal events.
47 If you specify show-all, it will show all events.58 If you specify show-all, it will show all events.
48 """59 """
49 show_all = action_get("show-all")60 command = None
50 command = [IPMI_SEL, "--output-event-state"]61 show_all = hookenv.action_get("show-all")
62 date_f = unitdata.kv().get("date_filter")
63 if not date_f:
64 command = [IPMI_SEL, "--output-event-state"]
65 else:
66 # if you ack-sel without specifying a date
67 # the ack-sel default to now()
68 # current date -> now is invalid date range
69 # now -> tomorrow
70 tomorrow = datetime.now() + timedelta(days=1)
71 drange = str(date_f) + "-" + tomorrow.strftime("%m/%d/%Y")
72 command = [IPMI_SEL, "--output-event-state", "--date-range", drange]
73
51 try:74 try:
52 header, body = None, None75 header, body = None, None
53 output = subprocess.check_output(command).decode("UTF-8")76 output = subprocess.check_output(command).decode("UTF-8")
@@ -59,12 +82,36 @@ def show_sel():
59 body = [line for line in body if "Nominal" not in line]82 body = [line for line in body if "Nominal" not in line]
60 if body:83 if body:
61 final_output = "\n".join([header] + body)84 final_output = "\n".join([header] + body)
85 if date_f:
86 final_output += "Has been date filtered: {}".format(date_f)
62 else:87 else:
63 final_output = "No matching entries found"88 final_output = "No matching entries found"
64 log("Action show-sel completed:\n{}".format(final_output))89 hookenv.log("Action show-sel completed:\n{}".format(final_output))
65 action_set({"message": final_output})90 hookenv.action_set({"message": final_output})
66 except subprocess.CalledProcessError as e:91 except subprocess.CalledProcessError as e:
67 action_fail("Action failed with {}".format(e))92 hookenv.action_fail("Action failed with {}".format(e))
93
94
95def ack_sel():
96 """Set the acknowledgement date filter."""
97 clear_flag("hw-health.configured")
98
99 date_filter = hookenv.action_get("date")
100 if not date_filter:
101 unitdata.kv().set("date_filter", datetime.now().strftime("%m/%d/%Y"))
102 unitdata.kv().flush()
103 message = "Filtering from now: " + datetime.now().strftime("%m/%d/%Y")
104 hookenv.action_set({"message": message})
105 return
106
107 try:
108 date_time_obj = datetime.strptime(date_filter, "%m/%d/%Y")
109 unitdata.kv().set("date_filter", date_time_obj.strftime("%m/%d/%Y"))
110 unitdata.kv().flush()
111 message = "Filtering from now: " + date_time_obj.strftime("%m/%d/%Y")
112 hookenv.action_set({"message": message})
113 except ValueError:
114 hookenv.action_fail("Action failed with date={} is invalid".format(date_filter))
68115
69116
70# A dictionary of all the defined actions to callables (which take117# A dictionary of all the defined actions to callables (which take
@@ -72,16 +119,27 @@ def show_sel():
72ACTIONS = {119ACTIONS = {
73 "clear-sel": clear_sel,120 "clear-sel": clear_sel,
74 "show-sel": show_sel,121 "show-sel": show_sel,
122 "ack-sel": ack_sel,
75}123}
76124
77125
78def main(args):126def main(args):
79 """Define main subroutine."""127 """Define main subroutine."""
80 action_name = os.path.basename(args[0])128 action_name = os.path.basename(args[0])
129
81 try:130 try:
82 ACTIONS[action_name]()131 ACTIONS[action_name]()
83 except Exception as e:132 except Exception as e:
84 action_fail(str(e))133 hookenv.action_fail(str(e))
134 else:
135 # try running handlers based on new state
136 unitdata.kv().flush()
137 try:
138 charms.reactive.main()
139 except Exception:
140 exc = format_exc()
141 hookenv.log(exc, hookenv.ERROR)
142 hookenv.action_fail(exc.splitlines()[-1])
85143
86144
87if __name__ == "__main__":145if __name__ == "__main__":
diff --git a/src/lib/hwhealth/tools.py b/src/lib/hwhealth/tools.py
index a3a92fa..ecc42ef 100644
--- a/src/lib/hwhealth/tools.py
+++ b/src/lib/hwhealth/tools.py
@@ -14,7 +14,7 @@ from zipfile import BadZipFile, ZipFile
1414
15from charmhelpers import fetch15from charmhelpers import fetch
16from charmhelpers.contrib.charmsupport import nrpe16from charmhelpers.contrib.charmsupport import nrpe
17from charmhelpers.core import hookenv17from charmhelpers.core import hookenv, unitdata
18from charmhelpers.core.host import lsb_release, write_file18from charmhelpers.core.host import lsb_release, write_file
19from charmhelpers.core.templating import render19from charmhelpers.core.templating import render
2020
@@ -233,6 +233,14 @@ class Tool:
233 minutes=",".join(minutes_offsets), user=cron_user, cmd=" ".join(cmdline)233 minutes=",".join(minutes_offsets), user=cron_user, cmd=" ".join(cmdline)
234 )234 )
235235
236 db = unitdata.kv()
237 if db.get("date_filter") and self._cron_script == "cron_ipmi_sensors.py":
238 hookenv.log("Added date filter to ipmi sensors cmdline", hookenv.DEBUG)
239 cronjob_line = cronjob_line.rstrip()
240 cronjob_line += (
241 ' --seloptions " --date-range ' + db.get("date_filter") + '-now"'
242 )
243
236 crond_file = os.path.join(self.CROND_DIR, "hwhealth_{}".format(self._shortname))244 crond_file = os.path.join(self.CROND_DIR, "hwhealth_{}".format(self._shortname))
237 with open(crond_file, "w") as crond_fd:245 with open(crond_file, "w") as crond_fd:
238 crond_fd.write(cronjob_line)246 crond_fd.write(cronjob_line)

Subscribers

People subscribed via source and target branches

to all changes: