mirror of
https://github.com/Icinga/icinga2.git
synced 2026-02-19 02:29:16 -05:00
I've used the following command to replace the original copyright header
lines in a C-style comment block:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{/\*[^*]*\(\s*c\s*\)\s*(\d{4})\s*Icinga\s+GmbH[^*]*\*/}{// SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n// SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
For files that use shell-style comments (#) like CMakeLists.txt, I've
used this command:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f -exec perl -pi -e 's{#.*\(\s*c\s*\)\s(\d{4})\sIcinga\s+GmbH.*}{# SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n# SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
And for SQL files:
```
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{--.*\(c\)\s(\d{4})\sIcinga\sGmbH.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
$ find . \( -type d \( -name '\..*' -o -name third-party -o -name scripts -o -name prefix -o -name malloc -o -name server -o -name docker -o -name build -o -name doc \) -prune \) -o -type f \( -name '*.sql' \) -exec perl -pi -e 's{-- Copyright \(c\)\s(\d{4})\sIcinga\s+Development\sTeam.*}{-- SPDX-FileCopyrightText: \1 Icinga GmbH <https://icinga.com>\n-- SPDX-License-Identifier: GPL-2.0-or-later}gi' {} +
```
92 lines
2.8 KiB
C++
92 lines
2.8 KiB
C++
// SPDX-FileCopyrightText: 2012 Icinga GmbH <https://icinga.com>
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
#include "db_ido/endpointdbobject.hpp"
|
|
#include "db_ido/dbtype.hpp"
|
|
#include "db_ido/dbvalue.hpp"
|
|
#include "icinga/icingaapplication.hpp"
|
|
#include "base/objectlock.hpp"
|
|
#include "base/initialize.hpp"
|
|
#include "base/configtype.hpp"
|
|
#include "base/utility.hpp"
|
|
#include "base/convert.hpp"
|
|
#include "base/logger.hpp"
|
|
|
|
using namespace icinga;
|
|
|
|
REGISTER_DBTYPE(Endpoint, "endpoint", DbObjectTypeEndpoint, "endpoint_object_id", EndpointDbObject);
|
|
|
|
INITIALIZE_ONCE(&EndpointDbObject::StaticInitialize);
|
|
|
|
void EndpointDbObject::StaticInitialize()
|
|
{
|
|
Endpoint::OnConnected.connect([](const Endpoint::Ptr& endpoint, const JsonRpcConnection::Ptr&) { EndpointDbObject::UpdateConnectedStatus(endpoint); });
|
|
Endpoint::OnDisconnected.connect([](const Endpoint::Ptr& endpoint, const JsonRpcConnection::Ptr&) { EndpointDbObject::UpdateConnectedStatus(endpoint); });
|
|
}
|
|
|
|
EndpointDbObject::EndpointDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
|
|
: DbObject(type, name1, name2)
|
|
{ }
|
|
|
|
Dictionary::Ptr EndpointDbObject::GetConfigFields() const
|
|
{
|
|
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject());
|
|
|
|
return new Dictionary({
|
|
{ "identity", endpoint->GetName() },
|
|
{ "node", IcingaApplication::GetInstance()->GetNodeName() },
|
|
{ "zone_object_id", endpoint->GetZone() }
|
|
});
|
|
}
|
|
|
|
Dictionary::Ptr EndpointDbObject::GetStatusFields() const
|
|
{
|
|
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject());
|
|
|
|
|
|
Log(LogDebug, "EndpointDbObject")
|
|
<< "update status for endpoint '" << endpoint->GetName() << "'";
|
|
|
|
return new Dictionary({
|
|
{ "identity", endpoint->GetName() },
|
|
{ "node", IcingaApplication::GetInstance()->GetNodeName() },
|
|
{ "zone_object_id", endpoint->GetZone() },
|
|
{ "is_connected", EndpointIsConnected(endpoint) }
|
|
});
|
|
}
|
|
|
|
void EndpointDbObject::UpdateConnectedStatus(const Endpoint::Ptr& endpoint)
|
|
{
|
|
bool connected = EndpointIsConnected(endpoint);
|
|
|
|
Log(LogDebug, "EndpointDbObject")
|
|
<< "update is_connected=" << connected << " for endpoint '" << endpoint->GetName() << "'";
|
|
|
|
DbQuery query1;
|
|
query1.Table = "endpointstatus";
|
|
query1.Type = DbQueryUpdate;
|
|
query1.Category = DbCatState;
|
|
|
|
query1.Fields = new Dictionary({
|
|
{ "is_connected", (connected ? 1 : 0) },
|
|
{ "status_update_time", DbValue::FromTimestamp(Utility::GetTime()) }
|
|
});
|
|
|
|
query1.WhereCriteria = new Dictionary({
|
|
{ "endpoint_object_id", endpoint },
|
|
{ "instance_id", 0 } /* DbConnection class fills in real ID */
|
|
});
|
|
|
|
OnQuery(query1);
|
|
}
|
|
|
|
int EndpointDbObject::EndpointIsConnected(const Endpoint::Ptr& endpoint)
|
|
{
|
|
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;
|
|
}
|