Merge branch 'feature/ido-options-4782' into next

Fixes #4782
This commit is contained in:
Gunnar Beutner 2013-10-30 10:23:05 +01:00
commit e74586e6a9
14 changed files with 129 additions and 6 deletions

View File

@ -405,6 +405,11 @@ void IdoMysqlConnection::ExecuteQuery(const DbQuery& query)
{
boost::mutex::scoped_lock lock(m_ConnectionMutex);
ASSERT(query.Category != DbCatInvalid);
if ((query.Category & GetCategories()) == 0)
return;
if (!m_Connected)
return;

View File

@ -44,9 +44,6 @@ protected:
virtual void Start(void);
virtual void Stop(void);
virtual void InternalSerialize(const Dictionary::Ptr& bag, int attributeTypes) const;
virtual void InternalDeserialize(const Dictionary::Ptr& bag, int attributeTypes);
virtual void ActivateObject(const DbObject::Ptr& dbobj);
virtual void DeactivateObject(const DbObject::Ptr& dbobj);
virtual void ExecuteQuery(const DbQuery& query);

View File

@ -523,7 +523,9 @@ Example:
cleanup = {
downtimehistory_age = 48h,
logentries_age = 31d,
}
},
categories = (DbCatConfig | DbCatState)
}
Attributes:
@ -539,6 +541,7 @@ Attributes:
instance\_name |**Optional.** Unique identifier for the local Icinga 2 instance. Defaults to "default".
instance\_description|**Optional.** Description for the Icinga 2 instance.
cleanup |**Optional.** Dictionary with items for historical table cleanup.
categories |**Optional.** The types of information that should be written to the database.
Cleanup Items:
@ -560,6 +563,27 @@ Cleanup Items:
servicechecks_age |**Optional.** Max age for servicechecks table rows (start_time). Defaults to 0 (never).
systemcommands_age |**Optional.** Max age for systemcommands table rows (start_time). Defaults to 0 (never).
Data Categories:
Name | Description
---------------------|----------------
DbCatConfig | Configuration data
DbCatState | Current state data
DbCatAcknowledgement | Acknowledgements
DbCatComment | Comments
DbCatDowntime | Downtimes
DbCatEventHandler | Event handler data
DbCatExternalCommand | External commands
DbCatFlapping | Flap detection data
DbCatCheck | Check results
DbCatLog | Log messages
DbCatNotification | Notifications
DbCatProgramStatus | Program status data
DbCatRetention | Retention data
DbCatStateHistory | Historical state data
Multiple categories can be combined using the `|` operator.
### <a id="objecttype-livestatuslistener"></a> LiveStatusListener
Livestatus API interface available as TCP or UNIX socket.

View File

@ -62,3 +62,22 @@ set DomainPrivCommand = (1<<2)
set DomainPrivReadOnly = (DomainPrivRead)
set DomainPrivReadWrite = (DomainPrivRead | DomainPrivCheckResult | DomainPrivCommand)
/*
* IDO filter categories
*/
set DbCatConfig = (1 << 0)
set DbCatState = (1 << 1)
set DbCatAcknowledgement = (1 << 2)
set DbCatComment = (1 << 3)
set DbCatDowntime = (1 << 4)
set DbCatEventHandler = (1 << 5)
set DbCatExternalCommand = (1 << 6)
set DbCatFlapping = (1 << 7)
set DbCatCheck = (1 << 8)
set DbCatLog = (1 << 9)
set DbCatNotification = (1 << 10)
set DbCatProgramStatus = (1 << 11)
set DbCatRetention = (1 << 12)
set DbCatStateHistory = (1 << 13)

View 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.Category = 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);

View File

@ -1,3 +1,4 @@
#include "db_ido/dbquery.h"
#include "base/dynamicobject.h"
#include <boost/smart_ptr/make_shared.hpp>
@ -13,6 +14,14 @@ class DbConnection : DynamicObject
[config] Dictionary::Ptr cleanup {
default {{{ return boost::make_shared<Dictionary>(); }}}
};
[config] int categories {
default {{{
return DbCatConfig | DbCatState | DbCatAcknowledgement |
DbCatComment | DbCatDowntime | DbCatEventHandler | DbCatExternalCommand | DbCatFlapping |
DbCatLog | DbCatNotification | DbCatProgramStatus | DbCatRetention | DbCatStateHistory;
}}}
};
};
}

View 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 */

View File

@ -32,11 +32,33 @@ enum DbQueryType
DbQueryDelete = 4
};
enum DbQueryCategory
{
DbCatInvalid = -1,
DbCatConfig = (1 << 0),
DbCatState = (1 << 1),
DbCatAcknowledgement = (1 << 2),
DbCatComment = (1 << 3),
DbCatDowntime = (1 << 4),
DbCatEventHandler = (1 << 5),
DbCatExternalCommand = (1 << 6),
DbCatFlapping = (1 << 7),
DbCatCheck = (1 << 8),
DbCatLog = (1 << 9),
DbCatNotification = (1 << 10),
DbCatProgramStatus = (1 << 11),
DbCatRetention = (1 << 12),
DbCatStateHistory = (1 << 13)
};
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)
{ }
};

View 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);
}

View 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));

View 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>();

View 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));

View 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));

View 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));