Skip to content
Merged
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------
Expand Down
5 changes: 5 additions & 0 deletions contrib/linux/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
27 changes: 22 additions & 5 deletions contrib/linux/actions/dig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion contrib/linux/pack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ keywords:
- open ports
- processes
- ps
version : 1.0.1
version : 1.0.2
python_versions:
- "2"
- "3"
Expand Down