From 55b4973f930062312c06a0b098e2ae54ccfa2c4e Mon Sep 17 00:00:00 2001 From: punkrokk Date: Sun, 30 Jun 2019 18:35:26 -0400 Subject: [PATCH 1/7] Add exception handler to dig.py to improve error if dig is not installed. Update readme. Bump pack version. --- contrib/linux/actions/dig.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py index e83282bc20..bb89086250 100644 --- a/contrib/linux/actions/dig.py +++ b/contrib/linux/actions/dig.py @@ -39,11 +39,17 @@ def run(self, rand, count, nameserver, hostname, queryopts): cmd_args.append('+' + v) cmd_args.append(hostname) - result_list = filter(None, subprocess.Popen(cmd_args, - stderr=subprocess.PIPE, - stdout=subprocess.PIPE) - .communicate()[0] - .split('\n')) + + try: + result_list = filter(None, subprocess.Popen(cmd_args, + stderr=subprocess.PIPE, + stdout=subprocess.PIPE) + .communicate()[0] + .split('\n')) + except OSError as e: + return False, "Can\'t find dig installed in our path (Usually /usr/bin/dig). Is dig installed? \n" + \ + "Exception: OSError: " + str(e) + if int(count) > len(result_list) or count <= 0: count = len(result_list) From 13388716329c1028a7e627c444c84320824fdf8d Mon Sep 17 00:00:00 2001 From: punkrokk Date: Sun, 30 Jun 2019 18:35:38 -0400 Subject: [PATCH 2/7] Add exception handler to dig.py to improve error if dig is not installed. Update readme. Bump pack version. --- contrib/linux/README.md | 5 +++++ contrib/linux/pack.yaml | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/contrib/linux/README.md b/contrib/linux/README.md index c34bbc2b47..33d872cf86 100644 --- a/contrib/linux/README.md +++ b/contrib/linux/README.md @@ -51,3 +51,8 @@ Example trigger payload: * ``check_loadavg`` - Action which retrieves load average from a remote host. * ``check_processes`` - Action which retrieves useful information about matching process on a remote host. +* ``dig`` - Python wrapper for dig command. Requires ``bind-utils`` rpm or ``dnsutils`` deb installed. + +## Troubleshooting + +* On CentOS7/RHEL7, dig is not installed by default. Run ``sudo yum install bind-utils`` to install. \ No newline at end of file diff --git a/contrib/linux/pack.yaml b/contrib/linux/pack.yaml index b3f7a42136..1012832fd3 100644 --- a/contrib/linux/pack.yaml +++ b/contrib/linux/pack.yaml @@ -16,7 +16,7 @@ keywords: - open ports - processes - ps -version : 1.0.1 +version : 1.0.2 python_versions: - "2" - "3" From e7a63fd660af53fc8dddd16744ccfea5cdd740de Mon Sep 17 00:00:00 2001 From: punkrokk Date: Mon, 1 Jul 2019 20:01:54 -0400 Subject: [PATCH 3/7] Linting fixes --- contrib/linux/actions/dig.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py index bb89086250..149614e428 100644 --- a/contrib/linux/actions/dig.py +++ b/contrib/linux/actions/dig.py @@ -47,8 +47,8 @@ def run(self, rand, count, nameserver, hostname, queryopts): .communicate()[0] .split('\n')) except OSError as e: - return False, "Can\'t find dig installed in our path (Usually /usr/bin/dig). Is dig installed? \n" + \ - "Exception: OSError: " + str(e) + return False, "Can\'t find dig installed in our path (Usually /usr/bin/dig). " \ + "Is dig installed? \n" + "Exception: OSError: " + str(e) if int(count) > len(result_list) or count <= 0: count = len(result_list) From edcdb2f914fde36d476363aeba481f4838b5fe6e Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Tue, 9 Jul 2019 23:52:27 -0400 Subject: [PATCH 4/7] changed OSError to ENOENT (FileNotFoundError) to support py2/3 and added a NOTE to revisit once py3 only. --- contrib/linux/actions/dig.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py index 149614e428..79095942ba 100644 --- a/contrib/linux/actions/dig.py +++ b/contrib/linux/actions/dig.py @@ -14,9 +14,11 @@ # See the License for the specific language governing permissions and # limitations under the License. +import errno import subprocess import random import re + from st2common.runners.base_action import Action @@ -46,9 +48,17 @@ def run(self, rand, count, nameserver, hostname, queryopts): stdout=subprocess.PIPE) .communicate()[0] .split('\n')) + + # NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat + # for Python3: + # except FileNotFoundError as e: + except OSError as e: - return False, "Can\'t find dig installed in our path (Usually /usr/bin/dig). " \ - "Is dig installed? \n" + "Exception: OSError: " + str(e) + if e.errno == errno.ENOENT: + return False, "Can\'t find dig installed in our path (Usually /usr/bin/dig). " \ + "Is dig installed? \n" + "Exception: OSError: " + str(e) + else: + raise e if int(count) > len(result_list) or count <= 0: count = len(result_list) From b0ce8e3a82b56f43077629cb07f25f18f2778c91 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Tue, 23 Jul 2019 14:42:13 -0400 Subject: [PATCH 5/7] changelog and error message fix --- CHANGELOG.rst | 15 ++++++++++++++- contrib/linux/actions/dig.py | 5 +++-- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 5337eb1ea3..7ee8e6b33f 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -4,6 +4,19 @@ Changelog in development -------------- +Fixed +~~~~~ + +* Fixed logging middleware to output a ``content_length`` of ``0`` instead of ``Infinity`` + when the type of data being returned is not supported. Previously, when the value was + set to ``Infinity`` this would result in invalid JSON being output into structured + logs. (bug fix) #4722 + + Contributed by Nick Maludy (@nmaludy Encore Technologies) +* Fix the workflow execution cancelation to proceed even if the workflow execution is not found or + completed. (bug fix) #4735 +* Added better error handling to `contrib/linux/actions/dig.py` to inform if dig is not installed. + Contributed by JP Bourget (@punkrokk Syncurity) #4732 3.1.0 - June 27, 2019 --------------------- @@ -3247,4 +3260,4 @@ v0.5.1 - November 3rd, 2014 Added ~~~~~ -* Initial public release +* Initial public release \ No newline at end of file diff --git a/contrib/linux/actions/dig.py b/contrib/linux/actions/dig.py index 79095942ba..ccf7e9a318 100644 --- a/contrib/linux/actions/dig.py +++ b/contrib/linux/actions/dig.py @@ -55,8 +55,9 @@ def run(self, rand, count, nameserver, hostname, queryopts): except OSError as e: if e.errno == errno.ENOENT: - return False, "Can\'t find dig installed in our path (Usually /usr/bin/dig). " \ - "Is dig installed? \n" + "Exception: OSError: " + str(e) + return False, "Can't find dig installed in the path (usually /usr/bin/dig). If " \ + "dig isn't installed, you can install it with 'sudo yum install " \ + "bind-utils' or 'sudo apt install dnsutils'" else: raise e From fe76f8c742e71d240d22678b801dce7efd15604b Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Tue, 23 Jul 2019 15:36:21 -0400 Subject: [PATCH 6/7] Update CHANGELOG.rst --- CHANGELOG.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7ee8e6b33f..fe5a3687e0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3259,5 +3259,4 @@ v0.5.1 - November 3rd, 2014 Added ~~~~~ - -* Initial public release \ No newline at end of file +* Initial public release From 1facce4f02367ff5a742bd01e9773ea1b9af48e6 Mon Sep 17 00:00:00 2001 From: JP Bourget Date: Tue, 23 Jul 2019 15:37:08 -0400 Subject: [PATCH 7/7] Update CHANGELOG.rst --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index fe5a3687e0..8d23479cf0 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -3259,4 +3259,5 @@ v0.5.1 - November 3rd, 2014 Added ~~~~~ + * Initial public release