static void pm_norepeat_log_repeat(nx_module_t *module) { nx_logdata_t *logdata; char msgbuf[256]; int len; nx_pm_norepeat_conf_t *modconf; nx_value_t eventtime; modconf = (nx_pm_norepeat_conf_t *) module->config; if ( modconf->repeatcnt == 1 ) { module->queue->needpop = FALSE; nx_module_progress_logdata(module, modconf->logdata); module->queue->needpop = TRUE; modconf->logdata = NULL; } else if ( modconf->repeatcnt > 1 ) { len = apr_snprintf(msgbuf, sizeof(msgbuf), "last message repeated %d times", modconf->repeatcnt); logdata = nx_logdata_new_logline(msgbuf, len); nx_logdata_set_string(logdata, "Message", msgbuf); nx_logdata_set_integer(logdata, "SeverityValue", NX_LOGLEVEL_INFO); nx_logdata_set_string(logdata, "Severity", nx_loglevel_to_string(NX_LOGLEVEL_INFO)); if ( nx_logdata_get_field_value(modconf->logdata, "EventTime", &eventtime) == TRUE ) { ASSERT(eventtime.type == NX_VALUE_TYPE_DATETIME); nx_logdata_set_datetime(logdata, "EventTime", eventtime.datetime); } else { nx_logdata_set_datetime(logdata, "EventTime", apr_time_now()); } nx_logdata_set_string(logdata, "SourceName", PACKAGE); nx_logdata_set_integer(logdata, "ProcessID", modconf->pid); module->queue->needpop = FALSE; nx_module_progress_logdata(module, logdata); module->queue->needpop = TRUE; nx_logdata_free(modconf->logdata); modconf->logdata = NULL; } else // modconf->repeatcnt == 0 { nx_logdata_free(modconf->logdata); modconf->logdata = NULL; } modconf->repeatcnt = 0; }
static void om_kafka_write(nx_module_t *module) { nx_om_kafka_conf_t* modconf; modconf = (nx_om_kafka_conf_t*) module->config; nx_logdata_t *logdata; if (nx_module_get_status(module) != NX_MODULE_STATUS_RUNNING) { log_warn("Kafka module not running."); return; } if (module->output.buflen == 0) { if ((logdata = nx_module_logqueue_peek(module)) != NULL) { module->output.logdata = logdata; if (rd_kafka_produce(modconf->rkt, modconf->partition, RD_KAFKA_MSG_F_COPY, /* Payload and length */ logdata->raw_event->buf, (int) logdata->raw_event->len, /* Optional key and its length */ NULL, 0, /* Message opaque, provided in delivery report callback as msg_opaque. */ NULL) == -1) { log_error("Unable to produce message"); rd_kafka_poll(modconf->rk, 0); } else { //TODO: report on message log_debug("Message sent"); rd_kafka_poll(modconf->rk, 0); nx_module_logqueue_pop(module, module->output.logdata); nx_logdata_free(module->output.logdata); module->output.logdata = NULL; } } } }
static nx_logdata_t *nx_patterndb_pattern_exec(nx_module_t *module, nx_logdata_t *logdata, nx_pattern_t *pattern) { nx_expr_eval_ctx_t eval_ctx; nx_exception_t e; nx_expr_eval_ctx_init(&eval_ctx, logdata, module, NULL); try { nx_expr_statement_list_execute(&eval_ctx, pattern->exec); } catch(e) { log_exception(e); } if ( eval_ctx.logdata == NULL ) { // dropped nx_module_logqueue_pop(module, logdata); nx_logdata_free(logdata); } logdata = eval_ctx.logdata; nx_expr_eval_ctx_destroy(&eval_ctx); return ( logdata ); }
static nx_logdata_t *pm_norepeat_process(nx_module_t *module, nx_logdata_t *logdata) { nx_pm_norepeat_conf_t *modconf; ASSERT ( logdata != NULL ); modconf = (nx_pm_norepeat_conf_t *) module->config; log_debug("nx_pm_norepeat_process()"); //log_debug("processing: [%s]", logdata->data); if ( modconf->logdata == NULL ) { modconf->logdata = nx_logdata_clone(logdata); } else { if ( nx_logdata_eq(modconf, modconf->logdata, logdata) == TRUE ) { (modconf->repeatcnt)++; pm_norepeat_add_event(module); nx_module_logqueue_pop(module, logdata); nx_logdata_free(logdata); return ( NULL ); } else { pm_norepeat_log_repeat(module); ASSERT(modconf->logdata == NULL); modconf->logdata = nx_logdata_clone(logdata); modconf->repeatcnt = 0; } } return ( logdata ); }
static nx_logdata_t *xm_multiline_input_func(nx_module_input_t *input, void *data) { volatile int i; nx_logdata_t * volatile retval = NULL; boolean foundcr = FALSE; nx_xm_multiline_ctx_t *ctx; nx_xm_multiline_conf_t *modconf; nx_module_t *module; boolean appendline; boolean gotline; volatile boolean done = FALSE; ASSERT(input != NULL); ASSERT(input->buflen >= 0); ASSERT(data != NULL); if ( input->buflen == 0 ) { return ( NULL ); } if ( input->ctx == NULL ) { input->ctx = apr_pcalloc(input->pool, sizeof(nx_xm_multiline_ctx_t)); } ctx = input->ctx; module = (nx_module_t *) data; modconf = (nx_xm_multiline_conf_t *) module->config; do { foundcr = FALSE; appendline = TRUE; gotline = FALSE; for ( i = 0; (i < input->buflen) && (gotline == FALSE) ; i++ ) { switch ( input->buf[input->bufstart + i] ) { case APR_ASCII_CR: if ( foundcr == TRUE ) { gotline = TRUE; i--; } else { foundcr = TRUE; } break; case APR_ASCII_LF: if ( foundcr == TRUE ) { gotline = TRUE; i--; } else { foundcr = TRUE; } break; default: if ( foundcr == TRUE ) { gotline = TRUE; i--; } break; } } if ( ctx->tmpline == NULL ) { ctx->tmpline = nx_logdata_new_logline(input->buf + input->bufstart, i); } else { nx_logdata_append_logline(ctx->tmpline, input->buf + input->bufstart, i); } //log_info("tmpline: [%s]", ctx->tmpline->raw_event->buf); if ( foundcr == TRUE ) { // got a complete line if ( module->exec != NULL ) { nx_expr_eval_ctx_t eval_ctx; nx_exception_t e; nx_expr_eval_ctx_init(&eval_ctx, ctx->tmpline, module, input); try { nx_expr_statement_list_execute(&eval_ctx, module->exec); } catch(e) { log_exception(e); } if ( eval_ctx.logdata == NULL ) { // dropped //log_info("dropped"); appendline = FALSE; ctx->tmpline = NULL; } else { // TODO: merge fields } nx_expr_eval_ctx_destroy(&eval_ctx); } if ( appendline == TRUE ) { // not dropped size_t len; boolean gotheaderline = FALSE; boolean gotendline = FALSE; //log_info("appendline"); // ignore trailing new line for ( len = ctx->tmpline->raw_event->len; (len > 0) && ((ctx->tmpline->raw_event->buf[len - 1] == APR_ASCII_CR) || (ctx->tmpline->raw_event->buf[len - 1] == APR_ASCII_LF)); len--); // Check headerline if ( modconf->headerline != NULL ) { gotheaderline = match_line(modconf->headerline, ctx->tmpline->raw_event->buf, len); } // Check endline if ( modconf->endline != NULL ) { gotendline = match_line(modconf->endline, ctx->tmpline->raw_event->buf, len); } // log_debug("gotheader: %d gotend: %d for [%s]", gotheaderline, gotendline, // ctx->tmpline->raw_event->buf); if ( (gotendline == TRUE) && (gotheaderline == TRUE) ) { log_error("HeaderLine and Endline both match"); } //log_info("gotheaderline: %d string: [%s]", gotheaderline, ctx->tmpline->raw_event->buf); if ( ctx->logdata == NULL ) { if ( (modconf->fixedlinecount <= 0) && (gotheaderline == FALSE) ) { // return if no header is found and there is no fixed linecount //log_info("return logdata: no header, no fixed linecount"); retval = ctx->tmpline; ctx->tmpline = NULL; ctx->linecount = 0; done = TRUE; } else { ctx->logdata = ctx->tmpline; ctx->tmpline = NULL; (ctx->linecount)++; } } else { // there is saved data if ( gotendline == TRUE ) { nx_string_append(ctx->logdata->raw_event, ctx->tmpline->raw_event->buf, (int) ctx->tmpline->raw_event->len); nx_logdata_free(ctx->tmpline); ctx->tmpline = NULL; retval = ctx->logdata; ctx->logdata = NULL; done = TRUE; } else if ( gotheaderline == TRUE ) { //log_info("return logdata %lu: header ok", ctx->logdata); retval = ctx->logdata; ctx->logdata = ctx->tmpline; ctx->tmpline = NULL; (ctx->linecount)++; done = TRUE; } else { nx_string_append(ctx->logdata->raw_event, ctx->tmpline->raw_event->buf, (int) ctx->tmpline->raw_event->len); nx_logdata_free(ctx->tmpline); ctx->tmpline = NULL; (ctx->linecount)++; } } // Check FixedLineCount if ( modconf->fixedlinecount > 0 ) { if ( ctx->linecount >= modconf->fixedlinecount ) { //log_info("return logdata: fixed linecount"); retval = ctx->logdata; ctx->logdata = NULL; ctx->linecount = 0; done = TRUE; } } } } input->buflen -= i; input->bufstart += i; //log_info("buflen: %d, foundcr: %d, i: %d, linecount: %d", input->buflen, foundcr, i, ctx->linecount); if ( input->buflen <= 0 ) { done = TRUE; } } while ( done != TRUE ); if ( retval != NULL ) { nx_string_strip_crlf(retval->raw_event); } return ( retval ); }