1 /* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
3 #include "livestatus/endpointstable.hpp"
4 #include "icinga/host.hpp"
5 #include "icinga/service.hpp"
6 #include "icinga/icingaapplication.hpp"
7 #include "remote/endpoint.hpp"
8 #include "remote/zone.hpp"
9 #include "base/configtype.hpp"
10 #include "base/objectlock.hpp"
11 #include "base/convert.hpp"
12 #include "base/utility.hpp"
13 #include <boost/tuple/tuple.hpp>
14 #include <boost/algorithm/string/replace.hpp>
16 using namespace icinga;
18 EndpointsTable::EndpointsTable()
23 void EndpointsTable::AddColumns(Table *table, const String& prefix,
24 const Column::ObjectAccessor& objectAccessor)
26 table->AddColumn(prefix + "name", Column(&EndpointsTable::NameAccessor, objectAccessor));
27 table->AddColumn(prefix + "identity", Column(&EndpointsTable::IdentityAccessor, objectAccessor));
28 table->AddColumn(prefix + "node", Column(&EndpointsTable::NodeAccessor, objectAccessor));
29 table->AddColumn(prefix + "is_connected", Column(&EndpointsTable::IsConnectedAccessor, objectAccessor));
30 table->AddColumn(prefix + "zone", Column(&EndpointsTable::ZoneAccessor, objectAccessor));
33 String EndpointsTable::GetName() const
38 String EndpointsTable::GetPrefix() const
43 void EndpointsTable::FetchRows(const AddRowFunction& addRowFn)
45 for (const Endpoint::Ptr& endpoint : ConfigType::GetObjectsByType<Endpoint>()) {
46 if (!addRowFn(endpoint, LivestatusGroupByNone, Empty))
51 Value EndpointsTable::NameAccessor(const Value& row)
53 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
58 return endpoint->GetName();
61 Value EndpointsTable::IdentityAccessor(const Value& row)
63 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
68 return endpoint->GetName();
71 Value EndpointsTable::NodeAccessor(const Value& row)
73 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
78 return IcingaApplication::GetInstance()->GetNodeName();
81 Value EndpointsTable::IsConnectedAccessor(const Value& row)
83 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
88 unsigned int is_connected = endpoint->GetConnected() ? 1 : 0;
90 /* if identity is equal to node, fake is_connected */
91 if (endpoint->GetName() == IcingaApplication::GetInstance()->GetNodeName())
97 Value EndpointsTable::ZoneAccessor(const Value& row)
99 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
104 Zone::Ptr zone = endpoint->GetZone();
109 return zone->GetName();