def _submit_via_check_result_file( host: HostName, service: ServiceName, state: ServiceState, output: ServiceDetails, cache_info: Optional[tuple[int, int]], ) -> None: output = output.replace("\n", "\\n") _open_checkresult_file() if _checkresult_file_fd: now = time.time() os.write( _checkresult_file_fd, ("""host_name=%s service_description=%s check_type=1 check_options=0 reschedule_check latency=0.0 start_time=%.1f finish_time=%.1f return_code=%d output=%s """ % (host, service, now, now, state, output)).encode(), )
def _output_check_result(servicedesc: ServiceName, state: ServiceState, infotext: ServiceDetails, perftexts: List[str]) -> None: if _show_perfdata: infotext_fmt = "%-56s" p = ' (%s)' % (" ".join(perftexts)) else: p = '' infotext_fmt = "%s" console.verbose("%-20s %s%s" + infotext_fmt + "%s%s\n", ensure_str(servicedesc), tty.bold, tty.states[state], ensure_str(infotext.split('\n')[0]), tty.normal, ensure_str(p))
def _submit_via_command_pipe(host: HostName, service: ServiceName, state: ServiceState, output: ServiceDetails) -> None: output = output.replace("\n", "\\n") _open_command_pipe() if _nagios_command_pipe is not None and not isinstance(_nagios_command_pipe, bool): # [<timestamp>] PROCESS_SERVICE_CHECK_RESULT;<host_name>;<svc_description>;<return_code>;<plugin_output> msg = "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" % (time.time(), host, service, state, output) _nagios_command_pipe.write(ensure_binary(msg)) # Important: Nagios needs the complete command in one single write() block! # Python buffers and sends chunks of 4096 bytes, if we do not flush. _nagios_command_pipe.flush()
def _submit_via_check_result_file(host: HostName, service: ServiceName, state: ServiceState, output: ServiceDetails) -> None: output = output.replace("\n", "\\n") _open_checkresult_file() if _checkresult_file_fd: now = time.time() os.write( _checkresult_file_fd, ensure_binary("""host_name=%s service_description=%s check_type=1 check_options=0 reschedule_check latency=0.0 start_time=%.1f finish_time=%.1f return_code=%d output=%s """ % (ensure_str(host), ensure_str(service), now, now, state, ensure_str(output))))
def _output_check_result( servicedesc: ServiceName, state: ServiceState, infotext: ServiceDetails, perftexts: List[str], *, show_perfdata: bool, ) -> None: if show_perfdata: infotext_fmt = "%-56s" p = ' (%s)' % (" ".join(perftexts)) else: p = '' infotext_fmt = "%s" console.verbose( "%-20s %s%s" + infotext_fmt + "%s%s\n", servicedesc, tty.bold, tty.states[state], infotext.split('\n', 1)[0], tty.normal, p, )
def _submit_via_command_pipe( host: HostName, service: ServiceName, state: ServiceState, output: ServiceDetails, cache_info: Optional[tuple[int, int]], ) -> None: """In case of CMC this is used when running "cmk" manually""" output = output.replace("\n", "\\n") _open_command_pipe() if _nagios_command_pipe is not None and not isinstance( _nagios_command_pipe, bool): # [<timestamp>] PROCESS_SERVICE_CHECK_RESULT;<host_name>;<svc_description>;<return_code>;<plugin_output> msg = "[%d] PROCESS_SERVICE_CHECK_RESULT;%s;%s;%d;%s\n" % ( time.time(), host, service, state, output, ) _nagios_command_pipe.write(msg.encode()) # Important: Nagios needs the complete command in one single write() block! # Python buffers and sends chunks of 4096 bytes, if we do not flush. _nagios_command_pipe.flush()
def _output_check_result( servicedesc: ServiceName, state: ServiceState, infotext: ServiceDetails, perftext: str, *, show_perfdata: bool, ) -> None: if show_perfdata: infotext_fmt = "%-56s" p = f" ({perftext})" else: p = "" infotext_fmt = "%s" console.verbose( "%-20s %s%s" + infotext_fmt + "%s%s\n", servicedesc, tty.bold, tty.states[state], infotext.split("\n", 1)[0], tty.normal, p, )