diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 55a1d244a3..ea0944760e 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -21,6 +21,8 @@ Fixed 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 --------------------- 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/actions/dig.py b/contrib/linux/actions/dig.py index e83282bc20..ccf7e9a318 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 @@ -39,11 +41,26 @@ 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')) + + # NOTE: Python3 supports the FileNotFoundError, the errono.ENOENT is for py2 compat + # for Python3: + # except FileNotFoundError as e: + + except OSError as e: + if e.errno == errno.ENOENT: + 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 + if int(count) > len(result_list) or count <= 0: count = len(result_list) 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"