Esempio n. 1
0
	void matchShowAll(const boost::program_options::variables_map &vm, Plugin::QueryRequestMessage::Request &request, std::string prefix) {
		if (vm.count("ShowAll")) {
			request.add_arguments("top-syntax=" + prefix + "${list}");
		} else {
			request.add_arguments("top-syntax=" + prefix + "${problem_list}");
		}

	}
Esempio n. 2
0
int main(int argc, char* argv[]) {
	Plugin::QueryResponseMessage response_message;
	std::vector<std::string> args;
	for (int i = 1; i < argc; i++) {
		args.push_back(argv[i]);
	}
	Plugin::QueryRequestMessage request_message;
	Plugin::QueryRequestMessage::Request *request = request_message.add_payload();
	request->set_command("check_nrpe");
	for (int i = 1; i < argc; i++) {
		request->add_arguments(argv[i]);
	}

	check_nrpe client;
	client.query(request_message, response_message);
	NSCAPI::nagiosReturn ret = NSCAPI::query_return_codes::returnOK;
	BOOST_FOREACH(const ::Plugin::QueryResponseMessage_Response &response, response_message.payload()) {
		ret = nscapi::plugin_helper::maxState(ret, nscapi::protobuf::functions::gbp_to_nagios_status(response.result()));
		BOOST_FOREACH(const ::Plugin::QueryResponseMessage_Response_Line &line, response.lines()) {
			std::cout << line.message();
			std::string tmp = nscapi::protobuf::functions::build_performance_data(line);
			if (!tmp.empty())
				std::cout << '|' << tmp;
		}
	}
	return ret;
}
Esempio n. 3
0
void CheckDisk::checkDriveSize(Plugin::QueryRequestMessage::Request &request, Plugin::QueryResponseMessage::Response *response) {
	boost::program_options::options_description desc;

	std::vector<std::string> times;
	std::vector<std::string> types;
	std::string perf_unit;
	nscapi::program_options::add_help(desc);
	desc.add_options()
		("CheckAll", po::value<std::string>()->implicit_value("true"), "Checks all drives.")
		("CheckAllOthers", po::value<std::string>()->implicit_value("true"), "Checks all drives turns the drive option into an exclude option.")
		("Drive", po::value<std::vector<std::string>>(&times), "The drives to check")
		("FilterType", po::value<std::vector<std::string>>(&types), "The type of drives to check fixed, remote, cdrom, ramdisk, removable")
		("perf-unit", po::value<std::string>(&perf_unit), "Force performance data to use a given unit prevents scaling which can cause problems over time in some graphing solutions.")
		;
	compat::addShowAll(desc);
	compat::addAllNumeric(desc);
	compat::addAllNumeric(desc, "Free");
	compat::addAllNumeric(desc, "Used");

	boost::program_options::variables_map vm;
	std::vector<std::string> extra;
	if (!nscapi::program_options::process_arguments_from_request(vm, desc, request, *response, true, extra))
		return;
	std::string warn, crit;

	request.clear_arguments();
	compat::matchFirstNumeric(vm, "used", "free", warn, crit);
	compat::matchFirstNumeric(vm, "used", "used", warn, crit, "Used");
	compat::matchFirstNumeric(vm, "free", "free", warn, crit, "Free");
	compat::inline_addarg(request, warn);
	compat::inline_addarg(request, crit);
	if (vm.count("CheckAll"))
		request.add_arguments("drive=*");
	bool exclude = false;
	if (vm.count("CheckAllOthers")) {
		request.add_arguments("drive=*");
		exclude = true;
	}
	if (!perf_unit.empty())
		request.add_arguments("perf-config=free(unit:" + perf_unit + ")used(unit:" + perf_unit + ")");
	request.add_arguments("detail-syntax=%(drive): Total: %(size) - Used: %(used) (%(used_pct)%) - Free: %(free) (%(free_pct)%)");
	compat::matchShowAll(vm, request);
	std::string keyword = exclude ? "exclude=" : "drive=";
	BOOST_FOREACH(const std::string &t, times) {
		request.add_arguments(keyword + t);
	}
Esempio n. 4
0
void CheckTaskSched::CheckTaskSched_(Plugin::QueryRequestMessage::Request &request, Plugin::QueryResponseMessage::Response *response) {
	boost::program_options::options_description desc;

	std::vector<std::string> counters;
	std::string syntax, topSyntax, filter, arg_warn, arg_crit;
	bool debug = false;
	nscapi::program_options::add_help(desc);
	desc.add_options()
		("warn", po::value<std::string>(&arg_warn), "Warning bounds.")
		("crit", po::value<std::string>(&arg_crit), "Critical bounds.")
		("MaxWarn", po::value<std::string>(), "Maximum value before a warning is returned.")
		("MaxCrit", po::value<std::string>(), "Maximum value before a critical is returned.")
		("MinWarn", po::value<std::string>(), "Minimum value before a warning is returned.")
		("MinCrit", po::value<std::string>(), "Minimum value before a critical is returned.")
		("Counter", po::value<std::vector<std::string>>(&counters), "The time to check")
		("truncate", po::value<std::string>(), "Deprecated option")
		("syntax", po::value<std::string>(&syntax), "Syntax (same as detail-syntax in the check_tasksched check)")
		("master-syntax", po::value<std::string>(&topSyntax), "Master Syntax (same as top-syntax in the check_tasksched check)")
		("filter", po::value<std::string>(&filter), "Filter (same as filter in the check_tasksched check)")
		("debug", po::bool_switch(&debug), "Filter (same as filter in the check_tasksched check)")
		;

	boost::program_options::variables_map vm;
	std::vector<std::string> extra;
	if (!nscapi::program_options::process_arguments_from_request(vm, desc, request, *response, true, extra))
		return;
	std::string warn, crit;

	request.clear_arguments();
	if (vm.count("MaxWarn"))
		warn = "warn=count > " + vm["MaxWarn"].as<std::string>();
	if (vm.count("MaxCrit"))
		crit = "crit=count > " + vm["MaxCrit"].as<std::string>();
	if (vm.count("MinWarn"))
		warn = "warn=count < " + vm["MinWarn"].as<std::string>();
	if (vm.count("MinCrit"))
		crit = "crit=count > " + vm["MinCrit"].as<std::string>();
	if (!arg_warn.empty())
		warn = "warn=count " + arg_warn;
	if (!arg_crit.empty())
		crit = "crit=count " + arg_crit;
	if (!warn.empty())
		request.add_arguments(warn);
	if (!crit.empty())
		request.add_arguments(crit);
	if (debug)
		request.add_arguments("debug");
	if (!filter.empty())
		request.add_arguments("filter=" + filter);
	if (!topSyntax.empty()) {
		boost::replace_all(topSyntax, "%status%", "${task_status}");
		request.add_arguments("top-syntax=" + topSyntax);
	}
	if (!syntax.empty()) {
		boost::replace_all(syntax, "%title%", "${title}");
		boost::replace_all(syntax, "%status%", "${task_status}");
		boost::replace_all(syntax, "%exit_code%", "${exit_code}");
		boost::replace_all(syntax, "%most_recent_run_time%", "${most_recent_run_time}");

		request.add_arguments("detail-syntax=" + syntax);
	}

	log_args(request);
	check_tasksched(request, response);
}
Esempio n. 5
0
	void matchShowAll(const boost::program_options::variables_map &vm, Plugin::QueryRequestMessage::Request &request, std::string prefix) {
		if (vm.count("ShowAll")) {
			request.add_arguments("show-all");
		}
	}