diff options
author | Edward Rudd <urkle@outoforder.cc> | 2008-10-27 02:10:15 (GMT) |
---|---|---|
committer | Edward Rudd <urkle@outoforder.cc> | 2008-10-27 02:10:15 (GMT) |
commit | f9f8794a67561c243823cac0a45d8906e90ee7bb (patch) | |
tree | f609050b6071cea68a928898ea9b1aa53e89fb4f /utility/logparse.c | |
parent | fc70e99444b2852f45303d9bf55332f247ec6b4f (diff) |
Added summary page including line count, duration, and final status of file
Diffstat (limited to 'utility/logparse.c')
-rw-r--r-- | utility/logparse.c | 90 |
1 files changed, 62 insertions, 28 deletions
diff --git a/utility/logparse.c b/utility/logparse.c index 923b581..afb1824 100644 --- a/utility/logparse.c +++ b/utility/logparse.c | |||
@@ -188,7 +188,7 @@ void parser_find_logs(config_t *cfg) | |||
188 | apr_pool_t *tp; | 188 | apr_pool_t *tp; |
189 | apr_dir_t *dir; | 189 | apr_dir_t *dir; |
190 | apr_finfo_t finfo; | 190 | apr_finfo_t finfo; |
191 | char **newp; | 191 | config_filestat_t *newp; |
192 | 192 | ||
193 | logging_log(cfg, LOGLEVEL_NOTICE, "Find Log files"); | 193 | logging_log(cfg, LOGLEVEL_NOTICE, "Find Log files"); |
194 | if (!cfg->input_dir) | 194 | if (!cfg->input_dir) |
@@ -199,9 +199,10 @@ void parser_find_logs(config_t *cfg) | |||
199 | == APR_SUCCESS) { | 199 | == APR_SUCCESS) { |
200 | if (finfo.filetype == APR_DIR) | 200 | if (finfo.filetype == APR_DIR) |
201 | continue; | 201 | continue; |
202 | newp = (char **)apr_array_push(cfg->input_files); | 202 | newp = (config_filestat_t *)apr_array_push(cfg->input_files); |
203 | apr_filepath_merge(newp, cfg->input_dir, finfo.name, | 203 | newp->result = "Not Parsed"; |
204 | APR_FILEPATH_TRUENAME, cfg->pool); | 204 | apr_filepath_merge(&(newp->fname), cfg->input_dir, finfo.name, |
205 | APR_FILEPATH_TRUENAME, cfg->pool); | ||
205 | } | 206 | } |
206 | apr_dir_close(dir); | 207 | apr_dir_close(dir); |
207 | } | 208 | } |
@@ -336,7 +337,7 @@ static apr_status_t tokenize_logline(const char *arg_str, char ***argv_out, | |||
336 | return APR_SUCCESS; | 337 | return APR_SUCCESS; |
337 | } | 338 | } |
338 | 339 | ||
339 | apr_status_t parse_logfile(config_t *cfg, const char *filename) | 340 | apr_status_t parser_parsefile(config_t *cfg, config_filestat_t *fstat) |
340 | { | 341 | { |
341 | apr_pool_t *tp, *targp; | 342 | apr_pool_t *tp, *targp; |
342 | apr_file_t *file; | 343 | apr_file_t *file; |
@@ -344,23 +345,27 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename) | |||
344 | char buff[2048]; | 345 | char buff[2048]; |
345 | char **targv; | 346 | char **targv; |
346 | int targc; | 347 | int targc; |
347 | int line; | ||
348 | 348 | ||
349 | apr_pool_create(&tp, cfg->pool); | 349 | apr_pool_create(&tp, cfg->pool); |
350 | apr_pool_create(&targp, tp); | 350 | apr_pool_create(&targp, tp); |
351 | 351 | ||
352 | logging_log(cfg, LOGLEVEL_NOTICE, "PARSER: Begin Parsing Log File '%s'", filename); | 352 | logging_log(cfg, LOGLEVEL_NOTICE, "PARSER: Begin Parsing Log File '%s'", fstat->fname); |
353 | 353 | ||
354 | rv = apr_file_open(&file, filename, APR_FOPEN_READ | APR_BUFFERED, | 354 | rv = apr_file_open(&file, fstat->fname, APR_FOPEN_READ | APR_BUFFERED, |
355 | APR_OS_DEFAULT, tp); | 355 | APR_OS_DEFAULT, tp); |
356 | if (rv != APR_SUCCESS) { | 356 | if (rv != APR_SUCCESS) { |
357 | logging_log(cfg, LOGLEVEL_NOISE, "PARSER: Could not open %s", filename); | 357 | logging_log(cfg, LOGLEVEL_NOISE, "PARSER: Could not open %s", fstat->fname); |
358 | return rv; | 358 | return rv; |
359 | } | 359 | } |
360 | 360 | ||
361 | line = 0; | 361 | fstat->linesparsed = 0; |
362 | // Start Transaction | 362 | // Start Transaction |
363 | database_trans_start(cfg,tp); | 363 | fstat->start = apr_time_now(); |
364 | if (database_trans_start(cfg,tp)) { | ||
365 | fstat->result = "Database Transaction Error"; | ||
366 | fstat->stop = apr_time_now(); | ||
367 | return rv; | ||
368 | } | ||
364 | 369 | ||
365 | do { | 370 | do { |
366 | rv = apr_file_gets(buff, 1024, file); | 371 | rv = apr_file_gets(buff, 1024, file); |
@@ -368,7 +373,7 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename) | |||
368 | int i,m, cont = 0; | 373 | int i,m, cont = 0; |
369 | config_filter_t *filters; | 374 | config_filter_t *filters; |
370 | 375 | ||
371 | line++; | 376 | fstat->linesparsed++; |
372 | // chomp off newline | 377 | // chomp off newline |
373 | line_chomp(buff); | 378 | line_chomp(buff); |
374 | // Run line filters | 379 | // Run line filters |
@@ -379,12 +384,13 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename) | |||
379 | if (filters[i].negative) { | 384 | if (filters[i].negative) { |
380 | logging_log(cfg, LOGLEVEL_DEBUG, | 385 | logging_log(cfg, LOGLEVEL_DEBUG, |
381 | "PARSER: LINEFILTER: Skipping Line %d due to Filter (%d)%s", | 386 | "PARSER: LINEFILTER: Skipping Line %d due to Filter (%d)%s", |
382 | line, i, filters[i].filter); | 387 | fstat->linesparsed, i, filters[i].filter); |
388 | fstat->lineskipped++; | ||
383 | cont = 1; | 389 | cont = 1; |
384 | } else { | 390 | } else { |
385 | logging_log(cfg, LOGLEVEL_DEBUG, | 391 | logging_log(cfg, LOGLEVEL_DEBUG, |
386 | "PARSER: LINEFILTER: Force Parsing Line %d due to Filter (%d)%s", | 392 | "PARSER: LINEFILTER: Force Parsing Line %d due to Filter (%d)%s", |
387 | line, i, filters[i].filter); | 393 | fstat->linesparsed, i, filters[i].filter); |
388 | } | 394 | } |
389 | break; | 395 | break; |
390 | } | 396 | } |
@@ -396,11 +402,11 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename) | |||
396 | targc = 0; | 402 | targc = 0; |
397 | while (targv[targc]) | 403 | while (targv[targc]) |
398 | targc++; | 404 | targc++; |
399 | rv = parse_processline(targp, cfg, line, targv, targc); | 405 | rv = parser_processline(targp, cfg, fstat, targv, targc); |
400 | if (rv != APR_SUCCESS) { | 406 | if (rv != APR_SUCCESS) { |
401 | int i; | 407 | int i; |
402 | database_trans_abort(cfg); | 408 | database_trans_abort(cfg); |
403 | logging_log(cfg, LOGLEVEL_ERROR, "Line %d(%d): %s", line, | 409 | logging_log(cfg, LOGLEVEL_ERROR, "Line %d(%d): %s", fstat->linesparsed, |
404 | targc, buff); | 410 | targc, buff); |
405 | for (i = 0; targv[i]; i++) { | 411 | for (i = 0; targv[i]; i++) { |
406 | logging_log(cfg, LOGLEVEL_ERROR, "Arg (%d): '%s'", i, | 412 | logging_log(cfg, LOGLEVEL_ERROR, "Arg (%d): '%s'", i, |
@@ -414,17 +420,25 @@ apr_status_t parse_logfile(config_t *cfg, const char *filename) | |||
414 | } while (rv == APR_SUCCESS); | 420 | } while (rv == APR_SUCCESS); |
415 | apr_file_close(file); | 421 | apr_file_close(file); |
416 | // Finish Transaction | 422 | // Finish Transaction |
417 | database_trans_stop(cfg,tp); | 423 | if (database_trans_stop(cfg,tp)) { |
424 | fstat->result = apr_psprintf(cfg->pool, | ||
425 | "Input line %d, Database Transaction Error", | ||
426 | fstat->linesparsed); | ||
427 | } | ||
418 | 428 | ||
419 | apr_pool_destroy(tp); | 429 | apr_pool_destroy(tp); |
420 | logging_log(cfg, LOGLEVEL_NOTICE, | 430 | logging_log(cfg, LOGLEVEL_NOTICE, |
421 | "PARSER: Finish Parsing Log File '%s'. Lines: %d", filename, line); | 431 | "PARSER: Finish Parsing Log File '%s'. Lines: (%d/%d)", |
422 | 432 | fstat->fname, fstat->linesparsed - fstat->lineskipped, fstat->linesparsed); | |
433 | if (!rv) { | ||
434 | fstat->result = "File Parsed Succesfully"; | ||
435 | } | ||
436 | fstat->stop = apr_time_now(); | ||
423 | return rv; | 437 | return rv; |
424 | } | 438 | } |
425 | 439 | ||
426 | apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, int line, | 440 | apr_status_t parser_processline(apr_pool_t *ptemp, config_t *cfg, |
427 | char **argv, int argc) | 441 | config_filestat_t *fstat, char **argv, int argc) |
428 | { | 442 | { |
429 | config_logformat_t *fmt; | 443 | config_logformat_t *fmt; |
430 | config_logformat_field_t *ifields; | 444 | config_logformat_field_t *ifields; |
@@ -436,10 +450,19 @@ apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, int line, | |||
436 | int i,m; | 450 | int i,m; |
437 | 451 | ||
438 | fmt = apr_hash_get(cfg->log_formats, cfg->logformat, APR_HASH_KEY_STRING); | 452 | fmt = apr_hash_get(cfg->log_formats, cfg->logformat, APR_HASH_KEY_STRING); |
439 | if (!fmt) | 453 | if (!fmt) { |
454 | logging_log(cfg, LOGLEVEL_NOISE, "PARSER: No Input Log format"); | ||
440 | return APR_EINVAL; | 455 | return APR_EINVAL; |
441 | if (fmt->fields->nelts != argc) | 456 | } |
457 | if (fmt->fields->nelts != argc) { | ||
458 | logging_log(cfg, LOGLEVEL_NOISE, | ||
459 | "PARSER: Input line field number differs from expected. Expected %d got %d.", | ||
460 | fmt->fields->nelts, argc); | ||
461 | fstat->result = apr_psprintf(cfg->pool, | ||
462 | "Input line %d is badly formatted (wrong number of fields)", | ||
463 | fstat->linesparsed); | ||
442 | return APR_EINVAL; | 464 | return APR_EINVAL; |
465 | } | ||
443 | 466 | ||
444 | datain = apr_table_make(ptemp, fmt->fields->nelts); | 467 | datain = apr_table_make(ptemp, fmt->fields->nelts); |
445 | dataout = apr_table_make(ptemp, cfg->output_fields->nelts); | 468 | dataout = apr_table_make(ptemp, cfg->output_fields->nelts); |
@@ -457,12 +480,13 @@ apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, int line, | |||
457 | if (filters[i].negative) { | 480 | if (filters[i].negative) { |
458 | logging_log(cfg, LOGLEVEL_DEBUG, | 481 | logging_log(cfg, LOGLEVEL_DEBUG, |
459 | "PARSER: PREFILTER: Skipping Line %d due to Filter (%d)%s", | 482 | "PARSER: PREFILTER: Skipping Line %d due to Filter (%d)%s", |
460 | line, i, filters[i].filter); | 483 | fstat->linesparsed, i, filters[i].filter); |
484 | fstat->lineskipped++; | ||
461 | return APR_SUCCESS; | 485 | return APR_SUCCESS; |
462 | } else { | 486 | } else { |
463 | logging_log(cfg, LOGLEVEL_DEBUG, | 487 | logging_log(cfg, LOGLEVEL_DEBUG, |
464 | "PARSER: PREFILTER: Force Parsing Line %d due to Filter (%d)%s", | 488 | "PARSER: PREFILTER: Force Parsing Line %d due to Filter (%d)%s", |
465 | line, i, filters[i].filter); | 489 | fstat->linesparsed, i, filters[i].filter); |
466 | } | 490 | } |
467 | break; | 491 | break; |
468 | } | 492 | } |
@@ -486,8 +510,12 @@ apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, int line, | |||
486 | const char *ret= NULL; | 510 | const char *ret= NULL; |
487 | rv = ((parser_func_t *)ofields[i].func)->func(ptemp, cfg, | 511 | rv = ((parser_func_t *)ofields[i].func)->func(ptemp, cfg, |
488 | &ofields[i], val, &ret); | 512 | &ofields[i], val, &ret); |
489 | if (rv) | 513 | if (rv) { |
514 | fstat->result = apr_psprintf(cfg->pool, | ||
515 | "Input line %d, Parser function %s returned error (%d)%s", | ||
516 | fstat->linesparsed, ofields[i].fname, rv, logging_strerror(rv)); | ||
490 | return rv; | 517 | return rv; |
518 | } | ||
491 | apr_table_setn(dataout, ofields[i].field, ret ? ret : ofields[i].def); | 519 | apr_table_setn(dataout, ofields[i].field, ret ? ret : ofields[i].def); |
492 | } | 520 | } |
493 | } | 521 | } |
@@ -501,12 +529,13 @@ apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, int line, | |||
501 | if (filters[i].negative) { | 529 | if (filters[i].negative) { |
502 | logging_log(cfg, LOGLEVEL_DEBUG, | 530 | logging_log(cfg, LOGLEVEL_DEBUG, |
503 | "PARSER: POSTFILTER: Skipping Line %d due to Filter (%d)%s", | 531 | "PARSER: POSTFILTER: Skipping Line %d due to Filter (%d)%s", |
504 | line, i, filters[i].filter); | 532 | fstat->linesparsed, i, filters[i].filter); |
533 | fstat->lineskipped++; | ||
505 | return APR_SUCCESS; | 534 | return APR_SUCCESS; |
506 | } else { | 535 | } else { |
507 | logging_log(cfg, LOGLEVEL_DEBUG, | 536 | logging_log(cfg, LOGLEVEL_DEBUG, |
508 | "PARSER: POSTFILTER: Force Parsing Line %d due to Filter (%d)%s", | 537 | "PARSER: POSTFILTER: Force Parsing Line %d due to Filter (%d)%s", |
509 | line, i, filters[i].filter); | 538 | fstat->linesparsed, i, filters[i].filter); |
510 | } | 539 | } |
511 | break; | 540 | break; |
512 | } | 541 | } |
@@ -515,6 +544,11 @@ apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, int line, | |||
515 | // Process DB Query | 544 | // Process DB Query |
516 | if (!cfg->dryrun) { | 545 | if (!cfg->dryrun) { |
517 | rv = database_insert(cfg, ptemp, dataout); | 546 | rv = database_insert(cfg, ptemp, dataout); |
547 | if (rv) { | ||
548 | fstat->result = apr_psprintf(cfg->pool, | ||
549 | "Input line %d, Database Error", | ||
550 | fstat->linesparsed); | ||
551 | } | ||
518 | } | 552 | } |
519 | return rv; | 553 | return rv; |
520 | } | 554 | } |