def test_prepend_search_path(self): log.info("Testing Prepending a path to the search path.") tmpdir = tempfile.mkdtemp() try: tdir_real = os.path.realpath(tmpdir) tdir_rel = os.path.relpath(tmpdir) log.debug("Using %r for prepending to search path.", tdir_rel) plugin = ExtNagiosPlugin( usage = '%(prog)s --hello', url = 'http://www.profitbricks.com', blurb = 'Senseless sample Nagios plugin.', licence = 'Licence: GNU Lesser General Public License (LGPL), Version 3', extra = 'Bla blub', verbose = self.verbose, prepend_searchpath = tdir_rel, ) if self.verbose > 1: log.debug("ExtNagiosPlugin object: %r", plugin) log.debug("ExtNagiosPlugin object: %s", str(plugin)) log.debug("Got as first search path: %r", plugin.search_path[0]) self.assertEqual(tdir_real, plugin.search_path[0]) finally: os.rmdir(tmpdir)
def test_plugin_object(self): log.info("Testing ExtNagiosPlugin object.") plugin = ExtNagiosPlugin( usage = '%(prog)s --hello', url = 'http://www.profitbricks.com', blurb = 'Senseless sample Nagios plugin.', licence = 'Licence: GNU Lesser General Public License (LGPL), Version 3', extra = 'Bla blub', verbose = self.verbose, ) plugin.add_perfdata('bla', 10, 'MByte', warning = '20', critical = '30') plugin.set_thresholds(warning = '10:25', critical = "~:25") plugin.add_message(nagios.state.ok, 'bli', 'bla') plugin.add_message('warning', 'blub') log.debug("ExtNagiosPlugin object: %r", plugin) log.debug("ExtNagiosPlugin object: %s", str(plugin))
def test_get_command(self): log.info("Testing method get_command() of ExtNagiosPlugin ...") plugin = ExtNagiosPlugin( usage = '%(prog)s --hello', url = 'http://www.profitbricks.com', blurb = 'Senseless sample Nagios plugin.', licence = 'Licence: GNU Lesser General Public License (LGPL), Version 3', extra = 'Bla blub', verbose = self.verbose, ) if self.verbose > 2: log.debug("ExtNagiosPlugin object: %r", plugin) log.debug("ExtNagiosPlugin object: %s", str(plugin)) log.debug("Testing for (obviously) existing command 'ls' ...") cmd = plugin.get_command('ls') log.debug("Got 'ls' command: %r", cmd) self.assertNotEqual(cmd, '') ls_cmd = os.sep +os.path.join('bin', 'ls')