mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-23 13:45:04 +02:00
Improve type logging for notifications
This commit is contained in:
parent
e1314ca80e
commit
8098f4d54d
@ -237,7 +237,7 @@ void CompatLogger::NotificationSentHandler(const Notification::Ptr& notification
|
|||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
String notification_type_str = Notification::NotificationTypeToString(notification_type);
|
String notification_type_str = Notification::NotificationTypeToStringCompat(notification_type);
|
||||||
|
|
||||||
/* override problem notifications with their current state string */
|
/* override problem notifications with their current state string */
|
||||||
if (notification_type == NotificationProblem) {
|
if (notification_type == NotificationProblem) {
|
||||||
|
@ -1071,7 +1071,7 @@ void DbEvents::AddNotificationSentLogHistory(const Notification::Ptr& notificati
|
|||||||
if (commandObj)
|
if (commandObj)
|
||||||
checkCommandName = commandObj->GetName();
|
checkCommandName = commandObj->GetName();
|
||||||
|
|
||||||
String notificationTypeStr = Notification::NotificationTypeToString(notification_type);
|
String notificationTypeStr = Notification::NotificationTypeToStringCompat(notification_type); //TODO: Change that to our own types.
|
||||||
|
|
||||||
String author_comment = "";
|
String author_comment = "";
|
||||||
if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) {
|
if (notification_type == NotificationCustom || notification_type == NotificationAcknowledgement) {
|
||||||
|
@ -132,7 +132,7 @@ void ApiEvents::NotificationSentToAllUsersHandler(const Notification::Ptr& notif
|
|||||||
}
|
}
|
||||||
|
|
||||||
result->Set("users", new Array(std::move(userNames)));
|
result->Set("users", new Array(std::move(userNames)));
|
||||||
result->Set("notification_type", Notification::NotificationTypeToString(type));
|
result->Set("notification_type", Notification::NotificationTypeToStringCompat(type)); //TODO: Change this to our own types.
|
||||||
result->Set("author", author);
|
result->Set("author", author);
|
||||||
result->Set("text", text);
|
result->Set("text", text);
|
||||||
result->Set("check_result", Serialize(cr));
|
result->Set("check_result", Serialize(cr));
|
||||||
|
@ -49,13 +49,21 @@ void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr&
|
|||||||
|
|
||||||
std::set<Notification::Ptr> notifications = GetNotifications();
|
std::set<Notification::Ptr> notifications = GetNotifications();
|
||||||
|
|
||||||
Log(LogInformation, "Checkable")
|
String notificationTypeName = Notification::NotificationTypeToString(type);
|
||||||
<< "Checkable '" << checkableName << "' has " << notifications.size() << " notification(s). Proceeding with filters, successful sends will be logged.";
|
|
||||||
|
|
||||||
if (notifications.empty())
|
// Bail early if there are no notifications.
|
||||||
|
if (notifications.empty()) {
|
||||||
|
Log(LogNotice, "Checkable")
|
||||||
|
<< "Skipping checkable '" << checkableName << "' which doesn't have any notification objects configured.";
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log(LogInformation, "Checkable")
|
||||||
|
<< "Checkable '" << checkableName << "' has " << notifications.size()
|
||||||
|
<< " notification(s). Checking filters for type '" << notificationTypeName << "', sends will be logged.";
|
||||||
|
|
||||||
for (const Notification::Ptr& notification : notifications) {
|
for (const Notification::Ptr& notification : notifications) {
|
||||||
|
// Re-send stashed notifications from cold startup.
|
||||||
if (ApiListener::UpdatedObjectAuthority()) {
|
if (ApiListener::UpdatedObjectAuthority()) {
|
||||||
try {
|
try {
|
||||||
if (!notification->IsPaused()) {
|
if (!notification->IsPaused()) {
|
||||||
@ -86,6 +94,7 @@ void Checkable::SendNotifications(NotificationType type, const CheckResult::Ptr&
|
|||||||
<< GetName() << "': " << DiagnosticInformation(ex, false);
|
<< GetName() << "': " << DiagnosticInformation(ex, false);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
// Cold startup phase. Stash notification for later.
|
||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Notification '" << notification->GetName() << "': object authority hasn't been updated, yet. Stashing notification.";
|
<< "Notification '" << notification->GetName() << "': object authority hasn't been updated, yet. Stashing notification.";
|
||||||
|
|
||||||
|
@ -12,6 +12,7 @@
|
|||||||
#include "base/exception.hpp"
|
#include "base/exception.hpp"
|
||||||
#include "base/initialize.hpp"
|
#include "base/initialize.hpp"
|
||||||
#include "base/scriptglobal.hpp"
|
#include "base/scriptglobal.hpp"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
using namespace icinga;
|
using namespace icinga;
|
||||||
|
|
||||||
@ -215,39 +216,15 @@ void Notification::ResetNotificationNumber()
|
|||||||
SetNotificationNumber(0);
|
SetNotificationNumber(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* the upper case string used in all interfaces */
|
|
||||||
String Notification::NotificationTypeToString(NotificationType type)
|
|
||||||
{
|
|
||||||
switch (type) {
|
|
||||||
case NotificationDowntimeStart:
|
|
||||||
return "DOWNTIMESTART";
|
|
||||||
case NotificationDowntimeEnd:
|
|
||||||
return "DOWNTIMEEND";
|
|
||||||
case NotificationDowntimeRemoved:
|
|
||||||
return "DOWNTIMECANCELLED";
|
|
||||||
case NotificationCustom:
|
|
||||||
return "CUSTOM";
|
|
||||||
case NotificationAcknowledgement:
|
|
||||||
return "ACKNOWLEDGEMENT";
|
|
||||||
case NotificationProblem:
|
|
||||||
return "PROBLEM";
|
|
||||||
case NotificationRecovery:
|
|
||||||
return "RECOVERY";
|
|
||||||
case NotificationFlappingStart:
|
|
||||||
return "FLAPPINGSTART";
|
|
||||||
case NotificationFlappingEnd:
|
|
||||||
return "FLAPPINGEND";
|
|
||||||
default:
|
|
||||||
return "UNKNOWN_NOTIFICATION";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, bool reminder, const String& author, const String& text)
|
void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, bool reminder, const String& author, const String& text)
|
||||||
{
|
{
|
||||||
String notificationName = GetName();
|
String notificationName = GetName();
|
||||||
|
String notificationTypeName = NotificationTypeToString(type);
|
||||||
|
|
||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Attempting to send " << (reminder ? "reminder " : "") << "notifications for notification object '" << notificationName << "'.";
|
<< "Attempting to send " << (reminder ? "reminder " : "")
|
||||||
|
<< "notifications of type '" << notificationTypeName
|
||||||
|
<< "' for notification object '" << notificationName << "'.";
|
||||||
|
|
||||||
Checkable::Ptr checkable = GetCheckable();
|
Checkable::Ptr checkable = GetCheckable();
|
||||||
|
|
||||||
@ -292,7 +269,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
|||||||
unsigned long ftype = type;
|
unsigned long ftype = type;
|
||||||
|
|
||||||
Log(LogDebug, "Notification")
|
Log(LogDebug, "Notification")
|
||||||
<< "Type '" << NotificationTypeToStringInternal(type)
|
<< "Type '" << NotificationTypeToString(type)
|
||||||
<< "', TypeFilter: " << NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap())
|
<< "', TypeFilter: " << NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap())
|
||||||
<< " (FType=" << ftype << ", TypeFilter=" << GetTypeFilter() << ")";
|
<< " (FType=" << ftype << ", TypeFilter=" << GetTypeFilter() << ")";
|
||||||
|
|
||||||
@ -300,7 +277,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
|||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Not sending " << (reminder ? "reminder " : "") << "notifications for notification object '"
|
<< "Not sending " << (reminder ? "reminder " : "") << "notifications for notification object '"
|
||||||
<< notificationName << "': type '"
|
<< notificationName << "': type '"
|
||||||
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
|
<< NotificationTypeToString(type) << "' does not match type filter: "
|
||||||
<< NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << ".";
|
<< NotificationFilterToString(GetTypeFilter(), GetTypeFilterMap()) << ".";
|
||||||
|
|
||||||
/* Ensure to reset no_more_notifications on Recovery notifications,
|
/* Ensure to reset no_more_notifications on Recovery notifications,
|
||||||
@ -419,7 +396,7 @@ void Notification::BeginExecuteNotification(NotificationType type, const CheckRe
|
|||||||
}
|
}
|
||||||
|
|
||||||
Log(LogInformation, "Notification")
|
Log(LogInformation, "Notification")
|
||||||
<< "Sending " << (reminder ? "reminder " : "") << "'" << NotificationTypeToStringInternal(type) << "' notification '"
|
<< "Sending " << (reminder ? "reminder " : "") << "'" << NotificationTypeToString(type) << "' notification '"
|
||||||
<< notificationName << "' for user '" << userName << "'";
|
<< notificationName << "' for user '" << userName << "'";
|
||||||
|
|
||||||
Utility::QueueAsyncCallback(std::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text));
|
Utility::QueueAsyncCallback(std::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text));
|
||||||
@ -460,7 +437,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use
|
|||||||
|
|
||||||
Log(LogDebug, "Notification")
|
Log(LogDebug, "Notification")
|
||||||
<< "User '" << userName << "' notification '" << notificationName
|
<< "User '" << userName << "' notification '" << notificationName
|
||||||
<< "', Type '" << NotificationTypeToStringInternal(type)
|
<< "', Type '" << NotificationTypeToString(type)
|
||||||
<< "', TypeFilter: " << NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap())
|
<< "', TypeFilter: " << NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap())
|
||||||
<< " (FType=" << ftype << ", TypeFilter=" << GetTypeFilter() << ")";
|
<< " (FType=" << ftype << ", TypeFilter=" << GetTypeFilter() << ")";
|
||||||
|
|
||||||
@ -469,7 +446,7 @@ bool Notification::CheckNotificationUserFilters(NotificationType type, const Use
|
|||||||
Log(LogNotice, "Notification")
|
Log(LogNotice, "Notification")
|
||||||
<< "Not sending " << (reminder ? "reminder " : "") << "notifications for notification object '"
|
<< "Not sending " << (reminder ? "reminder " : "") << "notifications for notification object '"
|
||||||
<< notificationName << " and user '" << userName << "': type '"
|
<< notificationName << " and user '" << userName << "': type '"
|
||||||
<< NotificationTypeToStringInternal(type) << "' does not match type filter: "
|
<< NotificationTypeToString(type) << "' does not match type filter: "
|
||||||
<< NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << ".";
|
<< NotificationFilterToString(user->GetTypeFilter(), GetTypeFilterMap()) << ".";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -542,7 +519,7 @@ void Notification::ExecuteNotificationHelper(NotificationType type, const User::
|
|||||||
Checkable::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, nr, author, text, command->GetName(), nullptr);
|
Checkable::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, nr, author, text, command->GetName(), nullptr);
|
||||||
|
|
||||||
Log(LogInformation, "Notification")
|
Log(LogInformation, "Notification")
|
||||||
<< "Completed sending '" << NotificationTypeToStringInternal(type)
|
<< "Completed sending '" << NotificationTypeToString(type)
|
||||||
<< "' notification '" << notificationName
|
<< "' notification '" << notificationName
|
||||||
<< "' for checkable '" << checkableName
|
<< "' for checkable '" << checkableName
|
||||||
<< "' and user '" << userName << "' using command '" << commandName << "'.";
|
<< "' and user '" << userName << "' using command '" << commandName << "'.";
|
||||||
@ -626,30 +603,51 @@ String Notification::NotificationFilterToString(int filter, const std::map<Strin
|
|||||||
return Utility::NaturalJoin(sFilters);
|
return Utility::NaturalJoin(sFilters);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* internal for logging */
|
/*
|
||||||
String Notification::NotificationTypeToStringInternal(NotificationType type)
|
* Main interface to translate NotificationType values into strings.
|
||||||
|
*/
|
||||||
|
String Notification::NotificationTypeToString(NotificationType type)
|
||||||
|
{
|
||||||
|
auto typeMap = Notification::m_TypeFilterMap;
|
||||||
|
|
||||||
|
auto it = std::find_if(typeMap.begin(), typeMap.end(),
|
||||||
|
[&type](const std::pair<String, int>& p) {
|
||||||
|
return p.second == type;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (it == typeMap.end())
|
||||||
|
return Empty;
|
||||||
|
|
||||||
|
return it->first;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Compat interface used in external features.
|
||||||
|
*/
|
||||||
|
String Notification::NotificationTypeToStringCompat(NotificationType type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case NotificationDowntimeStart:
|
case NotificationDowntimeStart:
|
||||||
return "DowntimeStart";
|
return "DOWNTIMESTART";
|
||||||
case NotificationDowntimeEnd:
|
case NotificationDowntimeEnd:
|
||||||
return "DowntimeEnd";
|
return "DOWNTIMEEND";
|
||||||
case NotificationDowntimeRemoved:
|
case NotificationDowntimeRemoved:
|
||||||
return "DowntimeRemoved";
|
return "DOWNTIMECANCELLED";
|
||||||
case NotificationCustom:
|
case NotificationCustom:
|
||||||
return "Custom";
|
return "CUSTOM";
|
||||||
case NotificationAcknowledgement:
|
case NotificationAcknowledgement:
|
||||||
return "Acknowledgement";
|
return "ACKNOWLEDGEMENT";
|
||||||
case NotificationProblem:
|
case NotificationProblem:
|
||||||
return "Problem";
|
return "PROBLEM";
|
||||||
case NotificationRecovery:
|
case NotificationRecovery:
|
||||||
return "Recovery";
|
return "RECOVERY";
|
||||||
case NotificationFlappingStart:
|
case NotificationFlappingStart:
|
||||||
return "FlappingStart";
|
return "FLAPPINGSTART";
|
||||||
case NotificationFlappingEnd:
|
case NotificationFlappingEnd:
|
||||||
return "FlappingEnd";
|
return "FLAPPINGEND";
|
||||||
default:
|
default:
|
||||||
return Empty;
|
return "UNKNOWN_NOTIFICATION";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -85,9 +85,15 @@ public:
|
|||||||
|
|
||||||
void ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin = nullptr);
|
void ProcessNotificationResult(const NotificationResult::Ptr& nr, const MessageOrigin::Ptr& origin = nullptr);
|
||||||
|
|
||||||
|
// Logging, etc.
|
||||||
static String NotificationTypeToString(NotificationType type);
|
static String NotificationTypeToString(NotificationType type);
|
||||||
|
// Compat, used for notifications, etc.
|
||||||
|
static String NotificationTypeToStringCompat(NotificationType type);
|
||||||
static String NotificationFilterToString(int filter, const std::map<String, int>& filterMap);
|
static String NotificationFilterToString(int filter, const std::map<String, int>& filterMap);
|
||||||
|
|
||||||
|
static String NotificationServiceStateToString(ServiceState state);
|
||||||
|
static String NotificationHostStateToString(HostState state);
|
||||||
|
|
||||||
static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
|
static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
|
||||||
static boost::signals2::signal<void (const Notification::Ptr&, const NotificationResult::Ptr&, const MessageOrigin::Ptr&)> OnNewNotificationResult;
|
static boost::signals2::signal<void (const Notification::Ptr&, const NotificationResult::Ptr&, const MessageOrigin::Ptr&)> OnNewNotificationResult;
|
||||||
|
|
||||||
@ -119,10 +125,6 @@ private:
|
|||||||
static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
|
static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule);
|
||||||
static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule);
|
static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule);
|
||||||
|
|
||||||
static String NotificationTypeToStringInternal(NotificationType type);
|
|
||||||
static String NotificationServiceStateToString(ServiceState state);
|
|
||||||
static String NotificationHostStateToString(HostState state);
|
|
||||||
|
|
||||||
static std::map<String, int> m_StateFilterMap;
|
static std::map<String, int> m_StateFilterMap;
|
||||||
static std::map<String, int> m_TypeFilterMap;
|
static std::map<String, int> m_TypeFilterMap;
|
||||||
};
|
};
|
||||||
|
@ -32,7 +32,7 @@ void PluginNotificationTask::ScriptFunc(const Notification::Ptr& notification,
|
|||||||
Checkable::Ptr checkable = notification->GetCheckable();
|
Checkable::Ptr checkable = notification->GetCheckable();
|
||||||
|
|
||||||
Dictionary::Ptr notificationExtra = new Dictionary({
|
Dictionary::Ptr notificationExtra = new Dictionary({
|
||||||
{ "type", Notification::NotificationTypeToString(type) },
|
{ "type", Notification::NotificationTypeToStringCompat(type) }, //TODO: Change that to our types.
|
||||||
{ "author", author },
|
{ "author", author },
|
||||||
{ "comment", comment }
|
{ "comment", comment }
|
||||||
});
|
});
|
||||||
|
@ -318,7 +318,7 @@ void ElasticsearchWriter::NotificationSentToAllUsersHandlerInternal(const Notifi
|
|||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
String notificationTypeString = Notification::NotificationTypeToString(type);
|
String notificationTypeString = Notification::NotificationTypeToStringCompat(type); //TODO: Change that to our own types.
|
||||||
|
|
||||||
Dictionary::Ptr fields = new Dictionary();
|
Dictionary::Ptr fields = new Dictionary();
|
||||||
|
|
||||||
|
@ -371,7 +371,7 @@ void GelfWriter::NotificationToUserHandlerInternal(const Notification::Ptr& noti
|
|||||||
Service::Ptr service;
|
Service::Ptr service;
|
||||||
tie(host, service) = GetHostService(checkable);
|
tie(host, service) = GetHostService(checkable);
|
||||||
|
|
||||||
String notificationTypeString = Notification::NotificationTypeToString(notificationType);
|
String notificationTypeString = Notification::NotificationTypeToStringCompat(notificationType); //TODO: Change that to our own types.
|
||||||
|
|
||||||
String authorComment = "";
|
String authorComment = "";
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user