Commit 7b52b027 authored by Libor Peltan's avatar Libor Peltan

Merge branch 'structured_log' into 'master'

Structured logging for the KSK submission event

Closes #551

See merge request !876
parents ea9895e9 5fb0811d
......@@ -411,6 +411,19 @@ operator must confirm it manually with ``knotc zone-ksk-submitted``::
2017-10-24T15:41:33 info: [example.com.] DNSSEC, successfully signed
2017-10-24T15:41:33 info: [example.com.] DNSSEC, next signing at 2017-10-24T15:41:47
.. TIP::
If systemd is available, the KSK submission event is logged into journald
in a structured way. The intended use case is to trigger a user-created script.
Example::
journalctl -f -t knotd -o json | python3 -c '
import json, sys
for line in sys.stdin:
k = json.loads(line);
if "KEY_SUBMISSION" in k:
print("%s, zone=%s, keytag=%s" % (k["__REALTIME_TIMESTAMP"], k["ZONE"], k["KEY_SUBMISSION"]))
'
Algorithm rollover example
--------------------------
......
......@@ -208,7 +208,7 @@ void log_levels_add(log_target_t target, log_source_t src, int levels)
}
static void emit_log_msg(int level, log_source_t src, const char *zone,
size_t zone_len, const char *msg)
size_t zone_len, const char *msg, const char *param)
{
log_t *log = s_log;
......@@ -220,7 +220,7 @@ static void emit_log_msg(int level, log_source_t src, const char *zone,
sd_journal_send("PRIORITY=%d", level,
"MESSAGE=%s", msg,
zone_fmt, zone_len, zone,
NULL);
param, NULL);
} else
#endif
{
......@@ -290,7 +290,7 @@ static int log_msg_add(char **write, size_t *capacity, const char *fmt, ...)
}
static void log_msg_text(int level, log_source_t src, const char *zone,
const char *fmt, va_list args)
const char *fmt, va_list args, const char *param)
{
if (!log_isopen() || src == LOG_SOURCE_ANY) {
return;
......@@ -332,7 +332,7 @@ static void log_msg_text(int level, log_source_t src, const char *zone,
int ret = vsnprintf(write, capacity, fmt, args);
if (ret >= 0) {
// Send to logging targets.
emit_log_msg(level, src, zone, zone_len, buff);
emit_log_msg(level, src, zone, zone_len, buff, param);
}
rcu_read_unlock();
......@@ -342,12 +342,12 @@ void log_fmt(int priority, log_source_t src, const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
log_msg_text(priority, src, NULL, fmt, args);
log_msg_text(priority, src, NULL, fmt, args, NULL);
va_end(args);
}
void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone,
const char *fmt, ...)
const char *param, const char *fmt, ...)
{
char buff[KNOT_DNAME_TXT_MAXLEN + 1];
char *zone_str = knot_dname_to_str(buff, zone, sizeof(buff));
......@@ -357,7 +357,7 @@ void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone,
va_list args;
va_start(args, fmt);
log_msg_text(priority, src, zone_str, fmt, args);
log_msg_text(priority, src, zone_str, fmt, args, param);
va_end(args);
}
......@@ -370,7 +370,7 @@ void log_fmt_zone_str(int priority, log_source_t src, const char *zone,
va_list args;
va_start(args, fmt);
log_msg_text(priority, src, zone, fmt, args);
log_msg_text(priority, src, zone, fmt, args, NULL);
va_end(args);
}
......
......@@ -117,8 +117,9 @@ __attribute__((format(printf, 3, 4)));
* \param src Message source (LOG_SOURCE_SERVER...LOG_SOURCE_ZONE).
* \param fmt Content of the logged message.
*/
void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone, const char *fmt, ...)
__attribute__((format(printf, 4, 5)));
void log_fmt_zone(int priority, log_source_t src, const knot_dname_t *zone,
const char *param, const char *fmt, ...)
__attribute__((format(printf, 5, 6)));
/*!
* \brief Log message into zone category.
......@@ -154,12 +155,12 @@ __attribute__((format(printf, 4, 5)));
#define log_ctl_zone_str_info(zone, msg, ...) log_fmt_zone_str(LOG_INFO, LOG_SOURCE_CONTROL, zone, msg, ##__VA_ARGS__)
#define log_ctl_zone_str_debug(zone, msg, ...) log_fmt_zone_str(LOG_DEBUG, LOG_SOURCE_CONTROL, zone, msg, ##__VA_ARGS__)
#define log_zone_fatal(zone, msg, ...) log_fmt_zone(LOG_CRIT, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_error(zone, msg, ...) log_fmt_zone(LOG_ERR, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_warning(zone, msg, ...) log_fmt_zone(LOG_WARNING, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_notice(zone, msg, ...) log_fmt_zone(LOG_NOTICE, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_info(zone, msg, ...) log_fmt_zone(LOG_INFO, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_debug(zone, msg, ...) log_fmt_zone(LOG_DEBUG, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_fatal(zone, msg, ...) log_fmt_zone(LOG_CRIT, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_error(zone, msg, ...) log_fmt_zone(LOG_ERR, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_warning(zone, msg, ...) log_fmt_zone(LOG_WARNING, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_notice(zone, msg, ...) log_fmt_zone(LOG_NOTICE, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_info(zone, msg, ...) log_fmt_zone(LOG_INFO, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_debug(zone, msg, ...) log_fmt_zone(LOG_DEBUG, LOG_SOURCE_ZONE, zone, NULL, msg, ##__VA_ARGS__)
#define log_zone_str_fatal(zone, msg, ...) log_fmt_zone_str(LOG_CRIT, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
#define log_zone_str_error(zone, msg, ...) log_fmt_zone_str(LOG_ERR, LOG_SOURCE_ZONE, zone, msg, ##__VA_ARGS__)
......
......@@ -49,7 +49,7 @@
} while (0)
#define CONF_LOG_ZONE(severity, zone, msg, ...) do { \
log_fmt_zone(severity, LOG_SOURCE_ZONE, zone, "config, " msg, ##__VA_ARGS__); \
log_fmt_zone(severity, LOG_SOURCE_ZONE, zone, NULL, "config, " msg, ##__VA_ARGS__); \
} while (0)
/*! Configuration getter output. */
......
......@@ -43,7 +43,6 @@ void event_dnssec_reschedule(conf_t *conf, zone_t *zone,
log_dnssec_next(zone->name, (time_t)refresh_at);
if (refresh->plan_ds_query) {
log_zone_notice(zone->name, "DNSSEC, KSK submission, waiting for confirmation");
zone->timers.next_parent_ds_q = now;
}
......
......@@ -14,6 +14,7 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "knot/common/log.h"
#include "knot/dnssec/ds_query.h"
#include "knot/zone/zone.h"
......@@ -33,6 +34,18 @@ int event_parent_ds_q(conf_t *conf, zone_t *zone)
return ret;
}
for (size_t i = 0; i < keyset.count; i++) {
zone_key_t *key = &keyset.keys[i];
if (key->is_ksk && key->cds_priority > 1) {
char param[32];
(void)snprintf(param, sizeof(param), "KEY_SUBMISSION=%hu",
dnssec_key_get_keytag(key->key));
log_fmt_zone(LOG_NOTICE, LOG_SOURCE_ZONE, zone->name, param,
"DNSSEC, KSK submission, waiting for confirmation");
}
}
ret = knot_parent_ds_query(&ctx, &keyset, conf->cache.srv_tcp_reply_timeout * 1000);
zone->timers.next_parent_ds_q = 0;
......
......@@ -84,7 +84,7 @@ static inline const char *log_direction_name(enum log_direction direction)
do { \
char address[SOCKADDR_STRLEN] = ""; \
sockaddr_tostr(address, sizeof(address), remote); \
log_fmt_zone(priority, LOG_SOURCE_ZONE, zone, "%s, %s, %s: " fmt, \
log_fmt_zone(priority, LOG_SOURCE_ZONE, zone, NULL, "%s, %s, %s: " fmt, \
log_operation_name(op), log_direction_name(dir), address, \
## __VA_ARGS__); \
} while (0)
......@@ -212,7 +212,7 @@ void knotd_mod_vlog(knotd_mod_t *mod, int priority, const char *fmt, va_list arg
if (mod->zone == NULL) {
log_fmt(priority, LOG_SOURCE_SERVER, LOG_ARGS(mod->id, msg));
} else {
log_fmt_zone(priority, LOG_SOURCE_ZONE, mod->zone,
log_fmt_zone(priority, LOG_SOURCE_ZONE, mod->zone, NULL,
LOG_ARGS(mod->id, msg));
}
......
......@@ -329,7 +329,7 @@ void err_handler_logger(sem_handler_t *handler, const zone_contents_t *zone,
}
log_fmt_zone(handler->fatal_error ? LOG_ERR : LOG_WARNING,
LOG_SOURCE_ZONE, zone->apex->owner,
LOG_SOURCE_ZONE, zone->apex->owner, NULL,
"check%s%s, %s%s%s",
(node != NULL ? ", node " : ""),
(node != NULL ? buff : ""),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment