Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix linux pack actions For CentOS 8 #5035

Merged
merged 17 commits into from
Apr 2, 2022
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ Fixed
* Fixed a regression in the ``linux.dig`` action on Python 3. (bug fix) #4993

Contributed by @blag
* Fix actions from the contrib/linux pack that fail on CentOS-8 but work on other operating systems and distributions.

Reported by @blag and contributed by winem (bug fix) #4999
arm4b marked this conversation as resolved.
Show resolved Hide resolved

Removed
~~~~~~~
Expand Down
3 changes: 2 additions & 1 deletion contrib/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,5 @@ Example trigger payload:

## Troubleshooting

* On CentOS7/RHEL7, dig is not installed by default. Run ``sudo yum install bind-utils`` to install.
* On CentOS7/RHEL7, dig is not installed by default. Run ``sudo yum install bind-utils`` to install.
* On CentOS8/RHEL8, lsof is not installed by default. Run ``sudo yum install lsof`` to install.
2 changes: 1 addition & 1 deletion contrib/linux/actions/checks/check_loadavg.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2

# Copyright 2020 The StackStorm Authors.
# Copyright 2019 Extreme Networks, Inc.
Expand Down
2 changes: 1 addition & 1 deletion contrib/linux/actions/checks/check_processes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python2
winem marked this conversation as resolved.
Show resolved Hide resolved

# Copyright 2020 The StackStorm Authors.
# Copyright 2019 Extreme Networks, Inc.
Expand Down
6 changes: 1 addition & 5 deletions contrib/linux/actions/workflows/diag_loadavg.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
hosts: "{{hostname}}"
period: "all"
on-success: "d_state_processes"
on-failure: "email_escalation"
-
name: "d_state_processes"
ref: "linux.check_processes"
Expand All @@ -17,7 +16,6 @@
criteria: "D"
args: "pidlist"
on-success: "r_state_processes"
on-failure: "email_escalation"
-
name: "r_state_processes"
ref: "linux.check_processes"
Expand All @@ -27,15 +25,13 @@
criteria: "R"
args: "pidlist"
on-success: "netstat"
on-failure: "email_escalation"
-
name: "netstat"
ref: "linux.netstat_grep"
parameters:
hosts: "{{hostname}}"
pids: "{{d_state_processes[hostname].stderr}} {{r_state_processes[hostname].stderr}}"
on-success: "lsof"
on-failure: "email_escalation"
-
name: "lsof"
ref: "linux.lsof_pids"
Expand All @@ -47,5 +43,5 @@
name: "dump_results"
ref: "core.local"
parameters:
cmd: "echo \"ST2 Workflow\tdiag_loadavg:\t{{__results}}\" >> /tmp/diag_loadavg && echo 'Output written to file /tmp/diag_loadavg'"
cmd: "echo \"{{__results}}\" | python2 -c \"import json; import sys; from datetime import datetime; diag_data=eval(sys.stdin.read()); diag_data['timestamp'] = str(datetime.now()); print(json.dumps(diag_data))\" >> /tmp/diag_loadavg.json && echo 'Output written to file /tmp/diag_loadavg.json'"
Copy link
Member

@arm4b arm4b Sep 22, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is the only place with the hardcoded python2 now.
Is it possible to do something with that so we don't rely on a specific version?

Besides of that, looks good.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, any reason why we need to use python2 here? I believe that line should also work fine with Python 3 (aka just using python system binary - should work if it's either python 2 or python 3).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wonder if there is a better way which doesn't rely on eval() which can be unsafe, especially in this context when we are passing 3rd party data to it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see any issues regarding py3 and it should work as well (I can put that on my list again).

Let's also tackle the eval. The safe alternative without a bunch of JSON processing on stdin is ast.literal_eval: https://docs.python.org/3/library/ast.html#ast.literal_eval

Would this be fine for everyone? Last resort would be some manual parsing & processing with the JSON library.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ast.literal_eval is awesome (and quite safe)! go for it.

This comment was marked as outdated.

default: "check_load"