コード例 #1
0
ファイル: check_drive.cpp プロジェクト: arathai/nscp
	void get_size(parsers::where::evaluation_context context) {
		if (has_size)
			return;

		ULARGE_INTEGER freeBytesAvailableToCaller;
		ULARGE_INTEGER totalNumberOfBytes;
		ULARGE_INTEGER totalNumberOfFreeBytes;
		std::string error;
		std::wstring drv = get_volume_or_letter_w();
		if (drv.size() == 1)
			drv = drv + L":\\";
		if (!GetDiskFreeSpaceEx(drv.c_str(), &freeBytesAvailableToCaller, &totalNumberOfBytes, &totalNumberOfFreeBytes)) {
			DWORD err = GetLastError();
			if (err == ERROR_NOT_READY) {
				has_size = true;
				user_free = 0;
				total_free = 0;
				drive_size = 0;
				return;
			}
			context->error("Failed to get size for: " + drive.name + error::lookup::last_error(err));
			unreadable = err == ERROR_ACCESS_DENIED;
			has_size = true;
			return;
		}
		has_size = true;
		user_free = freeBytesAvailableToCaller.QuadPart;
		total_free = totalNumberOfFreeBytes.QuadPart;
		drive_size = totalNumberOfBytes.QuadPart;
	}
コード例 #2
0
ファイル: filter.cpp プロジェクト: jonasoberschweiber/nscp
parsers::where::node_type get_percentage(boost::shared_ptr<ping_filter::filter_obj> object, parsers::where::evaluation_context context, parsers::where::node_type subject) {
	boost::tuple<long long, std::string> value = parsers::where::helpers::read_arguments(context, subject, "%");
	long long number = value.get<0>();
	std::string unit = value.get<1>();

	if (unit != "%")
		context->error("Invalid unit: " + unit);
	return parsers::where::factory::create_int(number);
}
コード例 #3
0
ファイル: check_drive.cpp プロジェクト: arathai/nscp
parsers::where::node_type convert_type(boost::shared_ptr<filter_obj> object, parsers::where::evaluation_context context, parsers::where::node_type subject) {
	std::string keyword = subject->get_string_value(context);
	boost::to_lower(keyword);
	int type = do_convert_type(keyword);
	if (type == -1) {
		context->error("Failed to convert type: " + keyword);
		return parsers::where::factory::create_false();
	}
	return parsers::where::factory::create_int(type);
}
コード例 #4
0
ファイル: filter.cpp プロジェクト: 0000-bigtree/nscp
	int convert_old_type(parsers::where::evaluation_context context, std::string str) {
		if (str == "error")
			return EVENTLOG_ERROR_TYPE;
		if (str == "warning")
			return EVENTLOG_WARNING_TYPE;
		if (str == "informational" || str == "info" || str == "information")
			return EVENTLOG_INFORMATION_TYPE;
		if (str == "success")
			return EVENTLOG_SUCCESS;
		if (str == "auditSuccess")
			return EVENTLOG_AUDIT_SUCCESS;
		if (str == "auditFailure")
			return EVENTLOG_AUDIT_FAILURE;
		try {
			context->error("Invalid severity: " + str);
			return strEx::s::stox<int>(str);
		} catch (const std::exception&) {
			context->error("Failed to convert: " + str);
			return EVENTLOG_ERROR_TYPE;
		}
	}
コード例 #5
0
ファイル: filter.cpp プロジェクト: 0000-bigtree/nscp
	int convert_old_severity(parsers::where::evaluation_context context, std::string str) {
		if (str == "success" || str == "ok")
			return 0;
		if (str == "informational" || str == "info" || str == "information")
			return 1;
		if (str == "warning" || str == "warn")
			return 2;
		if (str == "error" || str == "err")
			return 3;
		context->error("Invalid severity: " + str);
		return strEx::s::stox<int>(str);
	}
コード例 #6
0
ファイル: filter.cpp プロジェクト: historicbruno/nscp
parsers::where::node_type fun_convert_status(boost::shared_ptr<tasksched_filter::filter_obj> object, parsers::where::evaluation_context context, parsers::where::node_type subject) {
	std::string status = subject->get_string_value(context);
	long long istat = 0;
	if (object->is_new()) {
		if (status == "queued")
			istat = TASK_STATE_QUEUED;
		else if (status == "unknown")
			istat = TASK_STATE_UNKNOWN;
		else if (status == "ready")
			istat = TASK_STATE_READY;
		else if (status == "running")
			istat = TASK_STATE_RUNNING;
		else if (status == "disabled")
			istat = TASK_STATE_DISABLED;
		else 
			context->error("Failed to convert: " + status);
	} else {
		if (status == "ready")
			istat = SCHED_S_TASK_READY;
		else if (status == "running")
			istat = SCHED_S_TASK_RUNNING;
		else if (status == "not_scheduled")
			istat = SCHED_S_TASK_NOT_SCHEDULED;
		else if (status == "has_not_run")
			istat = SCHED_S_TASK_HAS_NOT_RUN;
		else if (status == "disabled")
			istat = SCHED_S_TASK_DISABLED;
		else if (status == "no_more_runs")
			istat = SCHED_S_TASK_NO_MORE_RUNS;
		else if (status == "no_valid_triggers")
			istat = SCHED_S_TASK_NO_VALID_TRIGGERS;
		else 
			context->error("Failed to convert: " + status);
	}
	return parsers::where::factory::create_int(istat);
}
コード例 #7
0
ファイル: filter.cpp プロジェクト: TaylorMonacelli/nscp
	parsers::where::node_type calculate_free(boost::shared_ptr<filter_obj> object, parsers::where::evaluation_context context, parsers::where::node_type subject) {
		std::list<parsers::where::node_type> list = subject->get_list_value(context);
		if (list.size() != 2) {
			context->error("Invalid list value");
			return parsers::where::factory::create_false();
		}
		std::list<parsers::where::node_type>::const_iterator cit = list.begin();
		parsers::where::node_type amount = *cit;
		++cit;
		parsers::where::node_type unit = *cit;

		long long percentage = amount->get_int_value(context);
		long long value = (object->get_total()*percentage)/100;
		return parsers::where::factory::create_int(value);
	}
コード例 #8
0
ファイル: filter.cpp プロジェクト: lazyfrosch/nscp
	int convert_new_type(parsers::where::evaluation_context context, std::string str) {
		if (str == "audit")
			return 0;
		if (str == "critical")
			return 1;
		if (str == "error")
			return 2;
		if (str == "warning" || str == "warn")
			return 3;
		if (str == "information" || str == "info")
			return 4;
		try {
			return strEx::s::stox<int>(str);
		} catch (const std::exception &e) {
			context->error("Failed to convert: " + str);
			return 2;
		}
	}