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/algorithm/string/replace.hpp>
15 using namespace icinga;
17 EndpointsTable::EndpointsTable()
22 void EndpointsTable::AddColumns(Table *table, const String& prefix,
23 const Column::ObjectAccessor& objectAccessor)
25 table->AddColumn(prefix + "name", Column(&EndpointsTable::NameAccessor, objectAccessor));
26 table->AddColumn(prefix + "identity", Column(&EndpointsTable::IdentityAccessor, objectAccessor));
27 table->AddColumn(prefix + "node", Column(&EndpointsTable::NodeAccessor, objectAccessor));
28 table->AddColumn(prefix + "is_connected", Column(&EndpointsTable::IsConnectedAccessor, objectAccessor));
29 table->AddColumn(prefix + "zone", Column(&EndpointsTable::ZoneAccessor, objectAccessor));
32 String EndpointsTable::GetName() const
37 String EndpointsTable::GetPrefix() const
42 void EndpointsTable::FetchRows(const AddRowFunction& addRowFn)
44 for (const Endpoint::Ptr& endpoint : ConfigType::GetObjectsByType<Endpoint>()) {
45 if (!addRowFn(endpoint, LivestatusGroupByNone, Empty))
50 Value EndpointsTable::NameAccessor(const Value& row)
52 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
57 return endpoint->GetName();
60 Value EndpointsTable::IdentityAccessor(const Value& row)
62 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
67 return endpoint->GetName();
70 Value EndpointsTable::NodeAccessor(const Value& row)
72 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
77 return IcingaApplication::GetInstance()->GetNodeName();
80 Value EndpointsTable::IsConnectedAccessor(const Value& row)
82 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
87 unsigned int is_connected = endpoint->GetConnected() ? 1 : 0;
89 /* if identity is equal to node, fake is_connected */
90 if (endpoint->GetName() == IcingaApplication::GetInstance()->GetNodeName())
96 Value EndpointsTable::ZoneAccessor(const Value& row)
98 Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row);
103 Zone::Ptr zone = endpoint->GetZone();
108 return zone->GetName();