]> granicus.if.org Git - icinga2/blob - lib/icinga/downtime.ti
Merge pull request #5964 from fedepires/fix/opentsdbwriter-host-tag-5963
[icinga2] / lib / icinga / downtime.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 class DowntimeNameComposer : public NameComposer
31 {
32 public:
33         virtual String MakeName(const String& shortName, const Object::Ptr& context) const;
34         virtual Dictionary::Ptr ParseName(const String& name) const;
35 };
36 }}}
37
38 class Downtime : ConfigObject < DowntimeNameComposer
39 {
40         load_after Host;
41         load_after Service;
42
43         [config, protected, required, navigation(host)] name(Host) host_name {
44                 navigate {{{
45                         return Host::GetByName(GetHostName());
46                 }}}
47         };
48         [config, protected, navigation(service)] String service_name {
49                 track {{{
50                         if (!oldValue.IsEmpty()) {
51                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), oldValue);
52                                 DependencyGraph::RemoveDependency(this, service.get());
53                         }
54
55                         if (!newValue.IsEmpty()) {
56                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
57                                 DependencyGraph::AddDependency(this, service.get());
58                         }
59                 }}}
60                 navigate {{{
61                         if (GetServiceName().IsEmpty())
62                                 return nullptr;
63
64                         Host::Ptr host = Host::GetByName(GetHostName());
65                         return host->GetServiceByShortName(GetServiceName());
66                 }}}
67         };
68
69         [config] Timestamp entry_time {
70                 default {{{ return Utility::GetTime(); }}}
71         };
72         [config, required] String author;
73         [config, required] String comment;
74         [config] Timestamp start_time;
75         [config] Timestamp end_time;
76         [state] Timestamp trigger_time;
77         [config] bool fixed;
78         [config] Timestamp duration;
79         [config] String triggered_by;
80         [config] String scheduled_by;
81         [state] Array::Ptr triggers {
82                 default {{{ return new Array(); }}}
83         };
84         [state] int legacy_id;
85         [state] bool was_cancelled;
86         [config] String config_owner;
87 };
88
89 }