diff options
author | Reyk Floeter <reyk@cvs.openbsd.org> | 2007-02-07 15:17:47 +0000 |
---|---|---|
committer | Reyk Floeter <reyk@cvs.openbsd.org> | 2007-02-07 15:17:47 +0000 |
commit | 3740f5b5e7e90adcd0be6513ddd3f8684cacde34 (patch) | |
tree | 7272f01760dc854689b773c8a27f5a0186cb8448 /usr.sbin/relayd/hce.c | |
parent | fe851fcc379376cc9a46baa630ec734083adbc3f (diff) |
add new "log (updates|all)" configuration option to log state
notifications after completed host checks. either only log the
"updates" to new states or log "all" state notifications, even if the
state didn't change. the log messages will be reported to syslog or to
stderr if the daemon is running in foreground mode.
ok claudio@ pyr@
Diffstat (limited to 'usr.sbin/relayd/hce.c')
-rw-r--r-- | usr.sbin/relayd/hce.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/usr.sbin/relayd/hce.c b/usr.sbin/relayd/hce.c index 831be46bffb..4ee1a0135b4 100644 --- a/usr.sbin/relayd/hce.c +++ b/usr.sbin/relayd/hce.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hce.c,v 1.14 2007/02/07 14:39:45 reyk Exp $ */ +/* $OpenBSD: hce.c,v 1.15 2007/02/07 15:17:46 reyk Exp $ */ /* * Copyright (c) 2006 Pierre-Yves Ritschard <pyr@spootnik.org> @@ -207,17 +207,43 @@ hce_launch_checks(int fd, short event, void *arg) void hce_notify_done(struct host *host, const char *msg) { + struct table *table; struct ctl_status st; + struct timeval tv_now, tv_dur; + u_long duration; + u_int logopt; st.id = host->id; st.up = host->up; host->flags |= (F_CHECK_SENT|F_CHECK_DONE); if (msg) log_debug("hce_notify_done: %s (%s)", host->name, msg); + if (host->up != host->last_up) { + logopt = HOSTSTATED_OPT_LOGUPDATE; imsg_compose(ibuf_pfe, IMSG_HOST_STATUS, 0, 0, &st, sizeof(st)); - host->last_up = host->up; + } else + logopt = HOSTSTATED_OPT_LOGNOTIFY; + + if ((table = table_find(env, host->tableid)) == NULL) + fatalx("hce_notify_done: invalid table id"); + + if (gettimeofday(&tv_now, NULL)) + fatal("hce_notify_done: gettimeofday"); + timersub(&tv_now, &host->cte.tv_start, &tv_dur); + if (timercmp(&host->cte.tv_start, &tv_dur, >)) + duration = (tv_dur.tv_sec * 1000) + (tv_dur.tv_usec / 1000.0); + else + duration = 0; + + if (env->opts & logopt) { + log_info("host %s, check %s%s (%lums), state %s -> %s", + host->name, table_check(table->check), + (table->flags & F_SSL) ? " use ssl" : "", duration, + host_status(host->last_up), host_status(host->up)); } + + host->last_up = host->up; } void |