]> granicus.if.org Git - icinga2/commitdiff
Implement DbQuery::Category field.
authorGunnar Beutner <gunnar.beutner@netways.de>
Tue, 29 Oct 2013 14:54:43 +0000 (15:54 +0100)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 30 Oct 2013 08:58:55 +0000 (09:58 +0100)
Refs #4782

components/db_ido_mysql/idomysqlconnection.cpp
lib/db_ido/dbconnection.cpp
lib/db_ido/dbobject.cpp
lib/db_ido/dbquery.h
lib/db_ido/hostdbobject.cpp
lib/db_ido/hostgroupdbobject.cpp
lib/db_ido/servicedbobject.cpp
lib/db_ido/servicegroupdbobject.cpp
lib/db_ido/timeperioddbobject.cpp
lib/db_ido/usergroupdbobject.cpp

index e380a26b4c8c1816d360719a98ec604f425c42a9..7797106b28afe28b4669754c7ddc0e6a3ee4f79c 100644 (file)
@@ -405,6 +405,8 @@ void IdoMysqlConnection::ExecuteQuery(const DbQuery& query)
 {
        boost::mutex::scoped_lock lock(m_ConnectionMutex);
 
+       ASSERT(query.Category != DbCatInvalid);
+
        if (!m_Connected)
                return;
 
index 8b70f354e356421b513fe56c8814ef9dbc8af3eb..75b9b93db0b90001887d432fe1aa54fd51919fef 100644 (file)
@@ -60,6 +60,7 @@ void DbConnection::InsertRuntimeVariable(const String& key, const Value& value)
        DbQuery query;
        query.Table = "runtimevariables";
        query.Type = DbQueryInsert;
+       query.Category = DbCatProgramStatus;
        query.Fields = boost::make_shared<Dictionary>();
        query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
        query.Fields->Set("varname", key);
@@ -72,6 +73,7 @@ void DbConnection::ProgramStatusHandler(void)
        DbQuery query1;
        query1.Table = "programstatus";
        query1.Type = DbQueryDelete;
+       query1.Type = DbCatProgramStatus;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
        DbObject::OnQuery(query1);
@@ -79,6 +81,7 @@ void DbConnection::ProgramStatusHandler(void)
        DbQuery query2;
        query2.Table = "programstatus";
        query2.Type = DbQueryInsert;
+       query2.Category = DbCatProgramStatus;
 
        query2.Fields = boost::make_shared<Dictionary>();
        query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
@@ -100,6 +103,7 @@ void DbConnection::ProgramStatusHandler(void)
        DbQuery query3;
        query3.Table = "runtimevariables";
        query3.Type = DbQueryDelete;
+       query3.Category = DbCatProgramStatus;
        query3.WhereCriteria = boost::make_shared<Dictionary>();
        query3.WhereCriteria->Set("instance_id", 0);  /* DbConnection class fills in real ID */
        DbObject::OnQuery(query3);
index 99669f635944164ccf4b070d6602fbc8395e6944..e9248a7b1883e0eb280a07d499936b191843b71e 100644 (file)
@@ -78,6 +78,7 @@ void DbObject::SendConfigUpdate(void)
        DbQuery query;
        query.Table = GetType()->GetTable() + "s";
        query.Type = DbQueryInsert | DbQueryUpdate;
+       query.Type = DbCatConfig;
        query.Fields = fields;
        query.Fields->Set(GetType()->GetIDColumn(), GetObject());
        query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
@@ -103,6 +104,7 @@ void DbObject::SendStatusUpdate(void)
        DbQuery query;
        query.Table = GetType()->GetTable() + "status";
        query.Type = DbQueryInsert | DbQueryUpdate;
+       query.Category = DbCatState;
        query.Fields = fields;
        query.Fields->Set(GetType()->GetIDColumn(), GetObject());
        query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
index 4e47f55e1b0bb5e173f72a5caafdeaacac50bf47..4dac7535794567c733c1c5f21dd80123ac5d7b75 100644 (file)
@@ -32,11 +32,33 @@ enum DbQueryType
        DbQueryDelete = 4
 };
 
+enum DbQueryCategory
+{
+       DbCatInvalid,
+
+       DbCatConfig,
+       DbCatState,
+
+       DbCatAcknowledgement,
+       DbCatComment,
+       DbCatDowntime,
+       DbCatEventHandler,
+       DbCatExternalCommand,
+       DbCatFlapping,
+       DbCatCheck,
+       DbCatLog,
+       DbCatNotification,
+       DbCatProgramStatus,
+       DbCatRetention,
+       DbCatStateHistory
+};
+
 class DbObject;
 
 struct DbQuery
 {
        int Type;
+       DbQueryCategory Category;
        String Table;
        Dictionary::Ptr Fields;
        Dictionary::Ptr WhereCriteria;
@@ -45,7 +67,7 @@ struct DbQuery
        bool StatusUpdate;
 
        DbQuery(void)
-               : Type(0), ConfigUpdate(false), StatusUpdate(false)
+               : Type(0), Category(DbCatInvalid), ConfigUpdate(false), StatusUpdate(false)
        { }
 };
 
index d456ca5805ca406ed769e601e91913e54a790250..106a9d6b713f1d058634b33c8fb5edfec030c9a0 100644 (file)
@@ -197,6 +197,7 @@ void HostDbObject::OnConfigUpdate(void)
        DbQuery query_del1;
        query_del1.Table = GetType()->GetTable() + "_parenthosts";
        query_del1.Type = DbQueryDelete;
+       query_del1.Category = DbCatConfig;
        query_del1.WhereCriteria = boost::make_shared<Dictionary>();
        query_del1.WhereCriteria->Set(GetType()->GetTable() + "_id", DbValue::FromObjectInsertID(GetObject()));
        OnQuery(query_del1);
@@ -204,6 +205,7 @@ void HostDbObject::OnConfigUpdate(void)
        DbQuery query_del2;
        query_del2.Table = GetType()->GetTable() + "dependencies";
        query_del2.Type = DbQueryDelete;
+       query_del2.Category = DbCatConfig;
        query_del2.WhereCriteria = boost::make_shared<Dictionary>();
        query_del2.WhereCriteria->Set("dependent_host_object_id", host);
        OnQuery(query_del2);
@@ -220,6 +222,7 @@ void HostDbObject::OnConfigUpdate(void)
                DbQuery query1;
                query1.Table = GetType()->GetTable() + "_parenthosts";
                query1.Type = DbQueryInsert;
+               query1.Category = DbCatConfig;
                query1.Fields = fields1;
                OnQuery(query1);
 
@@ -232,6 +235,7 @@ void HostDbObject::OnConfigUpdate(void)
                DbQuery query2;
                query2.Table = GetType()->GetTable() + "dependencies";
                query2.Type = DbQueryInsert;
+               query2.Category = DbCatConfig;
                query2.Fields = fields2;
                OnQuery(query2);
        }
@@ -253,6 +257,7 @@ void HostDbObject::OnConfigUpdate(void)
                        DbQuery query_contact;
                        query_contact.Table = GetType()->GetTable() + "_contacts";
                        query_contact.Type = DbQueryInsert;
+                       query_contact.Category = DbCatConfig;
                        query_contact.Fields = fields_contact;
                        OnQuery(query_contact);
                }
@@ -270,6 +275,7 @@ void HostDbObject::OnConfigUpdate(void)
                        DbQuery query_contact;
                        query_contact.Table = GetType()->GetTable() + "_contactgroups";
                        query_contact.Type = DbQueryInsert;
+                       query_contact.Category = DbCatConfig;
                        query_contact.Fields = fields_contact;
                        OnQuery(query_contact);
                }
@@ -281,6 +287,7 @@ void HostDbObject::OnConfigUpdate(void)
        DbQuery query_del3;
        query_del3.Table = "customvariables";
        query_del3.Type = DbQueryDelete;
+       query_del3.Category = DbCatConfig;
        query_del3.WhereCriteria = boost::make_shared<Dictionary>();
        query_del3.WhereCriteria->Set("object_id", host);
        OnQuery(query_del3);
@@ -310,6 +317,7 @@ void HostDbObject::OnConfigUpdate(void)
                        DbQuery query3;
                        query3.Table = "customvariables";
                        query3.Type = DbQueryInsert;
+                       query3.Category = DbCatConfig;
                        query3.Fields = fields3;
                        OnQuery(query3);
                }
index 74f9167ac1847b20237c920e91453e50fdf4d8db..3e20c8c967661ba34b3c0f9a7adf27fa79ef47fe 100644 (file)
@@ -55,6 +55,7 @@ void HostGroupDbObject::OnConfigUpdate(void)
        DbQuery query1;
        query1.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
        query1.Type = DbQueryDelete;
+       query1.Category = DbCatConfig;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
        OnQuery(query1);
@@ -63,6 +64,7 @@ void HostGroupDbObject::OnConfigUpdate(void)
                DbQuery query2;
                query2.Table = DbType::GetByName("HostGroup")->GetTable() + "_members";
                query2.Type = DbQueryInsert;
+               query2.Category = DbCatConfig;
                query2.Fields = boost::make_shared<Dictionary>();
                query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
                query2.Fields->Set("hostgroup_id", DbValue::FromObjectInsertID(group));
index ab723e216bdd912e13d25dacc37f683b99c8b22e..78dfb88117fe975670cb59b1f11e076ed92b2b8e 100644 (file)
@@ -217,6 +217,7 @@ void ServiceDbObject::OnConfigUpdate(void)
        DbQuery query_del1;
        query_del1.Table = GetType()->GetTable() + "dependencies";
        query_del1.Type = DbQueryDelete;
+       query_del1.Category = DbCatConfig;
        query_del1.WhereCriteria = boost::make_shared<Dictionary>();
        query_del1.WhereCriteria->Set("dependent_service_object_id", service);
        OnQuery(query_del1);
@@ -233,6 +234,7 @@ void ServiceDbObject::OnConfigUpdate(void)
                 DbQuery query1;
                 query1.Table = GetType()->GetTable() + "dependencies";
                 query1.Type = DbQueryInsert;
+               query1.Category = DbCatConfig;
                 query1.Fields = fields1;
                 OnQuery(query1);
        }
@@ -251,6 +253,7 @@ void ServiceDbObject::OnConfigUpdate(void)
                DbQuery query_contact;
                query_contact.Table = GetType()->GetTable() + "_contacts";
                query_contact.Type = DbQueryInsert;
+               query_contact.Category = DbCatConfig;
                query_contact.Fields = fields_contact;
                OnQuery(query_contact);
        }
@@ -268,6 +271,7 @@ void ServiceDbObject::OnConfigUpdate(void)
                DbQuery query_contact;
                query_contact.Table = GetType()->GetTable() + "_contactgroups";
                query_contact.Type = DbQueryInsert;
+               query_contact.Category = DbCatConfig;
                query_contact.Fields = fields_contact;
                OnQuery(query_contact);
        }
@@ -278,6 +282,7 @@ void ServiceDbObject::OnConfigUpdate(void)
        DbQuery query_del2;
        query_del2.Table = "customvariables";
        query_del2.Type = DbQueryDelete;
+       query_del2.Category = DbCatConfig;
        query_del2.WhereCriteria = boost::make_shared<Dictionary>();
        query_del2.WhereCriteria->Set("object_id", service);
        OnQuery(query_del2);
@@ -308,6 +313,7 @@ void ServiceDbObject::OnConfigUpdate(void)
                        DbQuery query2;
                        query2.Table = "customvariables";
                        query2.Type = DbQueryInsert;
+                       query2.Category = DbCatConfig;
                        query2.Fields = fields2;
                        OnQuery(query2);
                }
@@ -444,6 +450,7 @@ void ServiceDbObject::AddCommentByType(const DynamicObject::Ptr& object, const D
                query1.Table = "commenthistory";
        }
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatComment;
        query1.Fields = fields1;
        OnQuery(query1);
 }
@@ -460,6 +467,7 @@ void ServiceDbObject::RemoveComments(const Service::Ptr& service)
        DbQuery query1;
        query1.Table = "comments";
        query1.Type = DbQueryDelete;
+       query1.Category = DbCatComment;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("object_id", service);
        OnQuery(query1);
@@ -489,6 +497,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar
        DbQuery query1;
        query1.Table = "comments";
        query1.Type = DbQueryDelete;
+       query1.Category = DbCatComment;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("object_id", service);
        query1.WhereCriteria->Set("internal_comment_id", comment->Get("legacy_id"));
@@ -509,6 +518,7 @@ void ServiceDbObject::RemoveComment(const Service::Ptr& service, const Dictionar
        DbQuery query2;
        query2.Table = "commenthistory";
        query2.Type = DbQueryUpdate;
+       query2.Category = DbCatComment;
 
        Dictionary::Ptr fields2 = boost::make_shared<Dictionary>();
        fields2->Set("deletion_time", DbValue::FromTimestamp(deletion_time));
@@ -610,6 +620,7 @@ void ServiceDbObject::AddDowntimeByType(const DynamicObject::Ptr& object, const
                query1.Table = "downtimehistory";
        }
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatDowntime;
        query1.Fields = fields1;
        OnQuery(query1);
 }
@@ -626,6 +637,7 @@ void ServiceDbObject::RemoveDowntimes(const Service::Ptr& service)
        DbQuery query1;
        query1.Table = "scheduleddowntime";
        query1.Type = DbQueryDelete;
+       query1.Category = DbCatDowntime;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("object_id", service);
        OnQuery(query1);
@@ -655,6 +667,7 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona
        DbQuery query1;
        query1.Table = "scheduleddowntime";
        query1.Type = DbQueryDelete;
+       query1.Category = DbCatDowntime;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("object_id", service);
        query1.WhereCriteria->Set("internal_downtime_id", downtime->Get("legacy_id"));
@@ -674,6 +687,7 @@ void ServiceDbObject::RemoveDowntime(const Service::Ptr& service, const Dictiona
        DbQuery query3;
        query3.Table = "downtimehistory";
        query3.Type = DbQueryUpdate;
+       query3.Category = DbCatDowntime;
 
        Dictionary::Ptr fields3 = boost::make_shared<Dictionary>();
        fields3->Set("was_cancelled", downtime->Get("was_cancelled") ? 1 : 0);
@@ -713,6 +727,7 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
        DbQuery query1;
        query1.Table = "scheduleddowntime";
        query1.Type = DbQueryUpdate;
+       query1.Category = DbCatDowntime;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        fields1->Set("was_started", 1);
@@ -739,6 +754,7 @@ void ServiceDbObject::TriggerDowntime(const Service::Ptr& service, const Diction
        DbQuery query3;
        query3.Table = "downtimehistory";
        query3.Type = DbQueryUpdate;
+       query3.Category = DbCatDowntime;
 
        Dictionary::Ptr fields3 = boost::make_shared<Dictionary>();
        fields3->Set("was_started", 1);
@@ -777,6 +793,7 @@ void ServiceDbObject::AddAcknowledgementHistory(const Service::Ptr& service, con
        DbQuery query1;
        query1.Table = "acknowledgements";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatAcknowledgement;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        fields1->Set("entry_time", DbValue::FromTimestamp(entry_time));
@@ -822,6 +839,7 @@ void ServiceDbObject::AddContactNotificationHistory(const Service::Ptr& service,
        DbQuery query1;
        query1.Table = "contactnotifications";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatNotification;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        fields1->Set("contact_object_id", user);
@@ -862,6 +880,7 @@ void ServiceDbObject::AddNotificationHistory(const Service::Ptr& service, const
        DbQuery query1;
        query1.Table = "notifications";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatNotification;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        fields1->Set("notification_type", 1); /* service */
@@ -912,6 +931,7 @@ void ServiceDbObject::AddStateChangeHistory(const Service::Ptr& service, const D
        DbQuery query1;
        query1.Table = "statehistory";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatStateHistory;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        fields1->Set("state_time", DbValue::FromTimestamp(state_time));
@@ -1246,6 +1266,7 @@ void ServiceDbObject::AddLogHistory(const Service::Ptr& service, String buffer,
        DbQuery query1;
        query1.Table = "logentries";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatLog;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        fields1->Set("logentry_time", DbValue::FromTimestamp(entry_time));
@@ -1284,6 +1305,7 @@ void ServiceDbObject::AddFlappingHistory(const Service::Ptr& service, FlappingSt
        DbQuery query1;
        query1.Table = "flappinghistory";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatFlapping;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
 
@@ -1339,6 +1361,7 @@ void ServiceDbObject::AddServiceCheckHistory(const Service::Ptr& service, const
        DbQuery query1;
        query1.Table = "servicechecks";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatCheck;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
        Dictionary::Ptr attrs;
@@ -1410,6 +1433,7 @@ void ServiceDbObject::AddEventHandlerHistory(const Service::Ptr& service)
        DbQuery query1;
        query1.Table = "eventhandlers";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatEventHandler;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
 
@@ -1447,6 +1471,7 @@ void ServiceDbObject::AddExternalCommandHistory(double time, const String& comma
        DbQuery query1;
        query1.Table = "externalcommands";
        query1.Type = DbQueryInsert;
+       query1.Category = DbCatExternalCommand;
 
        Dictionary::Ptr fields1 = boost::make_shared<Dictionary>();
 
index 86e7a315a49129ac7c359fa1866373483b709242..5d24cb3b5cfd95a9f396d97251bb68eb26cdd55a 100644 (file)
@@ -54,6 +54,7 @@ void ServiceGroupDbObject::OnConfigUpdate(void)
        DbQuery query1;
        query1.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
        query1.Type = DbQueryDelete;
+       query1.Category = DbCatConfig;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
        OnQuery(query1);
@@ -62,6 +63,7 @@ void ServiceGroupDbObject::OnConfigUpdate(void)
                DbQuery query2;
                query2.Table = DbType::GetByName("ServiceGroup")->GetTable() + "_members";
                query2.Type = DbQueryInsert;
+               query2.Category = DbCatConfig;
                query2.Fields = boost::make_shared<Dictionary>();
                query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
                query2.Fields->Set("servicegroup_id", DbValue::FromObjectInsertID(group));
index f4af8635fba65b8172c451f41a8a7201bdf5207d..d7c2d43818940c5205d4137a4a4d2c59e5a50783 100644 (file)
@@ -58,6 +58,7 @@ void TimePeriodDbObject::OnConfigUpdate(void)
        DbQuery query_del1;
        query_del1.Table = GetType()->GetTable() + "_timeranges";
        query_del1.Type = DbQueryDelete;
+       query_del1.Category = DbCatConfig;
        query_del1.WhereCriteria = boost::make_shared<Dictionary>();
        query_del1.WhereCriteria->Set("timeperiod_id", DbValue::FromObjectInsertID(tp));
        OnQuery(query_del1);
@@ -109,6 +110,7 @@ void TimePeriodDbObject::OnConfigUpdate(void)
                        DbQuery query;
                        query.Table = GetType()->GetTable() + "_timeranges";
                        query.Type = DbQueryInsert;
+                       query.Category = DbCatConfig;
                        query.Fields = boost::make_shared<Dictionary>();
                        query.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
                        query.Fields->Set("timeperiod_id", DbValue::FromObjectInsertID(tp));
index eb5af31f73d583e29818e48c14eb0863bd2617cf..928b7137404157cf33fffe3675aa466568802cf4 100644 (file)
@@ -55,6 +55,7 @@ void UserGroupDbObject::OnConfigUpdate(void)
        DbQuery query1;
        query1.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
        query1.Type = DbQueryDelete;
+       query1.Category = DbCatConfig;
        query1.WhereCriteria = boost::make_shared<Dictionary>();
        query1.WhereCriteria->Set("instance_id", 0);
        query1.WhereCriteria->Set("contactgroup_id", DbValue::FromObjectInsertID(group));
@@ -64,6 +65,7 @@ void UserGroupDbObject::OnConfigUpdate(void)
                DbQuery query2;
                query2.Table = DbType::GetByName("UserGroup")->GetTable() + "_members";
                query2.Type = DbQueryInsert;
+               query2.Category = DbCatConfig;
                query2.Fields = boost::make_shared<Dictionary>();
                query2.Fields->Set("instance_id", 0); /* DbConnection class fills in real ID */
                query2.Fields->Set("contactgroup_id", DbValue::FromObjectInsertID(group));