Exemplo n.º 1
0
Dictionary::Ptr HostDbObject::GetConfigFields(void) const
{
	Dictionary::Ptr fields = new Dictionary();
	Host::Ptr host = static_pointer_cast<Host>(GetObject());

	fields->Set("alias", CompatUtility::GetHostAlias(host));
	fields->Set("display_name", host->GetDisplayName());
	fields->Set("address", host->GetAddress());
	fields->Set("address6", host->GetAddress6());

	fields->Set("check_command_object_id", host->GetCheckCommand());
	fields->Set("check_command_args", CompatUtility::GetCheckableCommandArgs(host));
	fields->Set("eventhandler_command_object_id", host->GetEventCommand());
	fields->Set("eventhandler_command_args", Empty);
	fields->Set("notification_timeperiod_object_id", Notification::GetByName(CompatUtility::GetCheckableNotificationNotificationPeriod(host)));
	fields->Set("check_timeperiod_object_id", host->GetCheckPeriod());
	fields->Set("failure_prediction_options", Empty);
	fields->Set("check_interval", CompatUtility::GetCheckableCheckInterval(host));
	fields->Set("retry_interval", CompatUtility::GetCheckableRetryInterval(host));
	fields->Set("max_check_attempts", host->GetMaxCheckAttempts());

	fields->Set("first_notification_delay", Empty);

	fields->Set("notification_interval", CompatUtility::GetCheckableNotificationNotificationInterval(host));
	fields->Set("notify_on_down", CompatUtility::GetHostNotifyOnDown(host));
	fields->Set("notify_on_unreachable", CompatUtility::GetHostNotifyOnDown(host));

	fields->Set("notify_on_recovery", CompatUtility::GetCheckableNotifyOnRecovery(host));
	fields->Set("notify_on_flapping", CompatUtility::GetCheckableNotifyOnFlapping(host));
	fields->Set("notify_on_downtime", CompatUtility::GetCheckableNotifyOnDowntime(host));

	fields->Set("stalk_on_up", Empty);
	fields->Set("stalk_on_down", Empty);
	fields->Set("stalk_on_unreachable", Empty);

	fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(host));
	fields->Set("flap_detection_on_up", Empty);
	fields->Set("flap_detection_on_down", Empty);
	fields->Set("flap_detection_on_unreachable", Empty);
	fields->Set("low_flap_threshold", CompatUtility::GetCheckableLowFlapThreshold(host));
	fields->Set("high_flap_threshold", CompatUtility::GetCheckableHighFlapThreshold(host));

	fields->Set("process_performance_data", 0);

	fields->Set("freshness_checks_enabled", CompatUtility::GetCheckableFreshnessChecksEnabled(host));
	fields->Set("freshness_threshold", CompatUtility::GetCheckableFreshnessThreshold(host));
	fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(host));
	fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(host));
	fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(host));

	fields->Set("retain_status_information", 1);
	fields->Set("retain_nonstatus_information", 1);

	fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(host));

	fields->Set("obsess_over_host", 0);
	fields->Set("failure_prediction_enabled", 0);

	fields->Set("notes", host->GetNotes());
	fields->Set("notes_url", host->GetNotesUrl());
	fields->Set("action_url", host->GetActionUrl());
	fields->Set("icon_image", host->GetIconImage());
	fields->Set("icon_image_alt", host->GetIconImageAlt());

	return fields;
}
Exemplo n.º 2
0
void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
{
	String notes = host->GetNotes();
	String notes_url = host->GetNotesUrl();
	String action_url = host->GetActionUrl();
	String icon_image = host->GetIconImage();
	String icon_image_alt = host->GetIconImageAlt();
	String display_name = host->GetDisplayName();
	String address = host->GetAddress();
	String address6 = host->GetAddress6();

	fp << "define host {" "\n"
		"\t" "host_name" "\t" << host->GetName() << "\n";
	if (!display_name.IsEmpty()) {
		fp << "\t" "display_name" "\t" << host->GetDisplayName() << "\n"
			"\t" "alias" "\t" << host->GetDisplayName() << "\n";
	}
	if (!address.IsEmpty())
		fp << "\t" "address" "\t" << address << "\n";
	if (!address6.IsEmpty())
		fp << "\t" "address6" "\t" << address6 << "\n";
	if (!notes.IsEmpty())
		fp << "\t" "notes" "\t" << notes << "\n";
	if (!notes_url.IsEmpty())
		fp << "\t" "notes_url" "\t" << notes_url << "\n";
	if (!action_url.IsEmpty())
		fp << "\t" "action_url" "\t" << action_url << "\n";
	if (!icon_image.IsEmpty())
		fp << "\t" "icon_image" "\t" << icon_image << "\n";
	if (!icon_image_alt.IsEmpty())
		fp << "\t" "icon_image_alt" "\t" << icon_image_alt << "\n";

	std::set<Checkable::Ptr> parents = host->GetParents();

	if (!parents.empty()) {
		fp << "\t" "parents" "\t";
		DumpNameList(fp, parents);
		fp << "\n";
	}

	ObjectLock olock(host);

	fp << "\t" "check_interval" "\t" << (host->GetCheckInterval() / 60.0) << "\n"
		"\t" "retry_interval" "\t" << (host->GetRetryInterval() / 60.0) << "\n"
		"\t" "max_check_attempts" "\t" << host->GetMaxCheckAttempts() << "\n"
		"\t" "active_checks_enabled" "\t" << Convert::ToLong(host->GetEnableActiveChecks()) << "\n"
		"\t" "passive_checks_enabled" "\t" << Convert::ToLong(host->GetEnablePassiveChecks()) << "\n"
		"\t" "notifications_enabled" "\t" << Convert::ToLong(host->GetEnableNotifications()) << "\n"
		"\t" "notification_options" "\t" << GetNotificationOptions(host) << "\n"
		"\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(host) << "\n"
		"\t" "event_handler_enabled" "\t" << Convert::ToLong(host->GetEnableEventHandler()) << "\n";

	CheckCommand::Ptr checkcommand = host->GetCheckCommand();
	if (checkcommand)
		fp << "\t" "check_command" "\t" << CompatUtility::GetCommandName(checkcommand) << "!" << CompatUtility::GetCheckableCommandArgs(host) << "\n";

	EventCommand::Ptr eventcommand = host->GetEventCommand();
	if (eventcommand && host->GetEnableEventHandler())
		fp << "\t" "event_handler" "\t" << CompatUtility::GetCommandName(eventcommand) << "\n";

	TimePeriod::Ptr checkPeriod = host->GetCheckPeriod();
	if (checkPeriod)
		fp << "\t" "check_period" "\t" << checkPeriod->GetName() << "\n";

	fp << "\t" "contacts" "\t";
	DumpNameList(fp, CompatUtility::GetCheckableNotificationUsers(host));
	fp << "\n";

	fp << "\t" "contact_groups" "\t";
	DumpNameList(fp, CompatUtility::GetCheckableNotificationUserGroups(host));
	fp << "\n";

	fp << "\t" << "initial_state" "\t" "o" "\n"
		"\t" "low_flap_threshold" "\t" << host->GetFlappingThresholdLow() << "\n"
		"\t" "high_flap_threshold" "\t" << host->GetFlappingThresholdHigh() << "\n"
		"\t" "process_perf_data" "\t" << Convert::ToLong(host->GetEnablePerfdata()) << "\n"
		"\t" "check_freshness" "\t" "1" "\n";

	fp << "\t" "host_groups" "\t";
	bool first = true;

	Array::Ptr groups = host->GetGroups();

	if (groups) {
		ObjectLock olock(groups);

		for (const String& name : groups) {
			HostGroup::Ptr hg = HostGroup::GetByName(name);

			if (hg) {
				if (!first)
					fp << ",";
				else
					first = false;

				fp << hg->GetName();
			}
		}
	}

	fp << "\n";

	DumpCustomAttributes(fp, host);

	fp << "\t" "}" "\n" "\n";
}
Exemplo n.º 3
0
Dictionary::Ptr HostDbObject::GetStatusFields(void) const
{
	Dictionary::Ptr fields = new Dictionary();
	Host::Ptr host = static_pointer_cast<Host>(GetObject());

	CheckResult::Ptr cr = host->GetLastCheckResult();

	if (cr) {
		fields->Set("output", CompatUtility::GetCheckResultOutput(cr));
		fields->Set("long_output", CompatUtility::GetCheckResultLongOutput(cr));
		fields->Set("perfdata", CompatUtility::GetCheckResultPerfdata(cr));
		fields->Set("check_source", cr->GetCheckSource());
	}

	fields->Set("current_state", host->IsReachable() ? host->GetState() : 2);
	fields->Set("has_been_checked", CompatUtility::GetCheckableHasBeenChecked(host));
	fields->Set("should_be_scheduled", host->GetEnableActiveChecks());
	fields->Set("current_check_attempt", host->GetCheckAttempt());
	fields->Set("max_check_attempts", host->GetMaxCheckAttempts());

	if (cr)
		fields->Set("last_check", DbValue::FromTimestamp(cr->GetScheduleEnd()));

	fields->Set("next_check", DbValue::FromTimestamp(host->GetNextCheck()));
	fields->Set("check_type", CompatUtility::GetCheckableCheckType(host));
	fields->Set("last_state_change", DbValue::FromTimestamp(host->GetLastStateChange()));
	fields->Set("last_hard_state_change", DbValue::FromTimestamp(host->GetLastHardStateChange()));
	fields->Set("last_time_up", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateUp())));
	fields->Set("last_time_down", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateDown())));
	fields->Set("last_time_unreachable", DbValue::FromTimestamp(static_cast<int>(host->GetLastStateUnreachable())));
	fields->Set("state_type", host->GetStateType());
	fields->Set("last_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationLastNotification(host)));
	fields->Set("next_notification", DbValue::FromTimestamp(CompatUtility::GetCheckableNotificationNextNotification(host)));
	fields->Set("no_more_notifications", Empty);
	fields->Set("notifications_enabled", CompatUtility::GetCheckableNotificationsEnabled(host));
	{
		ObjectLock olock(host);
		fields->Set("problem_has_been_acknowledged", CompatUtility::GetCheckableProblemHasBeenAcknowledged(host));
		fields->Set("acknowledgement_type", CompatUtility::GetCheckableAcknowledgementType(host));
	}
	fields->Set("current_notification_number", CompatUtility::GetCheckableNotificationNotificationNumber(host));
	fields->Set("passive_checks_enabled", CompatUtility::GetCheckablePassiveChecksEnabled(host));
	fields->Set("active_checks_enabled", CompatUtility::GetCheckableActiveChecksEnabled(host));
	fields->Set("event_handler_enabled", CompatUtility::GetCheckableEventHandlerEnabled(host));
	fields->Set("flap_detection_enabled", CompatUtility::GetCheckableFlapDetectionEnabled(host));
	fields->Set("is_flapping", CompatUtility::GetCheckableIsFlapping(host));
	fields->Set("percent_state_change", CompatUtility::GetCheckablePercentStateChange(host));

	if (cr) {
		fields->Set("latency", Convert::ToString(Service::CalculateLatency(cr)));
		fields->Set("execution_time", Convert::ToString(Service::CalculateExecutionTime(cr)));
	}

	fields->Set("scheduled_downtime_depth", host->GetDowntimeDepth());
	fields->Set("failure_prediction_enabled", Empty);
	fields->Set("process_performance_data", 0); /* this is a host which does not process any perf data */
	fields->Set("obsess_over_host", Empty);
	fields->Set("modified_host_attributes", host->GetModifiedAttributes());
	fields->Set("event_handler", CompatUtility::GetCheckableEventHandler(host));
	fields->Set("check_command", CompatUtility::GetCheckableCheckCommand(host));
	fields->Set("normal_check_interval", CompatUtility::GetCheckableCheckInterval(host));
	fields->Set("retry_check_interval", CompatUtility::GetCheckableRetryInterval(host));
	fields->Set("check_timeperiod_object_id", host->GetCheckPeriod());
	fields->Set("is_reachable", CompatUtility::GetCheckableIsReachable(host));

	return fields;
}