2013-02-09 11:42:22 +01:00
|
|
|
/******************************************************************************
|
|
|
|
* Icinga 2 *
|
2014-03-19 01:02:29 +01:00
|
|
|
* Copyright (C) 2012-2014 Icinga Development Team (http://www.icinga.org) *
|
2013-02-09 11:42:22 +01:00
|
|
|
* *
|
|
|
|
* This program is free software; you can redistribute it and/or *
|
|
|
|
* modify it under the terms of the GNU General Public License *
|
|
|
|
* as published by the Free Software Foundation; either version 2 *
|
|
|
|
* of the License, or (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program is distributed in the hope that it will be useful, *
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
|
|
* GNU General Public License for more details. *
|
|
|
|
* *
|
|
|
|
* You should have received a copy of the GNU General Public License *
|
|
|
|
* along with this program; if not, write to the Free Software Foundation *
|
|
|
|
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
|
|
|
|
******************************************************************************/
|
|
|
|
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "icinga/notification.h"
|
2013-06-13 11:33:00 +02:00
|
|
|
#include "icinga/notificationcommand.h"
|
2013-03-17 20:19:29 +01:00
|
|
|
#include "icinga/macroprocessor.h"
|
|
|
|
#include "icinga/service.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include "base/dynamictype.h"
|
|
|
|
#include "base/objectlock.h"
|
|
|
|
#include "base/logger_fwd.h"
|
2013-03-25 18:36:15 +01:00
|
|
|
#include "base/utility.h"
|
2013-06-26 09:08:50 +02:00
|
|
|
#include "base/convert.h"
|
2013-11-20 21:55:14 +01:00
|
|
|
#include "base/exception.h"
|
2013-12-17 14:24:29 +01:00
|
|
|
#include "base/initialize.h"
|
|
|
|
#include "base/scriptvariable.h"
|
2013-03-16 21:18:53 +01:00
|
|
|
#include <boost/foreach.hpp>
|
2013-02-09 11:42:22 +01:00
|
|
|
|
|
|
|
using namespace icinga;
|
|
|
|
|
2013-03-01 12:07:52 +01:00
|
|
|
REGISTER_TYPE(Notification);
|
2013-12-17 14:24:29 +01:00
|
|
|
INITIALIZE_ONCE(&Notification::StaticInitialize);
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2013-08-28 14:59:41 +02:00
|
|
|
boost::signals2::signal<void (const Notification::Ptr&, double, const String&)> Notification::OnNextNotificationChanged;
|
|
|
|
|
2014-04-06 08:09:49 +02:00
|
|
|
String NotificationNameComposer::MakeName(const String& shortName, const Dictionary::Ptr props) const
|
2014-04-05 22:17:20 +02:00
|
|
|
{
|
|
|
|
if (!props)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
String name = props->Get("host_name");
|
|
|
|
|
|
|
|
if (props->Contains("service_name"))
|
|
|
|
name += "!" + props->Get("service_name");
|
|
|
|
|
|
|
|
name += "!" + shortName;
|
|
|
|
|
|
|
|
return name;
|
|
|
|
}
|
|
|
|
|
2013-12-17 14:24:29 +01:00
|
|
|
void Notification::StaticInitialize(void)
|
|
|
|
{
|
|
|
|
ScriptVariable::Set("NotificationDowntimeStart", NotificationDowntimeStart, true, true);
|
|
|
|
ScriptVariable::Set("NotificationDowntimeEnd", NotificationDowntimeEnd, true, true);
|
|
|
|
ScriptVariable::Set("NotificationDowntimeRemoved", NotificationDowntimeRemoved, true, true);
|
|
|
|
ScriptVariable::Set("NotificationCustom", NotificationCustom, true, true);
|
|
|
|
ScriptVariable::Set("NotificationAcknowledgement", NotificationAcknowledgement, true, true);
|
|
|
|
ScriptVariable::Set("NotificationProblem", NotificationProblem, true, true);
|
|
|
|
ScriptVariable::Set("NotificationRecovery", NotificationRecovery, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFlappingStart", NotificationFlappingStart, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFlappingEnd", NotificationFlappingEnd, true, true);
|
|
|
|
|
|
|
|
ScriptVariable::Set("NotificationFilterDowntimeStart", 1 << NotificationDowntimeStart, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFilterDowntimeEnd", 1 << NotificationDowntimeEnd, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFilterDowntimeRemoved", 1 << NotificationDowntimeRemoved, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFilterCustom", 1 << NotificationCustom, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFilterAcknowledgement", 1 << NotificationAcknowledgement, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFilterProblem", 1 << NotificationProblem, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFilterRecovery", 1 << NotificationRecovery, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFilterFlappingStart", 1 << NotificationFlappingStart, true, true);
|
|
|
|
ScriptVariable::Set("NotificationFilterFlappingEnd", 1 << NotificationFlappingEnd, true, true);
|
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
void Notification::Start(void)
|
2013-02-09 15:20:10 +01:00
|
|
|
{
|
2013-08-20 11:06:04 +02:00
|
|
|
DynamicObject::Start();
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
GetCheckable()->AddNotification(GetSelf());
|
2013-02-09 11:42:22 +01:00
|
|
|
}
|
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
void Notification::Stop(void)
|
2013-02-09 11:42:22 +01:00
|
|
|
{
|
2013-08-20 11:06:04 +02:00
|
|
|
DynamicObject::Stop();
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
GetCheckable()->RemoveNotification(GetSelf());
|
2013-02-09 11:42:22 +01:00
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
Checkable::Ptr Notification::GetCheckable(void) const
|
2013-02-09 11:42:22 +01:00
|
|
|
{
|
2014-04-05 09:15:40 +02:00
|
|
|
Host::Ptr host = Host::GetByName(GetHostName());
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2014-04-05 09:15:40 +02:00
|
|
|
if (GetServiceName().IsEmpty())
|
2014-04-03 15:36:13 +02:00
|
|
|
return host;
|
2013-02-09 11:42:22 +01:00
|
|
|
else
|
2014-04-05 09:15:40 +02:00
|
|
|
return host->GetServiceByShortName(GetServiceName());
|
2013-02-09 11:42:22 +01:00
|
|
|
}
|
|
|
|
|
2013-06-13 11:33:00 +02:00
|
|
|
NotificationCommand::Ptr Notification::GetNotificationCommand(void) const
|
2013-02-09 11:42:22 +01:00
|
|
|
{
|
2013-10-26 09:41:45 +02:00
|
|
|
return NotificationCommand::GetByName(GetNotificationCommandRaw());
|
2013-03-22 14:40:55 +01:00
|
|
|
}
|
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<User::Ptr> Notification::GetUsers(void) const
|
2013-02-24 08:26:10 +01:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<User::Ptr> result;
|
2013-02-24 08:26:10 +01:00
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
Array::Ptr users = GetUsersRaw();
|
2013-02-24 08:26:10 +01:00
|
|
|
|
|
|
|
if (users) {
|
2013-03-01 12:07:52 +01:00
|
|
|
ObjectLock olock(users);
|
|
|
|
|
2013-03-15 18:21:29 +01:00
|
|
|
BOOST_FOREACH(const String& name, users) {
|
2013-02-27 21:49:03 +01:00
|
|
|
User::Ptr user = User::GetByName(name);
|
|
|
|
|
|
|
|
if (!user)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
result.insert(user);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-09-25 09:23:12 +02:00
|
|
|
std::set<UserGroup::Ptr> Notification::GetUserGroups(void) const
|
2013-02-27 21:49:03 +01:00
|
|
|
{
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<UserGroup::Ptr> result;
|
2013-02-27 21:49:03 +01:00
|
|
|
|
2013-10-26 09:41:45 +02:00
|
|
|
Array::Ptr groups = GetUserGroupsRaw();
|
2013-02-27 21:49:03 +01:00
|
|
|
|
|
|
|
if (groups) {
|
2013-03-01 12:07:52 +01:00
|
|
|
ObjectLock olock(groups);
|
|
|
|
|
2013-03-15 18:21:29 +01:00
|
|
|
BOOST_FOREACH(const String& name, groups) {
|
2013-02-27 21:49:03 +01:00
|
|
|
UserGroup::Ptr ug = UserGroup::GetByName(name);
|
|
|
|
|
|
|
|
if (!ug)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
result.insert(ug);
|
2013-02-24 08:26:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2013-03-21 13:42:46 +01:00
|
|
|
TimePeriod::Ptr Notification::GetNotificationPeriod(void) const
|
|
|
|
{
|
2013-10-26 09:41:45 +02:00
|
|
|
return TimePeriod::GetByName(GetNotificationPeriodRaw());
|
2013-03-20 10:08:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
double Notification::GetNextNotification(void) const
|
|
|
|
{
|
2013-10-26 09:41:45 +02:00
|
|
|
return GetNextNotificationRaw();
|
2013-03-20 10:08:27 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets the timestamp when the next periodical notification should be sent.
|
|
|
|
* This does not affect notifications that are sent for state changes.
|
|
|
|
*/
|
2013-08-28 14:59:41 +02:00
|
|
|
void Notification::SetNextNotification(double time, const String& authority)
|
2013-03-20 10:08:27 +01:00
|
|
|
{
|
2013-10-26 09:41:45 +02:00
|
|
|
SetNextNotificationRaw(time);
|
2013-08-28 14:59:41 +02:00
|
|
|
|
2013-11-10 16:53:57 +01:00
|
|
|
OnNextNotificationChanged(GetSelf(), time, authority);
|
2013-03-20 10:08:27 +01:00
|
|
|
}
|
|
|
|
|
2013-07-18 17:04:09 +02:00
|
|
|
void Notification::UpdateNotificationNumber(void)
|
|
|
|
{
|
2013-10-26 09:41:45 +02:00
|
|
|
SetNotificationNumber(GetNotificationNumber() + 1);
|
2013-07-18 17:04:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void Notification::ResetNotificationNumber(void)
|
|
|
|
{
|
2013-10-26 09:41:45 +02:00
|
|
|
SetNotificationNumber(0);
|
2013-07-18 17:04:09 +02:00
|
|
|
}
|
|
|
|
|
2013-02-24 01:10:34 +01:00
|
|
|
String Notification::NotificationTypeToString(NotificationType type)
|
2013-02-09 11:42:22 +01:00
|
|
|
{
|
2013-02-24 01:10:34 +01:00
|
|
|
switch (type) {
|
|
|
|
case NotificationDowntimeStart:
|
|
|
|
return "DOWNTIMESTART";
|
|
|
|
case NotificationDowntimeEnd:
|
|
|
|
return "DOWNTIMEEND";
|
|
|
|
case NotificationDowntimeRemoved:
|
|
|
|
return "DOWNTIMECANCELLED";
|
|
|
|
case NotificationCustom:
|
2013-02-24 12:47:24 +01:00
|
|
|
return "CUSTOM";
|
|
|
|
case NotificationAcknowledgement:
|
|
|
|
return "ACKNOWLEDGEMENT";
|
2013-02-24 01:10:34 +01:00
|
|
|
case NotificationProblem:
|
|
|
|
return "PROBLEM";
|
|
|
|
case NotificationRecovery:
|
|
|
|
return "RECOVERY";
|
2013-06-21 10:20:29 +02:00
|
|
|
case NotificationFlappingStart:
|
|
|
|
return "FLAPPINGSTART";
|
|
|
|
case NotificationFlappingEnd:
|
|
|
|
return "FLAPPINGEND";
|
2013-02-24 01:10:34 +01:00
|
|
|
default:
|
|
|
|
return "UNKNOWN_NOTIFICATION";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-11-09 14:22:38 +01:00
|
|
|
void Notification::BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force, const String& author, const String& text)
|
2013-02-24 01:10:34 +01:00
|
|
|
{
|
2013-03-07 16:00:10 +01:00
|
|
|
ASSERT(!OwnsLock());
|
2013-02-24 01:10:34 +01:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
Checkable::Ptr checkable = GetCheckable();
|
|
|
|
|
2013-05-13 13:44:57 +02:00
|
|
|
if (!force) {
|
2013-03-21 13:42:46 +01:00
|
|
|
TimePeriod::Ptr tp = GetNotificationPeriod();
|
|
|
|
|
|
|
|
if (tp && !tp->IsInside(Utility::GetTime())) {
|
|
|
|
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': not in timeperiod");
|
|
|
|
return;
|
|
|
|
}
|
2013-05-13 13:44:57 +02:00
|
|
|
|
|
|
|
double now = Utility::GetTime();
|
|
|
|
Dictionary::Ptr times = GetTimes();
|
|
|
|
|
2013-07-19 11:02:43 +02:00
|
|
|
if (type == NotificationProblem) {
|
2014-04-03 15:36:13 +02:00
|
|
|
if (times && times->Contains("begin") && now < checkable->GetLastHardStateChange() + times->Get("begin")) {
|
2013-07-19 11:02:43 +02:00
|
|
|
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': before escalation range");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
if (times && times->Contains("end") && now > checkable->GetLastHardStateChange() + times->Get("end")) {
|
2013-07-19 11:02:43 +02:00
|
|
|
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': after escalation range");
|
|
|
|
return;
|
|
|
|
}
|
2013-05-13 13:44:57 +02:00
|
|
|
}
|
2013-06-26 09:08:50 +02:00
|
|
|
|
|
|
|
unsigned long ftype = 1 << type;
|
|
|
|
|
2013-06-26 09:50:04 +02:00
|
|
|
Log(LogDebug, "icinga", "FType=" + Convert::ToString(ftype) + ", TypeFilter=" + Convert::ToString(GetNotificationTypeFilter()));
|
2013-06-26 09:08:50 +02:00
|
|
|
|
2013-06-26 09:50:04 +02:00
|
|
|
if (!(ftype & GetNotificationTypeFilter())) {
|
2013-06-26 09:08:50 +02:00
|
|
|
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': type filter does not match");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
|
|
|
|
Host::Ptr host;
|
|
|
|
|
|
|
|
if (service)
|
|
|
|
host = service->GetHost();
|
|
|
|
else
|
|
|
|
host = static_pointer_cast<Host>(checkable);
|
|
|
|
|
|
|
|
unsigned long fstate;
|
|
|
|
|
|
|
|
if (service)
|
|
|
|
fstate = 1 << service->GetState();
|
|
|
|
else
|
|
|
|
fstate = 1 << host->GetState();
|
2013-06-26 09:08:50 +02:00
|
|
|
|
2013-06-26 09:50:04 +02:00
|
|
|
if (!(fstate & GetNotificationStateFilter())) {
|
2013-06-26 09:08:50 +02:00
|
|
|
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': state filter does not match");
|
|
|
|
return;
|
|
|
|
}
|
2013-03-21 13:42:46 +01:00
|
|
|
}
|
|
|
|
|
2013-03-20 10:08:27 +01:00
|
|
|
{
|
|
|
|
ObjectLock olock(this);
|
|
|
|
|
2013-11-06 08:36:22 +01:00
|
|
|
double now = Utility::GetTime();
|
|
|
|
SetLastNotification(now);
|
|
|
|
|
|
|
|
if (type == NotificationProblem)
|
|
|
|
SetLastProblemNotification(now);
|
2013-03-20 10:08:27 +01:00
|
|
|
}
|
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<User::Ptr> allUsers;
|
2013-02-27 21:49:03 +01:00
|
|
|
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<User::Ptr> users = GetUsers();
|
2013-02-27 21:49:03 +01:00
|
|
|
std::copy(users.begin(), users.end(), std::inserter(allUsers, allUsers.begin()));
|
|
|
|
|
2013-09-25 09:23:12 +02:00
|
|
|
BOOST_FOREACH(const UserGroup::Ptr& ug, GetUserGroups()) {
|
2013-03-16 21:18:53 +01:00
|
|
|
std::set<User::Ptr> members = ug->GetMembers();
|
2013-02-27 21:49:03 +01:00
|
|
|
std::copy(members.begin(), members.end(), std::inserter(allUsers, allUsers.begin()));
|
|
|
|
}
|
2013-02-24 08:26:10 +01:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
Service::OnNotificationSendStart(GetSelf(), checkable, allUsers, type, cr, author, text);
|
2014-01-27 17:22:48 +01:00
|
|
|
|
2014-01-28 17:53:40 +01:00
|
|
|
std::set<User::Ptr> allNotifiedUsers;
|
2013-02-27 21:49:03 +01:00
|
|
|
BOOST_FOREACH(const User::Ptr& user, allUsers) {
|
2014-01-28 17:53:40 +01:00
|
|
|
if (!CheckNotificationUserFilters(type, user, force))
|
|
|
|
continue;
|
|
|
|
|
2013-06-13 11:33:00 +02:00
|
|
|
Log(LogDebug, "icinga", "Sending notification for user '" + user->GetName() + "'");
|
2013-07-01 11:17:58 +02:00
|
|
|
Utility::QueueAsyncCallback(boost::bind(&Notification::ExecuteNotificationHelper, this, type, user, cr, force, author, text));
|
2014-01-28 17:53:40 +01:00
|
|
|
|
|
|
|
/* collect all notified users */
|
|
|
|
allNotifiedUsers.insert(user);
|
2013-02-24 08:26:10 +01:00
|
|
|
}
|
2013-09-24 18:49:25 +02:00
|
|
|
|
2014-01-28 17:53:40 +01:00
|
|
|
/* used in db_ido for notification history */
|
2014-04-03 15:36:13 +02:00
|
|
|
Service::OnNotificationSentToAllUsers(GetSelf(), checkable, allNotifiedUsers, type, cr, author, text);
|
2013-02-24 08:26:10 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 17:53:40 +01:00
|
|
|
bool Notification::CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force)
|
2013-02-24 08:26:10 +01:00
|
|
|
{
|
2013-03-07 16:00:10 +01:00
|
|
|
ASSERT(!OwnsLock());
|
2013-03-02 09:07:47 +01:00
|
|
|
|
2013-06-26 09:08:50 +02:00
|
|
|
if (!force) {
|
2013-03-21 13:42:46 +01:00
|
|
|
TimePeriod::Ptr tp = user->GetNotificationPeriod();
|
2013-02-24 08:26:10 +01:00
|
|
|
|
2013-03-21 13:42:46 +01:00
|
|
|
if (tp && !tp->IsInside(Utility::GetTime())) {
|
|
|
|
Log(LogInformation, "icinga", "Not sending notifications for notification object '" +
|
|
|
|
GetName() + " and user '" + user->GetName() + "': user not in timeperiod");
|
2014-01-28 17:53:40 +01:00
|
|
|
return false;
|
2013-03-21 13:42:46 +01:00
|
|
|
}
|
2013-06-26 09:08:50 +02:00
|
|
|
|
|
|
|
unsigned long ftype = 1 << type;
|
|
|
|
|
2013-06-26 09:50:04 +02:00
|
|
|
if (!(ftype & user->GetNotificationTypeFilter())) {
|
2013-06-26 09:08:50 +02:00
|
|
|
Log(LogInformation, "icinga", "Not sending notifications for notification object '" +
|
|
|
|
GetName() + " and user '" + user->GetName() + "': type filter does not match");
|
2014-01-28 17:53:40 +01:00
|
|
|
return false;
|
2013-06-26 09:08:50 +02:00
|
|
|
}
|
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
Checkable::Ptr checkable = GetCheckable();
|
|
|
|
Service::Ptr service = dynamic_pointer_cast<Service>(checkable);
|
|
|
|
Host::Ptr host;
|
|
|
|
|
|
|
|
if (service)
|
|
|
|
host = service->GetHost();
|
|
|
|
else
|
|
|
|
host = static_pointer_cast<Host>(checkable);
|
|
|
|
|
|
|
|
unsigned long fstate;
|
|
|
|
|
|
|
|
if (service)
|
|
|
|
fstate = 1 << service->GetState();
|
|
|
|
else
|
|
|
|
fstate = 1 << host->GetState();
|
2013-06-26 09:08:50 +02:00
|
|
|
|
2013-06-26 09:50:04 +02:00
|
|
|
if (!(fstate & user->GetNotificationStateFilter())) {
|
2013-06-26 09:08:50 +02:00
|
|
|
Log(LogInformation, "icinga", "Not sending notifications for notification object '" +
|
|
|
|
GetName() + " and user '" + user->GetName() + "': state filter does not match");
|
2014-01-28 17:53:40 +01:00
|
|
|
return false;
|
2013-06-26 09:08:50 +02:00
|
|
|
}
|
2013-02-24 08:26:10 +01:00
|
|
|
}
|
|
|
|
|
2014-01-28 17:53:40 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author, const String& text)
|
|
|
|
{
|
|
|
|
ASSERT(!OwnsLock());
|
|
|
|
|
2013-02-09 11:42:22 +01:00
|
|
|
try {
|
2013-09-24 18:58:51 +02:00
|
|
|
NotificationCommand::Ptr command = GetNotificationCommand();
|
2013-09-24 18:49:25 +02:00
|
|
|
|
2013-09-24 18:58:51 +02:00
|
|
|
if (!command) {
|
|
|
|
Log(LogDebug, "icinga", "No notification_command found for notification '" + GetName() + "'. Skipping execution.");
|
|
|
|
return;
|
|
|
|
}
|
2013-09-24 18:49:25 +02:00
|
|
|
|
2013-10-19 00:19:16 +02:00
|
|
|
command->Execute(GetSelf(), user, cr, type, author, text);
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2013-07-18 17:04:09 +02:00
|
|
|
{
|
|
|
|
ObjectLock olock(this);
|
|
|
|
UpdateNotificationNumber();
|
2013-08-08 08:30:19 +02:00
|
|
|
SetLastNotification(Utility::GetTime());
|
2013-07-18 17:04:09 +02:00
|
|
|
}
|
|
|
|
|
2014-01-28 17:53:40 +01:00
|
|
|
/* required by compatlogger */
|
2014-04-03 15:36:13 +02:00
|
|
|
Service::OnNotificationSentToUser(GetSelf(), GetCheckable(), user, type, cr, author, text, command->GetName());
|
2013-06-28 21:31:38 +02:00
|
|
|
|
2014-04-03 15:36:13 +02:00
|
|
|
Log(LogInformation, "icinga", "Completed sending notification for object '" + GetCheckable()->GetName() + "'");
|
2013-03-16 21:18:53 +01:00
|
|
|
} catch (const std::exception& ex) {
|
|
|
|
std::ostringstream msgbuf;
|
2014-04-03 15:36:13 +02:00
|
|
|
msgbuf << "Exception occured during notification for object '"
|
|
|
|
<< GetCheckable()->GetName() << "': " << DiagnosticInformation(ex);
|
2013-09-03 15:23:47 +02:00
|
|
|
Log(LogWarning, "icinga", msgbuf.str());
|
2013-02-09 11:42:22 +01:00
|
|
|
}
|
|
|
|
}
|
2013-02-11 14:01:52 +01:00
|
|
|
|
2013-11-09 14:22:38 +01:00
|
|
|
bool Notification::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
|
2013-03-22 14:40:55 +01:00
|
|
|
{
|
2014-04-03 10:30:11 +02:00
|
|
|
Dictionary::Ptr vars = GetVars();
|
|
|
|
|
2014-04-04 22:57:56 +02:00
|
|
|
if (macro.SubStr(0, 13) == "notification.") {
|
|
|
|
String key = vars->Get(macro.SubStr(13));
|
2013-03-22 14:40:55 +01:00
|
|
|
|
2014-04-04 22:57:56 +02:00
|
|
|
if (vars && vars->Contains(key)) {
|
|
|
|
*result = vars->Get(key);
|
|
|
|
return true;
|
|
|
|
}
|
2013-03-22 14:40:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|