| 228 | } |
| 229 | |
| 230 | void DbConnection::CleanUpHandler() |
| 231 | { |
| 232 | auto now = static_cast<long>(Utility::GetTime()); |
| 233 | |
| 234 | struct { |
| 235 | String name; |
| 236 | String time_column; |
| 237 | } tables[] = { |
| 238 | { "acknowledgements", "entry_time" }, |
| 239 | { "commenthistory", "entry_time" }, |
| 240 | { "contactnotifications", "start_time" }, |
| 241 | { "contactnotificationmethods", "start_time" }, |
| 242 | { "downtimehistory", "entry_time" }, |
| 243 | { "eventhandlers", "start_time" }, |
| 244 | { "externalcommands", "entry_time" }, |
| 245 | { "flappinghistory", "event_time" }, |
| 246 | { "hostchecks", "start_time" }, |
| 247 | { "logentries", "logentry_time" }, |
| 248 | { "notifications", "start_time" }, |
| 249 | { "processevents", "event_time" }, |
| 250 | { "statehistory", "state_time" }, |
| 251 | { "servicechecks", "start_time" }, |
| 252 | { "systemcommands", "start_time" } |
| 253 | }; |
| 254 | |
| 255 | for (auto& table : tables) { |
| 256 | double max_age = GetCleanup()->Get(table.name + "_age"); |
| 257 | |
| 258 | if (max_age == 0) |
| 259 | continue; |
| 260 | |
| 261 | CleanUpExecuteQuery(table.name, table.time_column, now - max_age); |
| 262 | Log(LogNotice, "DbConnection") |
| 263 | << "Cleanup (" << table.name << "): " << max_age |
| 264 | << " now: " << now |
| 265 | << " old: " << now - max_age; |
| 266 | } |
| 267 | |
| 268 | } |
| 269 | |
| 270 | void DbConnection::LogStatsHandler() |
| 271 | { |