]> granicus.if.org Git - icinga2/blob - lib/icinga/notification.ti
Merge pull request #7002 from Icinga/bugfix/check_network-percent-6155
[icinga2] / lib / icinga / notification.ti
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "icinga/customvarobject.hpp"
4 #impl_include "icinga/notificationcommand.hpp"
5 #impl_include "icinga/service.hpp"
6
7 library icinga;
8
9 namespace icinga
10 {
11
12 code {{{
13 class NotificationNameComposer : public NameComposer
14 {
15 public:
16         virtual String MakeName(const String& shortName, const Object::Ptr& context) const;
17         virtual Dictionary::Ptr ParseName(const String& name) const;
18 };
19 }}}
20
21 class Notification : CustomVarObject < NotificationNameComposer
22 {
23         load_after Host;
24         load_after Service;
25
26         [config, protected, required, navigation] name(NotificationCommand) command (CommandRaw) {
27                 navigate {{{
28                         return NotificationCommand::GetByName(GetCommandRaw());
29                 }}}
30         };
31         [config] double interval {
32                 default {{{ return 1800; }}}
33         };
34         [config, navigation] name(TimePeriod) period (PeriodRaw) {
35                 navigate {{{
36                         return TimePeriod::GetByName(GetPeriodRaw());
37                 }}}
38         };
39         [config, protected] array(name(User)) users (UsersRaw);
40         [config, protected] array(name(UserGroup)) user_groups (UserGroupsRaw);
41         [config] Dictionary::Ptr times;
42         [config] array(Value) types;
43         [no_user_view, no_user_modify] int type_filter_real (TypeFilter);
44         [config] array(Value) states;
45         [no_user_view, no_user_modify] int state_filter_real (StateFilter);
46         [config, protected, required, navigation(host)] name(Host) host_name {
47                 navigate {{{
48                         return Host::GetByName(GetHostName());
49                 }}}
50         };
51         [config, protected, navigation(service)] String service_name {
52                 track {{{
53                         if (!oldValue.IsEmpty()) {
54                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), oldValue);
55                                 DependencyGraph::RemoveDependency(this, service.get());
56                         }
57
58                         if (!newValue.IsEmpty()) {
59                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
60                                 DependencyGraph::AddDependency(this, service.get());
61                         }
62                 }}}
63                 navigate {{{
64                         if (GetServiceName().IsEmpty())
65                                 return nullptr;
66
67                         Host::Ptr host = Host::GetByName(GetHostName());
68                         return host->GetServiceByShortName(GetServiceName());
69                 }}}
70         };
71
72         [state, no_user_modify] Array::Ptr notified_problem_users {
73                 default {{{ return new Array(); }}}
74         };
75
76         [state, no_user_modify] bool no_more_notifications {
77                 default {{{ return false; }}}
78         };
79
80         [state] Timestamp last_notification;
81         [state] Timestamp next_notification;
82         [state] int notification_number;
83         [state] Timestamp last_problem_notification;
84
85         [config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
86                 navigate {{{
87                         return Endpoint::GetByName(GetCommandEndpointRaw());
88                 }}}
89         };
90 };
91
92 validator Notification {
93         Dictionary times {
94                 Number begin;
95                 Number end;
96         };
97 };
98
99 }