Move notification options wrapper into StatusDataWriter

That's the only location which requires the old mapping.
This commit is contained in:
Michael Friedrich 2017-12-06 17:17:47 +01:00
parent 87b99c17b5
commit 15e3524e42
4 changed files with 55 additions and 55 deletions

View File

@ -270,7 +270,7 @@ void StatusDataWriter::DumpHostObject(std::ostream& fp, const Host::Ptr& host)
"\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" << CompatUtility::GetCheckableNotificationNotificationOptions(host) << "\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";
@ -372,7 +372,7 @@ void StatusDataWriter::DumpCheckableStatusAttrs(std::ostream& fp, const Checkabl
if (cr) {
fp << "\t" "plugin_output=" << CompatUtility::GetCheckResultOutput(cr) << "\n"
"\t" "long_plugin_output=" << CompatUtility::GetCheckResultLongOutput(cr) << "\n"
"\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n"
"\t" "performance_data=" << PluginUtility::FormatPerfdata(cr->GetPerformanceData()) << "\n";
}
fp << "\t" << "next_check=" << static_cast<long>(checkable->GetNextCheck()) << "\n"
@ -436,7 +436,7 @@ void StatusDataWriter::DumpServiceObject(std::ostream& fp, const Service::Ptr& s
"\t" "flap_detection_enabled" "\t" << Convert::ToLong(service->GetEnableFlapping()) << "\n"
"\t" "is_volatile" "\t" << Convert::ToLong(service->GetVolatile()) << "\n"
"\t" "notifications_enabled" "\t" << Convert::ToLong(service->GetEnableNotifications()) << "\n"
"\t" "notification_options" "\t" << CompatUtility::GetCheckableNotificationNotificationOptions(service) << "\n"
"\t" "notification_options" "\t" << GetNotificationOptions(service) << "\n"
"\t" "notification_interval" "\t" << CompatUtility::GetCheckableNotificationNotificationInterval(service) << "\n"
"\t" "notification_period" "\t" << "" << "\n"
"\t" "event_handler_enabled" "\t" << Convert::ToLong(service->GetEnableEventHandler()) << "\n";
@ -864,3 +864,53 @@ void StatusDataWriter::ObjectHandler()
{
m_ObjectsCacheOutdated = true;
}
String StatusDataWriter::GetNotificationOptions(const Checkable::Ptr& checkable)
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
unsigned long notification_type_filter = 0;
unsigned long notification_state_filter = 0;
for (const Notification::Ptr& notification : checkable->GetNotifications()) {
notification_type_filter |= notification->GetTypeFilter();
notification_state_filter |= notification->GetStateFilter();
}
std::vector<String> notification_options;
/* notification state filters */
if (service) {
if (notification_state_filter & ServiceWarning) {
notification_options.push_back("w");
}
if (notification_state_filter & ServiceUnknown) {
notification_options.push_back("u");
}
if (notification_state_filter & ServiceCritical) {
notification_options.push_back("c");
}
} else {
if (notification_state_filter & HostDown) {
notification_options.push_back("d");
}
}
/* notification type filters */
if (notification_type_filter & NotificationRecovery) {
notification_options.push_back("r");
}
if ((notification_type_filter & NotificationFlappingStart) ||
(notification_type_filter & NotificationFlappingEnd)) {
notification_options.push_back("f");
}
if ((notification_type_filter & NotificationDowntimeStart) ||
(notification_type_filter & NotificationDowntimeEnd) ||
(notification_type_filter & NotificationDowntimeRemoved)) {
notification_options.push_back("s");
}
return boost::algorithm::join(notification_options, ",");
}

View File

@ -97,6 +97,8 @@ private:
void UpdateObjectsCache();
void StatusTimerHandler();
void ObjectHandler();
static String GetNotificationOptions(const Checkable::Ptr& checkable);
};
}

View File

@ -282,57 +282,6 @@ double CompatUtility::GetCheckableNotificationNotificationInterval(const Checkab
return notification_interval / 60.0;
}
String CompatUtility::GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable)
{
Host::Ptr host;
Service::Ptr service;
tie(host, service) = GetHostService(checkable);
unsigned long notification_type_filter = 0;
unsigned long notification_state_filter = 0;
for (const Notification::Ptr& notification : checkable->GetNotifications()) {
notification_type_filter |= notification->GetTypeFilter();
notification_state_filter |= notification->GetStateFilter();
}
std::vector<String> notification_options;
/* notification state filters */
if (service) {
if (notification_state_filter & ServiceWarning) {
notification_options.emplace_back("w");
}
if (notification_state_filter & ServiceUnknown) {
notification_options.emplace_back("u");
}
if (notification_state_filter & ServiceCritical) {
notification_options.emplace_back("c");
}
} else {
if (notification_state_filter & HostDown) {
notification_options.emplace_back("d");
}
}
/* notification type filters */
if (notification_type_filter & NotificationRecovery) {
notification_options.emplace_back("r");
}
if ((notification_type_filter & NotificationFlappingStart) ||
(notification_type_filter & NotificationFlappingEnd)) {
notification_options.emplace_back("f");
}
if ((notification_type_filter & NotificationDowntimeStart) ||
(notification_type_filter & NotificationDowntimeEnd) ||
(notification_type_filter & NotificationDowntimeRemoved)) {
notification_options.emplace_back("s");
}
return boost::algorithm::join(notification_options, ",");
}
int CompatUtility::GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable)
{
unsigned long notification_type_filter = 0;

View File

@ -65,7 +65,6 @@ public:
static int GetCheckableNotificationNextNotification(const Checkable::Ptr& checkable);
static int GetCheckableNotificationNotificationNumber(const Checkable::Ptr& checkable);
static double GetCheckableNotificationNotificationInterval(const Checkable::Ptr& checkable);
static String GetCheckableNotificationNotificationOptions(const Checkable::Ptr& checkable);
static int GetCheckableNotificationTypeFilter(const Checkable::Ptr& checkable);
static int GetCheckableNotificationStateFilter(const Checkable::Ptr& checkable);
static int GetCheckableNotifyOnWarning(const Checkable::Ptr& checkable);