Whilst trying to learn how to write func modules I stumbled across nagios-check.py, which looks like it could use a little love. The attached patch gets it to work, cleans up some formatting, changes the name to nagios_check.py so you can import it easily to test, and allows for the use of configuration files to modify the nagios plugins path. I also changed the class name, there is already a newer Nagios class in the nagios.py module, and though this may not matter, I believe it can for the conf files that are created. Perhaps I don't understand the whole structure of things, but it looks to me like this could lead to a collision. -Erinn diff --git a/func/minion/modules/nagios_check.py b/func/minion/modules/nagios_check.py index c080e56..041e698 100644 --- a/func/minion/modules/nagios_check.py +++ b/func/minion/modules/nagios_check.py @@ -10,26 +10,34 @@ # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. """ -Abitrary command execution module for func. +Arbitrary command execution module for func. """ +from certmaster.config import BaseConfig, Option import func_module -import sub_process +from func.minion import sub_process -class Nagios(func_module.FuncModule): +class NagiosCheck(func_module.FuncModule): - version = "0.0.1" + version = "0.0.2" api_version = "0.0.1" - description = "Runs nagios checks." + description = "Runs Nagios checks." + + class Config(BaseConfig): + nagios_path = Option('/usr/lib/nagios/plugins') def run(self, check_command): """ - Runs a nagios check returning the return code, stdout, and stderr as a tuple. + Runs a Nagios check gathering the return code, stdout, and stderr + as a tuple. """ - nagios_path='/usr/lib/nagios/plugins' - command = '%s/%s' % (nagios_path, check_command) + command = '%s/%s' % (self.options.nagios_path, check_command) - cmdref = sub_process.Popen(command.split(),stdout=sub_process.PIPE,stderr=sub_process.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]) _______________________________________________ Func-list mailing list Func-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/func-list