]> granicus.if.org Git - icinga2/blob - lib/icinga/scheduleddowntime.ti
Service: be handled while host is down
[icinga2] / lib / icinga / scheduleddowntime.ti
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "icinga/customvarobject.hpp"
4 #impl_include "icinga/service.hpp"
5
6 library icinga;
7
8 namespace icinga
9 {
10
11 code {{{
12 class ScheduledDowntimeNameComposer : public NameComposer
13 {
14 public:
15         virtual String MakeName(const String& shortName, const Object::Ptr& context) const;
16         virtual Dictionary::Ptr ParseName(const String& name) const;
17 };
18 }}}
19
20 class ScheduledDowntime : CustomVarObject < ScheduledDowntimeNameComposer
21 {
22         // Scheduled Downtimes have a dependency on Downtimes. This is to make sure ScheduledDowntimes are activated after
23         // the Downtimes (and other checkables)
24         activation_priority 20;
25
26         load_after Host;
27         load_after Service;
28
29         [config, protected, required, navigation(host)] name(Host) host_name {
30                 navigate {{{
31                         return Host::GetByName(GetHostName());
32                 }}}
33         };
34         [config, protected, navigation(service)] String service_name {
35                 track {{{
36                         if (!oldValue.IsEmpty()) {
37                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), oldValue);
38                                 DependencyGraph::RemoveDependency(this, service.get());
39                         }
40
41                         if (!newValue.IsEmpty()) {
42                                 Service::Ptr service = Service::GetByNamePair(GetHostName(), newValue);
43                                 DependencyGraph::AddDependency(this, service.get());
44                         }
45                 }}}
46                 navigate {{{
47                         if (GetServiceName().IsEmpty())
48                                 return nullptr;
49
50                         Host::Ptr host = Host::GetByName(GetHostName());
51                         return host->GetServiceByShortName(GetServiceName());
52                 }}}
53         };
54
55         [config, required] String author;
56         [config, required] String comment;
57
58         [config] double duration;
59         [config] bool fixed {
60                 default {{{ return true; }}}
61         };
62
63         [config] Value child_options {
64             default {{{ return "DowntimeNoChildren"; }}}
65         };
66
67         [config, required] Dictionary::Ptr ranges;
68 };
69
70 validator ScheduledDowntime {
71         Dictionary ranges {
72                 String "*";
73         };
74 };
75
76 }