]> granicus.if.org Git - icinga2/blob - lib/icinga/notification.ti
Merge pull request #5927 from Icinga/feature/static-libraries
[icinga2] / lib / icinga / notification.ti
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/)  *
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 #include "icinga/customvarobject.hpp"
21 #impl_include "icinga/notificationcommand.hpp"
22 #impl_include "icinga/service.hpp"
23
24 library icinga;
25
26 namespace icinga
27 {
28
29 code {{{
30 class NotificationNameComposer : public NameComposer
31 {
32 public:
33         virtual String MakeName(const String& shortName, const Object::Ptr& context) const;
34         virtual Dictionary::Ptr ParseName(const String& name) const;
35 };
36 }}}
37
38 class Notification : CustomVarObject < NotificationNameComposer
39 {
40         load_after Host;
41         load_after Service;
42
43         [config, protected, required, navigation] name(NotificationCommand) command (CommandRaw) {
44                 navigate {{{
45                         return NotificationCommand::GetByName(GetCommandRaw());
46                 }}}
47         };
48         [config] double interval {
49                 default {{{ return 1800; }}}
50         };
51         [config, navigation] name(TimePeriod) period (PeriodRaw) {
52                 navigate {{{
53                         return TimePeriod::GetByName(GetPeriodRaw());
54                 }}}
55         };
56         [config, protected] array(name(User)) users (UsersRaw);
57         [config, protected] array(name(UserGroup)) user_groups (UserGroupsRaw);
58         [config] Dictionary::Ptr times;
59         [config] array(Value) types;
60         [no_user_view, no_user_modify] int type_filter_real (TypeFilter);
61         [config] array(Value) states;
62         [no_user_view, no_user_modify] int state_filter_real (StateFilter);
63         [config, protected, required, navigation(host)] name(Host) host_name {
64                 navigate {{{
65                         return Host::GetByName(GetHostName());
66                 }}}
67         };
68         [config, protected, navigation(service)] String service_name {
69                 track {{{
70                         if (!oldValue.IsEmpty()) {
71                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), oldValue);
72                                 DependencyGraph::RemoveDependency(this, service.get());
73                         }
74
75                         if (!newValue.IsEmpty()) {
76                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
77                                 DependencyGraph::AddDependency(this, service.get());
78                         }
79                 }}}
80                 navigate {{{
81                         if (GetServiceName().IsEmpty())
82                                 return nullptr;
83
84                         Host::Ptr host = Host::GetByName(GetHostName());
85                         return host->GetServiceByShortName(GetServiceName());
86                 }}}
87         };
88
89         [state, no_user_modify] Array::Ptr notified_problem_users {
90                 default {{{ return new Array(); }}}
91         };
92
93         [state, no_user_modify] bool no_more_notifications {
94                 default {{{ return false; }}}
95         };
96
97         [state] Timestamp last_notification;
98         [state] Timestamp next_notification;
99         [state] int notification_number;
100         [state] Timestamp last_problem_notification;
101
102         [config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
103                 navigate {{{
104                         return Endpoint::GetByName(GetCommandEndpointRaw());
105                 }}}
106         };
107 };
108
109 validator Notification {
110         Dictionary times {
111                 Number begin;
112                 Number end;
113         };
114 };
115
116 }