]> granicus.if.org Git - icinga2/blob - lib/icinga/comment.ti
Merge pull request #5964 from fedepires/fix/opentsdbwriter-host-tag-5963
[icinga2] / lib / icinga / comment.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 "base/configobject.hpp"
21 #include "base/utility.hpp"
22 #impl_include "icinga/service.hpp"
23
24 library icinga;
25
26 namespace icinga
27 {
28
29 code {{{
30 /**
31  * The type of a service comment.
32  *
33  * @ingroup icinga
34  */
35 enum CommentType
36 {
37         CommentUser = 1,
38         CommentDowntime = 2,
39         CommentFlapping = 3,
40         CommentAcknowledgement = 4
41 };
42
43 class CommentNameComposer : public NameComposer
44 {
45 public:
46         virtual String MakeName(const String& shortName, const Object::Ptr& context) const;
47         virtual Dictionary::Ptr ParseName(const String& name) const;
48 };
49 }}}
50
51 class Comment : ConfigObject < CommentNameComposer
52 {
53         load_after Host;
54         load_after Service;
55
56         [config, protected, required, navigation(host)] name(Host) host_name {
57                 navigate {{{
58                         return Host::GetByName(GetHostName());
59                 }}}
60         };
61         [config, protected, navigation(service)] String service_name {
62                 track {{{
63                         if (!oldValue.IsEmpty()) {
64                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), oldValue);
65                                 DependencyGraph::RemoveDependency(this, service.get());
66                         }
67
68                         if (!newValue.IsEmpty()) {
69                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
70                                 DependencyGraph::AddDependency(this, service.get());
71                         }
72                 }}}
73                 navigate {{{
74                         if (GetServiceName().IsEmpty())
75                                 return nullptr;
76
77                         Host::Ptr host = Host::GetByName(GetHostName());
78                         return host->GetServiceByShortName(GetServiceName());
79                 }}}
80         };
81
82         [config] Timestamp entry_time {
83                 default {{{ return Utility::GetTime(); }}}
84         };
85         [config, enum] CommentType entry_type {
86                 default {{{ return CommentUser; }}}
87         };
88         [config, required] String author;
89         [config, required] String text;
90         [config] bool persistent;
91         [config] Timestamp expire_time;
92         [state] int legacy_id;
93 };
94
95 }