]> granicus.if.org Git - icinga2/blob - lib/icinga/notification.h
Implemented LAST*STATE* macros.
[icinga2] / lib / icinga / notification.h
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012 Icinga Development Team (http://www.icinga.org/)        *
4  *                                                                            *
5  * This program is free software; you can redistribute it and/or              *
6  * modify it under the terms of the GNU General Public License                *
7  * as published by the Free Software Foundation; either version 2             *
8  * of the License, or (at your option) any later version.                     *
9  *                                                                            *
10  * This program is distributed in the hope that it will be useful,            *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
13  * GNU General Public License for more details.                               *
14  *                                                                            *
15  * You should have received a copy of the GNU General Public License          *
16  * along with this program; if not, write to the Free Software Foundation     *
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
18  ******************************************************************************/
19
20 #ifndef NOTIFICATION_H
21 #define NOTIFICATION_H
22
23 namespace icinga
24 {
25
26 /**
27  * The notification type.
28  *
29  * @ingroup icinga
30  */
31 enum NotificationType
32 {
33         NotificationDowntimeStart,
34         NotificationDowntimeEnd,
35         NotificationDowntimeRemoved,
36         NotificationCustom,
37         NotificationAcknowledgement,
38         NotificationProblem,
39         NotificationRecovery
40 };
41
42 class Service;
43
44 /**
45  * An Icinga notification specification.
46  *
47  * @ingroup icinga
48  */
49 class I2_ICINGA_API Notification : public DynamicObject
50 {
51 public:
52         typedef shared_ptr<Notification> Ptr;
53         typedef weak_ptr<Notification> WeakPtr;
54
55         Notification(const Dictionary::Ptr& properties);
56         ~Notification(void);
57
58         static Notification::Ptr GetByName(const String& name);
59
60         shared_ptr<Service> GetService(void) const;
61         Value GetNotificationCommand(void) const;
62         Dictionary::Ptr GetMacros(void) const;
63         set<User::Ptr> GetUsers(void) const;
64         set<UserGroup::Ptr> GetGroups(void) const;
65
66         void BeginExecuteNotification(NotificationType type, const Dictionary::Ptr& cr);
67
68         static String NotificationTypeToString(NotificationType type);
69
70 protected:
71         void OnAttributeChanged(const String& name);
72
73 private:
74         Attribute<Value> m_NotificationCommand;
75         Attribute<Dictionary::Ptr> m_Macros;
76         Attribute<Dictionary::Ptr> m_Users;
77         Attribute<Dictionary::Ptr> m_Groups;
78         Attribute<String> m_HostName;
79         Attribute<String> m_Service;
80
81         set<ScriptTask::Ptr> m_Tasks;
82
83         void NotificationCompletedHandler(const ScriptTask::Ptr& task);
84
85         void BeginExecuteNotificationHelper(const Dictionary::Ptr& notificationMacros,
86             NotificationType type, const User::Ptr& user);
87 };
88
89 }
90
91 #endif /* NOTIFICATION_H */