/* * NOTE: suppress_lock must be held. */ static void log_writer_last_msg_flush(LogWriter *self) { LogMessage *m; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; gchar buf[1024]; gssize len; const gchar *p; msg_debug("Suppress timer elapsed, emitting suppression summary", NULL); m = log_msg_new_empty(); m->timestamps[LM_TS_STAMP] = m->timestamps[LM_TS_RECVD]; m->pri = self->last_msg->pri; m->flags = LF_INTERNAL | LF_LOCAL; p = log_msg_get_value(self->last_msg, LM_V_HOST, &len); log_msg_set_value(m, LM_V_HOST, p, len); p = log_msg_get_value(self->last_msg, LM_V_PROGRAM, &len); log_msg_set_value(m, LM_V_PROGRAM, p, len); len = g_snprintf(buf, sizeof(buf), "Last message '%.20s' repeated %d times, suppressed by syslog-ng on %s", log_msg_get_value(self->last_msg, LM_V_MESSAGE, NULL), self->last_msg_count, get_local_hostname(NULL)); log_msg_set_value(m, LM_V_MESSAGE, buf, len); path_options.ack_needed = FALSE; log_queue_push_tail(self->queue, m, &path_options); log_writer_last_msg_release(self); }
static void log_writer_last_msg_flush(LogWriter *self) { LogMessage *m; LogPathOptions path_options = LOG_PATH_OPTIONS_INIT; gchar hostname[256]; gchar buf[1024]; gssize len; const gchar *p; msg_debug("Suppress timer elapsed, emitting suppression summary", NULL); getlonghostname(hostname, sizeof(hostname)); m = log_msg_new_empty(); m->timestamps[LM_TS_STAMP] = m->timestamps[LM_TS_RECVD]; m->pri = self->last_msg->pri; m->flags = LF_INTERNAL | LF_LOCAL; p = log_msg_get_value(self->last_msg, LM_V_HOST, &len); log_msg_set_value(m, LM_V_HOST, p, len); p = log_msg_get_value(self->last_msg, LM_V_PROGRAM, &len); log_msg_set_value(m, LM_V_PROGRAM, p, len); len = g_snprintf(buf, sizeof(buf), "Last message '%.20s' repeated %d times, supressed by syslog-ng on %s", log_msg_get_value(self->last_msg, LM_V_MESSAGE, NULL), self->last_msg_count, hostname); log_msg_set_value(m, LM_V_MESSAGE, buf, len); path_options.flow_control = FALSE; if (!log_queue_push_tail(self->queue, m, &path_options)) { stats_counter_inc(self->dropped_messages); msg_debug("Destination queue full, dropping suppressed message", evt_tag_int("queue_len", log_queue_get_length(self->queue)), evt_tag_int("mem_fifo_size", self->options->mem_fifo_size), NULL); log_msg_drop(m, &path_options); } log_writer_last_msg_release(self); }
/** * log_writer_last_msg_check: * * This function is called to suppress duplicate messages from a given host. * * Returns TRUE to indicate that the message was consumed. **/ static gboolean log_writer_last_msg_check(LogWriter *self, LogMessage *lm, const LogPathOptions *path_options) { g_static_mutex_lock(&self->suppress_lock); if (self->last_msg) { if (self->last_msg->timestamps[LM_TS_RECVD].tv_sec >= lm->timestamps[LM_TS_RECVD].tv_sec - self->options->suppress && strcmp(log_msg_get_value(self->last_msg, LM_V_MESSAGE, NULL), log_msg_get_value(lm, LM_V_MESSAGE, NULL)) == 0 && strcmp(log_msg_get_value(self->last_msg, LM_V_HOST, NULL), log_msg_get_value(lm, LM_V_HOST, NULL)) == 0 && strcmp(log_msg_get_value(self->last_msg, LM_V_PROGRAM, NULL), log_msg_get_value(lm, LM_V_PROGRAM, NULL)) == 0 && strcmp(log_msg_get_value(self->last_msg, LM_V_PID, NULL), log_msg_get_value(lm, LM_V_PID, NULL)) == 0 && strcmp(log_msg_get_value(lm, LM_V_MESSAGE, NULL), "-- MARK --") != 0) { stats_counter_inc(self->suppressed_messages); self->last_msg_count++; if (self->last_msg_count == 1) { /* we only create the timer if this is the first suppressed message, otherwise it is already running. */ log_writer_update_suppress_timer(self, self->options->suppress); } g_static_mutex_unlock(&self->suppress_lock); msg_debug("Suppressing duplicate message", evt_tag_str("host", log_msg_get_value(lm, LM_V_HOST, NULL)), evt_tag_str("msg", log_msg_get_value(lm, LM_V_MESSAGE, NULL)), NULL); log_msg_drop(lm, path_options); return TRUE; } if (self->last_msg_count) log_writer_last_msg_flush(self); else log_writer_last_msg_release(self); } log_writer_last_msg_record(self, lm); g_static_mutex_unlock(&self->suppress_lock); return FALSE; }
/** * log_writer_last_msg_check: * * This function is called to suppress duplicate messages from a given host. * * Returns TRUE to indicate that the message was consumed. **/ static gboolean log_writer_last_msg_check(LogWriter *self, LogMessage *lm, const LogPathOptions *path_options) { if (self->last_msg) { if (self->last_msg->timestamps[LM_TS_RECVD].time.tv_sec >= lm->timestamps[LM_TS_RECVD].time.tv_sec - self->options->suppress && strcmp(log_msg_get_value(self->last_msg, LM_V_MESSAGE, NULL), log_msg_get_value(lm, LM_V_MESSAGE, NULL)) == 0 && strcmp(log_msg_get_value(self->last_msg, LM_V_HOST, NULL), log_msg_get_value(lm, LM_V_HOST, NULL)) == 0 && strcmp(log_msg_get_value(self->last_msg, LM_V_PROGRAM, NULL), log_msg_get_value(lm, LM_V_PROGRAM, NULL)) == 0 && strcmp(log_msg_get_value(self->last_msg, LM_V_PID, NULL), log_msg_get_value(lm, LM_V_PID, NULL)) == 0 && strcmp(log_msg_get_value(lm, LM_V_MESSAGE, NULL), "-- MARK --") != 0) { stats_counter_inc(self->suppressed_messages); msg_debug("Suppressing duplicate message", evt_tag_str("host", log_msg_get_value(lm, LM_V_HOST, NULL)), evt_tag_str("msg", log_msg_get_value(lm, LM_V_MESSAGE, NULL)), NULL); self->last_msg_count++; if (self->last_msg_count == 1) { /* we only create the timer if there's at least one suppressed message */ self->last_msg_timerid = g_timeout_add(self->options->suppress * 1000, last_msg_timer, self); } log_msg_drop(lm, path_options); return TRUE; } if (self->last_msg_count) log_writer_last_msg_flush(self); else log_writer_last_msg_release(self); } log_writer_last_msg_record(self, lm); return FALSE; }