mirror of https://github.com/Icinga/icinga2.git
commit
561b1d7c37
|
@ -65,7 +65,7 @@ void IdoMysqlConnection::Stop(void)
|
|||
|
||||
void IdoMysqlConnection::AssertOnWorkQueue(void)
|
||||
{
|
||||
VERIFY(boost::this_thread::get_id() == m_QueryQueue.GetThreadId());
|
||||
ASSERT(boost::this_thread::get_id() == m_QueryQueue.GetThreadId());
|
||||
}
|
||||
|
||||
void IdoMysqlConnection::Disconnect(void)
|
||||
|
@ -570,12 +570,12 @@ void IdoMysqlConnection::InternalExecuteQuery(const DbQuery& query)
|
|||
}
|
||||
}
|
||||
|
||||
void IdoMysqlConnection::CleanUpExecuteQuery(const String& table, const String& time_key, double time_value)
|
||||
void IdoMysqlConnection::CleanUpExecuteQuery(const String& table, const String& time_column, double max_age)
|
||||
{
|
||||
m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::InternalCleanUpExecuteQuery, this, table, time_key, time_value));
|
||||
m_QueryQueue.Enqueue(boost::bind(&IdoMysqlConnection::InternalCleanUpExecuteQuery, this, table, time_column, max_age));
|
||||
}
|
||||
|
||||
void IdoMysqlConnection::InternalCleanUpExecuteQuery(const String& table, const String& time_key, double time_value)
|
||||
void IdoMysqlConnection::InternalCleanUpExecuteQuery(const String& table, const String& time_column, double max_age)
|
||||
{
|
||||
boost::mutex::scoped_lock lock(m_ConnectionMutex);
|
||||
|
||||
|
@ -583,7 +583,6 @@ void IdoMysqlConnection::InternalCleanUpExecuteQuery(const String& table, const
|
|||
return;
|
||||
|
||||
Query("DELETE FROM " + GetTablePrefix() + table + " WHERE instance_id = " +
|
||||
Convert::ToString(static_cast<long>(m_InstanceID)) + " AND " + time_key +
|
||||
"<FROM_UNIXTIME(" + Convert::ToString(static_cast<long>(time_value)) + ")");
|
||||
Convert::ToString(static_cast<long>(m_InstanceID)) + " AND " + time_column +
|
||||
" < FROM_UNIXTIME(" + Convert::ToString(static_cast<long>(max_age)) + ")");
|
||||
}
|
||||
|
||||
|
|
|
@ -547,7 +547,7 @@ Cleanup Items:
|
|||
|
||||
Name | Description
|
||||
----------------|----------------
|
||||
acknowledgement_age |**Optional.** Max age for acknowledgement table rows (entry_time). Defaults to 0 (never).
|
||||
acknowledgements_age |**Optional.** Max age for acknowledgements table rows (entry_time). Defaults to 0 (never).
|
||||
commenthistory_age |**Optional.** Max age for commenthistory table rows (entry_time). Defaults to 0 (never).
|
||||
contactnotifications_age |**Optional.** Max age for contactnotifications table rows (start_time). Defaults to 0 (never).
|
||||
contactnotificationmethods_age |**Optional.** Max age for contactnotificationmethods table rows (start_time). Defaults to 0 (never).
|
||||
|
|
|
@ -118,178 +118,46 @@ void DbConnection::CleanUpHandler(void)
|
|||
{
|
||||
long now = static_cast<long>(Utility::GetTime());
|
||||
|
||||
if (GetCleanupAcknowledgementsAge() > 0) {
|
||||
CleanUpExecuteQuery("acknowledgements", "entry_time", now - GetCleanupAcknowledgementsAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupAcknowledgementsAge: " + Convert::ToString(GetCleanupAcknowledgementsAge()) +
|
||||
struct {
|
||||
String name;
|
||||
String time_column;
|
||||
} tables[] = {
|
||||
{ "acknowledgements", "entry_time" },
|
||||
{ "commenthistory", "entry_time" },
|
||||
{ "contactnotifications", "start_time" },
|
||||
{ "contactnotificationmethods", "start_time" },
|
||||
{ "downtimehistory", "entry_time" },
|
||||
{ "eventhandlers", "start_time" },
|
||||
{ "externalcommands", "entry_time" },
|
||||
{ "flappinghistory" "event_time" },
|
||||
{ "hostchecks", "start_time" },
|
||||
{ "logentries", "logentry_time" },
|
||||
{ "notifications", "start_time" },
|
||||
{ "processevents", "event_time" },
|
||||
{ "statehistory", "state_time" },
|
||||
{ "servicechecks", "start_time" },
|
||||
{ "systemcommands", "start_time" }
|
||||
};
|
||||
|
||||
for (int i = 0; i < sizeof(tables) / sizeof(tables[0]); i++) {
|
||||
double max_age = GetCleanup()->Get(tables[i].name + "_age");
|
||||
|
||||
if (max_age == 0)
|
||||
continue;
|
||||
|
||||
CleanUpExecuteQuery(tables[i].name, tables[i].time_column, now - max_age);
|
||||
Log(LogDebug, "db_ido", "Cleanup (" + tables[i].name + "): " + Convert::ToString(max_age) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupAcknowledgementsAge()));
|
||||
}
|
||||
if (GetCleanupCommentHistoryAge() > 0) {
|
||||
CleanUpExecuteQuery("commenthistory", "entry_time", now - GetCleanupCommentHistoryAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupCommentHistoryAge: " + Convert::ToString(GetCleanupCommentHistoryAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupCommentHistoryAge()));
|
||||
}
|
||||
if (GetCleanupContactNotificationsAge() > 0) {
|
||||
CleanUpExecuteQuery("contactnotifications", "start_time", now - GetCleanupContactNotificationsAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupContactNotificationsAge: " + Convert::ToString(GetCleanupContactNotificationsAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupContactNotificationsAge()));
|
||||
}
|
||||
if (GetCleanupContactNotificationMethodsAge() > 0) {
|
||||
CleanUpExecuteQuery("contactnotificationmethods", "start_time", now - GetCleanupContactNotificationMethodsAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupContactNotificationMethodsAge: " + Convert::ToString(GetCleanupContactNotificationMethodsAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupContactNotificationMethodsAge()));
|
||||
}
|
||||
if (GetCleanupDowntimeHistoryAge() > 0) {
|
||||
CleanUpExecuteQuery("downtimehistory", "entry_time", now - GetCleanupDowntimeHistoryAge());
|
||||
Log(LogDebug, "db_ido", "CleanUpDowntimeHistoryAge: " + Convert::ToString(GetCleanupDowntimeHistoryAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupDowntimeHistoryAge()));
|
||||
}
|
||||
if (GetCleanupEventHandlersAge() > 0) {
|
||||
CleanUpExecuteQuery("eventhandlers", "start_time", now - GetCleanupEventHandlersAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupEventHandlersAge: " + Convert::ToString(GetCleanupEventHandlersAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupEventHandlersAge()));
|
||||
}
|
||||
if (GetCleanupExternalCommandsAge() > 0) {
|
||||
CleanUpExecuteQuery("externalcommands", "entry_time", now - GetCleanupExternalCommandsAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupExternalCommandsAge: " + Convert::ToString(GetCleanupExternalCommandsAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupExternalCommandsAge()));
|
||||
}
|
||||
if (GetCleanupFlappingHistoryAge() > 0) {
|
||||
CleanUpExecuteQuery("flappinghistory", "event_time", now - GetCleanupFlappingHistoryAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupFlappingHistoryAge: " + Convert::ToString(GetCleanupFlappingHistoryAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupFlappingHistoryAge()));
|
||||
}
|
||||
if (GetCleanupHostChecksAge() > 0) {
|
||||
CleanUpExecuteQuery("hostchecks", "start_time", now - GetCleanupHostChecksAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupHostChecksAge: " + Convert::ToString(GetCleanupHostChecksAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupHostChecksAge()));
|
||||
}
|
||||
if (GetCleanupLogEntriesAge() > 0) {
|
||||
CleanUpExecuteQuery("logentries", "logentry_time", now - GetCleanupLogEntriesAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupLogEntriesAge: " + Convert::ToString(GetCleanupLogEntriesAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupLogEntriesAge()));
|
||||
}
|
||||
if (GetCleanupNotificationsAge() > 0) {
|
||||
CleanUpExecuteQuery("notifications", "start_time", now - GetCleanupNotificationsAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupNotificationsAge: " + Convert::ToString(GetCleanupNotificationsAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupNotificationsAge()));
|
||||
}
|
||||
if (GetCleanupProcessEventsAge() > 0) {
|
||||
CleanUpExecuteQuery("processevents", "event_time", now - GetCleanupProcessEventsAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupProcessEventsAge: " + Convert::ToString(GetCleanupProcessEventsAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupProcessEventsAge()));
|
||||
}
|
||||
if (GetCleanupStateHistoryAge() > 0) {
|
||||
CleanUpExecuteQuery("statehistory", "state_time", now - GetCleanupStateHistoryAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupStateHistoryAge: " + Convert::ToString(GetCleanupStateHistoryAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupStateHistoryAge()));
|
||||
}
|
||||
if (GetCleanupServiceChecksAge() > 0) {
|
||||
CleanUpExecuteQuery("servicechecks", "start_time", now - GetCleanupServiceChecksAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupServiceChecksAge: " + Convert::ToString(GetCleanupServiceChecksAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupServiceChecksAge()));
|
||||
}
|
||||
if (GetCleanupSystemCommandsAge() > 0) {
|
||||
CleanUpExecuteQuery("systemcommands", "start_time", now - GetCleanupSystemCommandsAge());
|
||||
Log(LogDebug, "db_ido", "GetCleanupSystemCommandsAge: " + Convert::ToString(GetCleanupSystemCommandsAge()) +
|
||||
" now: " + Convert::ToString(now) +
|
||||
" old: " + Convert::ToString(now - GetCleanupSystemCommandsAge()));
|
||||
" old: " + Convert::ToString(now - max_age));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void DbConnection::CleanUpExecuteQuery(const String& table, const String& time_key, double time_value)
|
||||
void DbConnection::CleanUpExecuteQuery(const String& table, const String& time_column, double max_age)
|
||||
{
|
||||
/* Default handler does nothing. */
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupAcknowledgementsAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("acknowledgement_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupCommentHistoryAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("commenthistory_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupContactNotificationsAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("contactnotifications_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupContactNotificationMethodsAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("contactnotificationmethods_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupDowntimeHistoryAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("downtimehistory_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupEventHandlersAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("eventhandlers_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupExternalCommandsAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("externalcommands_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupFlappingHistoryAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("flappinghistory_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupHostChecksAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("hostchecks_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupLogEntriesAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("logentries_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupNotificationsAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("notifications_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupProcessEventsAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("processevents_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupStateHistoryAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("statehistory_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupServiceChecksAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("servicechecks_age");
|
||||
}
|
||||
|
||||
double DbConnection::GetCleanupSystemCommandsAge(void) const
|
||||
{
|
||||
return GetCleanup()->Get("systemcommands_age");
|
||||
}
|
||||
|
||||
void DbConnection::SetObjectID(const DbObject::Ptr& dbobj, const DbReference& dbref)
|
||||
{
|
||||
if (dbref.IsValid())
|
||||
|
|
|
@ -52,22 +52,6 @@ public:
|
|||
void SetStatusUpdate(const DbObject::Ptr& dbobj, bool hasupdate);
|
||||
bool GetStatusUpdate(const DbObject::Ptr& dbobj) const;
|
||||
|
||||
double GetCleanupAcknowledgementsAge(void) const;
|
||||
double GetCleanupCommentHistoryAge(void) const;
|
||||
double GetCleanupContactNotificationsAge(void) const;
|
||||
double GetCleanupContactNotificationMethodsAge(void) const;
|
||||
double GetCleanupDowntimeHistoryAge(void) const;
|
||||
double GetCleanupEventHandlersAge(void) const;
|
||||
double GetCleanupExternalCommandsAge(void) const;
|
||||
double GetCleanupFlappingHistoryAge(void) const;
|
||||
double GetCleanupHostChecksAge(void) const;
|
||||
double GetCleanupLogEntriesAge(void) const;
|
||||
double GetCleanupNotificationsAge(void) const;
|
||||
double GetCleanupProcessEventsAge(void) const;
|
||||
double GetCleanupStateHistoryAge(void) const;
|
||||
double GetCleanupServiceChecksAge(void) const;
|
||||
double GetCleanupSystemCommandsAge(void) const;
|
||||
|
||||
protected:
|
||||
virtual void Start(void);
|
||||
|
||||
|
@ -75,7 +59,7 @@ protected:
|
|||
virtual void ActivateObject(const DbObject::Ptr& dbobj) = 0;
|
||||
virtual void DeactivateObject(const DbObject::Ptr& dbobj) = 0;
|
||||
|
||||
virtual void CleanUpExecuteQuery(const String& table, const String& time_key, double time_value) = 0;
|
||||
virtual void CleanUpExecuteQuery(const String& table, const String& time_column, double max_age);
|
||||
|
||||
void UpdateAllObjects(void);
|
||||
|
||||
|
|
Loading…
Reference in New Issue