mirror of https://github.com/Icinga/icinga2.git
parent
5426431b77
commit
96fa29793c
|
@ -364,14 +364,14 @@ void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
|
||||||
DbObject::Ptr dbobj = DbObject::GetOrCreateByObject(object);
|
DbObject::Ptr dbobj = DbObject::GetOrCreateByObject(object);
|
||||||
|
|
||||||
if (dbobj) {
|
if (dbobj) {
|
||||||
|
bool dbActive = GetObjectActive(dbobj);
|
||||||
bool active = object->IsActive();
|
bool active = object->IsActive();
|
||||||
|
|
||||||
if (active) {
|
if (active && !dbActive) {
|
||||||
ActivateObject(dbobj);
|
ActivateObject(dbobj);
|
||||||
|
|
||||||
dbobj->SendConfigUpdate();
|
dbobj->SendConfigUpdate();
|
||||||
dbobj->SendStatusUpdate();
|
dbobj->SendStatusUpdate();
|
||||||
} else
|
} else if (!active && dbActive)
|
||||||
DeactivateObject(dbobj);
|
DeactivateObject(dbobj);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -171,8 +171,6 @@ void IdoMysqlConnection::Reconnect(void)
|
||||||
|
|
||||||
SetShouldConnect(true);
|
SetShouldConnect(true);
|
||||||
|
|
||||||
std::vector<DbObject::Ptr> active_dbobjs;
|
|
||||||
|
|
||||||
bool reconnect = false;
|
bool reconnect = false;
|
||||||
|
|
||||||
if (GetConnected()) {
|
if (GetConnected()) {
|
||||||
|
@ -351,6 +349,8 @@ void IdoMysqlConnection::Reconnect(void)
|
||||||
q1buf << "SELECT object_id, objecttype_id, name1, name2, is_active FROM " + GetTablePrefix() + "objects WHERE instance_id = " << static_cast<long>(m_InstanceID);
|
q1buf << "SELECT object_id, objecttype_id, name1, name2, is_active FROM " + GetTablePrefix() + "objects WHERE instance_id = " << static_cast<long>(m_InstanceID);
|
||||||
result = Query(q1buf.str());
|
result = Query(q1buf.str());
|
||||||
|
|
||||||
|
std::vector<DbObject::Ptr> activeDbObjs;
|
||||||
|
|
||||||
while ((row = FetchRow(result))) {
|
while ((row = FetchRow(result))) {
|
||||||
DbType::Ptr dbtype = DbType::GetByID(row->Get("objecttype_id"));
|
DbType::Ptr dbtype = DbType::GetByID(row->Get("objecttype_id"));
|
||||||
|
|
||||||
|
@ -359,26 +359,29 @@ void IdoMysqlConnection::Reconnect(void)
|
||||||
|
|
||||||
DbObject::Ptr dbobj = dbtype->GetOrCreateObjectByName(row->Get("name1"), row->Get("name2"));
|
DbObject::Ptr dbobj = dbtype->GetOrCreateObjectByName(row->Get("name1"), row->Get("name2"));
|
||||||
SetObjectID(dbobj, DbReference(row->Get("object_id")));
|
SetObjectID(dbobj, DbReference(row->Get("object_id")));
|
||||||
SetObjectActive(dbobj, row->Get("is_active"));
|
bool active = row->Get("is_active");
|
||||||
|
SetObjectActive(dbobj, active);
|
||||||
|
|
||||||
if (GetObjectActive(dbobj))
|
if (active)
|
||||||
active_dbobjs.push_back(dbobj);
|
activeDbObjs.push_back(dbobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
Query("BEGIN");
|
Query("BEGIN");
|
||||||
|
|
||||||
UpdateAllObjects();
|
BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
|
||||||
|
|
||||||
/* deactivate all deleted configuration objects */
|
|
||||||
BOOST_FOREACH(const DbObject::Ptr& dbobj, active_dbobjs) {
|
|
||||||
if (dbobj->GetObject() == NULL) {
|
if (dbobj->GetObject() == NULL) {
|
||||||
Log(LogNotice, "IdoMysqlConnection")
|
Log(LogNotice, "IdoMysqlConnection")
|
||||||
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
|
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
|
||||||
<< "' name2: '" << dbobj->GetName2() + "'.";
|
<< "' name2: '" << dbobj->GetName2() + "'.";
|
||||||
DeactivateObject(dbobj);
|
DeactivateObject(dbobj);
|
||||||
|
} else {
|
||||||
|
dbobj->SendConfigUpdate();
|
||||||
|
dbobj->SendStatusUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateAllObjects();
|
||||||
|
|
||||||
/* delete all customvariables without current session token */
|
/* delete all customvariables without current session token */
|
||||||
ClearCustomVarTable("customvariables");
|
ClearCustomVarTable("customvariables");
|
||||||
ClearCustomVarTable("customvariablestatus");
|
ClearCustomVarTable("customvariablestatus");
|
||||||
|
|
|
@ -168,9 +168,6 @@ void IdoPgsqlConnection::Reconnect(void)
|
||||||
|
|
||||||
SetShouldConnect(true);
|
SetShouldConnect(true);
|
||||||
|
|
||||||
std::vector<DbObject::Ptr> active_dbobjs;
|
|
||||||
|
|
||||||
{
|
|
||||||
bool reconnect = false;
|
bool reconnect = false;
|
||||||
|
|
||||||
if (GetConnected()) {
|
if (GetConnected()) {
|
||||||
|
@ -339,6 +336,8 @@ void IdoPgsqlConnection::Reconnect(void)
|
||||||
q1buf << "SELECT object_id, objecttype_id, name1, name2, is_active FROM " + GetTablePrefix() + "objects WHERE instance_id = " << static_cast<long>(m_InstanceID);
|
q1buf << "SELECT object_id, objecttype_id, name1, name2, is_active FROM " + GetTablePrefix() + "objects WHERE instance_id = " << static_cast<long>(m_InstanceID);
|
||||||
result = Query(q1buf.str());
|
result = Query(q1buf.str());
|
||||||
|
|
||||||
|
std::vector<DbObject::Ptr> activeDbObjs;
|
||||||
|
|
||||||
int index = 0;
|
int index = 0;
|
||||||
while ((row = FetchRow(result, index))) {
|
while ((row = FetchRow(result, index))) {
|
||||||
index++;
|
index++;
|
||||||
|
@ -350,27 +349,29 @@ void IdoPgsqlConnection::Reconnect(void)
|
||||||
|
|
||||||
DbObject::Ptr dbobj = dbtype->GetOrCreateObjectByName(row->Get("name1"), row->Get("name2"));
|
DbObject::Ptr dbobj = dbtype->GetOrCreateObjectByName(row->Get("name1"), row->Get("name2"));
|
||||||
SetObjectID(dbobj, DbReference(row->Get("object_id")));
|
SetObjectID(dbobj, DbReference(row->Get("object_id")));
|
||||||
SetObjectActive(dbobj, row->Get("is_active"));
|
bool active = row->Get("is_active");
|
||||||
|
SetObjectActive(dbobj, active);
|
||||||
|
|
||||||
if (GetObjectActive(dbobj))
|
if (active)
|
||||||
active_dbobjs.push_back(dbobj);
|
activeDbObjs.push_back(dbobj);
|
||||||
}
|
}
|
||||||
|
|
||||||
Query("BEGIN");
|
Query("BEGIN");
|
||||||
}
|
|
||||||
|
|
||||||
UpdateAllObjects();
|
BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
|
||||||
|
|
||||||
/* deactivate all deleted configuration objects */
|
|
||||||
BOOST_FOREACH(const DbObject::Ptr& dbobj, active_dbobjs) {
|
|
||||||
if (dbobj->GetObject() == NULL) {
|
if (dbobj->GetObject() == NULL) {
|
||||||
Log(LogNotice, "IdoPgsqlConnection")
|
Log(LogNotice, "IdoPgsqlConnection")
|
||||||
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
|
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
|
||||||
<< "' name2: '" << dbobj->GetName2() + "'.";
|
<< "' name2: '" << dbobj->GetName2() + "'.";
|
||||||
DeactivateObject(dbobj);
|
DeactivateObject(dbobj);
|
||||||
|
} else {
|
||||||
|
dbobj->SendConfigUpdate();
|
||||||
|
dbobj->SendStatusUpdate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UpdateAllObjects();
|
||||||
|
|
||||||
/* delete all customvariables without current session token */
|
/* delete all customvariables without current session token */
|
||||||
ClearCustomVarTable("customvariables");
|
ClearCustomVarTable("customvariables");
|
||||||
ClearCustomVarTable("customvariablestatus");
|
ClearCustomVarTable("customvariablestatus");
|
||||||
|
|
Loading…
Reference in New Issue