mirror of https://github.com/Icinga/icinga2.git
parent
9f8cb8dd36
commit
ed53366490
|
@ -138,7 +138,7 @@ static Object::Ptr DeserializeObject(const Object::Ptr& object, const Dictionary
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes));
|
instance->SetField(fid, Deserialize(kv.second, safe_mode, attributeTypes), true);
|
||||||
} catch (const std::exception&) {
|
} catch (const std::exception&) {
|
||||||
instance->SetField(fid, Empty);
|
instance->SetField(fid, Empty);
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,7 +39,8 @@ Timer::Ptr DbConnection::m_ProgramStatusTimer;
|
||||||
boost::once_flag DbConnection::m_OnceFlag = BOOST_ONCE_INIT;
|
boost::once_flag DbConnection::m_OnceFlag = BOOST_ONCE_INIT;
|
||||||
|
|
||||||
DbConnection::DbConnection(void)
|
DbConnection::DbConnection(void)
|
||||||
: m_QueryStats(15 * 60), m_PendingQueries(0), m_PendingQueriesTimestamp(0), m_IDCacheValid(false)
|
: m_QueryStats(15 * 60), m_PendingQueries(0), m_PendingQueriesTimestamp(0),
|
||||||
|
m_IDCacheValid(false), m_ActiveChangedHandler(false)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
void DbConnection::OnConfigLoaded(void)
|
void DbConnection::OnConfigLoaded(void)
|
||||||
|
@ -74,7 +75,14 @@ void DbConnection::Start(bool runtimeCreated)
|
||||||
|
|
||||||
DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
|
DbObject::OnQuery.connect(boost::bind(&DbConnection::ExecuteQuery, this, _1));
|
||||||
DbObject::OnMultipleQueries.connect(boost::bind(&DbConnection::ExecuteMultipleQueries, this, _1));
|
DbObject::OnMultipleQueries.connect(boost::bind(&DbConnection::ExecuteMultipleQueries, this, _1));
|
||||||
ConfigObject::OnActiveChanged.connect(boost::bind(&DbConnection::UpdateObject, this, _1));
|
}
|
||||||
|
|
||||||
|
void DbConnection::EnableActiveChangedHandler(void)
|
||||||
|
{
|
||||||
|
if (!m_ActiveChangedHandler) {
|
||||||
|
ConfigObject::OnActiveChanged.connect(boost::bind(&DbConnection::UpdateObject, this, _1));
|
||||||
|
m_ActiveChangedHandler = true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void DbConnection::StatsLoggerTimerHandler(void)
|
void DbConnection::StatsLoggerTimerHandler(void)
|
||||||
|
@ -394,8 +402,10 @@ void DbConnection::UpdateObject(const ConfigObject::Ptr& object)
|
||||||
bool dbActive = GetObjectActive(dbobj);
|
bool dbActive = GetObjectActive(dbobj);
|
||||||
bool active = object->IsActive();
|
bool active = object->IsActive();
|
||||||
|
|
||||||
if (active && !dbActive) {
|
if (active) {
|
||||||
ActivateObject(dbobj);
|
if (!dbActive)
|
||||||
|
ActivateObject(dbobj);
|
||||||
|
|
||||||
dbobj->SendConfigUpdate();
|
dbobj->SendConfigUpdate();
|
||||||
dbobj->SendStatusUpdate();
|
dbobj->SendStatusUpdate();
|
||||||
} else if (!active) {
|
} else if (!active) {
|
||||||
|
|
|
@ -98,6 +98,8 @@ protected:
|
||||||
bool IsIDCacheValid(void) const;
|
bool IsIDCacheValid(void) const;
|
||||||
void SetIDCacheValid(bool valid);
|
void SetIDCacheValid(bool valid);
|
||||||
|
|
||||||
|
void EnableActiveChangedHandler(void);
|
||||||
|
|
||||||
static void UpdateProgramStatus(void);
|
static void UpdateProgramStatus(void);
|
||||||
|
|
||||||
static int GetSessionToken(void);
|
static int GetSessionToken(void);
|
||||||
|
@ -127,6 +129,7 @@ private:
|
||||||
RingBuffer m_QueryStats;
|
RingBuffer m_QueryStats;
|
||||||
int m_PendingQueries;
|
int m_PendingQueries;
|
||||||
double m_PendingQueriesTimestamp;
|
double m_PendingQueriesTimestamp;
|
||||||
|
bool m_ActiveChangedHandler;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct database_error : virtual std::exception, virtual boost::exception { };
|
struct database_error : virtual std::exception, virtual boost::exception { };
|
||||||
|
|
|
@ -399,16 +399,16 @@ void IdoMysqlConnection::Reconnect(void)
|
||||||
|
|
||||||
SetIDCacheValid(true);
|
SetIDCacheValid(true);
|
||||||
|
|
||||||
|
EnableActiveChangedHandler();
|
||||||
|
|
||||||
BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
|
BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
|
||||||
if (dbobj->GetObject() == NULL) {
|
if (dbobj->GetObject())
|
||||||
Log(LogNotice, "IdoMysqlConnection")
|
continue;
|
||||||
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
|
|
||||||
<< "' name2: '" << dbobj->GetName2() + "'.";
|
Log(LogNotice, "IdoMysqlConnection")
|
||||||
DeactivateObject(dbobj);
|
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
|
||||||
} else {
|
<< "' name2: '" << dbobj->GetName2() + "'.";
|
||||||
dbobj->SendConfigUpdate();
|
DeactivateObject(dbobj);
|
||||||
dbobj->SendStatusUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateAllObjects();
|
UpdateAllObjects();
|
||||||
|
|
|
@ -372,16 +372,16 @@ void IdoPgsqlConnection::Reconnect(void)
|
||||||
|
|
||||||
SetIDCacheValid(true);
|
SetIDCacheValid(true);
|
||||||
|
|
||||||
|
EnableActiveChangedHandler();
|
||||||
|
|
||||||
BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
|
BOOST_FOREACH(const DbObject::Ptr& dbobj, activeDbObjs) {
|
||||||
if (dbobj->GetObject() == NULL) {
|
if (dbobj->GetObject())
|
||||||
Log(LogNotice, "IdoPgsqlConnection")
|
continue;
|
||||||
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
|
|
||||||
<< "' name2: '" << dbobj->GetName2() + "'.";
|
Log(LogNotice, "IdoPgsqlConnection")
|
||||||
DeactivateObject(dbobj);
|
<< "Deactivate deleted object name1: '" << dbobj->GetName1()
|
||||||
} else {
|
<< "' name2: '" << dbobj->GetName2() + "'.";
|
||||||
dbobj->SendConfigUpdate();
|
DeactivateObject(dbobj);
|
||||||
dbobj->SendStatusUpdate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateAllObjects();
|
UpdateAllObjects();
|
||||||
|
|
Loading…
Reference in New Issue