Exemple #1
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);
	}
Exemple #2
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);
}