2019-02-25 14:48:22 +01:00
|
|
|
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
|
2013-02-09 11:42:22 +01:00
|
|
|
|
|
|
|
#ifndef NOTIFICATION_H
|
|
|
|
#define NOTIFICATION_H
|
|
|
|
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/i2-icinga.hpp"
|
2018-01-18 13:50:38 +01:00
|
|
|
#include "icinga/notification-ti.hpp"
|
|
|
|
#include "icinga/checkable-ti.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "icinga/user.hpp"
|
|
|
|
#include "icinga/usergroup.hpp"
|
|
|
|
#include "icinga/timeperiod.hpp"
|
|
|
|
#include "icinga/checkresult.hpp"
|
2014-11-13 11:23:57 +01:00
|
|
|
#include "remote/endpoint.hpp"
|
2014-05-25 16:23:35 +02:00
|
|
|
#include "remote/messageorigin.hpp"
|
|
|
|
#include "base/array.hpp"
|
2013-03-17 20:19:29 +01:00
|
|
|
|
2013-02-09 11:42:22 +01:00
|
|
|
namespace icinga
|
|
|
|
{
|
|
|
|
|
2014-04-07 13:59:41 +02:00
|
|
|
/**
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum NotificationFilter
|
|
|
|
{
|
|
|
|
StateFilterOK = 1,
|
|
|
|
StateFilterWarning = 2,
|
|
|
|
StateFilterCritical = 4,
|
|
|
|
StateFilterUnknown = 8,
|
|
|
|
|
|
|
|
StateFilterUp = 16,
|
|
|
|
StateFilterDown = 32
|
|
|
|
};
|
|
|
|
|
2013-02-09 11:42:22 +01:00
|
|
|
/**
|
|
|
|
* The notification type.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
|
|
|
enum NotificationType
|
|
|
|
{
|
2016-06-21 14:46:01 +02:00
|
|
|
NotificationDowntimeStart = 1,
|
|
|
|
NotificationDowntimeEnd = 2,
|
|
|
|
NotificationDowntimeRemoved = 4,
|
|
|
|
NotificationCustom = 8,
|
|
|
|
NotificationAcknowledgement = 16,
|
|
|
|
NotificationProblem = 32,
|
|
|
|
NotificationRecovery = 64,
|
|
|
|
NotificationFlappingStart = 128,
|
|
|
|
NotificationFlappingEnd = 256
|
2013-02-09 11:42:22 +01:00
|
|
|
};
|
|
|
|
|
2013-06-13 11:33:00 +02:00
|
|
|
class NotificationCommand;
|
2014-05-11 17:14:35 +02:00
|
|
|
class ApplyRule;
|
2014-12-12 15:33:02 +01:00
|
|
|
struct ScriptFrame;
|
2014-11-16 16:20:39 +01:00
|
|
|
class Host;
|
|
|
|
class Service;
|
2013-02-09 11:42:22 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* An Icinga notification specification.
|
|
|
|
*
|
|
|
|
* @ingroup icinga
|
|
|
|
*/
|
2018-01-04 06:11:04 +01:00
|
|
|
class Notification final : public ObjectImpl<Notification>
|
2013-02-09 11:42:22 +01:00
|
|
|
{
|
|
|
|
public:
|
2014-11-03 00:44:04 +01:00
|
|
|
DECLARE_OBJECT(Notification);
|
|
|
|
DECLARE_OBJECTNAME(Notification);
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static void StaticInitialize();
|
2013-12-17 14:24:29 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
intrusive_ptr<Checkable> GetCheckable() const;
|
|
|
|
intrusive_ptr<NotificationCommand> GetCommand() const;
|
|
|
|
TimePeriod::Ptr GetPeriod() const;
|
|
|
|
std::set<User::Ptr> GetUsers() const;
|
|
|
|
std::set<UserGroup::Ptr> GetUserGroups() const;
|
2013-03-20 10:08:27 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
void UpdateNotificationNumber();
|
|
|
|
void ResetNotificationNumber();
|
2013-07-18 17:04:09 +02:00
|
|
|
|
2016-08-12 14:49:29 +02:00
|
|
|
void BeginExecuteNotification(NotificationType type, const CheckResult::Ptr& cr, bool force,
|
2017-12-19 15:50:05 +01:00
|
|
|
bool reminder = false, const String& author = "", const String& text = "");
|
2014-01-28 17:53:40 +01:00
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
Endpoint::Ptr GetCommandEndpoint() const;
|
2014-11-04 22:03:39 +01:00
|
|
|
|
2019-07-02 16:33:11 +02:00
|
|
|
// Logging, etc.
|
2013-02-24 01:10:34 +01:00
|
|
|
static String NotificationTypeToString(NotificationType type);
|
2019-07-02 16:33:11 +02:00
|
|
|
// Compat, used for notifications, etc.
|
|
|
|
static String NotificationTypeToStringCompat(NotificationType type);
|
2016-06-21 14:46:01 +02:00
|
|
|
static String NotificationFilterToString(int filter, const std::map<String, int>& filterMap);
|
2013-02-09 11:42:22 +01:00
|
|
|
|
2019-07-02 16:33:11 +02:00
|
|
|
static String NotificationServiceStateToString(ServiceState state);
|
|
|
|
static String NotificationHostStateToString(HostState state);
|
|
|
|
|
2015-08-04 14:47:44 +02:00
|
|
|
static boost::signals2::signal<void (const Notification::Ptr&, const MessageOrigin::Ptr&)> OnNextNotificationChanged;
|
2013-08-28 14:59:41 +02:00
|
|
|
|
2018-01-04 05:12:56 +01:00
|
|
|
void Validate(int types, const ValidationUtils& utils) override;
|
2014-11-30 23:32:13 +01:00
|
|
|
|
2018-01-11 07:08:09 +01:00
|
|
|
void ValidateStates(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
|
|
|
void ValidateTypes(const Lazy<Array::Ptr>& lvalue, const ValidationUtils& utils) override;
|
2019-04-30 15:56:57 +02:00
|
|
|
void ValidateTimes(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
|
2014-04-07 13:59:41 +02:00
|
|
|
|
2014-11-16 16:20:39 +01:00
|
|
|
static void EvaluateApplyRules(const intrusive_ptr<Host>& host);
|
|
|
|
static void EvaluateApplyRules(const intrusive_ptr<Service>& service);
|
|
|
|
|
2018-01-04 04:25:35 +01:00
|
|
|
static const std::map<String, int>& GetStateFilterMap();
|
|
|
|
static const std::map<String, int>& GetTypeFilterMap();
|
2016-06-21 14:46:01 +02:00
|
|
|
|
2013-02-11 14:01:52 +01:00
|
|
|
protected:
|
2018-01-04 05:12:56 +01:00
|
|
|
void OnConfigLoaded() override;
|
|
|
|
void OnAllConfigLoaded() override;
|
|
|
|
void Start(bool runtimeCreated) override;
|
|
|
|
void Stop(bool runtimeRemoved) override;
|
2013-02-11 14:01:52 +01:00
|
|
|
|
2013-08-20 11:06:04 +02:00
|
|
|
private:
|
2015-10-29 08:06:03 +01:00
|
|
|
ObjectImpl<Checkable>::Ptr m_Checkable;
|
2015-08-20 17:18:48 +02:00
|
|
|
|
2016-08-12 14:49:29 +02:00
|
|
|
bool CheckNotificationUserFilters(NotificationType type, const User::Ptr& user, bool force, bool reminder);
|
|
|
|
|
2013-11-09 14:22:38 +01:00
|
|
|
void ExecuteNotificationHelper(NotificationType type, const User::Ptr& user, const CheckResult::Ptr& cr, bool force, const String& author = "", const String& text = "");
|
2014-04-05 12:56:56 +02:00
|
|
|
|
2022-10-27 16:15:35 +02:00
|
|
|
static bool EvaluateApplyRuleInstance(const intrusive_ptr<Checkable>& checkable, const String& name, ScriptFrame& frame, const ApplyRule& rule, bool skipFilter);
|
|
|
|
static bool EvaluateApplyRule(const intrusive_ptr<Checkable>& checkable, const ApplyRule& rule, bool skipFilter = false);
|
2015-03-12 17:09:26 +01:00
|
|
|
|
2016-06-21 14:46:01 +02:00
|
|
|
static std::map<String, int> m_StateFilterMap;
|
|
|
|
static std::map<String, int> m_TypeFilterMap;
|
2013-02-09 11:42:22 +01:00
|
|
|
};
|
|
|
|
|
2017-12-31 07:22:16 +01:00
|
|
|
int ServiceStateToFilter(ServiceState state);
|
|
|
|
int HostStateToFilter(HostState state);
|
2014-04-07 13:59:41 +02:00
|
|
|
|
2013-02-09 11:42:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* NOTIFICATION_H */
|