summaryrefslogtreecommitdiffstats
path: root/lib/icinga/notification.ti
blob: ab633c5dc8de03f762f2872d9047bafb90401149 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */

#include "icinga/customvarobject.hpp"
#impl_include "icinga/notificationcommand.hpp"
#impl_include "icinga/service.hpp"

library icinga;

namespace icinga
{

code {{{
class NotificationNameComposer : public NameComposer
{
public:
	virtual String MakeName(const String& shortName, const Object::Ptr& context) const;
	virtual Dictionary::Ptr ParseName(const String& name) const;
};
}}}

class Notification : CustomVarObject < NotificationNameComposer
{
	load_after Host;
	load_after Service;

	[config, protected, required, navigation] name(NotificationCommand) command (CommandRaw) {
		navigate {{{
			return NotificationCommand::GetByName(GetCommandRaw());
		}}}
	};
	[config] double interval {
		default {{{ return 1800; }}}
	};
	[config, navigation] name(TimePeriod) period (PeriodRaw) {
		navigate {{{
			return TimePeriod::GetByName(GetPeriodRaw());
		}}}
	};
	[config, signal_with_old_value] array(name(User)) users (UsersRaw);
	[config, signal_with_old_value] array(name(UserGroup)) user_groups (UserGroupsRaw);
	[config] Dictionary::Ptr times;
	[config] array(Value) types;
	[no_user_view, no_user_modify] int type_filter_real (TypeFilter);
	[config] array(Value) states;
	[no_user_view, no_user_modify] int state_filter_real (StateFilter);
	[config, protected, required, navigation(host)] name(Host) host_name {
		navigate {{{
			return Host::GetByName(GetHostName());
		}}}
	};
	[config, protected, navigation(service)] String service_name {
		track {{{
			if (!oldValue.IsEmpty()) {
				Service::Ptr service = Service::GetByNamePair(GetHostName(), oldValue);
				DependencyGraph::RemoveDependency(this, service.get());
			}

			if (!newValue.IsEmpty()) {
				Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
				DependencyGraph::AddDependency(this, service.get());
			}
		}}}
		navigate {{{
			if (GetServiceName().IsEmpty())
				return nullptr;

			Host::Ptr host = Host::GetByName(GetHostName());
			return host->GetServiceByShortName(GetServiceName());
		}}}
	};

	[state, no_user_modify] Array::Ptr notified_problem_users {
		default {{{ return new Array(); }}}
	};

	[state, no_user_modify] bool no_more_notifications {
		default {{{ return false; }}}
	};

	[state, no_user_view, no_user_modify] Array::Ptr stashed_notifications {
		default {{{ return new Array(); }}}
	};

	[state] Timestamp last_notification;
	[state] Timestamp next_notification;
	[state] int notification_number;
	[state] Timestamp last_problem_notification;

	[state, no_user_view, no_user_modify] int suppressed_notifications {
		default {{{ return 0; }}}
	};

	[config, navigation] name(Endpoint) command_endpoint (CommandEndpointRaw) {
		navigate {{{
			return Endpoint::GetByName(GetCommandEndpointRaw());
		}}}
	};
};

validator Notification {
	Dictionary times {
		Number begin;
		Number end;
	};
};

}