Skip to content

Commit

Permalink
update last_update for some more cornercases
Browse files Browse the repository at this point in the history
there were some corner cases where the last_update timestamp has not been updated. Update
the timestamp whenever the last_check changes.
  • Loading branch information
sni committed Mar 18, 2024
1 parent 3e07412 commit 7031173
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/naemon/checks_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,7 @@ int update_host_state_post_check(struct host *hst, struct check_result *cr)
{
int result;
char *temp_ptr = NULL;
time_t now = time(NULL);

if (!hst || !cr)
return ERROR;
Expand Down Expand Up @@ -413,6 +414,7 @@ int update_host_state_post_check(struct host *hst, struct check_result *cr)

/* get the last check time */
hst->last_check = cr->start_time.tv_sec;
hst->last_update = now;

/* save the old host state */
hst->last_state = hst->current_state;
Expand Down Expand Up @@ -629,6 +631,7 @@ static void handle_worker_host_check(wproc_result *wpres, void *arg, int flags)
{
check_result *cr = (check_result *)arg;
struct host *hst;
time_t now = time(NULL);

/* decrement the number of host checks still out there... */
if (currently_running_host_checks > 0)
Expand All @@ -638,6 +641,7 @@ static void handle_worker_host_check(wproc_result *wpres, void *arg, int flags)
hst = find_host(cr->host_name);
if (hst) {
hst->is_executing = FALSE;
hst->last_update = now;
memcpy(&cr->rusage, &wpres->rusage, sizeof(wpres->rusage));
cr->start_time.tv_sec = wpres->start.tv_sec;
cr->start_time.tv_usec = wpres->start.tv_usec;
Expand Down Expand Up @@ -1180,6 +1184,8 @@ static void check_for_orphaned_hosts_eventhandler(struct nm_event_execution_prop
/* disable the executing flag */
temp_host->is_executing = FALSE;

temp_host->last_update = current_time;

/* schedule an immediate check of the host */
schedule_next_host_check(temp_host, 0, CHECK_OPTION_ORPHAN_CHECK);
}
Expand Down
4 changes: 3 additions & 1 deletion src/naemon/checks_service.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,8 @@ int handle_async_service_check_result(service *temp_service, check_result *queue
}
}

temp_service->last_update = current_time;

/* clear the freshening flag (it would have been set if this service was determined to be stale) */
if (queued_check_result->check_options & CHECK_OPTION_FRESHNESS_CHECK)
temp_service->is_being_freshened = FALSE;
Expand Down Expand Up @@ -1083,7 +1085,6 @@ int handle_async_service_check_result(service *temp_service, check_result *queue
nm_free(old_plugin_output);
nm_free(old_long_plugin_output);

temp_service->last_update = current_time;
return OK;
}

Expand Down Expand Up @@ -1135,6 +1136,7 @@ static void check_for_orphaned_services_eventhandler(struct nm_event_execution_p

/* disable the executing flag */
temp_service->is_executing = FALSE;
temp_service->last_update = current_time;

/* schedule an immediate check of the service */
schedule_next_service_check(temp_service, 0, CHECK_OPTION_ORPHAN_CHECK);
Expand Down

0 comments on commit 7031173

Please sign in to comment.