mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-24 22:24:44 +02:00
parent
fbdadea24c
commit
d31ca31e90
@ -413,7 +413,7 @@ bool IdoMysqlConnection::FieldToEscapedString(const String& key, const Value& va
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (key == "notification_id") {
|
if (key == "notification_id") {
|
||||||
*result = static_cast<long>(m_LastNotificationID);
|
*result = static_cast<long>(GetNotificationInsertID(value));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -585,9 +585,9 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query)
|
|||||||
SetInsertID(query.Object, GetLastInsertID());
|
SetInsertID(query.Object, GetLastInsertID());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (type == DbQueryInsert && query.Table == "notifications") { // FIXME remove hardcoded table name
|
if (type == DbQueryInsert && query.Table == "notifications" && query.NotificationObject) { // FIXME remove hardcoded table name
|
||||||
m_LastNotificationID = GetLastInsertID();
|
SetNotificationInsertID(query.NotificationObject, GetLastInsertID());
|
||||||
Log(LogDebug, "db_ido", "saving contactnotification notification_id=" + Convert::ToString(static_cast<long>(m_LastNotificationID)));
|
Log(LogDebug, "db_ido", "saving contactnotification notification_id=" + Convert::ToString(static_cast<long>(GetLastInsertID())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DbReference m_InstanceID;
|
DbReference m_InstanceID;
|
||||||
DbReference m_LastNotificationID;
|
|
||||||
|
|
||||||
WorkQueue m_QueryQueue;
|
WorkQueue m_QueryQueue;
|
||||||
|
|
||||||
|
@ -416,7 +416,7 @@ bool IdoPgsqlConnection::FieldToEscapedString(const String& key, const Value& va
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (key == "notification_id") {
|
if (key == "notification_id") {
|
||||||
*result = static_cast<long>(m_LastNotificationID);
|
*result = static_cast<long>(GetNotificationInsertID(value));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -592,9 +592,11 @@ void IdoPgsqlConnection::InternalExecuteQuery(const DbQuery& query)
|
|||||||
SetInsertID(query.Object, GetSequenceValue(GetTablePrefix() + query.Table, idField));
|
SetInsertID(query.Object, GetSequenceValue(GetTablePrefix() + query.Table, idField));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (type == DbQueryInsert && query.Table == "notifications") { // FIXME remove hardcoded table name
|
|
||||||
m_LastNotificationID = GetSequenceValue(GetTablePrefix() + "notifications", "notification_id");
|
if (type == DbQueryInsert && query.Table == "notifications" && query.NotificationObject) { // FIXME remove hardcoded table name
|
||||||
Log(LogDebug, "db_ido", "saving contactnotification notification_id=" + Convert::ToString(static_cast<long>(m_LastNotificationID)));
|
String idField = "notification_id";
|
||||||
|
SetNotificationInsertID(query.NotificationObject, GetSequenceValue(GetTablePrefix() + query.Table, idField));
|
||||||
|
Log(LogDebug, "db_ido", "saving contactnotification notification_id=" + Convert::ToString(static_cast<long>(GetSequenceValue(GetTablePrefix() + query.Table, idField))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,7 +52,6 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
DbReference m_InstanceID;
|
DbReference m_InstanceID;
|
||||||
DbReference m_LastNotificationID;
|
|
||||||
|
|
||||||
WorkQueue m_QueryQueue;
|
WorkQueue m_QueryQueue;
|
||||||
|
|
||||||
|
@ -201,6 +201,26 @@ DbReference DbConnection::GetInsertID(const DbObject::Ptr& dbobj) const
|
|||||||
return it->second;
|
return it->second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DbConnection::SetNotificationInsertID(const DynamicObject::Ptr& obj, const DbReference& dbref)
|
||||||
|
{
|
||||||
|
if (dbref.IsValid())
|
||||||
|
m_NotificationInsertIDs[obj] = dbref;
|
||||||
|
else
|
||||||
|
m_NotificationInsertIDs.erase(obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
DbReference DbConnection::GetNotificationInsertID(const DynamicObject::Ptr& obj) const
|
||||||
|
{
|
||||||
|
std::map<DynamicObject::Ptr, DbReference>::const_iterator it;
|
||||||
|
|
||||||
|
it = m_NotificationInsertIDs.find(obj);
|
||||||
|
|
||||||
|
if (it == m_NotificationInsertIDs.end())
|
||||||
|
return DbReference();
|
||||||
|
|
||||||
|
return it->second;
|
||||||
|
}
|
||||||
|
|
||||||
void DbConnection::SetObjectActive(const DbObject::Ptr& dbobj, bool active)
|
void DbConnection::SetObjectActive(const DbObject::Ptr& dbobj, bool active)
|
||||||
{
|
{
|
||||||
if (active)
|
if (active)
|
||||||
@ -218,6 +238,7 @@ void DbConnection::ClearIDCache(void)
|
|||||||
{
|
{
|
||||||
m_ObjectIDs.clear();
|
m_ObjectIDs.clear();
|
||||||
m_InsertIDs.clear();
|
m_InsertIDs.clear();
|
||||||
|
m_NotificationInsertIDs.clear();
|
||||||
m_ActiveObjects.clear();
|
m_ActiveObjects.clear();
|
||||||
m_ConfigUpdates.clear();
|
m_ConfigUpdates.clear();
|
||||||
m_StatusUpdates.clear();
|
m_StatusUpdates.clear();
|
||||||
|
@ -47,6 +47,9 @@ public:
|
|||||||
void SetInsertID(const DbObject::Ptr& dbobj, const DbReference& dbref);
|
void SetInsertID(const DbObject::Ptr& dbobj, const DbReference& dbref);
|
||||||
DbReference GetInsertID(const DbObject::Ptr& dbobj) const;
|
DbReference GetInsertID(const DbObject::Ptr& dbobj) const;
|
||||||
|
|
||||||
|
void SetNotificationInsertID(const DynamicObject::Ptr& obj, const DbReference& dbref);
|
||||||
|
DbReference GetNotificationInsertID(const DynamicObject::Ptr& obj) const;
|
||||||
|
|
||||||
void SetObjectActive(const DbObject::Ptr& dbobj, bool active);
|
void SetObjectActive(const DbObject::Ptr& dbobj, bool active);
|
||||||
bool GetObjectActive(const DbObject::Ptr& dbobj) const;
|
bool GetObjectActive(const DbObject::Ptr& dbobj) const;
|
||||||
|
|
||||||
@ -72,6 +75,7 @@ protected:
|
|||||||
private:
|
private:
|
||||||
std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
|
std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
|
||||||
std::map<DbObject::Ptr, DbReference> m_InsertIDs;
|
std::map<DbObject::Ptr, DbReference> m_InsertIDs;
|
||||||
|
std::map<DynamicObject::Ptr, DbReference> m_NotificationInsertIDs;
|
||||||
std::set<DbObject::Ptr> m_ActiveObjects;
|
std::set<DbObject::Ptr> m_ActiveObjects;
|
||||||
std::set<DbObject::Ptr> m_ConfigUpdates;
|
std::set<DbObject::Ptr> m_ConfigUpdates;
|
||||||
std::set<DbObject::Ptr> m_StatusUpdates;
|
std::set<DbObject::Ptr> m_StatusUpdates;
|
||||||
|
@ -22,6 +22,7 @@
|
|||||||
|
|
||||||
#include "db_ido/i2-db_ido.h"
|
#include "db_ido/i2-db_ido.h"
|
||||||
#include "base/dictionary.h"
|
#include "base/dictionary.h"
|
||||||
|
#include "base/dynamicobject.h"
|
||||||
|
|
||||||
namespace icinga
|
namespace icinga
|
||||||
{
|
{
|
||||||
@ -65,6 +66,7 @@ struct I2_DB_IDO_API DbQuery
|
|||||||
Dictionary::Ptr Fields;
|
Dictionary::Ptr Fields;
|
||||||
Dictionary::Ptr WhereCriteria;
|
Dictionary::Ptr WhereCriteria;
|
||||||
shared_ptr<DbObject> Object;
|
shared_ptr<DbObject> Object;
|
||||||
|
shared_ptr<DynamicObject> NotificationObject;
|
||||||
bool ConfigUpdate;
|
bool ConfigUpdate;
|
||||||
bool StatusUpdate;
|
bool StatusUpdate;
|
||||||
|
|
||||||
|
@ -773,6 +773,8 @@ void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notificati
|
|||||||
query1.Table = "notifications";
|
query1.Table = "notifications";
|
||||||
query1.Type = DbQueryInsert;
|
query1.Type = DbQueryInsert;
|
||||||
query1.Category = DbCatNotification;
|
query1.Category = DbCatNotification;
|
||||||
|
/* store the object ptr for caching the insert id for this object */
|
||||||
|
query1.NotificationObject = notification;
|
||||||
|
|
||||||
Dictionary::Ptr fields1 = make_shared<Dictionary>();
|
Dictionary::Ptr fields1 = make_shared<Dictionary>();
|
||||||
fields1->Set("notification_type", 1); /* service */
|
fields1->Set("notification_type", 1); /* service */
|
||||||
@ -821,7 +823,7 @@ void ServiceDbObject::AddNotificationHistory(const Notification::Ptr& notificati
|
|||||||
fields2->Set("end_time", DbValue::FromTimestamp(time_bag.first));
|
fields2->Set("end_time", DbValue::FromTimestamp(time_bag.first));
|
||||||
fields2->Set("end_time_usec", time_bag.second);
|
fields2->Set("end_time_usec", time_bag.second);
|
||||||
|
|
||||||
fields2->Set("notification_id", 0); /* DbConnection class fills in real ID */
|
fields2->Set("notification_id", notification); /* DbConnection class fills in real ID from notification insert id cache */
|
||||||
fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
|
||||||
|
|
||||||
query2.Fields = fields2;
|
query2.Fields = fields2;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user