From 50ed32b57fb7ea17838ca3ece87490d35bf77593 Mon Sep 17 00:00:00 2001 From: Sven Panne Date: Thu, 21 Nov 2024 08:42:41 +0100 Subject: [PATCH] Simplify fill_new_state()'s signature. Fixed a comment. Change-Id: I506f7d2c84adeb2dcc431e2eab3ee06dcefcb719 --- .../include/livestatus/TableStateHistory.h | 3 +-- packages/livestatus/src/TableStateHistory.cc | 20 +++++++++---------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/packages/livestatus/include/livestatus/TableStateHistory.h b/packages/livestatus/include/livestatus/TableStateHistory.h index 36684b741c6..63aada3a6fc 100644 --- a/packages/livestatus/include/livestatus/TableStateHistory.h +++ b/packages/livestatus/include/livestatus/TableStateHistory.h @@ -126,8 +126,7 @@ class TableStateHistory : public Table { static void fill_new_state(HostServiceState *hss, const LogEntry *entry, bool only_update, const TimePeriods &time_periods, - state_info_t &state_info, - const LogPeriod &period); + state_info_t &state_info); void handle_timeperiod_transition(Processor &processor, Logger *logger, const LogEntry *entry, bool only_update, diff --git a/packages/livestatus/src/TableStateHistory.cc b/packages/livestatus/src/TableStateHistory.cc index 428069e9991..59bcca22129 100644 --- a/packages/livestatus/src/TableStateHistory.cc +++ b/packages/livestatus/src/TableStateHistory.cc @@ -484,6 +484,7 @@ HostServiceState *TableStateHistory::get_state_for_entry( hss->_service = entry_service; hss->_host_name = entry->host_name(); hss->_service_description = entry->service_description(); + hss->_from = period.since; // No state found. Now check if this host/services is filtered out. // Note: we currently do not filter out hosts since they might be needed @@ -497,8 +498,7 @@ HostServiceState *TableStateHistory::get_state_for_entry( } } - fill_new_state(hss.get(), entry, only_update, time_periods, state_info, - period); + fill_new_state(hss.get(), entry, only_update, time_periods, state_info); state_info[key] = std::move(hss); } return state_info[key].get(); @@ -508,8 +508,7 @@ HostServiceState *TableStateHistory::get_state_for_entry( void TableStateHistory::fill_new_state(HostServiceState *hss, const LogEntry *entry, bool only_update, const TimePeriods &time_periods, - state_info_t &state_info, - const LogPeriod &period) { + state_info_t &state_info) { // Host/Service relations if (hss->_is_host) { for (const auto &[_, s] : state_info) { @@ -526,8 +525,6 @@ void TableStateHistory::fill_new_state(HostServiceState *hss, } } - hss->_from = period.since; - // Get notification period of host/service. If this host/service is no // longer available in nagios -> set to "" hss->_notification_period = @@ -553,10 +550,11 @@ void TableStateHistory::fill_new_state(HostServiceState *hss, } } - // Log UNMONITORED state if this host or service just appeared within - // the query timeframe. It gets a grace period of ten minutes (nagios - // startup) - if (!only_update && entry->time() - period.since > 10min) { + // Log UNMONITORED state if this host or service just appeared within the + // query timeframe. It gets a grace period of ten minutes (Nagios startup). + // Note that _from is at the beginning of the requested log period for fresh + // states. + if (!only_update && entry->time() - hss->_from > 10min) { hss->_debug_info = "UNMONITORED "; hss->_state = -1; } @@ -826,7 +824,7 @@ ObjectBlacklist::ObjectBlacklist(const Query &query, const User &user) , filter_{query.partialFilter( "current host/service columns", [](const std::string &columnName) { // NOTE: This is quite brittle and must be kept in sync with its - // usage in TableStateHistory::insert_new_state()! + // usage in TableStateHistory::get_state_for_entry()! return ( // joined via HostServiceState::_host columnName.starts_with("current_host_") ||