|
47 | 47 | DROP PROCEDURE IF EXISTS extract_ipaddr// |
48 | 48 | CREATE PROCEDURE extract_ipaddr(IN msg VARCHAR(5000)) |
49 | 49 | BEGIN |
50 | | -DECLARE matching INT default 1; |
51 | | -DECLARE ipaddr VARCHAR(255); |
52 | | -SET ipaddr=(SELECT REGEXP_SUBSTR(msg, '/(([0-9]+)(?:\.[0-9]+){3})/')); |
53 | | -tfer_loop:WHILE (ipaddr IS NOT NULL and length(ipaddr)>0 ) DO |
54 | | - SELECT ipaddr; |
55 | | - set matching=matching+1; |
56 | | - SET ipaddr=(SELECT REGEXP_SUBSTR(msg, '/(([0-9]+)(?:\.[0-9]+){3})/')); |
| 50 | + DECLARE matching INT default 1; |
| 51 | + DECLARE ipaddr VARCHAR(255); |
| 52 | + SET ipaddr=(SELECT REGEXP_SUBSTR(msg, '\\d{1,3}(?:\.\\d{1,3}){3}')); |
| 53 | + tfer_loop:WHILE ( ipaddr IS NOT NULL and length(ipaddr)>0 ) DO |
| 54 | + SELECT ipaddr; |
| 55 | + SET matching=matching+1; |
| 56 | + SET msg=(SELECT REPLACE( msg, @ipaddr, '' )); |
| 57 | + SET ipaddr=(SELECT REGEXP_SUBSTR(msg, '?:\\d{1,3}(?:\.\\d{1,3}){3})')); |
57 | 58 | END WHILE tfer_loop; |
58 | 59 | END; |
59 | 60 | // |
@@ -139,23 +140,32 @@ END; |
139 | 140 | DROP PROCEDURE IF EXISTS abuser_parser// |
140 | 141 | CREATE PROCEDURE abuser_parser(IN aid BIGINT UNSIGNED,IN ahost BIGINT UNSIGNED,IN aprogram VARCHAR(255),IN afacility INT,in alevel INT,IN apid BIGINT,in amsg TEXT,in areceived_ts TIMESTAMP) |
141 | 142 | BEGIN |
142 | | -DECLARE done,mts,Ccapture INT DEFAULT 0; |
143 | | -DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = -1; |
| 143 | + DECLARE done,mts,Ccapture INT DEFAULT 0; |
| 144 | + DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = -1; |
144 | 145 |
|
145 | | -SELECT id,pattern,grouping,capture INTO mts,@pattern,@grouping,Ccapture FROM abuser_trigger WHERE |
| 146 | + SELECT id,pattern,grouping,capture INTO mts,@pattern,@grouping,Ccapture FROM abuser_trigger WHERE |
146 | 147 | amsg LIKE msg AND |
147 | 148 | aprogram LIKE if(program='' or program is null,'%',program) AND |
148 | 149 | afacility like if(facility<0,'%',facility) AND |
149 | 150 | alevel like if(`severity`<0,'%',`severity`) and active=1 |
150 | 151 | LIMIT 1; |
151 | | - IF mts>0 AND Ccapture IS NOT NULL AND INET_ATON(REGEXP_REPLACE(amsg,@pattern,CONCAT('\\' COLLATE utf8_general_ci,@grouping))) IS NOT NULL THEN |
152 | | - INSERT INTO abuser_incident (ip,trigger_id,counter,first_occurrence,last_occurrence) |
153 | | - VALUES (INET_ATON(REGEXP_REPLACE(amsg,@pattern,CONCAT('\\' COLLATE utf8_general_ci,@grouping))), |
154 | | - mts,1,areceived_ts,areceived_ts) |
155 | | - ON DUPLICATE KEY UPDATE counter=counter+1,last_occurrence=areceived_ts; |
156 | | - SELECT id INTO @incident_id FROM abuser_incident WHERE ip=INET_ATON(REGEXP_REPLACE(amsg,@pattern,CONCAT('\\' COLLATE utf8_general_ci,@grouping))) AND trigger_id=mts; |
157 | | - CALL abuser_log_evidence(@incident_id,aid); |
158 | | - END IF; |
| 152 | + |
| 153 | + SET @grouping = (CONVERT(CONCAT('\\',@grouping) USING utf8) COLLATE utf8_unicode_ci); |
| 154 | + IF @pattern REGEXP '^\\^' != '1' THEN |
| 155 | + SET @pattern = (CONCAT('^.*',@pattern)); |
| 156 | + END IF; |
| 157 | + if @pattern REGEXP '\\$$' != '1' THEN |
| 158 | + SET @pattern = (CONCAT(@pattern,'.*$')); |
| 159 | + END IF; |
| 160 | + |
| 161 | + IF mts>0 AND Ccapture IS NOT NULL AND INET_ATON(REGEXP_REPLACE(amsg,@pattern,@grouping)) IS NOT NULL THEN |
| 162 | + INSERT INTO abuser_incident (ip,trigger_id,counter,first_occurrence,last_occurrence) |
| 163 | + VALUES (INET_ATON(REGEXP_REPLACE(amsg,@pattern,@grouping)), |
| 164 | + mts,1,areceived_ts,areceived_ts) |
| 165 | + ON DUPLICATE KEY UPDATE counter=counter+1,last_occurrence=areceived_ts; |
| 166 | + SELECT id INTO @incident_id FROM abuser_incident WHERE ip=INET_ATON(REGEXP_REPLACE(amsg,@pattern,@grouping)) AND trigger_id=mts; |
| 167 | + CALL abuser_log_evidence(@incident_id,aid); |
| 168 | + END IF; |
159 | 169 | END;// |
160 | 170 |
|
161 | 171 |
|
|
0 commit comments