summaryrefslogtreecommitdiff
path: root/libadhocutil/nagios.cpp
blob: 8bd7f62894ca1e15475c9ce5da0ff55e4dde153c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include "nagios.h"
#include "ctf-impl/printf-compat.h"
#include <fstream>
#include <sys/utsname.h>

namespace AdHoc {
	// [<timestamp>] PROCESS_SERVICE_CHECK_RESULT;<host_name>;<svc_description>;<return_code>;<plugin_output>
	AdHocFormatter(NagiosPassiveServiceCheck, "[%?] PROCESS_SERVICE_CHECK_RESULT;%?;%?;%d;%?\n");

	bool
	submitNagiosPassiveServiceCheck(const std::string_view & svc, NagiosStatusCode code, const std::string_view & output)
	{
		std::ofstream command_file("/var/nagios/rw/nagios.cmd");
		return submitNagiosPassiveServiceCheck(command_file, svc, code, output);
	}

	bool
	submitNagiosPassiveServiceCheck(std::ostream & command_file, const std::string_view & svc,
			NagiosStatusCode code, const std::string_view & output)
	{
		if (command_file.good()) {
			struct utsname buf;
			uname(&buf);
			NagiosPassiveServiceCheck::write(command_file, time(nullptr), buf.nodename, svc, (uint8_t)code, output);
			command_file.flush();
		}
		return command_file.good();
	}
}