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