]> granicus.if.org Git - icinga2/blob - lib/icinga/downtime.ti
Activate downtimes before any checkable object
[icinga2] / lib / icinga / downtime.ti
1 /******************************************************************************
2  * Icinga 2                                                                   *
3  * Copyright (C) 2012-2018 Icinga Development Team (https://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         activation_priority -10;
41
42         load_after Host;
43         load_after Service;
44
45         [config, protected, required, navigation(host)] name(Host) host_name {
46                 navigate {{{
47                         return Host::GetByName(GetHostName());
48                 }}}
49         };
50         [config, protected, navigation(service)] String service_name {
51                 track {{{
52                         if (!oldValue.IsEmpty()) {
53                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), oldValue);
54                                 DependencyGraph::RemoveDependency(this, service.get());
55                         }
56
57                         if (!newValue.IsEmpty()) {
58                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
59                                 DependencyGraph::AddDependency(this, service.get());
60                         }
61                 }}}
62                 navigate {{{
63                         if (GetServiceName().IsEmpty())
64                                 return nullptr;
65
66                         Host::Ptr host = Host::GetByName(GetHostName());
67                         return host->GetServiceByShortName(GetServiceName());
68                 }}}
69         };
70
71         [config] Timestamp entry_time {
72                 default {{{ return Utility::GetTime(); }}}
73         };
74         [config, required] String author;
75         [config, required] String comment;
76         [config] Timestamp start_time;
77         [config] Timestamp end_time;
78         [state] Timestamp trigger_time;
79         [config] bool fixed;
80         [config] Timestamp duration;
81         [config] String triggered_by;
82         [config] String scheduled_by;
83         [state] Array::Ptr triggers {
84                 default {{{ return new Array(); }}}
85         };
86         [state] int legacy_id;
87         [state] bool was_cancelled;
88         [config] String config_owner;
89         [config] String authoritative_zone;
90 };
91
92 }