This is clean up work, much the same as was done on nagios-check, in fact almost exactly the same. I tested the module and it works, however, I would of course encourage someone else to test it. My plan here is to add SNMP v3 support in, and make the module a little more flexible, allowing the configuration of the snmpget command location etc. But that is to come. As always, let me know if there is something I can be doing to make this easier. -Erinn
>From d56f04ba46ef15fee04e458acc1515126b75871f Mon Sep 17 00:00:00 2001 From: Erinn Looney-Triggs <erinn.looneytriggs@xxxxxxxxx> Date: Mon, 3 Oct 2011 12:35:57 -0800 Subject: [PATCH 2/2] Cleaned up SNMP module with no functional changes. Cleaned syntax, changed sub_process import to subprocess to allow for future removal of sub_process. Bumped version number, fixed pep8 errors. --- func/minion/modules/snmp.py | 56 ++++++++++++++++++++++++++----------------- 1 files changed, 34 insertions(+), 22 deletions(-) diff --git a/func/minion/modules/snmp.py b/func/minion/modules/snmp.py index 594d915..0f2bec5 100644 --- a/func/minion/modules/snmp.py +++ b/func/minion/modules/snmp.py @@ -10,27 +10,38 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. """ -Abitrary command execution module for func. +Arbitrary command execution module for func. """ import func_module -from func.minion import sub_process +#Needed for compatibility with Python < 2.4 +try: + import subprocess +except ImportError: + from func.minion import sub_process as subprocess + base_snmp_command = '/usr/bin/snmpget -v2c -Ov -OQ' + class Snmp(func_module.FuncModule): - version = "0.0.1" + version = "0.0.2" api_version = "0.0.1" - description = "SNMP related calls through func." + description = "SNMP related calls through FUNC." def get(self, oid, rocommunity, hostname='localhost'): """ Runs an snmpget on a specific oid returns the output of the call. """ - command = '%s -c %s %s %s' % (base_snmp_command, rocommunity, hostname, oid) + command = '%s -c %s %s %s' % (base_snmp_command, rocommunity, + hostname, oid) + + cmdref = subprocess.Popen(command.split(), stdout=subprocess.PIPE, + stderr=subprocess.PIPE, shell=False, + close_fds=True) - cmdref = sub_process.Popen(command.split(), stdout=sub_process.PIPE, stderr=sub_process.PIPE, shell=False, close_fds=True) data = cmdref.communicate() + return (cmdref.returncode, data[0], data[1]) def register_method_args(self): @@ -39,26 +50,27 @@ class Snmp(func_module.FuncModule): """ return { - 'get':{ - 'args':{ - 'oid':{ - 'type':'string', - 'optional':False, - 'description':'The oid' + 'get': { + 'args': { + 'oid': { + 'type': 'string', + 'optional': False, + 'description': 'The OID' }, - 'rocommunity':{ - 'type':'string', - 'optional':False, - 'description':"The rocommunity" + 'rocommunity': { + 'type': 'string', + 'optional': False, + 'description': "The read only community string" }, - 'hostname':{ - 'type':'string', - 'optional':True, - 'default':'localhost', - 'description':"The hostname tobe apllied on" + 'hostname': { + 'type': 'string', + 'optional': True, + 'default': 'localhost', + 'description': "The host name to be applied on" } }, - 'description':"Runs an snmpget on a specific oid returns the output of the call" + 'description': ("Runs an snmpget on a specific oid " + "returns the output of the call") } } #def walk(self, oid, rocommunity): -- 1.7.6.4
_______________________________________________ Func-list mailing list Func-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/func-list