ConfigCompilerContext::SetContext(&context);
- BOOST_FOREACH(const String& configPath, g_AppParams["config"].as<std::vector<String> >()) {
- ConfigCompiler::CompileFile(configPath);
- }
-
String name, fragment;
BOOST_FOREACH(boost::tie(name, fragment), ConfigFragmentRegistry::GetInstance()->GetItems()) {
ConfigCompiler::CompileText(name, fragment);
}
+ BOOST_FOREACH(const String& configPath, g_AppParams["config"].as<std::vector<String> >()) {
+ ConfigCompiler::CompileFile(configPath);
+ }
+
ConfigCompilerContext::SetContext(NULL);
bool hasError = false;
******************************************************************************/
#include "base/scriptvariable.h"
+#include "base/logger_fwd.h"
using namespace icinga;
Value ScriptVariable::Get(const String& name)
{
- return m_Registry.GetItem(name);
+ Value value = m_Registry.GetItem(name);
+ if (value.IsEmpty())
+ Log(LogWarning, "icinga", "Tried to access empty variable: " + name);
+
+ return value;
}
void ScriptVariable::Set(const String& name, const Value& value)
%attribute number "end",
},
+ %attribute number "type_filter",
+ %attribute number "state_filter"
}
}
}
%attribute string "action_url"
}
+set StateOK = (0)
+set StateWarning = (1)
+set StateCritical = (2)
+set StateUnknown = (3)
+set StateUncheckable = (4)
+
+/*
+ * Converting states to their filter values: 1<<state
+ */
+set StateFilterOK = (1<<StateOK)
+set StateFilterWarning = (1<<StateWarning)
+set StateFilterCritical = (1<<StateCritical)
+set StateFilterUnknown = (1<<StateUnknown)
+set StateFilterUncheckable = (1<<StateUncheckable)
+
+set NotificationDowntimeStart = (0)
+set NotificationDowntimeEnd = (1)
+set NotificationDowntimeRemoved = (2)
+set NotificationCustom = (3)
+set NotificationAcknowledgement = (4)
+set NotificationProblem = (5)
+set NotificationRecovery = (6)
+set NotificationFlappingStart = (7)
+set NotificationFlappingEnd = (8)
+
+/*
+ * Converting notification types to their filter values: 1<<type
+ */
+set NotificationFilterDowntimeStart = (1<<NotificationDowntimeStart)
+set NotificationFilterDowntimeEnd = (1<<NotificationDowntimeEnd)
+set NotificationFilterDowntimeRemoved = (1<<NotificationDowntimeRemoved)
+set NotificationFilterCustom = (1<<NotificationCustom)
+set NotificationFilterAcknowledgement = (1<<NotificationAcknowledgement)
+set NotificationFilterProblem = (1<<NotificationProblem)
+set NotificationFilterRecovery = (1<<NotificationRecovery)
+set NotificationFilterFlappingStart = (1<<NotificationFlappingStart)
+set NotificationFilterFlappingEnd = (1<<NotificationFlappingEnd)
+
type Notification {
%require "host_name",
%attribute string "host_name",
%attribute name(NotificationCommand) "notification_command",
%attribute number "notification_interval",
- %attribute name(TimePeriod) "notification_period"
+ %attribute name(TimePeriod) "notification_period",
+
+ %attribute number "type_filter",
+ %attribute number "state_filter"
}
type User {
%attribute array "groups" {
%attribute name(UserGroup) "*"
- }
+ },
+
+ %attribute number "type_filter",
+ %attribute number "state_filter"
+
}
type UserGroup {
#include "base/objectlock.h"
#include "base/logger_fwd.h"
#include "base/utility.h"
+#include "base/convert.h"
#include <boost/tuple/tuple.hpp>
#include <boost/foreach.hpp>
#include <boost/exception/diagnostic_information.hpp>
RegisterAttribute("users", Attribute_Config, &m_Users);
RegisterAttribute("groups", Attribute_Config, &m_Groups);
RegisterAttribute("times", Attribute_Config, &m_Times);
+ RegisterAttribute("type_filter", Attribute_Config, &m_TypeFilter);
+ RegisterAttribute("state_filter", Attribute_Config, &m_StateFilter);
RegisterAttribute("host_name", Attribute_Config, &m_HostName);
RegisterAttribute("service", Attribute_Config, &m_Service);
RegisterAttribute("export_macros", Attribute_Config, &m_ExportMacros);
return m_Times;
}
+unsigned long Notification::GetTypeFilter(void) const
+{
+ if (m_TypeFilter.IsEmpty())
+ return ~(unsigned long)0; /* All states. */
+ else
+ return m_TypeFilter;
+}
+
+unsigned long Notification::GetStateFilter(void) const
+{
+ if (m_StateFilter.IsEmpty())
+ return ~(unsigned long)0; /* All states. */
+ else
+ return m_StateFilter;
+}
+
double Notification::GetNotificationInterval(void) const
{
if (m_NotificationInterval.IsEmpty())
Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': after escalation range");
return;
}
+
+ unsigned long ftype = 1 << type;
+
+ Log(LogDebug, "icinga", "FType=" + Convert::ToString(ftype) + ", TypeFilter=" + Convert::ToString(GetTypeFilter()));
+
+ if (!(ftype & GetTypeFilter())) {
+ Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': type filter does not match");
+ return;
+ }
+
+ unsigned long fstate = 1 << GetService()->GetState();
+
+ Log(LogDebug, "icinga", "FState=" + Convert::ToString(fstate) + ", StateFilter=" + Convert::ToString(GetStateFilter()));
+
+ if (!(fstate & GetStateFilter())) {
+ Log(LogInformation, "icinga", "Not sending notifications for notification object '" + GetName() + "': state filter does not match");
+ return;
+ }
}
{
}
}
-void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool ignore_timeperiod)
+void Notification::ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const Dictionary::Ptr& cr, bool force)
{
ASSERT(!OwnsLock());
- if (!ignore_timeperiod) {
+ if (!force) {
TimePeriod::Ptr tp = user->GetNotificationPeriod();
if (tp && !tp->IsInside(Utility::GetTime())) {
GetName() + " and user '" + user->GetName() + "': user not in timeperiod");
return;
}
+
+ unsigned long ftype = 1 << type;
+
+ if (!(ftype & user->GetTypeFilter())) {
+ Log(LogInformation, "icinga", "Not sending notifications for notification object '" +
+ GetName() + " and user '" + user->GetName() + "': type filter does not match");
+ return;
+ }
+
+ unsigned long fstate = 1 << GetService()->GetState();
+
+ if (!(fstate & user->GetStateFilter())) {
+ Log(LogInformation, "icinga", "Not sending notifications for notification object '" +
+ GetName() + " and user '" + user->GetName() + "': state filter does not match");
+ return;
+ }
}
try {
*/
enum NotificationType
{
- NotificationDowntimeStart,
- NotificationDowntimeEnd,
- NotificationDowntimeRemoved,
- NotificationCustom,
- NotificationAcknowledgement,
- NotificationProblem,
- NotificationRecovery,
- NotificationFlappingStart,
- NotificationFlappingEnd,
+ NotificationDowntimeStart = 0,
+ NotificationDowntimeEnd = 1,
+ NotificationDowntimeRemoved = 2,
+ NotificationCustom = 3,
+ NotificationAcknowledgement = 4,
+ NotificationProblem = 5,
+ NotificationRecovery = 6,
+ NotificationFlappingStart = 7 ,
+ NotificationFlappingEnd = 8,
};
class Service;
std::set<User::Ptr> GetUsers(void) const;
std::set<UserGroup::Ptr> GetGroups(void) const;
Dictionary::Ptr GetTimes(void) const;
+ unsigned long GetTypeFilter(void) const;
+ unsigned long GetStateFilter(void) const;
double GetLastNotification(void) const;
void SetLastNotification(double time);
Attribute<Array::Ptr> m_Users;
Attribute<Array::Ptr> m_Groups;
Attribute<Dictionary::Ptr> m_Times;
+ Attribute<long> m_TypeFilter;
+ Attribute<long> m_StateFilter;
Attribute<String> m_HostName;
Attribute<String> m_Service;
RegisterAttribute("macros", Attribute_Config, &m_Macros);
RegisterAttribute("groups", Attribute_Config, &m_Groups);
RegisterAttribute("notification_period", Attribute_Config, &m_NotificationPeriod);
+ RegisterAttribute("type_filter", Attribute_Config, &m_TypeFilter);
+ RegisterAttribute("state_filter", Attribute_Config, &m_StateFilter);
}
User::~User(void)
return TimePeriod::GetByName(m_NotificationPeriod);
}
+unsigned long User::GetTypeFilter(void) const
+{
+ if (m_TypeFilter.IsEmpty())
+ return ~(unsigned long)0; /* All states. */
+ else
+ return m_TypeFilter;
+}
+
+unsigned long User::GetStateFilter(void) const
+{
+ if (m_StateFilter.IsEmpty())
+ return ~(unsigned long)0; /* All states. */
+ else
+ return m_StateFilter;
+}
+
bool User::ResolveMacro(const String& macro, const Dictionary::Ptr& cr, String *result) const
{
if (macro == "CONTACTNAME") {
String GetDisplayName(void) const;
Array::Ptr GetGroups(void) const;
TimePeriod::Ptr GetNotificationPeriod(void) const;
+ unsigned long GetTypeFilter(void) const;
+ unsigned long GetStateFilter(void) const;
Dictionary::Ptr GetMacros(void) const;
Attribute<Dictionary::Ptr> m_Macros;
Attribute<String> m_NotificationPeriod;
Attribute<Array::Ptr> m_Groups;
+ Attribute<long> m_TypeFilter;
+ Attribute<long> m_StateFilter;
};
}