if ( perform_update(ip) == 0 )
{
// if update was successful, we need to set the Lastupdated and ActualIP base member.
- LastUpdates.push_front(current_time);
+ set_last_update(current_time);
ActualIP = ip;
Log->print_update_service_successful(get_service_name());
}
/**
+* Sets the given time into the LastUpdates member and deletes expired entries.
+* @param _timeout Value to set into LastUpdates.
+*/
+void Service::set_last_update(const time_t current_time)
+{
+ // Insert value into the list.
+ LastUpdates.push_front(current_time);
+
+ // Check for expired entries:
+
+ // MaxUpdatesWithinInterval given in service config, then use this to check for expired entries.
+ if ( MaxUpdatesWithinInterval > 0 )
+ {
+ // Delete the oldest entry if there are more than MaxUpdatesWithinInterval+1 entries in the list.
+ if (LastUpdates.size() > (MaxUpdatesWithinInterval+1))
+ LastUpdates.pop_back();
+ return;
+ }
+ // UpdateInterval given in service config, then use this to check for expired entries.
+ else if ( UpdateInterval > 0 )
+ {
+ // Delete the oldest entry if it's older than current_time - UpdateInterval(minutes) + 1.
+ if ( (current_time - ((time_t)UpdateInterval*60) + 1) > LastUpdates.back() )
+ LastUpdates.pop_back();
+ return;
+ }
+ // Neither MaxUpdatesWithinInterval nor UpdateInterval are given, so keep fix number of 10 entries.
+ else
+ {
+ if ( LastUpdates.size() > 10 )
+ LastUpdates.pop_back();
+ return;
+ }
+}
+
+
+/**
* Setter for member Timeout.
* @param _timeout Value to set Timeout to.
*/