summaryrefslogtreecommitdiffstats
path: root/lib/icinga/comment.ti
blob: 853c28faca2f03bbbf32f5d6822843154d1a8187 (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
/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */

#include "base/configobject.hpp"
#include "base/utility.hpp"
#impl_include "icinga/service.hpp"

library icinga;

namespace icinga
{

code {{{
/**
 * The type of a service comment.
 *
 * @ingroup icinga
 */
enum CommentType
{
	CommentUser = 1,
	CommentAcknowledgement = 4
};

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

class Comment : ConfigObject < CommentNameComposer
{
	load_after Host;
	load_after Service;

	[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());
		}}}
	};

	[config] Timestamp entry_time {
		default {{{ return Utility::GetTime(); }}}
	};
	[config, enum] CommentType entry_type {
		default {{{ return CommentUser; }}}
	};
	[config, no_user_view, no_user_modify] bool sticky;
	[config, required] String author;
	[config, required] String text;
	[config] bool persistent;
	[config] Timestamp expire_time;
	[state] int legacy_id;

	[no_user_view, no_user_modify] String removed_by;
	[no_user_view, no_user_modify] Timestamp remove_time;
};

}