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