return it->second;
}
-void DbConnection::SetNotificationInsertID(const CustomVarObject::Ptr& obj, const DbReference& dbref)
-{
- if (dbref.IsValid())
- m_NotificationInsertIDs[obj] = dbref;
- else
- m_NotificationInsertIDs.erase(obj);
-}
-
-DbReference DbConnection::GetNotificationInsertID(const CustomVarObject::Ptr& obj) const
-{
- std::map<CustomVarObject::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)
{
if (active)
{
m_ObjectIDs.clear();
m_InsertIDs.clear();
- m_NotificationInsertIDs.clear();
m_ActiveObjects.clear();
m_ConfigUpdates.clear();
m_StatusUpdates.clear();
DbReference GetInsertID(const DbObject::Ptr& dbobj) const;
DbReference GetInsertID(const DbType::Ptr& type, const DbReference& objid) const;
- void SetNotificationInsertID(const CustomVarObject::Ptr& obj, const DbReference& dbref);
- DbReference GetNotificationInsertID(const CustomVarObject::Ptr& obj) const;
-
void SetObjectActive(const DbObject::Ptr& dbobj, bool active);
bool GetObjectActive(const DbObject::Ptr& dbobj) const;
private:
std::map<DbObject::Ptr, DbReference> m_ObjectIDs;
std::map<std::pair<DbType::Ptr, DbReference>, DbReference> m_InsertIDs;
- std::map<CustomVarObject::Ptr, DbReference> m_NotificationInsertIDs;
std::set<DbObject::Ptr> m_ActiveObjects;
std::set<DbObject::Ptr> m_ConfigUpdates;
std::set<DbObject::Ptr> m_StatusUpdates;
query1.Table = "notifications";
query1.Type = DbQueryInsert;
query1.Category = DbCatNotification;
- /* store the object ptr for caching the insert id for this object */
- query1.NotificationObject = notification;
+ query1.NotificationInsertID = new DbValue(DbValueObjectInsertID, -1);
Host::Ptr host;
Service::Ptr service;
query1.Fields = fields1;
DbObject::OnQuery(query1);
- DbQuery query2;
- query2.Table = "contactnotifications";
- query2.Type = DbQueryInsert;
- query2.Category = DbCatNotification;
+ std::vector<DbQuery> queries;
- /* filtered users */
BOOST_FOREACH(const User::Ptr& user, users) {
Log(LogDebug, "DbEvents")
<< "add contact notification history for service '" << checkable->GetName() << "' and user '" << user->GetName() << "'.";
+ DbQuery query2;
+ query2.Table = "contactnotifications";
+ query2.Type = DbQueryInsert;
+ query2.Category = DbCatNotification;
+
Dictionary::Ptr fields2 = new Dictionary();
fields2->Set("contact_object_id", user);
fields2->Set("start_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("notification_id", notification); /* DbConnection class fills in real ID from notification insert id cache */
+ fields2->Set("notification_id", query1.NotificationInsertID);
fields2->Set("instance_id", 0); /* DbConnection class fills in real ID */
query2.Fields = fields2;
- DbObject::OnQuery(query2);
+ queries.push_back(query2);
}
+
+ DbObject::OnMultipleQueries(queries);
}
/* statehistory */
#define DBQUERY_H
#include "db_ido/i2-db_ido.hpp"
+#include "db_ido/dbvalue.hpp"
#include "icinga/customvarobject.hpp"
#include "base/dictionary.hpp"
#include "base/configobject.hpp"
Dictionary::Ptr Fields;
Dictionary::Ptr WhereCriteria;
intrusive_ptr<DbObject> Object;
- intrusive_ptr<CustomVarObject> NotificationObject;
+ DbValue::Ptr NotificationInsertID;
bool ConfigUpdate;
bool StatusUpdate;
WorkQueuePriority Priority;
{
return m_Value;
}
+
+void DbValue::SetValue(const Value& value)
+{
+ m_Value = value;
+}
{
DbValueTimestamp,
DbValueTimestampNow,
- DbValueObjectInsertID,
+ DbValueObjectInsertID
};
/**
static Value ExtractValue(const Value& value);
DbValueType GetType(void) const;
+
Value GetValue(void) const;
+ void SetValue(const Value& value);
private:
DbValueType m_Type;
} else if (key == "session_token") {
*result = m_SessionToken;
return true;
- } else if (key == "notification_id") {
- DbReference ref = GetNotificationInsertID(value);
-
- if (!ref.IsValid())
- return false;
-
- *result = static_cast<long>(ref);
- return true;
}
Value rawvalue = DbValue::ExtractValue(value);
*result = Value(msgbuf.str());
} else if (DbValue::IsTimestampNow(value)) {
*result = "NOW()";
+ } else if (DbValue::IsObjectInsertID(value)) {
+ long id = static_cast<long>(rawvalue);
+
+ if (id <= 0)
+ return false;
+
+ *result = id;
+ return true;
} else {
Value fvalue;
SetStatusUpdate(query.Object, true);
}
- if (type == DbQueryInsert && query.Table == "notifications" && query.NotificationObject) { // FIXME remove hardcoded table name
- SetNotificationInsertID(query.NotificationObject, GetLastInsertID());
- Log(LogDebug, "IdoMysqlConnection")
- << "saving contactnotification notification_id=" << static_cast<long>(GetLastInsertID());
- }
+ if (type == DbQueryInsert && query.Table == "notifications" && query.NotificationInsertID)
+ query.NotificationInsertID->SetValue(static_cast<long>(GetLastInsertID()));
}
void IdoMysqlConnection::CleanUpExecuteQuery(const String& table, const String& time_column, double max_age)
} else if (key == "session_token") {
*result = m_SessionToken;
return true;
- } else if (key == "notification_id") {
- DbReference ref = GetNotificationInsertID(value);
-
- if (!ref.IsValid())
- return false;
-
- *result = static_cast<long>(ref);
- return true;
}
Value rawvalue = DbValue::ExtractValue(value);
*result = Value(msgbuf.str());
} else if (DbValue::IsTimestampNow(value)) {
*result = "NOW()";
+ } else if (DbValue::IsObjectInsertID(value)) {
+ long id = static_cast<long>(rawvalue);
+
+ if (id <= 0)
+ return false;
+
+ *result = id;
+ return true;
} else {
Value fvalue;
SetStatusUpdate(query.Object, true);
}
- if (type == DbQueryInsert && query.Table == "notifications" && query.NotificationObject) { // FIXME remove hardcoded table name
- String idField = "notification_id";
- DbReference seqval = GetSequenceValue(GetTablePrefix() + query.Table, idField);
- SetNotificationInsertID(query.NotificationObject, seqval);
- Log(LogDebug, "IdoPgsqlConnection")
- << "saving contactnotification notification_id=" << Convert::ToString(seqval);
+ if (type == DbQueryInsert && query.Table == "notifications" && query.NotificationInsertID) {
+ DbReference seqval = GetSequenceValue(GetTablePrefix() + query.Table, "notification_id");
+ query.NotificationInsertID->SetValue(static_cast<long>(seqval));
}
}
if (!command) {
Log(LogDebug, "Notification")
- << "No notification_command found for notification '" << GetName() << "'. Skipping execution.";
+ << "No command found for notification '" << GetName() << "'. Skipping execution.";
return;
}
Service::OnNotificationSentToUser(this, GetCheckable(), user, type, cr, author, text, command->GetName());
Log(LogInformation, "Notification")
- << "Completed sending notification '" << GetName() << "' for checkable '" << GetCheckable()->GetName() << "'";
+ << "Completed sending notification '" << GetName()
+ << "' for checkable '" << GetCheckable()->GetName()
+ << "' and user '" << user->GetName() << "'.";
} catch (const std::exception& ex) {
Log(LogWarning, "Notification")
<< "Exception occured during notification for checkable '"