def execute(self, cmd: str, args: List[str]) -> Any: self._handle_generic_arguments(args) try: try: automation = self._automations[cmd] except KeyError: raise MKAutomationError("Automation command '%s' is not implemented." % cmd) if automation.needs_checks: with redirect_stdout(open(os.devnull, "w")): log.setup_console_logging() config.load_all_agent_based_plugins( check_api.get_check_api_context, inventory_plugins.load_legacy_inventory_plugins, ) if automation.needs_config: config.load(validate_hosts=False) result = automation.execute(args) except (MKAutomationError, MKTimeout) as e: console.error("%s\n" % e) if cmk.utils.debug.enabled(): raise return 1 except Exception as e: if cmk.utils.debug.enabled(): raise console.error("%s\n" % e) return 2 finally: profiling.output_profile() out.output(result.serialize()) out.output("\n") return 0
def execute(self, cmd, args): # type: (str, List[str]) -> Any self._handle_generic_arguments(args) try: try: automation = self._automations[cmd] except KeyError: raise MKAutomationError( "Automation command '%s' is not implemented." % cmd) if automation.needs_checks: config.load_all_checks(check_api.get_check_api_context) if automation.needs_config: config.load(validate_hosts=False) result = automation.execute(args) except (MKAutomationError, MKTimeout) as e: console.error("%s\n" % e) if cmk.utils.debug.enabled(): raise return 1 except Exception as e: if cmk.utils.debug.enabled(): raise console.error("%s\n" % e) return 2 finally: profiling.output_profile() if cmk.utils.debug.enabled(): console.output(pprint.pformat(result) + "\n") else: console.output("%r\n" % (result, )) return 0
def execute(self, cmd: str, args: List[str]) -> Any: self._handle_generic_arguments(args) try: try: automation = self._automations[cmd] except KeyError: raise MKAutomationError( "Automation command '%s' is not implemented." % cmd) if automation.needs_checks: config.load_all_agent_based_plugins( check_api.get_check_api_context) if automation.needs_config: config.load(validate_hosts=False) result = automation.execute(args) except (MKAutomationError, MKTimeout) as e: console.error("%s\n" % e) if cmk.utils.debug.enabled(): raise return 1 except Exception as e: if cmk.utils.debug.enabled(): raise console.error("%s\n" % e) return 2 finally: profiling.output_profile() out.output(python_printer.pformat(result)) out.output('\n') return 0