Browse code

modules:sipcapture Adedd HEPv2 support. Fixed some SQL and config issues. Deleted partitioning_mode.

Alexandr Dubovikov authored on 03/02/2012 14:21:42
Showing 13 changed files
... ...
@@ -29,18 +29,17 @@ Alexandr Dubovikov
29 29
 
30 30
               3.1. db_url (str)
31 31
               3.2. table_name (str)
32
-              3.3. partitioning_mode (integer)
33
-              3.4. db_insert_mode (integer)
34
-              3.5. capture_on (integer)
35
-              3.6. hep_capture_on (integer)
36
-              3.7. raw_ipip_capture_on (integer)
37
-              3.8. raw_moni_capture_on (integer)
38
-              3.9. raw_socket_listen (string)
39
-              3.10. raw_interface (string)
40
-              3.11. raw_sock_children (integer)
41
-              3.12. promiscuous_on (integer)
42
-              3.13. raw_moni_bpf_on (integer)
43
-              3.14. capture_node (str)
32
+              3.3. db_insert_mode (integer)
33
+              3.4. capture_on (integer)
34
+              3.5. hep_capture_on (integer)
35
+              3.6. raw_ipip_capture_on (integer)
36
+              3.7. raw_moni_capture_on (integer)
37
+              3.8. raw_socket_listen (string)
38
+              3.9. raw_interface (string)
39
+              3.10. raw_sock_children (integer)
40
+              3.11. promiscuous_on (integer)
41
+              3.12. raw_moni_bpf_on (integer)
42
+              3.13. capture_node (str)
44 43
 
45 44
         4. MI Commands
46 45
 
... ...
@@ -53,18 +52,17 @@ Alexandr Dubovikov
53 52
 
54 53
    1.1. Set db_url parameter
55 54
    1.2. Set sip_capture parameter
56
-   1.3. partitioning_mode
57
-   1.4. db_insert_mode example
58
-   1.5. Set capture_on parameter
59
-   1.6. Set hep_capture_on parameter
60
-   1.7. Set raw_ipip_capture_on parameter
61
-   1.8. Set raw_moni_capture_on parameter
55
+   1.3. db_insert_mode example
56
+   1.4. Set capture_on parameter
57
+   1.5. Set hep_capture_on parameter
58
+   1.6. Set raw_ipip_capture_on parameter
59
+   1.7. Set raw_moni_capture_on parameter
60
+   1.8. Set raw_socket_listen parameter
62 61
    1.9. Set raw_socket_listen parameter
63 62
    1.10. Set raw_socket_listen parameter
64
-   1.11. Set raw_socket_listen parameter
65
-   1.12. Set hep_capture_on parameter
66
-   1.13. Set raw_moni_bpf_on parameter
67
-   1.14. Set capture_node parameter
63
+   1.11. Set hep_capture_on parameter
64
+   1.12. Set raw_moni_bpf_on parameter
65
+   1.13. Set capture_node parameter
68 66
 
69 67
 Chapter 1. Admin Guide
70 68
 
... ...
@@ -80,18 +78,17 @@ Chapter 1. Admin Guide
80 78
 
81 79
         3.1. db_url (str)
82 80
         3.2. table_name (str)
83
-        3.3. partitioning_mode (integer)
84
-        3.4. db_insert_mode (integer)
85
-        3.5. capture_on (integer)
86
-        3.6. hep_capture_on (integer)
87
-        3.7. raw_ipip_capture_on (integer)
88
-        3.8. raw_moni_capture_on (integer)
89
-        3.9. raw_socket_listen (string)
90
-        3.10. raw_interface (string)
91
-        3.11. raw_sock_children (integer)
92
-        3.12. promiscuous_on (integer)
93
-        3.13. raw_moni_bpf_on (integer)
94
-        3.14. capture_node (str)
81
+        3.3. db_insert_mode (integer)
82
+        3.4. capture_on (integer)
83
+        3.5. hep_capture_on (integer)
84
+        3.6. raw_ipip_capture_on (integer)
85
+        3.7. raw_moni_capture_on (integer)
86
+        3.8. raw_socket_listen (string)
87
+        3.9. raw_interface (string)
88
+        3.10. raw_sock_children (integer)
89
+        3.11. promiscuous_on (integer)
90
+        3.12. raw_moni_bpf_on (integer)
91
+        3.13. capture_node (str)
95 92
 
96 93
    4. MI Commands
97 94
 
... ...
@@ -136,18 +133,17 @@ Chapter 1. Admin Guide
136 133
 
137 134
    3.1. db_url (str)
138 135
    3.2. table_name (str)
139
-   3.3. partitioning_mode (integer)
140
-   3.4. db_insert_mode (integer)
141
-   3.5. capture_on (integer)
142
-   3.6. hep_capture_on (integer)
143
-   3.7. raw_ipip_capture_on (integer)
144
-   3.8. raw_moni_capture_on (integer)
145
-   3.9. raw_socket_listen (string)
146
-   3.10. raw_interface (string)
147
-   3.11. raw_sock_children (integer)
148
-   3.12. promiscuous_on (integer)
149
-   3.13. raw_moni_bpf_on (integer)
150
-   3.14. capture_node (str)
136
+   3.3. db_insert_mode (integer)
137
+   3.4. capture_on (integer)
138
+   3.5. hep_capture_on (integer)
139
+   3.6. raw_ipip_capture_on (integer)
140
+   3.7. raw_moni_capture_on (integer)
141
+   3.8. raw_socket_listen (string)
142
+   3.9. raw_interface (string)
143
+   3.10. raw_sock_children (integer)
144
+   3.11. promiscuous_on (integer)
145
+   3.12. raw_moni_bpf_on (integer)
146
+   3.13. capture_node (str)
151 147
 
152 148
 3.1. db_url (str)
153 149
 
... ...
@@ -162,9 +158,7 @@ modparam("sipcapture", "db_url", "mysql://user:passwd@host/dbname")
162 158
 
163 159
 3.2. table_name (str)
164 160
 
165
-   Name of the table's name where to store the SIP messages. If
166
-   partitioning_mode set to 1, the table_name is a prefix to separate
167
-   table. i.e. sip_capture_01_02.
161
+   Name of the table's name where to store the SIP messages.
168 162
 
169 163
    Default value is "sip_capture".
170 164
 
... ...
@@ -173,18 +167,7 @@ modparam("sipcapture", "db_url", "mysql://user:passwd@host/dbname")
173 167
 modparam("sipcapture", "table_name", "homer_capture")
174 168
 ...
175 169
 
176
-3.3. partitioning_mode (integer)
177
-
178
-   If set to 0, records will store to separate table, depends on the day
179
-   of the week and the hour of the day. Otherwise records will store into
180
-   partitioning table.
181
-
182
-   Default value is 1.
183
-
184
-   Example 1.3. partitioning_mode
185
-modparam("sipcapture", "partitioning_mode", 0)
186
-
187
-3.4. db_insert_mode (integer)
170
+3.3. db_insert_mode (integer)
188 171
 
189 172
    If set to 1, use INSERT DELAYED to store sip message into capture table
190 173
    when the DB driver has support for it. If no INSERT DELAYED support is
... ...
@@ -192,43 +175,43 @@ modparam("sipcapture", "partitioning_mode", 0)
192 175
 
193 176
    Default value is 0 (no INSERT DELAYED).
194 177
 
195
-   Example 1.4. db_insert_mode example
178
+   Example 1.3. db_insert_mode example
196 179
 modparam("sipcapture", "db_insert_mode", 1)
197 180
 
198
-3.5. capture_on (integer)
181
+3.4. capture_on (integer)
199 182
 
200 183
    Parameter to enable/disable capture globaly (on(1)/off(0))
201 184
 
202 185
    Default value is "0".
203 186
 
204
-   Example 1.5. Set capture_on parameter
187
+   Example 1.4. Set capture_on parameter
205 188
 ...
206 189
 modparam("sipcapture", "capture_on", 1)
207 190
 ...
208 191
 
209
-3.6. hep_capture_on (integer)
192
+3.5. hep_capture_on (integer)
210 193
 
211 194
    Parameter to enable/disable capture of HEP (on(1)/off(0))
212 195
 
213 196
    Default value is "0".
214 197
 
215
-   Example 1.6. Set hep_capture_on parameter
198
+   Example 1.5. Set hep_capture_on parameter
216 199
 ...
217 200
 modparam("sipcapture", "hep_capture_on", 1)
218 201
 ...
219 202
 
220
-3.7. raw_ipip_capture_on (integer)
203
+3.6. raw_ipip_capture_on (integer)
221 204
 
222 205
    Parameter to enable/disable IPIP capturing (on(1)/off(0))
223 206
 
224 207
    Default value is "0".
225 208
 
226
-   Example 1.7. Set raw_ipip_capture_on parameter
209
+   Example 1.6. Set raw_ipip_capture_on parameter
227 210
 ...
228 211
 modparam("sipcapture", "raw_ipip_capture_on", 1)
229 212
 ...
230 213
 
231
-3.8. raw_moni_capture_on (integer)
214
+3.7. raw_moni_capture_on (integer)
232 215
 
233 216
    Parameter to enable/disable monitoring/mirroring port capturing
234 217
    (on(1)/off(0)) Only one mode on raw socket can be enabled! Monitoring
... ...
@@ -236,12 +219,12 @@ modparam("sipcapture", "raw_ipip_capture_on", 1)
236 219
 
237 220
    Default value is "0".
238 221
 
239
-   Example 1.8. Set raw_moni_capture_on parameter
222
+   Example 1.7. Set raw_moni_capture_on parameter
240 223
 ...
241 224
 modparam("sipcapture", "raw_moni_capture_on", 1)
242 225
 ...
243 226
 
244
-3.9. raw_socket_listen (string)
227
+3.8. raw_socket_listen (string)
245 228
 
246 229
    Parameter indicate an listen IP address of RAW socket for IPIP
247 230
    capturing. You can also define a port/portrange for IPIP/Mirroring
... ...
@@ -259,49 +242,49 @@ modparam("sipcapture", "raw_moni_capture_on", 1)
259 242
 
260 243
    Default value is "".
261 244
 
262
-   Example 1.9. Set raw_socket_listen parameter
245
+   Example 1.8. Set raw_socket_listen parameter
263 246
 ...
264 247
 modparam("sipcapture", "raw_socket_listen", "10.0.0.1:5060-5090")
265 248
 ...
266 249
 modparam("sipcapture", "raw_socket_listen", "10.0.0.1:5060")
267 250
 ...
268 251
 
269
-3.10. raw_interface (string)
252
+3.9. raw_interface (string)
270 253
 
271 254
    Name of the interface to bind on the raw socket.
272 255
 
273 256
    Default value is "".
274 257
 
275
-   Example 1.10. Set raw_socket_listen parameter
258
+   Example 1.9. Set raw_socket_listen parameter
276 259
 ...
277 260
 modparam("sipcapture", "raw_interface", "eth0")
278 261
 ...
279 262
 
280
-3.11. raw_sock_children (integer)
263
+3.10. raw_sock_children (integer)
281 264
 
282 265
    Parameter define how much children must be created to listen the raw
283 266
    socket.
284 267
 
285 268
    Default value is "1".
286 269
 
287
-   Example 1.11. Set raw_socket_listen parameter
270
+   Example 1.10. Set raw_socket_listen parameter
288 271
 ...
289 272
 modparam("sipcapture", "raw_sock_children", 6)
290 273
 ...
291 274
 
292
-3.12. promiscuous_on (integer)
275
+3.11. promiscuous_on (integer)
293 276
 
294 277
    Parameter to enable/disable promiscuous mode on the raw socket. Linux
295 278
    only.
296 279
 
297 280
    Default value is "0".
298 281
 
299
-   Example 1.12. Set hep_capture_on parameter
282
+   Example 1.11. Set hep_capture_on parameter
300 283
 ...
301 284
 modparam("sipcapture", "promiscuous_on", 1)
302 285
 ...
303 286
 
304
-3.13. raw_moni_bpf_on (integer)
287
+3.12. raw_moni_bpf_on (integer)
305 288
 
306 289
    Activate Linux Socket Filter (LSF based on BPF) on the mirroring
307 290
    interface. The structure is defined in linux/filter.h. The default LSF
... ...
@@ -310,18 +293,18 @@ modparam("sipcapture", "promiscuous_on", 1)
310 293
 
311 294
    Default value is "0".
312 295
 
313
-   Example 1.13. Set raw_moni_bpf_on parameter
296
+   Example 1.12. Set raw_moni_bpf_on parameter
314 297
 ...
315 298
 modparam("sipcapture", "raw_moni_bpf_on", 1)
316 299
 ...
317 300
 
318
-3.14. capture_node (str)
301
+3.13. capture_node (str)
319 302
 
320 303
    Name of the capture node.
321 304
 
322 305
    Default value is "homer01".
323 306
 
324
-   Example 1.14. Set capture_node parameter
307
+   Example 1.13. Set capture_node parameter
325 308
 ...
326 309
 modparam("sipcapture", "capture_node", "homer03")
327 310
 ...
... ...
@@ -353,10 +336,9 @@ modparam("sipcapture", "capture_node", "homer03")
353 336
    Before running Kamailio with sipcapture, you have to setup the database
354 337
    tables where the module will store the data. For that, if the table
355 338
    were not created by the installation script or you choose to install
356
-   everything by yourself you can use the sipcapture-create.sql or the
357
-   sipcapture-st-create.sql SQL script in the database directories in the
358
-   kamailio/scripts folder as template. You can also find the complete
359
-   database documentation on the project webpage,
339
+   everything by yourself you can use the sipcapture_create.sql, SQL
340
+   script in the sql folder of sipcapture module as template. You can also
341
+   find the complete database documentation on the project webpage,
360 342
    http://www.kamailio.org/docs/db-tables/kamailio-db-devel.html.
361 343
 
362 344
 6. Limitation
... ...
@@ -364,6 +346,5 @@ modparam("sipcapture", "capture_node", "homer03")
364 346
    1. Only one capturing mode on RAW socket is supported: IPIP or
365 347
    monitoring/mirroring port. Don't activate both at the same time. 2. By
366 348
    default MySQL doesn't support INSERT DELAYED for partitioning table.
367
-   You can patch MySQL (http://bugs.mysql.com/bug.php?id=50393) or use
368
-   separate tables (pseudo partitioning) 3. Mirroring port capturing works
369
-   only on Linux.
349
+   You can patch MySQL (http://bugs.mysql.com/bug.php?id=50393) 3.
350
+   Mirroring port capturing works only on Linux.
... ...
@@ -105,8 +105,6 @@ modparam("sipcapture", "db_url", "mysql://user:passwd@host/dbname")
105 105
 		<title><varname>table_name</varname> (str)</title>
106 106
 		<para>
107 107
 		Name of the table's name where to store the SIP messages. 
108
-		If partitioning_mode set to 1, the table_name is a prefix 
109
-		to separate table. i.e. sip_capture_01_02.
110 108
 		</para>
111 109
 		<para>
112 110
 		<emphasis>
... ...
@@ -123,23 +121,6 @@ modparam("sipcapture", "table_name", "homer_capture")
123 121
 </programlisting>
124 122
 		</example>
125 123
 	</section>
126
-        <section>
127
-                <title><varname>partitioning_mode</varname> (integer)</title>
128
-                <para>
129
-                If set to 0, records will store to separate table, depends on 
130
-		the day of the week and the hour of the day. Otherwise records 
131
-		will store into partitioning table. 
132
-                </para>
133
-                <para>
134
-                Default value is 1.
135
-                </para>
136
-                <example>
137
-                <title>partitioning_mode</title>
138
-                <programlisting format="linespecific">
139
-modparam("sipcapture", "partitioning_mode", 0)
140
-</programlisting>
141
-                </example>
142
-        </section>
143 124
         <section>
144 125
                 <title><varname>db_insert_mode</varname> (integer)</title>
145 126
                 <para>
... ...
@@ -411,13 +392,11 @@ modparam("sipcapture", "capture_node", "homer03")
411 392
 		<title>Database setup</title>
412 393
 		<para>
413 394
 		Before running &kamailio; with sipcapture, you have to setup the database 
414
-		tables where the module will store the data. For that, if the
415
-		table were not created by the installation script or you choose
416
-		to install everything by yourself you can use the sipcapture-create.sql or 
417
-		the sipcapture-st-create.sql <acronym>SQL</acronym> script in the database 
418
-		directories in the kamailio/scripts folder as template.
419
-		You can also find the complete database documentation on the
420
-		project webpage, &kamailiodbdocslink;.
395
+		tables where the module will store the data. For that, if the table were not 
396
+		created by the installation script or you choose to install everything by 
397
+		yourself you can use the sipcapture_create.sql, <acronym>SQL</acronym> script 
398
+		in the sql folder of sipcapture module as template. You can also find the 
399
+		complete database documentation on the project webpage, &kamailiodbdocslink;.
421 400
 		</para>
422 401
 	</section>
423 402
 	<section>
... ...
@@ -427,7 +406,7 @@ modparam("sipcapture", "capture_node", "homer03")
427 406
 		1. Only one capturing mode on RAW socket is supported: IPIP or monitoring/mirroring port. 
428 407
 		   Don't activate both at the same time.
429 408
 		2. By default MySQL doesn't support INSERT DELAYED for partitioning table. You can patch MySQL 
430
-		  (http://bugs.mysql.com/bug.php?id=50393) or use separate tables (pseudo partitioning)
409
+		  (http://bugs.mysql.com/bug.php?id=50393)
431 410
 		3. Mirroring port capturing works only on Linux.
432 411
 	
433 412
         </para>
434 413
deleted file mode 100644
... ...
@@ -1,34 +0,0 @@
1
-#!/usr/bin/perl
2
-
3
-#DEPRICATED. USE Partitioning scripts.
4
-
5
-#Crontab script, to clear table/partition for the next day
6
-#set crontab at 23:50
7
-
8
-my $mysqlstring = "/usr/bin/mysql -uhomer_user -phomer_password -hlocalhost homer_db";
9
-
10
-#homer node
11
-my $wday = (localtime())[6] + 1;
12
-#uncomment if you use separate tables
13
-#Separate tables
14
-#for(my $i=0; $i < 24; $i++) {
15
-#  my $query = sprintf("TRUNCATE TABLE sip_capture_%02d_%02d", $wday, $i);
16
-# `echo \"$query\"| $mysqlstring`;
17
-#}
18
-
19
-#uncomment if you use partitioning table and  MySQL >= 5.5
20
-#my $query = sprintf("ALTER TABLE sip_capture TRUNCATE PARTITION p%d", $wday);
21
-#`echo \"$query\"| $mysqlstring`;
22
-
23
-#or Mysql < 5.5
24
-my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time() - (86400*6));
25
-$year+=1900;
26
-$mon++;
27
-
28
-my $query = sprintf("DELETE FROM sip_capture WHERE `date` < '%d-%02d-%02d 00:00:00' ", $year, $mon, $mday);
29
-`echo \"$query\"| $mysqlstring`;
30
-
31
-#
32
-#   TODAYS TABLE
33
-#
34
-#
... ...
@@ -61,7 +61,7 @@ route {
61 61
 	#if (is_method("INVITE|UPDATE|NOTIFY|SUBSCRIBE|OPTIONS|REGISTER|BYE")) {
62 62
 		sip_capture();
63 63
 	#}
64
-	exit;
64
+	drop;
65 65
 }
66 66
 
67 67
 onreply_route {
... ...
@@ -71,5 +71,5 @@ onreply_route {
71 71
 	#if($rm =~ "^(INVITE|UPDATE|NOTIFY|SUBSCRIBE|OPTIONS|REGISTER|BYE)$") {
72 72
 		sip_capture();
73 73
 	#}	
74
-	exit;
74
+	drop;
75 75
 }
76 76
deleted file mode 100644
... ...
@@ -1,87 +0,0 @@
1
-#!/usr/bin/perl
2
-use DBI;
3
-
4
-$table = "sip_capture";
5
-$dbname = "homer_db";
6
-$maxparts = 20; #20 days
7
-$newparts = 1; #new partitions for 1 day. Script must start daily!
8
-
9
-my $db = DBI->connect("DBI:mysql:$dbname:localhost:3306", "mysql_login", "mysql_password");
10
-
11
-#$db->{PrintError} = 0;
12
-
13
-my $query = "SELECT TO_DAYS(NOW()),UNIX_TIMESTAMP(NOW() + INTERVAL 1 DAY)";
14
-$sth = $db->prepare($query);
15
-$sth->execute();
16
-my ($curtodays,$curtstamp) = $sth->fetchrow_array();
17
-$curtodays+=0; 
18
-$curtstamp+=0; 
19
-
20
-
21
-my $query = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.PARTITIONS"
22
-            ."\n WHERE TABLE_NAME='".$table."' AND TABLE_SCHEMA='".$dbname."'";
23
-$sth = $db->prepare($query);
24
-$sth->execute();
25
-my ($partcount) = $sth->fetchrow_array();
26
-
27
-while($partcount > ($maxparts + $newparts)) {
28
-
29
-    $query = "SELECT PARTITION_NAME, MIN(PARTITION_DESCRIPTION)"
30
-             ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$table."'"
31
-             ."\n AND TABLE_SCHEMA='".$dbname."';";
32
-             
33
-    $sth = $db->prepare($query);
34
-    $sth->execute();
35
-    my ($minpart,$todays) = $sth->fetchrow_array();
36
-    $todays+=0;
37
-    
38
-    #Dont' delete the partition for the current day or for future. Bad idea!
39
-    if($curtodays <= $todays) {    
40
-            $partcount=0;
41
-            next;
42
-    }
43
-        
44
-    #Delete
45
-    $query = "ALTER TABLE ".$table." DROP PARTITION ".$minpart;
46
-    $db->do($query);
47
-    if (!$db->{Executed}) {
48
-           print "Couldn't drop partition: $minpart\n";
49
-           break;
50
-    }
51
-}
52
-
53
-# < condition
54
-$curtodays+=1;
55
-
56
-#Create new partitions 
57
-for(my $i=0; $i<$newparts; $i++) {
58
-
59
-    $curtodays+=1;
60
-    
61
-    ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($curtstamp);
62
-
63
-    my $newpartname = sprintf("p%04d%02d%02d",($year+=1900),(++$mon),$mday);    
64
-    
65
-    $query = "SELECT COUNT(*) "
66
-             ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$table."'"
67
-             ."\n AND TABLE_SCHEMA='".$dbname."' AND PARTITION_NAME='".$newpartname."'"
68
-             ."\n AND PARTITION_DESCRIPTION = '".$curtodays."'";
69
-             
70
-    $sth = $db->prepare($query);
71
-    $sth->execute();
72
-    my ($exist) = $sth->fetchrow_array();
73
-    $exist+=0;
74
-    
75
-    if(!$exist) {
76
-    
77
-        # Fix MAXVALUE. Thanks Dorn B. <djbinter@gmail.com> for report and fix.
78
-        $query = "ALTER TABLE ".$table." REORGANIZE PARTITION pmax INTO (PARTITION ".$newpartname
79
-                                        ."\n VALUES LESS THAN (".$curtodays.") ENGINE = MyISAM, PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = MyISAM)";                                                         
80
-        $db->do($query);
81
-        if (!$db->{Executed}) {
82
-             print "Couldn't add partition: $newpartname\n";
83
-        }
84
-    }
85
-    
86
-    $curtstamp += 86400;
87
-}
... ...
@@ -1,19 +1,109 @@
1 1
 #!/usr/bin/perl
2
+#
3
+# partrotate_unixtimestamp - perl script for mySQL partition rotation
4
+#
5
+# Copyright (C) 2011 Alexandr Dubovikov (QSC AG) (alexandr.dubovikov@gmail.com)
6
+#
7
+# This file is part of webhomer, a free capture server.
8
+#
9
+# partrotate_unixtimestamp is free software; you can redistribute it and/or modify
10
+# it under the terms of the GNU General Public License as published by
11
+# the Free Software Foundation; either version 2 of the License, or
12
+# (at your option) any later version
13
+#
14
+# partrotate_unixtimestamp is distributed in the hope that it will be useful,
15
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+# GNU General Public License for more details.
18
+#
19
+# You should have received a copy of the GNU General Public License
20
+# along with this program; if not, write to the Free Software
21
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2 22
 
3 23
 use DBI;
4 24
 
5
-$table = "sip_capture";
6
-$dbname = "homer_db";
7
-$maxparts = 6; #6 days
8
-$newparts = 1; #new partitions for 1 day. Script must start daily!
25
+$version = "0.2.2";
26
+$mysql_table = "sip_capture";
27
+$mysql_dbname = "homer_db";
28
+$mysql_user = "mysql_login";
29
+$mysql_password = "mysql_password";
30
+$mysql_host = "localhost";
31
+$maxparts = 6; #6 days How long keep the data in the DB
32
+$newparts = 2; #new partitions for 2 days. Anyway, start this script daily!
33
+@stepsvalues = (86400, 3600, 1800, 900); 
34
+$partstep = 0; # 0 - Day, 1 - Hour, 2 - 30 Minutes, 3 - 15 Minutes 
35
+
36
+#Check it
37
+$partstep=0 if(!defined $stepsvalues[$partstep]);
38
+#Mystep
39
+$mystep = $stepsvalues[$partstep];
40
+#Coof
41
+$coof=int(86400/$mystep);
42
+
43
+#How much partitions
44
+$maxparts*=$coof;
45
+$newparts*=$coof;
46
+
47
+my $db = DBI->connect("DBI:mysql:$mysql_dbname:$mysql_host:3306", $mysql_user, $mysql_password);
9 48
 
10
-#Hours
11
-$maxparts*=24;
12
-$newparts*=24;
49
+#$db->{PrintError} = 0;
13 50
 
14
-my $db = DBI->connect("DBI:mysql:$dbname:localhost:3306", "mysql_login", "mysql_password");
51
+my $sth = $db->do("
52
+CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
53
+  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
54
+  `date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
55
+  `micro_ts` bigint(18) NOT NULL DEFAULT '0',
56
+  `method` varchar(50) NOT NULL DEFAULT '',
57
+  `reply_reason` varchar(100) NOT NULL,
58
+  `ruri` varchar(200) NOT NULL DEFAULT '',
59
+  `ruri_user` varchar(100) NOT NULL DEFAULT '',
60
+  `from_user` varchar(100) NOT NULL DEFAULT '',
61
+  `from_tag` varchar(64) NOT NULL DEFAULT '',
62
+  `to_user` varchar(100) NOT NULL DEFAULT '',
63
+  `to_tag` varchar(64) NOT NULL,
64
+  `pid_user` varchar(100) NOT NULL DEFAULT '',
65
+  `contact_user` varchar(120) NOT NULL,
66
+  `auth_user` varchar(120) NOT NULL,
67
+  `callid` varchar(100) NOT NULL DEFAULT '',
68
+  `callid_aleg` varchar(100) NOT NULL DEFAULT '',
69
+  `via_1` varchar(256) NOT NULL,
70
+  `via_1_branch` varchar(80) NOT NULL,
71
+  `cseq` varchar(25) NOT NULL,
72
+  `diversion` varchar(256) NOT NULL,
73
+  `reason` varchar(200) NOT NULL,
74
+  `content_type` varchar(256) NOT NULL,
75
+  `authorization` varchar(256) NOT NULL,
76
+  `user_agent` varchar(256) NOT NULL,
77
+  `source_ip` varchar(50) NOT NULL DEFAULT '',
78
+  `source_port` int(10) NOT NULL,
79
+  `destination_ip` varchar(50) NOT NULL DEFAULT '',
80
+  `destination_port` int(10) NOT NULL,
81
+  `contact_ip` varchar(60) NOT NULL,
82
+  `contact_port` int(10) NOT NULL,
83
+  `originator_ip` varchar(60) NOT NULL DEFAULT '',
84
+  `originator_port` int(10) NOT NULL,
85
+  `proto` int(5) NOT NULL,
86
+  `family` int(1) DEFAULT NULL,
87
+  `rtp_stat` varchar(256) NOT NULL,
88
+  `type` int(2) NOT NULL,
89
+  `node` varchar(125) NOT NULL,
90
+  `msg` text NOT NULL,
91
+  PRIMARY KEY (`id`,`date`),
92
+  KEY `ruri_user` (`ruri_user`),
93
+  KEY `from_user` (`from_user`),
94
+  KEY `to_user` (`to_user`),
95
+  KEY `pid_user` (`pid_user`),
96
+  KEY `auth_user` (`auth_user`),
97
+  KEY `callid_aleg` (`callid_aleg`),
98
+  KEY `date` (`date`),
99
+  KEY `callid` (`callid`),
100
+  KEY `method` (`method`),
101
+  KEY `source_ip` (`source_ip`),
102
+  KEY `destination_ip` (`destination_ip`)
103
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
104
+PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`)) (PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = MyISAM);
105
+");
15 106
 
16
-#$db->{PrintError} = 0;
17 107
 
18 108
 my $query = "SELECT UNIX_TIMESTAMP(CURDATE() - INTERVAL 1 DAY)";
19 109
 $sth = $db->prepare($query);
... ...
@@ -21,22 +111,17 @@ $sth->execute();
21 111
 my ($curtstamp) = $sth->fetchrow_array();
22 112
 $curtstamp+=0; 
23 113
 
24
-#print "ZZ: $curtstamp: $maxparts, $newparts\n";
25
-#exit;
26
-
27 114
 my $query = "SELECT COUNT(*) FROM INFORMATION_SCHEMA.PARTITIONS"
28
-            ."\n WHERE TABLE_NAME='".$table."' AND TABLE_SCHEMA='".$dbname."'";
115
+            ."\n WHERE TABLE_NAME='".$mysql_table."' AND TABLE_SCHEMA='".$mysql_dbname."'";
29 116
 $sth = $db->prepare($query);
30 117
 $sth->execute();
31 118
 my ($partcount) = $sth->fetchrow_array();
32 119
 
33
-#print "$query\nZ: $partcount\n";
34
-
35
-while($partcount > ($maxparts + $newparts)) {
120
+while($partcount > $maxparts ) {
36 121
 
37 122
     $query = "SELECT PARTITION_NAME, MIN(PARTITION_DESCRIPTION)"
38
-             ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$table."'"
39
-             ."\n AND TABLE_SCHEMA='".$dbname."';";
123
+             ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$mysql_table."'"
124
+             ."\n AND TABLE_SCHEMA='".$mysql_dbname."';";
40 125
 
41 126
     $sth = $db->prepare($query);
42 127
     $sth->execute();
... ...
@@ -50,12 +135,15 @@ while($partcount > ($maxparts + $newparts)) {
50 135
     }
51 136
            
52 137
     #Delete
53
-    $query = "ALTER TABLE ".$table." DROP PARTITION ".$minpart;
138
+    $query = "ALTER TABLE ".$mysql_table." DROP PARTITION ".$minpart;
54 139
     $db->do($query);
55 140
     if (!$db->{Executed}) {
56 141
            print "Couldn't drop partition: $minpart\n";
57 142
            break;
58 143
     }
144
+    
145
+    #decrease partcount
146
+    $partcount--;
59 147
 }
60 148
 
61 149
 # < condition
... ...
@@ -65,15 +153,16 @@ $curtstamp+=(86400);
65 153
 for(my $i=0; $i<$newparts; $i++) {
66 154
 
67 155
     $oldstamp = $curtstamp;
68
-    $curtstamp+=3600;
156
+    $curtstamp+=$mystep;
69 157
     
70 158
     ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($oldstamp);
71 159
 
72 160
     my $newpartname = sprintf("p%04d%02d%02d%02d",($year+=1900),(++$mon),$mday,$hour);    
161
+    $newpartname.= sprintf("%02d", $min) if($partstep > 1);
73 162
     
74 163
     $query = "SELECT COUNT(*) "
75
-             ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$table."'"
76
-             ."\n AND TABLE_SCHEMA='".$dbname."' AND PARTITION_NAME='".$newpartname."'"
164
+             ."\n FROM INFORMATION_SCHEMA.PARTITIONS WHERE TABLE_NAME='".$mysql_table."'"
165
+             ."\n AND TABLE_SCHEMA='".$mysql_dbname."' AND PARTITION_NAME='".$newpartname."'"
77 166
              ."\n AND PARTITION_DESCRIPTION = '".$curtstamp."'";
78 167
              
79 168
     $sth = $db->prepare($query);
... ...
@@ -84,7 +173,7 @@ for(my $i=0; $i<$newparts; $i++) {
84 173
     if(!$exist) {
85 174
 
86 175
 	# Fix MAXVALUE. Thanks Dorn B. <djbinter@gmail.com> for report and fix.
87
-        $query = "ALTER TABLE ".$table." REORGANIZE PARTITION pmax INTO (PARTITION ".$newpartname
176
+        $query = "ALTER TABLE ".$mysql_table." REORGANIZE PARTITION pmax INTO (PARTITION ".$newpartname
88 177
                                 ."\n VALUES LESS THAN (".$curtstamp.") ENGINE = MyISAM, PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = MyISAM)";  
89 178
 
90 179
         $db->do($query);
91 180
new file mode 100644
... ...
@@ -0,0 +1,156 @@
1
+#!/usr/bin/perl
2
+#
3
+# statistics.pl - perl script for Homer statistic
4
+#
5
+# Copyright (C) 2011 Alexandr Dubovikov (QSC AG) (alexandr.dubovikov@gmail.com)
6
+#
7
+# This file is part of webhomer, a free capture server.
8
+#
9
+# statistics is free software; you can redistribute it and/or modify
10
+# it under the terms of the GNU General Public License as published by
11
+# the Free Software Foundation; either version 2 of the License, or
12
+# (at your option) any later version
13
+#
14
+# statistics is distributed in the hope that it will be useful,
15
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
+# GNU General Public License for more details.
18
+#
19
+# You should have received a copy of the GNU General Public License
20
+# along with this program; if not, write to the Free Software
21
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
+
23
+use DBI;
24
+
25
+$version = "0.0.2";
26
+$mysql_table = "sip_capture";
27
+$mysql_dbname = "homer_db";
28
+$mysql_user = "homer_user";
29
+$mysql_password = "homer_password";
30
+$mysql_host = "localhost";
31
+$statsmethod = "stats_method";
32
+$statsuseragent = "stats_useragent";
33
+$keepdays = 100; #How long statistic must be keeped in DB
34
+$step = 300; # in seconds! for 5 minutes statistic. Script must start each 5 minutes 
35
+#Crontab:
36
+#*/5 * * * * statistic.pl 2>&1 > /dev/null
37
+
38
+my $db = DBI->connect("DBI:mysql:$mysql_dbname:$mysql_host:3306", $mysql_user, $mysql_password);
39
+
40
+#$db->{PrintError} = 0;
41
+
42
+@nowtime = localtime();
43
+@oldtime = localtime(time()-$step);
44
+
45
+#($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime();
46
+
47
+my $to_date = sprintf("'%04d-%02d-%02d %02d:%02d:00'",($nowtime[5]+=1900),(++$nowtime[4]),$nowtime[3],$nowtime[2], $nowtime[1]);
48
+my $from_date = sprintf("'%04d-%02d-%02d %02d:%02d:00'",($oldtime[5]+=1900),(++$oldtime[4]),$oldtime[3],$oldtime[2], $oldtime[1]);
49
+
50
+#QUERY
51
+my $mainquery = "FROM ".$mysql_table.$wheredata." WHERE `date` BETWEEN $from_date AND $to_date";
52
+#My ASR AND NER == 0 at this time;
53
+$ner = 0;
54
+$asr = 0;
55
+
56
+#statistic
57
+#ALL AND CURRENT PACKETS. ALL = ALL MESSAGES IN DB. CURRENT = MESSAGES IN THIS INTERVALL
58
+##############################################################################################
59
+$all = loadResult("SELECT COUNT(*) FROM ".$mysql_table);
60
+insertStat("stats_method","method='ALL',total='".$all."'");
61
+
62
+$current = loadResult("SELECT COUNT(*) ".$mainquery);
63
+insertStat("stats_method","method='CURRENT',total='".$current."'");
64
+
65
+##################################   INVITE ########################################################
66
+#ALL INVITES
67
+$invites = loadResult("SELECT COUNT(*) ".$mainquery." AND method = 'INVITE'");
68
+#ALL 407 for INVITE
69
+$auth = loadResult("SELECT COUNT(*) ".$mainquery." AND method = '407' AND cseq like '% INVITE'");
70
+#Total invites without AUTH
71
+$totalinvites = $invites - $auth;
72
+
73
+#ASR/NER
74
+#Ansered INVITES
75
+$answered = loadResult("SELECT COUNT(*) ".$mainquery." AND method='200' AND cseq like '% INVITE'");
76
+#NER
77
+$bad486 = loadResult("SELECT COUNT(*) ".$mainquery." AND method IN ('486','487','603') AND cseq like '% INVITE'");
78
+#UNSANSWERED
79
+$unanswered = $totalinvites - $answered;
80
+
81
+#fix for retransmitions
82
+if($unanswered < 0) { $unanswered = 0; }
83
+if($answered > $totalinvites) { $answered=$totalinvites; }
84
+
85
+if($totalinvites > 0) {
86
+  $ner = sprintf( "%.0f", ($answered+$bad486)/$totalinvites*100);
87
+  $asr = sprintf( "%.0f", $answered/$totalinvites*100);
88
+}
89
+
90
+$value="method='INVITE',total='".$invites."',auth='".$auth."',completed='"
91
+    .$answered."',uncompleted='".$unanswered."',rejected='".$bad486."',asr='".$asr."',ner='".$ner."'";
92
+insertStat($statsmethod,$value);
93
+
94
+##################################  REGISTERED ########################################################
95
+#ALL REGISTRATION
96
+$registers = loadResult("SELECT COUNT(*) ".$mainquery." AND method = 'REGISTER'");
97
+#ALL 401 for REGISTER
98
+$regiserauth = loadResult("SELECT COUNT(*) ".$mainquery." AND method = '401' AND cseq like '% REGISTER'");
99
+#REGISTERED! for expire =0 will be also calculate as registered. Bad idea but no chance :-/
100
+$registered = loadResult("SELECT COUNT(*) ".$mainquery." AND method='200' AND cseq like '% REGISTER'");
101
+
102
+#Bad register
103
+$badregister=0;
104
+$badregister = $regiserauth - $registered if($registered < $regiserauth);
105
+insertStat($statsmethod,"method='REGISTER', uncompleted='".$badregister."', total='".$registers."',auth='".$regiserauth."',completed='".$registered."'");
106
+
107
+#USER AGENT
108
+#REGISTRATION
109
+$query = "SELECT user_agent, COUNT(*) as cnt ".$mainquery." AND method = 'REGISTER' GROUP BY user_agent";
110
+$sth = $db->prepare($query);
111
+$sth->execute();
112
+while ( @row = $sth->fetchrow_array ) {
113
+    $myuas = $db->quote($row[0]);
114
+    insertStat($statsuseragent,"method='REGISTER',useragent=".$myuas.",total=".$row[1]);
115
+}
116
+
117
+#INVITES
118
+$query = "SELECT user_agent, COUNT(*) as cnt ".$mainquery." AND method = 'INVITE' GROUP BY user_agent";
119
+$sth = $db->prepare($query);
120
+$sth->execute();
121
+while ( @row = $sth->fetchrow_array ) {
122
+    $myuas = $db->quote($row[0]);
123
+    insertStat($statsuseragent,"method='INVITE',useragent=".$myuas.",total=".$row[1]);
124
+}
125
+
126
+#Time for CLEAR OLD records;
127
+clearOldData() if($nowtime[2] == 0 && $nowtime[1] == 0) ;
128
+
129
+sub loadResult() {
130
+    my $query = shift;
131
+    $sth = $db->prepare($query);
132
+    $sth->execute();
133
+    my $result = $sth->fetchrow_array();
134
+    return $result;
135
+}
136
+
137
+sub insertStat() {
138
+    my $table = shift;
139
+    my $values = shift;
140
+    my $query = "INSERT INTO ".$table." SET `from_date`=".$from_date.", `to_date`=".$to_date.",".$values;
141
+    $sth2 = $db->prepare($query);
142
+    $sth2->execute();
143
+    return 1;
144
+}
145
+
146
+sub clearOldData() {
147
+  $query = "DELETE FROM ".$statsmethod." WHERE `from_date` < UNIX_TIMESTAMP(CURDATE() - INTERVAL ".$keepdays." DAY)";
148
+  $sth = $db->prepare($query);
149
+  $sth->execute();
150
+
151
+  $query = "DELETE FROM ".$statsuseragent." WHERE `from_date` < UNIX_TIMESTAMP(CURDATE() - INTERVAL ".$keepdays." DAY)";
152
+  $sth = $db->prepare($query);
153
+  $sth->execute();
154
+}
155
+
156
+
... ...
@@ -116,6 +116,7 @@ struct _sipcapture_object {
116 116
 	int family;
117 117
 	str rtp_stat;
118 118
 	int type;
119
+        long long tmstamp;
119 120
 	str node;	
120 121
 	str msg;	
121 122
 #ifdef STATISTICS
... ...
@@ -199,7 +200,6 @@ int moni_port_start = 0;
199 200
 int moni_port_end   = 0;
200 201
 int *capture_on_flag = NULL;
201 202
 int db_insert_mode = 0;
202
-int partitioning_mode = 1;
203 203
 int promisc_on = 0;
204 204
 int bpf_on = 0;
205 205
 
... ...
@@ -225,6 +225,9 @@ static struct sock_filter BPF_code[] = { { 0x28, 0, 0, 0x0000000c }, { 0x15, 0,
225 225
 db1_con_t *db_con = NULL; 		/*!< database connection */
226 226
 db_func_t db_funcs;      		/*!< Database functions */
227 227
 
228
+struct hep_timehdr* heptime;
229
+
230
+
228 231
 /*! \brief
229 232
  * Exported functions
230 233
  */
... ...
@@ -286,7 +289,6 @@ static param_export_t params[] = {
286 289
         {"raw_ipip_capture_on",  	INT_PARAM, &ipip_capture_on  },	
287 290
         {"raw_moni_capture_on",  	INT_PARAM, &moni_capture_on  },	
288 291
         {"db_insert_mode",  		INT_PARAM, &db_insert_mode  },	
289
-        {"partitioning_mode",  		INT_PARAM, &partitioning_mode  },
290 292
 	{"raw_interface",     		STR_PARAM, &raw_interface.s   },
291 293
         {"promiscious_on",  		INT_PARAM, &promisc_on   },		
292 294
         {"raw_moni_bpf_on",  		INT_PARAM, &bpf_on   },		
... ...
@@ -419,8 +421,8 @@ static int mod_init(void) {
419 421
 	}
420 422
 
421 423
 
422
-	if(partitioning_mode && db_insert_mode) {
423
-                LM_INFO("INFO: sipcapture: mod_init: you have enabled INSERT DELAYED for partitioning table \
424
+	if(db_insert_mode) {
425
+                LM_INFO("INFO: sipcapture: mod_init: you have enabled INSERT DELAYED \
424 426
                                 Make sure your DB can support it\n");
425 427
         }
426 428
 
... ...
@@ -434,12 +436,12 @@ static int mod_init(void) {
434 436
 	
435 437
 	/* register DGRAM event */
436 438
 	if(sr_event_register_cb(SREV_NET_DGRAM_IN, hep_msg_received) < 0) {
437
-		LM_ERR("ERROR:sipcapture:mod_init: failed to register SREV_NET_DGRAM_IN event\n");
439
+		LM_ERR("failed to register SREV_NET_DGRAM_IN event\n");
438 440
 		return -1;		                	
439 441
 	}
440 442
 
441 443
 	if(ipip_capture_on && moni_capture_on) {
442
-		LM_ERR("ERROR:sipcapture:mod_init: only one RAW mode is supported. Please disable ipip_capture_on or moni_capture_on\n");
444
+		LM_ERR("only one RAW mode is supported. Please disable ipip_capture_on or moni_capture_on\n");
443 445
 		return -1;		                		
444 446
 	}
445 447
 	
... ...
@@ -551,6 +553,13 @@ static int child_init(int rank)
551 553
 		LM_ERR("unable to connect to database. Please check configuration.\n");
552 554
 		return -1;
553 555
 	}
556
+	
557
+	heptime = (struct hep_timehdr*)pkg_malloc(sizeof(struct hep_timehdr));
558
+        if(heptime==NULL) {
559
+                LM_ERR("no more pkg memory left\n");
560
+                return -1;
561
+        }
562
+
554 563
 
555 564
 	return 0;
556 565
 }
... ...
@@ -586,6 +595,8 @@ static void destroy(void)
586 595
 	if (capture_on_flag)
587 596
 		shm_free(capture_on_flag);
588 597
 		
598
+        if(heptime) pkg_free(heptime);
599
+
589 600
 	if(raw_sock_desc > 0) {
590 601
 		 if(promisc_on && raw_interface.len) {
591 602
 #ifdef __OS_linux
... ...
@@ -619,6 +630,9 @@ int hep_msg_received(void *data)
619 630
         char *hep_payload, *end, *p, *hep_ip;
620 631
         struct hep_iphdr *hepiph = NULL;
621 632
 
633
+	struct hep_timehdr* heptime_tmp = NULL;
634
+        memset(heptime, 0, sizeof(struct hep_timehdr));
635
+
622 636
 #ifdef USE_IPV6
623 637
         struct hep_ip6hdr *hepip6h = NULL;
624 638
 #endif /* USE_IPV6 */
... ...
@@ -660,7 +674,7 @@ int hep_msg_received(void *data)
660 674
                 }
661 675
 
662 676
 	/* Check version */
663
-        if(heph->hp_v != 1 || hl != heph->hp_l) {
677
+        if((heph->hp_v != 1 && heph->hp_v != 2) || hl != heph->hp_l) {
664 678
         	LOG(L_ERR, "ERROR: sipcapture:hep_msg_received: not supported version or bad length: v:[%d] l:[%d] vs [%d]\n",
665 679
                                                 heph->hp_v, heph->hp_l, hl);
666 680
                 return -1;
... ...
@@ -708,6 +722,18 @@ int hep_msg_received(void *data)
708 722
                 return -1;
709 723
 	}
710 724
 
725
+	/* timming */
726
+        if(heph->hp_v == 2) {
727
+                offset+=sizeof(struct hep_timehdr);
728
+                heptime_tmp = (struct hep_timehdr*) hep_payload;
729
+
730
+                heptime->tv_sec = heptime_tmp->tv_sec;
731
+                heptime->tv_usec = heptime_tmp->tv_usec;
732
+                heptime->captid = heptime_tmp->captid;
733
+        }
734
+
735
+
736
+
711 737
 	/* fill ip from the packet to dst_ip && to */
712 738
         switch(heph->hp_f){
713 739
 
... ...
@@ -759,12 +785,6 @@ static int sip_capture_store(struct _sipcapture_object *sco)
759 785
 {
760 786
 	db_key_t db_keys[NR_KEYS];
761 787
 	db_val_t db_vals[NR_KEYS];
762
-	struct timeval tvb;
763
-	struct timezone tz;
764
-	char tmptable[TABLE_LEN];
765
-        int ret = 0;
766
-        struct tm *t;
767
-        str dbtable;
768 788
 	               	
769 789
 	if(sco==NULL)
770 790
 	{
... ...
@@ -772,10 +792,6 @@ static int sip_capture_store(struct _sipcapture_object *sco)
772 792
 		return -1;
773 793
 	}
774 794
 	
775
-	gettimeofday( &tvb, &tz );
776
-	
777
-	t = localtime(&tvb.tv_sec);
778
-
779 795
 	db_keys[0] = &id_column;			
780 796
         db_vals[0].type = DB1_INT;
781 797
         db_vals[0].nul = 0;
... ...
@@ -789,7 +805,7 @@ static int sip_capture_store(struct _sipcapture_object *sco)
789 805
 	db_keys[2] = &micro_ts_column;			
790 806
         db_vals[2].type = DB1_BIGINT;
791 807
         db_vals[2].nul = 0;
792
-        db_vals[2].val.ll_val = (unsigned long long)tvb.tv_sec*1000000+tvb.tv_usec; /* micro ts */
808
+        db_vals[2].val.ll_val = sco->tmstamp;
793 809
 	
794 810
 	db_keys[3] = &method_column;
795 811
 	db_vals[3].type = DB1_STR;
... ...
@@ -961,23 +977,9 @@ static int sip_capture_store(struct _sipcapture_object *sco)
961 977
 	db_vals[36].nul = 0;
962 978
 	db_vals[36].val.blob_val = sco->msg;	
963 979
 		
964
-	DBG("homer table: [%.*s]\n", table_name.len, table_name.s);		
965
-	if(!partitioning_mode) {
966
-                ret = snprintf(tmptable, TABLE_LEN, "%.*s_%02d_%02d",
967
-                        table_name.len, table_name.s, (t->tm_wday == 0) ? 7 : t->tm_wday , t->tm_hour);
968
-                if(ret < 0 || ret >=TABLE_LEN) {
969
-                        LM_ERR("error create table name\n");
970
-                        goto error;
971
-                }
972
-
973
-                dbtable.s = tmptable;
974
-                dbtable.len = strlen(tmptable);
975
-        }
976
-        else { 
977
-           dbtable =  table_name;
978
-        }
979
-        
980
-	db_funcs.use_table(db_con, &dbtable);
980
+	LM_DBG("homer table: [%.*s]\n", table_name.len, table_name.s);		
981
+                
982
+	db_funcs.use_table(db_con, &table_name);
981 983
 
982 984
 	LM_DBG("storing info...\n");
983 985
 	
... ...
@@ -1010,9 +1012,17 @@ static int sip_capture(struct sip_msg *msg, char *s1, char *s2)
1010 1012
 	contact_body_t*  cb=0;	        	        
1011 1013
 	char buf_ip[IP_ADDR_MAX_STR_SIZE+12];
1012 1014
 	char *port_str = NULL, *tmp = NULL;
1015
+	struct timeval tvb;
1016
+        struct timezone tz;
1017
+        char tmp_node[100];
1018
+        char rtpinfo[256];
1019
+        unsigned int len = 0;
1013 1020
 	                                          
1014 1021
 	LM_DBG("CAPTURE DEBUG...\n");
1015 1022
 
1023
+	gettimeofday( &tvb, &tz );
1024
+	        
1025
+
1016 1026
 	if(msg==NULL) {
1017 1027
 		LM_DBG("nothing to capture\n");
1018 1028
 		return -1;
... ...
@@ -1051,6 +1061,17 @@ static int sip_capture(struct sip_msg *msg, char *s1, char *s2)
1051 1061
 		EMPTY_STR(sco.ruri);
1052 1062
 		EMPTY_STR(sco.ruri_user);
1053 1063
 	}
1064
+
1065
+	if(heptime && heptime->tv_sec != 0) {
1066
+               sco.tmstamp = (unsigned long long)heptime->tv_sec*1000000+heptime->tv_usec; /* micro ts */
1067
+               snprintf(tmp_node, 100, "%.*s:%i", capture_node.len, capture_node.s, heptime->captid);
1068
+               sco.node.s = tmp_node;
1069
+               sco.node.len = strlen(tmp_node);
1070
+        }
1071
+        else {
1072
+               sco.tmstamp = (unsigned long long)tvb.tv_sec*1000000+tvb.tv_usec; /* micro ts */
1073
+               sco.node = capture_node;
1074
+        }
1054 1075
 	
1055 1076
 	/* Parse FROM */
1056 1077
         if(msg->from) {
... ...
@@ -1217,6 +1238,22 @@ static int sip_capture(struct sip_msg *msg, char *s1, char *s2)
1217 1238
 	else if((tmphdr[3] = get_hdr_by_name(msg,"P-RTP-Stat", 10)) != NULL) {
1218 1239
 		sco.rtp_stat =  tmphdr[3]->body;
1219 1240
 	}	                         	
1241
+	/* RTP-RxStat */
1242
+        else if((tmphdr[3] = get_hdr_by_name(msg,"RTP-RxStat", 10)) != NULL) {
1243
+                if(tmphdr[3]->body.len > 250) tmphdr[3]->body.len = 250;
1244
+
1245
+                memcpy(&rtpinfo, tmphdr[3]->body.s, tmphdr[3]->body.len);
1246
+                len = tmphdr[3]->body.len;
1247
+                if((tmphdr[3] = get_hdr_by_name(msg,"RTP-TxStat", 10)) != NULL) {
1248
+                        memcpy(&rtpinfo[len], ", ", 2);
1249
+                        if((len + 2 + tmphdr[3]->body.len) > 256) tmphdr[3]->body.len = 256 - (len+2);
1250
+                        memcpy(&rtpinfo[len+2], tmphdr[3]->body.s, tmphdr[3]->body.len);
1251
+                }
1252
+                sco.rtp_stat.s =  rtpinfo;
1253
+                sco.rtp_stat.len =  strlen(rtpinfo);
1254
+        }
1255
+
1256
+
1220 1257
 	else { EMPTY_STR(sco.rtp_stat); }	
1221 1258
 	
1222 1259
 		
... ...
@@ -1229,9 +1266,6 @@ static int sip_capture(struct sip_msg *msg, char *s1, char *s2)
1229 1266
 	/* MESSAGE TYPE */
1230 1267
 	sco.type = msg->first_line.type;
1231 1268
 	
1232
-	/* Our node name */
1233
-	sco.node = capture_node;
1234
-	
1235 1269
 	/* MSG */	
1236 1270
 	sco.msg.s = msg->buf;
1237 1271
 	sco.msg.len = msg->len;	        
... ...
@@ -44,6 +44,12 @@ struct hep_iphdr{
44 44
         struct in_addr hp_dst;      /* source and dest address */
45 45
 };
46 46
 
47
+struct hep_timehdr{
48
+   u_int32_t tv_sec;         /* seconds */
49
+   u_int32_t tv_usec;        /* useconds */
50
+   u_int16_t captid;          /* Capture ID node */
51
+};
52
+
47 53
 #ifdef USE_IPV6
48 54
 struct hep_ip6hdr {
49 55
         struct in6_addr hp6_src;        /* source address */
50 56
deleted file mode 100644
... ...
@@ -1,83 +0,0 @@
1
-/* 
2
- * only for MYSQL >= 5.1.58 and if you expect MASSIV SIP TRAFFIC
3
-*/
4
-
5
-/*!40101 SET @saved_cs_client     = @@character_set_client */;
6
-/*!40101 SET character_set_client = utf8 */;
7
-CREATE TABLE `sip_capture` (
8
-  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
9
-  `date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
10
-  `micro_ts` bigint(18) NOT NULL DEFAULT '0',
11
-  `method` varchar(50) NOT NULL DEFAULT '',
12
-  `reply_reason` varchar(100) NOT NULL,
13
-  `ruri` varchar(200) NOT NULL DEFAULT '',
14
-  `ruri_user` varchar(100) NOT NULL DEFAULT '',
15
-  `from_user` varchar(100) NOT NULL DEFAULT '',
16
-  `from_tag` varchar(64) NOT NULL DEFAULT '',
17
-  `to_user` varchar(100) NOT NULL DEFAULT '',
18
-  `to_tag` varchar(64) NOT NULL,
19
-  `pid_user` varchar(100) NOT NULL DEFAULT '',
20
-  `contact_user` varchar(120) NOT NULL,
21
-  `auth_user` varchar(120) NOT NULL,
22
-  `callid` varchar(100) NOT NULL DEFAULT '',
23
-  `callid_aleg` varchar(100) NOT NULL DEFAULT '',
24
-  `via_1` varchar(256) NOT NULL,
25
-  `via_1_branch` varchar(80) NOT NULL,
26
-  `cseq` varchar(25) NOT NULL,
27
-  `diversion` varchar(256) NOT NULL,
28
-  `reason` varchar(200) NOT NULL,
29
-  `content_type` varchar(256) NOT NULL,
30
-  `authorization` varchar(256) NOT NULL,
31
-  `user_agent` varchar(256) NOT NULL,
32
-  `source_ip` varchar(50) NOT NULL DEFAULT '',
33
-  `source_port` int(10) NOT NULL,
34
-  `destination_ip` varchar(50) NOT NULL DEFAULT '',
35
-  `destination_port` int(10) NOT NULL,
36
-  `contact_ip` varchar(60) NOT NULL,
37
-  `contact_port` int(10) NOT NULL,
38
-  `originator_ip` varchar(60) NOT NULL DEFAULT '',
39
-  `originator_port` int(10) NOT NULL,
40
-  `proto` int(5) NOT NULL,
41
-  `family` int(1) DEFAULT NULL,
42
-  `rtp_stat` varchar(256) NOT NULL,
43
-  `type` int(2) NOT NULL,
44
-  `node` varchar(125) NOT NULL,
45
-  `msg` blob NOT NULL,
46
-  PRIMARY KEY (`id`,`date`),
47
-  KEY `ruri_user` (`ruri_user`),
48
-  KEY `from_user` (`from_user`),
49
-  KEY `to_user` (`to_user`),
50
-  KEY `pid_user` (`pid_user`),
51
-  KEY `auth_user` (`auth_user`),
52
-  KEY `callid_aleg` (`callid_aleg`),
53
-  KEY `date` (`date`),
54
-  KEY `callid` (`callid`)
55
-) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
56
-PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`) ) (
57
-PARTITION p2011082500 VALUES LESS THAN (1314216000) ENGINE = MyISAM,
58
-PARTITION p2011082501 VALUES LESS THAN (1314219600) ENGINE = MyISAM,
59
-PARTITION p2011082502 VALUES LESS THAN (1314223200) ENGINE = MyISAM,
60
-PARTITION p2011082503 VALUES LESS THAN (1314226800) ENGINE = MyISAM,
61
-PARTITION p2011082504 VALUES LESS THAN (1314230400) ENGINE = MyISAM,
62
-PARTITION p2011082505 VALUES LESS THAN (1314234000) ENGINE = MyISAM,
63
-PARTITION p2011082506 VALUES LESS THAN (1314237600) ENGINE = MyISAM,
64
-PARTITION p2011082507 VALUES LESS THAN (1314241200) ENGINE = MyISAM,
65
-PARTITION p2011082508 VALUES LESS THAN (1314244800) ENGINE = MyISAM,
66
-PARTITION p2011082509 VALUES LESS THAN (1314248400) ENGINE = MyISAM,
67
-PARTITION p2011082510 VALUES LESS THAN (1314252000) ENGINE = MyISAM,
68
-PARTITION p2011082511 VALUES LESS THAN (1314255600) ENGINE = MyISAM,
69
-PARTITION p2011082512 VALUES LESS THAN (1314259200) ENGINE = MyISAM,
70
-PARTITION p2011082513 VALUES LESS THAN (1314262800) ENGINE = MyISAM,
71
-PARTITION p2011082514 VALUES LESS THAN (1314266400) ENGINE = MyISAM,
72
-PARTITION p2011082515 VALUES LESS THAN (1314270000) ENGINE = MyISAM,
73
-PARTITION p2011082516 VALUES LESS THAN (1314273600) ENGINE = MyISAM,
74
-PARTITION p2011082517 VALUES LESS THAN (1314277200) ENGINE = MyISAM,
75
-PARTITION p2011082518 VALUES LESS THAN (1314280800) ENGINE = MyISAM,
76
-PARTITION p2011082519 VALUES LESS THAN (1314284400) ENGINE = MyISAM,
77
-PARTITION p2011082520 VALUES LESS THAN (1314288000) ENGINE = MyISAM,
78
-PARTITION p2011082521 VALUES LESS THAN (1314291600) ENGINE = MyISAM,
79
-PARTITION p2011082522 VALUES LESS THAN (1314295200) ENGINE = MyISAM,
80
-PARTITION p2011082523 VALUES LESS THAN (1314298800) ENGINE = MyISAM,
81
-PARTITION pmax VALUES LESS THAN (MAXVALUE)
82
-);
83
-
84 0
similarity index 73%
85 1
rename from modules/sipcapture/sql/sipcapture-create.sql
86 2
rename to modules/sipcapture/sql/create_sipcapture.sql
... ...
@@ -1,6 +1,7 @@
1
+/* 
2
+ * only for MYSQL >= 5.1.43
3
+*/
1 4
 
2
-
3
-DROP TABLE IF EXISTS `sip_capture`;
4 5
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
5 6
 /*!40101 SET character_set_client = utf8 */;
6 7
 CREATE TABLE `sip_capture` (
... ...
@@ -41,7 +42,7 @@ CREATE TABLE `sip_capture` (
41 42
   `rtp_stat` varchar(256) NOT NULL,
42 43
   `type` int(2) NOT NULL,
43 44
   `node` varchar(125) NOT NULL,
44
-  `msg` blob NOT NULL,
45
+  `msg` varchar(1500) NOT NULL,
45 46
   PRIMARY KEY (`id`,`date`),
46 47
   KEY `ruri_user` (`ruri_user`),
47 48
   KEY `from_user` (`from_user`),
... ...
@@ -52,17 +53,7 @@ CREATE TABLE `sip_capture` (
52 53
   KEY `date` (`date`),
53 54
   KEY `callid` (`callid`)
54 55
 ) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
55
-PARTITION BY RANGE ( TO_DAYS(`date`) ) (
56
-PARTITION p20110824 VALUES LESS THAN (734739) ENGINE = MyISAM,
57
-PARTITION p20110825 VALUES LESS THAN (734740) ENGINE = MyISAM,
58
-PARTITION p20110826 VALUES LESS THAN (734741) ENGINE = MyISAM,
59
-PARTITION p20110827 VALUES LESS THAN (734742) ENGINE = MyISAM,
60
-PARTITION p20110828 VALUES LESS THAN (734743) ENGINE = MyISAM,
61
-PARTITION p20110829 VALUES LESS THAN (734744) ENGINE = MyISAM,
62
-PARTITION p20110830 VALUES LESS THAN (734745) ENGINE = MyISAM,
63
-PARTITION p20110831 VALUES LESS THAN (734746) ENGINE = MyISAM,
64
-PARTITION p20110901 VALUES LESS THAN (734747) ENGINE = MyISAM,
65
-PARTITION p20110902 VALUES LESS THAN (734748) ENGINE = MyISAM,
56
+PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`) ) (
66 57
 PARTITION pmax VALUES LESS THAN (MAXVALUE)
67 58
 );
68 59
 
69 60
deleted file mode 100644
... ...
@@ -1,9919 +0,0 @@
1
-
2
-
3
-DROP TABLE IF EXISTS `sip_capture_01_00`;
4
-/*!40101 SET @saved_cs_client     = @@character_set_client */;
5
-/*!40101 SET character_set_client = utf8 */;
6
-CREATE TABLE `sip_capture_01_00` (
7
-  `id` int(11) NOT NULL AUTO_INCREMENT,
8
-  `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
9
-  `micro_ts` bigint(18) NOT NULL DEFAULT '0',
10
-  `method` varchar(50) NOT NULL DEFAULT '',
11
-  `reply_reason` varchar(100) NOT NULL,
12
-  `ruri` varchar(200) NOT NULL DEFAULT '',
13
-  `ruri_user` varchar(100) NOT NULL DEFAULT '',
14
-  `from_user` varchar(100) NOT NULL DEFAULT '',
15
-  `from_tag` varchar(64) NOT NULL DEFAULT '',
16
-  `to_user` varchar(100) NOT NULL DEFAULT '',
17
-  `to_tag` varchar(64) NOT NULL,
18
-  `pid_user` varchar(100) NOT NULL DEFAULT '',
19
-  `contact_user` varchar(120) NOT NULL,
20
-  `auth_user` varchar(120) NOT NULL,
21
-  `callid` varchar(100) NOT NULL DEFAULT '',
22
-  `callid_aleg` varchar(100) NOT NULL DEFAULT '',
23
-  `via_1` varchar(256) NOT NULL,
24
-  `via_1_branch` varchar(80) NOT NULL,
25
-  `cseq` varchar(25) NOT NULL,
26
-  `diversion` varchar(256) NOT NULL,
27
-  `reason` varchar(200) NOT NULL,
28
-  `content_type` varchar(256) NOT NULL,
29
-  `authorization` varchar(256) NOT NULL,
30
-  `user_agent` varchar(256) NOT NULL,
31
-  `source_ip` varchar(50) NOT NULL DEFAULT '',
32
-  `source_port` int(10) NOT NULL,
33
-  `destination_ip` varchar(50) NOT NULL DEFAULT '',
34
-  `destination_port` int(10) NOT NULL,
35
-  `contact_ip` varchar(60) NOT NULL,
36
-  `contact_port` int(10) NOT NULL,
37
-  `originator_ip` varchar(60) NOT NULL DEFAULT '',
38
-  `originator_port` int(10) NOT NULL,
39
-  `proto` int(5) NOT NULL,
40
-  `family` int(1) DEFAULT NULL,
41
-  `rtp_stat` varchar(256) NOT NULL,
42
-  `type` int(2) NOT NULL,
43
-  `node` varchar(125) NOT NULL,
44
-  `msg` longblob NOT NULL,
45
-  PRIMARY KEY (`id`),
46
-  KEY `ruri_user` (`ruri_user`),
47
-  KEY `from_user` (`from_user`),
48
-  KEY `to_user` (`to_user`),
49
-  KEY `pid_user` (`pid_user`),
50
-  KEY `auth_user` (`auth_user`),
51
-  KEY `callid_aleg` (`callid_aleg`),
52
-  KEY `date` (`date`),
53
-  KEY `callid` (`callid`)
54
-) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
55
-/*!40101 SET character_set_client = @saved_cs_client */;
56
-
57
-
58
-DROP TABLE IF EXISTS `sip_capture_01_01`;
59
-/*!40101 SET @saved_cs_client     = @@character_set_client */;
60
-/*!40101 SET character_set_client = utf8 */;
61
-CREATE TABLE `sip_capture_01_01` (
62
-  `id` int(11) NOT NULL AUTO_INCREMENT,
63
-  `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
64
-  `micro_ts` bigint(18) NOT NULL DEFAULT '0',
65
-  `method` varchar(50) NOT NULL DEFAULT '',
66
-  `reply_reason` varchar(100) NOT NULL,
67
-  `ruri` varchar(200) NOT NULL DEFAULT '',
68
-  `ruri_user` varchar(100) NOT NULL DEFAULT '',
69
-  `from_user` varchar(100) NOT NULL DEFAULT '',
70
-  `from_tag` varchar(64) NOT NULL DEFAULT '',
71
-  `to_user` varchar(100) NOT NULL DEFAULT '',
72
-  `to_tag` varchar(64) NOT NULL,
73
-  `pid_user` varchar(100) NOT NULL DEFAULT '',
74
-  `contact_user` varchar(120) NOT NULL,
75
-  `auth_user` varchar(120) NOT NULL,
76
-  `callid` varchar(100) NOT NULL DEFAULT '',
77
-  `callid_aleg` varchar(100) NOT NULL DEFAULT '',
78
-  `via_1` varchar(256) NOT NULL,
79
-  `via_1_branch` varchar(80) NOT NULL,
80
-  `cseq` varchar(25) NOT NULL,
81
-  `diversion` varchar(256) NOT NULL,
82
-  `reason` varchar(200) NOT NULL,
83
-  `content_type` varchar(256) NOT NULL,
84
-  `authorization` varchar(256) NOT NULL,
85
-  `user_agent` varchar(256) NOT NULL,
86
-  `source_ip` varchar(50) NOT NULL DEFAULT '',
87
-  `source_port` int(10) NOT NULL,
88
-  `destination_ip` varchar(50) NOT NULL DEFAULT '',
89
-  `destination_port` int(10) NOT NULL,
90
-  `contact_ip` varchar(60) NOT NULL,
91
-  `contact_port` int(10) NOT NULL,
92
-  `originator_ip` varchar(60) NOT NULL DEFAULT '',
93
-  `originator_port` int(10) NOT NULL,
94
-  `proto` int(5) NOT NULL,
95
-  `family` int(1) DEFAULT NULL,
96
-  `rtp_stat` varchar(256) NOT NULL,
97
-  `type` int(2) NOT NULL,
98
-  `node` varchar(125) NOT NULL,
99
-  `msg` longblob NOT NULL,
100
-  `direction` varchar(4) NOT NULL DEFAULT '',
101
-  PRIMARY KEY (`id`),
102
-  KEY `ruri_user` (`ruri_user`),
103
-  KEY `from_user` (`from_user`),
104
-  KEY `to_user` (`to_user`),
105
-  KEY `pid_user` (`pid_user`),
106
-  KEY `auth_user` (`auth_user`),
107
-  KEY `callid_aleg` (`callid_aleg`),
108
-  KEY `date` (`date`),
109
-  KEY `callid` (`callid`)
110
-) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;
111
-/*!40101 SET character_set_client = @saved_cs_client */;
112
-
113
-
114
-DROP TABLE IF EXISTS `sip_capture_01_02`;
115
-/*!40101 SET @saved_cs_client     = @@character_set_client */;
116
-/*!40101 SET character_set_client = utf8 */;
117
-CREATE TABLE `sip_capture_01_02` (
118
-  `id` int(11) NOT NULL AUTO_INCREMENT,
119
-  `date` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
120
-  `micro_ts` bigint(18) NOT NULL DEFAULT '0',
121
-  `method` varchar(50) NOT NULL DEFAULT '',
122
-  `reply_reason` varchar(100) NOT NULL,
123
-  `ruri` varchar(200) NOT NULL DEFAULT '',
124
-  `ruri_user` varchar(100) NOT NULL DEFAULT '',
125
-  `from_user` varchar(100) NOT NULL DEFAULT '',
126
-  `from_tag` varchar(64) NOT NULL DEFAULT '',
127
-  `to_user` varchar(100) NOT NULL DEFAULT '',
128
-  `to_tag` varchar(64) NOT NULL,
129
-  `pid_user` varchar(100) NOT NULL DEFAULT '',
130
-  `contact_user` varchar(120) NOT NULL,
131
-  `auth_user` varchar(120) NOT NULL,
132
-  `callid` varchar(100) NOT NULL DEFAULT '',
133
-  `callid_aleg` varchar(100) NOT NULL DEFAULT '',
134
-  `via_1` varchar(256) NOT NULL,
135
-  `via_1_branch` varchar(80) NOT NULL,
136
-  `cseq` varchar(25) NOT NULL,
137
-  `diversion` varchar(256) NOT NULL,
138
-  `reason` varchar(200) NOT NULL,
139
-  `content_type` varchar(256) NOT NULL,
140
-  `authorization` varchar(256) NOT NULL,
141
-  `user_agent` varchar(256) NOT NULL,
142
-  `source_ip` varchar(50) NOT NULL DEFAULT '',
143
-  `source_port` int(10) NOT NULL,
144
-  `destination_ip` varchar(50) NOT NULL DEFAULT '',
145
-  `destination_port` int(10) NOT NULL,
146
-  `contact_ip` varchar(60) NOT NULL,
147
-  `contact_port` int(10) NOT NULL,
148
-  `originator_ip` varchar(60) NOT NULL DEFAULT '',
149
-  `originator_port` int(10) NOT NULL,
150
-  `proto` int(5) NOT NULL,
151