summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkuri igen <kuri@e4.enlightenment.org>2011-02-08 19:47:39 +0100
committerkuri igen <kuri@e4.enlightenment.org>2011-02-08 19:47:39 +0100
commite1c5cab153d40f42f7f971b52db56b4b1ad17737 (patch)
treedd20bb43bfdd546346554dda17b59496e8674805 /src
parentc123d0409e8a13b91205ad3fdd4ad69c3282c104 (diff)
Added support for multi regex filters for log messages
Diffstat (limited to 'src')
-rw-r--r--src/bin/global.h13
-rw-r--r--src/bin/rules.c44
2 files changed, 42 insertions, 15 deletions
diff --git a/src/bin/global.h b/src/bin/global.h
index 7728d68..07143f8 100644
--- a/src/bin/global.h
+++ b/src/bin/global.h
@@ -45,12 +45,23 @@ struct rule
45{ 45{
46 char *name, /**< Rule's name (Guessed using the filename of the rule inside the rules directory) */ 46 char *name, /**< Rule's name (Guessed using the filename of the rule inside the rules directory) */
47 *filename, /**< It is the filename of the logfile(s) that match this rule (see this as a condition) */ 47 *filename, /**< It is the filename of the logfile(s) that match this rule (see this as a condition) */
48 *message, /**< Regexp to apply to message we get from syslog, the match them (see this as a condition) */
49 *type, /**< Type we will apply to the matched log message (see this as an affectation) */ 48 *type, /**< Type we will apply to the matched log message (see this as an affectation) */
50 *source_host, /**< Host we will apply to the matched log message (see this as an affectation) */ 49 *source_host, /**< Host we will apply to the matched log message (see this as an affectation) */
51 *source_path, /**< Log path we will apply to the matched log message (its like renaming the log, without mv it) (see this as an affectation) */ 50 *source_path, /**< Log path we will apply to the matched log message (its like renaming the log, without mv it) (see this as an affectation) */
52 *tags; /**< tags we will apply to the matched log message (see this as an affectation) */ 51 *tags; /**< tags we will apply to the matched log message (see this as an affectation) */
53 int todel; /**< If set to something other than 0, every matched rule will not be indexed */ 52 int todel; /**< If set to something other than 0, every matched rule will not be indexed */
53 Eina_List *list_regex; /**< Regexps to apply to message we get from syslog, then match them (see this as a condition) */
54};
55
56/**
57 * @struct regex
58 * @brief This structure can handle a regex that will be compared to log messages
59 * in order to see if they are affected by a rule or not
60 */
61struct regex
62{
63 char *message;
64 int must_match;
54}; 65};
55 66
56/** 67/**
diff --git a/src/bin/rules.c b/src/bin/rules.c
index 8f7b66f..8cf75d8 100644
--- a/src/bin/rules.c
+++ b/src/bin/rules.c
@@ -90,7 +90,6 @@ int rules_load_rule(char *rule_name)
90 90
91 // We init default values for our struct 91 // We init default values for our struct
92 rules_temp->filename = NULL; 92 rules_temp->filename = NULL;
93 rules_temp->message = NULL;
94 rules_temp->type = NULL; 93 rules_temp->type = NULL;
95 rules_temp->source_host = NULL; 94 rules_temp->source_host = NULL;
96 rules_temp->source_path = NULL; 95 rules_temp->source_path = NULL;
@@ -123,10 +122,23 @@ int rules_load_rule_loadspec(char *variable, char *value)
123 rules_temp->filename = malloc(sizeof(char) * ( strlen(value) + 1 )); 122 rules_temp->filename = malloc(sizeof(char) * ( strlen(value) + 1 ));
124 strcpy(rules_temp->filename, value); 123 strcpy(rules_temp->filename, value);
125 } 124 }
126 else if( !strcmp(variable, "message") ) 125 else if( ( !strcmp(variable, "message") )
126 || ( !strcmp(variable, "message_match") )
127 || ( !strcmp(variable, "message_unmatch") )
128 )
127 { 129 {
128 rules_temp->message = malloc(sizeof(char) * ( strlen(value) + 1 )); 130 struct regex *tmp_regex;
129 strcpy(rules_temp->message, value); 131 tmp_regex = malloc(sizeof(struct regex));
132
133 tmp_regex->message = malloc(sizeof(char) * ( strlen(value) + 1 ));
134 strcpy(tmp_regex->message, value);
135
136 if( !strcmp(variable, "message_unmatch") )
137 tmp_regex->must_match = 0;
138 else
139 tmp_regex->must_match = 1;
140
141 rules_temp->list_regex = eina_list_append(rules_temp->list_regex, tmp_regex);
130 } 142 }
131 else if( !strcmp(variable, "type") ) 143 else if( !strcmp(variable, "type") )
132 { 144 {
@@ -177,7 +189,6 @@ int rules_print(void)
177 EINA_LOG_DOM_INFO(einadom_rules, 189 EINA_LOG_DOM_INFO(einadom_rules,
178 "\n[%s]\n" 190 "\n[%s]\n"
179 "\tfilename\t= %s\n" 191 "\tfilename\t= %s\n"
180 "\tmessage\t\t= %s\n"
181 "\ttype\t\t= %s\n" 192 "\ttype\t\t= %s\n"
182 "\tsource_host\t= %s\n" 193 "\tsource_host\t= %s\n"
183 "\tsource_path\t= %s\n" 194 "\tsource_path\t= %s\n"
@@ -185,7 +196,6 @@ int rules_print(void)
185 "\tdelete\t= %d\n\n", 196 "\tdelete\t= %d\n\n",
186 foundrule->name, 197 foundrule->name,
187 foundrule->filename, 198 foundrule->filename,
188 foundrule->message,
189 foundrule->type, 199 foundrule->type,
190 foundrule->source_host, 200 foundrule->source_host,
191 foundrule->source_path, 201 foundrule->source_path,
@@ -228,9 +238,11 @@ int rules_list(int (*callback)(struct rule *foundrule))
228 */ 238 */
229int rules_filtermessage(struct logmessage *new_logmessage) 239int rules_filtermessage(struct logmessage *new_logmessage)
230{ 240{
231 Eina_List *l; 241 Eina_List *l, *l2;
232 struct rule *foundrule = NULL; 242 struct rule *foundrule = NULL;
233 int ret; 243 struct regex *foundregex = NULL;
244 int ret,
245 excluded = 0;
234 246
235 // We check each rules to see what we have to do 247 // We check each rules to see what we have to do
236 EINA_LIST_FOREACH(list_rules, l, foundrule) 248 EINA_LIST_FOREACH(list_rules, l, foundrule)
@@ -248,30 +260,34 @@ int rules_filtermessage(struct logmessage *new_logmessage)
248 } 260 }
249 261
250 // Now we check for message filtering 262 // Now we check for message filtering
251 if( foundrule->message ) 263 EINA_LIST_FOREACH(foundrule->list_regex, l2, foundregex)
252 { 264 {
253 regex_t preg; 265 regex_t preg;
254 size_t nmatch = 2; 266 size_t nmatch = 2;
255 regmatch_t pmatch[2]; 267 regmatch_t pmatch[2];
256 268
257 ret = regcomp(&preg, foundrule->message, REG_EXTENDED); 269 ret = regcomp(&preg, foundregex->message, REG_EXTENDED);
258 if( ret ) 270 if( ret )
259 { 271 {
260 EINA_LOG_DOM_ERR(einadom_rules, "Regcomp failed to compile regexp %s", foundrule->message); 272 EINA_LOG_DOM_ERR(einadom_rules, "Regcomp failed to compile regexp %s", foundregex->message);
261 regfree(&preg); 273 regfree(&preg);
262 continue; 274 continue;
263 } 275 }
264 276
265 ret = regexec(&preg, new_logmessage->message,nmatch, pmatch, 0); 277 ret = regexec(&preg, new_logmessage->message,nmatch, pmatch, 0);
266 if( ret ) 278 if( ret == foundregex->must_match )
267 { 279 {
268 EINA_LOG_DOM_INFO(einadom_rules, "Log \"%s\" from \"%s\" is not affected by rule %s (message exclude)", new_logmessage->message, new_logmessage->source_path, foundrule->name); 280 EINA_LOG_DOM_INFO(einadom_rules, "Log \"%s\" from \"%s\" is not affected by rule %s (message exclude : %s / %d / %d)", new_logmessage->message, new_logmessage->source_path, foundrule->name, foundregex->message, foundregex->must_match, ret);
269 regfree(&preg); 281 regfree(&preg);
270 continue; 282 excluded = 1;
283 break;
271 } 284 }
272 regfree(&preg); 285 regfree(&preg);
273 } 286 }
274 287
288 if( excluded )
289 continue;
290
275 // If we get here, then our log message have to be filtered 291 // If we get here, then our log message have to be filtered
276 292
277 // If type is specified, then we have to override it 293 // If type is specified, then we have to override it