]> granicus.if.org Git - icinga2/blob - lib/livestatus/zonestable.cpp
Docs: Explain across midnight time periods with an overlapping range
[icinga2] / lib / livestatus / zonestable.cpp
1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
2
3 #include "livestatus/zonestable.hpp"
4 #include "remote/zone.hpp"
5 #include "base/configtype.hpp"
6
7 using namespace icinga;
8
9 ZonesTable::ZonesTable()
10 {
11         AddColumns(this);
12 }
13
14 void ZonesTable::AddColumns(Table *table, const String& prefix,
15         const Column::ObjectAccessor& objectAccessor)
16 {
17         table->AddColumn(prefix + "name", Column(&ZonesTable::NameAccessor, objectAccessor));
18         table->AddColumn(prefix + "parent", Column(&ZonesTable::ParentAccessor, objectAccessor));
19         table->AddColumn(prefix + "endpoints", Column(&ZonesTable::EndpointsAccessor, objectAccessor));
20         table->AddColumn(prefix + "global", Column(&ZonesTable::GlobalAccessor, objectAccessor));
21 }
22
23 String ZonesTable::GetName() const
24 {
25         return "zones";
26 }
27
28 String ZonesTable::GetPrefix() const
29 {
30         return "zone";
31 }
32
33 void ZonesTable::FetchRows(const AddRowFunction& addRowFn)
34 {
35         for (const Zone::Ptr& zone : ConfigType::GetObjectsByType<Zone>()) {
36                 if (!addRowFn(zone, LivestatusGroupByNone, Empty))
37                         return;
38         }
39 }
40
41 Value ZonesTable::NameAccessor(const Value& row)
42 {
43         Zone::Ptr zone = static_cast<Zone::Ptr>(row);
44
45         if (!zone)
46                 return Empty;
47
48         return zone->GetName();
49 }
50
51 Value ZonesTable::ParentAccessor(const Value& row)
52 {
53         Zone::Ptr zone = static_cast<Zone::Ptr>(row);
54
55         if (!zone)
56                 return Empty;
57
58         Zone::Ptr parent_zone = zone->GetParent();
59
60         if (!parent_zone)
61                 return Empty;
62
63         return parent_zone->GetName();
64 }
65
66 Value ZonesTable::EndpointsAccessor(const Value& row)
67 {
68         Zone::Ptr zone = static_cast<Zone::Ptr>(row);
69
70         if (!zone)
71                 return Empty;
72
73         std::set<Endpoint::Ptr> endpoints = zone->GetEndpoints();
74
75         ArrayData result;
76
77         for (const Endpoint::Ptr& endpoint : endpoints) {
78                 result.push_back(endpoint->GetName());
79         }
80
81         return new Array(std::move(result));
82 }
83
84 Value ZonesTable::GlobalAccessor(const Value& row)
85 {
86         Zone::Ptr zone = static_cast<Zone::Ptr>(row);
87
88         if (!zone)
89                 return Empty;
90
91         return zone->GetGlobal() ? 1 : 0;
92 }