diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 12:34:54 +0000 |
commit | 0915b3ef56dfac3113cce55a59a5765dc94976be (patch) | |
tree | a8fea11d50b4f083e1bf0f90025ece7f0824784a /lib/livestatus/endpointstable.cpp | |
parent | Initial commit. (diff) | |
download | icinga2-upstream.tar.xz icinga2-upstream.zip |
Adding upstream version 2.13.6.upstream/2.13.6upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | lib/livestatus/endpointstable.cpp | 109 |
1 files changed, 109 insertions, 0 deletions
diff --git a/lib/livestatus/endpointstable.cpp b/lib/livestatus/endpointstable.cpp new file mode 100644 index 0000000..3d407eb --- /dev/null +++ b/lib/livestatus/endpointstable.cpp @@ -0,0 +1,109 @@ +/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */ + +#include "livestatus/endpointstable.hpp" +#include "icinga/host.hpp" +#include "icinga/service.hpp" +#include "icinga/icingaapplication.hpp" +#include "remote/endpoint.hpp" +#include "remote/zone.hpp" +#include "base/configtype.hpp" +#include "base/objectlock.hpp" +#include "base/convert.hpp" +#include "base/utility.hpp" +#include <boost/algorithm/string/replace.hpp> + +using namespace icinga; + +EndpointsTable::EndpointsTable() +{ + AddColumns(this); +} + +void EndpointsTable::AddColumns(Table *table, const String& prefix, + const Column::ObjectAccessor& objectAccessor) +{ + table->AddColumn(prefix + "name", Column(&EndpointsTable::NameAccessor, objectAccessor)); + table->AddColumn(prefix + "identity", Column(&EndpointsTable::IdentityAccessor, objectAccessor)); + table->AddColumn(prefix + "node", Column(&EndpointsTable::NodeAccessor, objectAccessor)); + table->AddColumn(prefix + "is_connected", Column(&EndpointsTable::IsConnectedAccessor, objectAccessor)); + table->AddColumn(prefix + "zone", Column(&EndpointsTable::ZoneAccessor, objectAccessor)); +} + +String EndpointsTable::GetName() const +{ + return "endpoints"; +} + +String EndpointsTable::GetPrefix() const +{ + return "endpoint"; +} + +void EndpointsTable::FetchRows(const AddRowFunction& addRowFn) +{ + for (const Endpoint::Ptr& endpoint : ConfigType::GetObjectsByType<Endpoint>()) { + if (!addRowFn(endpoint, LivestatusGroupByNone, Empty)) + return; + } +} + +Value EndpointsTable::NameAccessor(const Value& row) +{ + Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row); + + if (!endpoint) + return Empty; + + return endpoint->GetName(); +} + +Value EndpointsTable::IdentityAccessor(const Value& row) +{ + Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row); + + if (!endpoint) + return Empty; + + return endpoint->GetName(); +} + +Value EndpointsTable::NodeAccessor(const Value& row) +{ + Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row); + + if (!endpoint) + return Empty; + + return IcingaApplication::GetInstance()->GetNodeName(); +} + +Value EndpointsTable::IsConnectedAccessor(const Value& row) +{ + Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row); + + if (!endpoint) + return Empty; + + unsigned int is_connected = endpoint->GetConnected() ? 1 : 0; + + /* if identity is equal to node, fake is_connected */ + if (endpoint->GetName() == IcingaApplication::GetInstance()->GetNodeName()) + is_connected = 1; + + return is_connected; +} + +Value EndpointsTable::ZoneAccessor(const Value& row) +{ + Endpoint::Ptr endpoint = static_cast<Endpoint::Ptr>(row); + + if (!endpoint) + return Empty; + + Zone::Ptr zone = endpoint->GetZone(); + + if (!zone) + return Empty; + + return zone->GetName(); +} |