def test_exit_from_errorcode(self): """test calling the correct exit function.""" for (ec, expected) in [ (0, NAGIOS_EXIT_OK), (1, NAGIOS_EXIT_WARNING), (2, NAGIOS_EXIT_CRITICAL), (3, NAGIOS_EXIT_UNKNOWN), (101, NAGIOS_EXIT_UNKNOWN), ]: try: exit_from_errorcode(ec, "boem") except SystemExit as err: print err self.assertTrue(err.code == expected[0])
def test_exit_from_errorcode(self): """test calling the correct exit function.""" for (ec, expected) in [ (0, NAGIOS_EXIT_OK), (1, NAGIOS_EXIT_WARNING), (2, NAGIOS_EXIT_CRITICAL), (3, NAGIOS_EXIT_UNKNOWN), (101, NAGIOS_EXIT_UNKNOWN), ]: try: exit_from_errorcode(ec, "boem") except SystemExit as err: print(err) self.assertTrue(err.code == expected[0])
def unknown(self, msg): """ Convenience method that exists with nagios unknown exitcode """ exit_from_errorcode(3, msg)
def critical(self, msg): """ Convenience method that exists with nagios critical exitcode """ exit_from_errorcode(2, msg)
def warning(self, msg): """ Convenience method exists with nagios warning exitcode """ exit_from_errorcode(1, msg)
def ok(self, msg): """ Convenience method that exists with nagios OK exitcode """ exit_from_errorcode(0, msg)
def critical_exception(self, msg, exception): """ Convenience method: report exception and critical method """ logging.exception("%s: %s", msg, exception) exit_from_errorcode(2, msg)