diff options
Diffstat (limited to 'utility')
-rw-r--r-- | utility/logparse.c | 41 | ||||
-rw-r--r-- | utility/mod_log_sql.conf | 2 |
2 files changed, 32 insertions, 11 deletions
diff --git a/utility/logparse.c b/utility/logparse.c index 086f454..6a21964 100644 --- a/utility/logparse.c +++ b/utility/logparse.c | |||
@@ -14,6 +14,28 @@ | |||
14 | apr_hash_t *g_parser_funcs; | 14 | apr_hash_t *g_parser_funcs; |
15 | void **g_parser_linedata; | 15 | void **g_parser_linedata; |
16 | 16 | ||
17 | static apr_status_t parser_func_wrap(apr_pool_t *p, config_t *cfg, | ||
18 | config_output_field_t *field, const char *value, const char **ret) | ||
19 | { | ||
20 | if (field->args[0] && field->args[1]) { | ||
21 | struct iovec vec[3]; | ||
22 | apr_size_t len; | ||
23 | |||
24 | vec[0].iov_base = (void *)field->args[0]; | ||
25 | vec[0].iov_len = strlen(field->args[0]); | ||
26 | vec[1].iov_base = (void *)value; | ||
27 | vec[1].iov_len = strlen(value); | ||
28 | vec[2].iov_base = (void *)field->args[1]; | ||
29 | vec[2].iov_len = strlen(field->args[1]); | ||
30 | |||
31 | *ret = apr_pstrcatv(p, vec, 3, &len); | ||
32 | } else { | ||
33 | logging_log(cfg, LOGLEVEL_NOISE, "wrap requires before and after strings"); | ||
34 | return APR_EINVAL; | ||
35 | } | ||
36 | return APR_SUCCESS; | ||
37 | } | ||
38 | |||
17 | static apr_status_t parser_func_regexmatch(apr_pool_t *p, config_t *cfg, | 39 | static apr_status_t parser_func_regexmatch(apr_pool_t *p, config_t *cfg, |
18 | config_output_field_t *field, const char *value, const char **ret) | 40 | config_output_field_t *field, const char *value, const char **ret) |
19 | { | 41 | { |
@@ -29,22 +51,22 @@ static apr_status_t parser_func_regexmatch(apr_pool_t *p, config_t *cfg, | |||
29 | // pre compile the regex | 51 | // pre compile the regex |
30 | _data = apr_palloc(cfg->pool, sizeof(ap_regex_t)+sizeof(const char *)); | 52 | _data = apr_palloc(cfg->pool, sizeof(ap_regex_t)+sizeof(const char *)); |
31 | _data->rx = ap_pregcomp(cfg->pool, field->args[0], | 53 | _data->rx = ap_pregcomp(cfg->pool, field->args[0], |
32 | AP_REG_EXTENDED|AP_REG_ICASE); | 54 | AP_REG_EXTENDED|AP_REG_ICASE); |
33 | if (field->args[1]) { | 55 | if (field->args[1]) { |
34 | _data->substr = field->args[1]; | 56 | _data->substr = field->args[1]; |
35 | } else { | 57 | } else { |
36 | _data->substr = "$1"; | 58 | _data->substr = "$1"; |
37 | } | 59 | } |
38 | if (!_data->rx) | 60 | if (!_data->rx) { |
61 | logging_log(cfg, LOGLEVEL_NOISE, "Failed to compile regular expression"); | ||
39 | return APR_EINVAL; | 62 | return APR_EINVAL; |
63 | } | ||
40 | field->data = _data; | 64 | field->data = _data; |
41 | } else | 65 | } else |
42 | _data = field->data; | 66 | _data = field->data; |
43 | 67 | ||
44 | if (!ap_regexec(_data->rx, value, AP_MAX_REG_MATCH, regm, 0)) { | 68 | if (!ap_regexec(_data->rx, value, AP_MAX_REG_MATCH, regm, 0)) { |
45 | *ret = ap_pregsub(p, _data->substr, value, AP_MAX_REG_MATCH, regm); | 69 | *ret = ap_pregsub(p, _data->substr, value, AP_MAX_REG_MATCH, regm); |
46 | } else { | ||
47 | *ret = field->def; | ||
48 | } | 70 | } |
49 | logging_log(cfg, LOGLEVEL_DEBUG, "REGEX: matched %s against %s to %s", value, | 71 | logging_log(cfg, LOGLEVEL_DEBUG, "REGEX: matched %s against %s to %s", value, |
50 | field->args[0], *ret); | 72 | field->args[0], *ret); |
@@ -71,20 +93,19 @@ static apr_status_t parser_func_machineid(apr_pool_t *p, config_t *cfg, | |||
71 | { | 93 | { |
72 | if (cfg->machineid) { | 94 | if (cfg->machineid) { |
73 | *ret = apr_pstrdup(p, cfg->machineid); | 95 | *ret = apr_pstrdup(p, cfg->machineid); |
74 | } else { | ||
75 | *ret = field->def; | ||
76 | } | 96 | } |
77 | return APR_SUCCESS; | 97 | return APR_SUCCESS; |
78 | } | 98 | } |
79 | 99 | ||
80 | /** @todo Implement Query arg ripping function */ | ||
81 | static apr_status_t parser_func_queryarg(apr_pool_t *p, config_t *cfg, | 100 | static apr_status_t parser_func_queryarg(apr_pool_t *p, config_t *cfg, |
82 | config_output_field_t *field, const char *value, const char **ret) | 101 | config_output_field_t *field, const char *value, const char **ret) |
83 | { | 102 | { |
84 | apr_table_t *query = parser_get_linedata(field->func); | 103 | apr_table_t *query = parser_get_linedata(field->func); |
85 | 104 | ||
86 | if (!field->args[0]) | 105 | if (!field->args[0]) { |
106 | logging_log(cfg, LOGLEVEL_NOISE, "queryarg requires name of query arg"); | ||
87 | return APR_EINVAL; | 107 | return APR_EINVAL; |
108 | } | ||
88 | 109 | ||
89 | if (!query) { | 110 | if (!query) { |
90 | char *query_beg; | 111 | char *query_beg; |
@@ -127,7 +148,6 @@ static apr_status_t parser_func_queryarg(apr_pool_t *p, config_t *cfg, | |||
127 | parser_set_linedata(field->func,query); | 148 | parser_set_linedata(field->func,query); |
128 | } | 149 | } |
129 | *ret = apr_table_get(query, field->args[0]); | 150 | *ret = apr_table_get(query, field->args[0]); |
130 | if (*ret == NULL) *ret = field->def; | ||
131 | return APR_SUCCESS; | 151 | return APR_SUCCESS; |
132 | } | 152 | } |
133 | 153 | ||
@@ -158,6 +178,7 @@ void parser_init(apr_pool_t *p) | |||
158 | parser_add_func(p, "totimestamp", parser_func_totimestamp, ++i); | 178 | parser_add_func(p, "totimestamp", parser_func_totimestamp, ++i); |
159 | parser_add_func(p, "machineid", parser_func_machineid, ++i); | 179 | parser_add_func(p, "machineid", parser_func_machineid, ++i); |
160 | parser_add_func(p, "queryarg", parser_func_queryarg, ++i); | 180 | parser_add_func(p, "queryarg", parser_func_queryarg, ++i); |
181 | parser_add_func(p, "wrap", parser_func_wrap, ++i); | ||
161 | g_parser_linedata = apr_pcalloc(p, sizeof(void *) * (i+1)); | 182 | g_parser_linedata = apr_pcalloc(p, sizeof(void *) * (i+1)); |
162 | g_parser_linedata[0] = (void *)i; | 183 | g_parser_linedata[0] = (void *)i; |
163 | } | 184 | } |
@@ -417,7 +438,7 @@ apr_status_t parse_processline(apr_pool_t *ptemp, config_t *cfg, char **argv, | |||
417 | &ofields[i], val, &ret); | 438 | &ofields[i], val, &ret); |
418 | if (rv) | 439 | if (rv) |
419 | return rv; | 440 | return rv; |
420 | apr_table_setn(dataout, ofields[i].field, ret); | 441 | apr_table_setn(dataout, ofields[i].field, ret ? ret : ofields[i].def); |
421 | } | 442 | } |
422 | } | 443 | } |
423 | 444 | ||
diff --git a/utility/mod_log_sql.conf b/utility/mod_log_sql.conf index 8822bb5..ee0cb07 100644 --- a/utility/mod_log_sql.conf +++ b/utility/mod_log_sql.conf | |||
@@ -44,7 +44,7 @@ OutputField status smallint 0 status | |||
44 | OutputField request_uri varchar(255) "" request regexmatch "^\\w+ (.+) \\w+/[\\d\\.]+$" | 44 | OutputField request_uri varchar(255) "" request regexmatch "^\\w+ (.+) \\w+/[\\d\\.]+$" |
45 | OutputField remote_user varchar(50) "" user | 45 | OutputField remote_user varchar(50) "" user |
46 | OutputField remote_logname varchar(50) "" ident | 46 | OutputField remote_logname varchar(50) "" ident |
47 | OutputField request_time char(28) "" date regexmatch ".+" "[$0]" | 47 | OutputField request_time char(28) "" date wrap "[" "]" |
48 | #Only used for Combined log input, if standard CLF input, they are ignored | 48 | #Only used for Combined log input, if standard CLF input, they are ignored |
49 | OutputField agent varchar(255) "" agent | 49 | OutputField agent varchar(255) "" agent |
50 | OutputField referer varchar(255) "" referer | 50 | OutputField referer varchar(255) "" referer |