mirror of https://github.com/Icinga/icinga2.git
DB IDO: Add status/history references from local node to endpoint object.
Refs #5636
This commit is contained in:
parent
dfd08ec6ea
commit
b4f0148871
|
@ -326,6 +326,8 @@ void DbConnection::PrepareDatabase(void)
|
||||||
//ClearConfigTable("contactstatus");
|
//ClearConfigTable("contactstatus");
|
||||||
ClearConfigTable("customvariables");
|
ClearConfigTable("customvariables");
|
||||||
ClearConfigTable("customvariablestatus");
|
ClearConfigTable("customvariablestatus");
|
||||||
|
ClearConfigTable("endpoints");
|
||||||
|
ClearConfigTable("endpointstatus");
|
||||||
ClearConfigTable("host_contactgroups");
|
ClearConfigTable("host_contactgroups");
|
||||||
ClearConfigTable("host_contacts");
|
ClearConfigTable("host_contacts");
|
||||||
ClearConfigTable("host_parenthosts");
|
ClearConfigTable("host_parenthosts");
|
||||||
|
|
|
@ -109,15 +109,19 @@ void DbObject::SendStatusUpdate(void)
|
||||||
query.Category = DbCatState;
|
query.Category = DbCatState;
|
||||||
query.Fields = fields;
|
query.Fields = fields;
|
||||||
query.Fields->Set(GetType()->GetIDColumn(), GetObject());
|
query.Fields->Set(GetType()->GetIDColumn(), GetObject());
|
||||||
query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
|
||||||
|
|
||||||
|
/* do not override our own endpoint dbobject id */
|
||||||
|
if (GetType()->GetTable() != "endpoint") {
|
||||||
String node = IcingaApplication::GetInstance()->GetNodeName();
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
Log(LogWarning, "db_ido", "Endpoint node: '" + node + "'");
|
Log(LogDebug, "db_ido", "Endpoint node: '" + node + "' status update for '" + GetObject()->GetName() + "'");
|
||||||
|
|
||||||
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
if (endpoint)
|
if (endpoint)
|
||||||
query.Fields->Set("endpoint_object_id", endpoint);
|
query.Fields->Set("endpoint_object_id", endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
query.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
query.Fields->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
||||||
query.WhereCriteria = make_shared<Dictionary>();
|
query.WhereCriteria = make_shared<Dictionary>();
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "base/initialize.h"
|
#include "base/initialize.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
#include "base/utility.h"
|
#include "base/utility.h"
|
||||||
|
#include "base/convert.h"
|
||||||
#include "base/logger_fwd.h"
|
#include "base/logger_fwd.h"
|
||||||
#include <boost/foreach.hpp>
|
#include <boost/foreach.hpp>
|
||||||
|
|
||||||
|
@ -38,7 +39,7 @@ INITIALIZE_ONCE(&EndpointDbObject::StaticInitialize);
|
||||||
void EndpointDbObject::StaticInitialize(void)
|
void EndpointDbObject::StaticInitialize(void)
|
||||||
{
|
{
|
||||||
Endpoint::OnConnected.connect(boost::bind(&EndpointDbObject::UpdateConnectedStatus, _1));
|
Endpoint::OnConnected.connect(boost::bind(&EndpointDbObject::UpdateConnectedStatus, _1));
|
||||||
Endpoint::OnDisconnected.connect(boost::bind(&EndpointDbObject::UpdateConnectedStatus, _1));
|
Endpoint::OnDisconnected.connect(boost::bind(&EndpointDbObject::UpdateDisconnectedStatus, _1));
|
||||||
}
|
}
|
||||||
|
|
||||||
EndpointDbObject::EndpointDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
|
EndpointDbObject::EndpointDbObject(const DbType::Ptr& type, const String& name1, const String& name2)
|
||||||
|
@ -61,6 +62,8 @@ Dictionary::Ptr EndpointDbObject::GetStatusFields(void) const
|
||||||
Dictionary::Ptr fields = make_shared<Dictionary>();
|
Dictionary::Ptr fields = make_shared<Dictionary>();
|
||||||
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject());
|
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject());
|
||||||
|
|
||||||
|
Log(LogDebug, "db_ido", "update status for endpoint '" + endpoint->GetName() + "'");
|
||||||
|
|
||||||
fields->Set("identity", endpoint->GetName());
|
fields->Set("identity", endpoint->GetName());
|
||||||
fields->Set("node", IcingaApplication::GetInstance()->GetNodeName());
|
fields->Set("node", IcingaApplication::GetInstance()->GetNodeName());
|
||||||
fields->Set("is_connected", EndpointIsConnected(endpoint));
|
fields->Set("is_connected", EndpointIsConnected(endpoint));
|
||||||
|
@ -70,14 +73,24 @@ Dictionary::Ptr EndpointDbObject::GetStatusFields(void) const
|
||||||
|
|
||||||
void EndpointDbObject::UpdateConnectedStatus(const Endpoint::Ptr& endpoint)
|
void EndpointDbObject::UpdateConnectedStatus(const Endpoint::Ptr& endpoint)
|
||||||
{
|
{
|
||||||
Log(LogDebug, "db_ido", "update is_connected for endpoint '" + endpoint->GetName() + "'");
|
UpdateConnectedStatusInternal(endpoint, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndpointDbObject::UpdateDisconnectedStatus(const Endpoint::Ptr& endpoint)
|
||||||
|
{
|
||||||
|
UpdateConnectedStatusInternal(endpoint, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EndpointDbObject::UpdateConnectedStatusInternal(const Endpoint::Ptr& endpoint, bool connected)
|
||||||
|
{
|
||||||
|
Log(LogDebug, "db_ido", "update is_connected=" + Convert::ToString(connected ? 1 : 0) + " for endpoint '" + endpoint->GetName() + "'");
|
||||||
|
|
||||||
DbQuery query1;
|
DbQuery query1;
|
||||||
query1.Table = "endpointstatus";
|
query1.Table = "endpointstatus";
|
||||||
query1.Type = DbQueryUpdate;
|
query1.Type = DbQueryUpdate;
|
||||||
|
|
||||||
Dictionary::Ptr fields1 = make_shared<Dictionary>();
|
Dictionary::Ptr fields1 = make_shared<Dictionary>();
|
||||||
fields1->Set("is_connected", EndpointIsConnected(endpoint));
|
fields1->Set("is_connected", (connected ? 1 : 0));
|
||||||
fields1->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
fields1->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
|
|
||||||
|
@ -98,3 +111,24 @@ int EndpointDbObject::EndpointIsConnected(const Endpoint::Ptr& endpoint)
|
||||||
|
|
||||||
return is_connected;
|
return is_connected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EndpointDbObject::OnConfigUpdate(void)
|
||||||
|
{
|
||||||
|
/* update current status on config dump once */
|
||||||
|
Endpoint::Ptr endpoint = static_pointer_cast<Endpoint>(GetObject());
|
||||||
|
|
||||||
|
DbQuery query1;
|
||||||
|
query1.Table = "endpointstatus";
|
||||||
|
query1.Type = DbQueryInsert;
|
||||||
|
|
||||||
|
Dictionary::Ptr fields1 = make_shared<Dictionary>();
|
||||||
|
fields1->Set("identity", endpoint->GetName());
|
||||||
|
fields1->Set("node", IcingaApplication::GetInstance()->GetNodeName());
|
||||||
|
fields1->Set("is_connected", EndpointIsConnected(endpoint));
|
||||||
|
fields1->Set("status_update_time", DbValue::FromTimestamp(Utility::GetTime()));
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
query1.Fields = fields1;
|
||||||
|
|
||||||
|
OnQuery(query1);
|
||||||
|
}
|
||||||
|
|
|
@ -44,8 +44,13 @@ public:
|
||||||
virtual Dictionary::Ptr GetConfigFields(void) const;
|
virtual Dictionary::Ptr GetConfigFields(void) const;
|
||||||
virtual Dictionary::Ptr GetStatusFields(void) const;
|
virtual Dictionary::Ptr GetStatusFields(void) const;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
virtual void OnConfigUpdate(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static void UpdateConnectedStatus(const Endpoint::Ptr& endpoint);
|
static void UpdateConnectedStatus(const Endpoint::Ptr& endpoint);
|
||||||
|
static void UpdateDisconnectedStatus(const Endpoint::Ptr& endpoint);
|
||||||
|
static void UpdateConnectedStatusInternal(const Endpoint::Ptr& endpoint, bool connected);
|
||||||
static int EndpointIsConnected(const Endpoint::Ptr& endpoint);
|
static int EndpointIsConnected(const Endpoint::Ptr& endpoint);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -25,6 +25,7 @@
|
||||||
#include "base/initialize.h"
|
#include "base/initialize.h"
|
||||||
#include "base/dynamictype.h"
|
#include "base/dynamictype.h"
|
||||||
#include "base/utility.h"
|
#include "base/utility.h"
|
||||||
|
#include "remote/endpoint.h"
|
||||||
#include "icinga/notification.h"
|
#include "icinga/notification.h"
|
||||||
#include "icinga/checkcommand.h"
|
#include "icinga/checkcommand.h"
|
||||||
#include "icinga/eventcommand.h"
|
#include "icinga/eventcommand.h"
|
||||||
|
@ -398,6 +399,12 @@ void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const C
|
||||||
fields1->Set("expiration_time", DbValue::FromTimestamp(comment->GetExpireTime()));
|
fields1->Set("expiration_time", DbValue::FromTimestamp(comment->GetExpireTime()));
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
DbQuery query1;
|
DbQuery query1;
|
||||||
if (!historical) {
|
if (!historical) {
|
||||||
query1.Table = "comments";
|
query1.Table = "comments";
|
||||||
|
@ -563,6 +570,12 @@ void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const
|
||||||
fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
|
fields1->Set("trigger_time", DbValue::FromTimestamp(downtime->GetTriggerTime()));
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
DbQuery query1;
|
DbQuery query1;
|
||||||
if (!historical) {
|
if (!historical) {
|
||||||
query1.Table = "scheduleddowntime";
|
query1.Table = "scheduleddowntime";
|
||||||
|
@ -746,6 +759,12 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
|
||||||
fields1->Set("end_time", DbValue::FromTimestamp(end_time));
|
fields1->Set("end_time", DbValue::FromTimestamp(end_time));
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
|
@ -796,6 +815,12 @@ void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notificati
|
||||||
fields1->Set("contacts_notified", static_cast<long>(users.size()));
|
fields1->Set("contacts_notified", static_cast<long>(users.size()));
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
|
@ -867,6 +892,12 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const C
|
||||||
|
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
|
@ -1170,6 +1201,12 @@ void ServiceDbObject::AddLogHistory(const Service::Ptr& service, String buffer,
|
||||||
|
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
|
@ -1226,6 +1263,12 @@ void ServiceDbObject::AddFlappingHistory(const Service::Ptr& service, FlappingSt
|
||||||
|
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
|
@ -1285,6 +1328,12 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
fields1->Set("service_object_id", service);
|
fields1->Set("service_object_id", service);
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
|
@ -1331,6 +1380,12 @@ void ServiceDbObject::AddEventHandlerHistory(const Service::Ptr& service)
|
||||||
|
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
|
|
||||||
|
@ -1364,6 +1419,12 @@ void ServiceDbObject::AddExternalCommandHistory(double time, const String& comma
|
||||||
|
|
||||||
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields1->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
|
String node = IcingaApplication::GetInstance()->GetNodeName();
|
||||||
|
|
||||||
|
Endpoint::Ptr endpoint = Endpoint::GetByName(node);
|
||||||
|
if (endpoint)
|
||||||
|
fields1->Set("endpoint_object_id", endpoint);
|
||||||
|
|
||||||
query1.Fields = fields1;
|
query1.Fields = fields1;
|
||||||
OnQuery(query1);
|
OnQuery(query1);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue