Browse code

modules:sipcapture Added PSQL schema, fixed columns length, fixed id column for PostgreSQL

Thanks Ovind Kolbu for schema and patch

Alexandr Dubovikov authored on 22/01/2013 14:45:38
Showing 4 changed files
... ...
@@ -8,7 +8,7 @@
8 8
 #
9 9
 # partrotate_unixtimestamp is free software; you can redistribute it and/or modify
10 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
11
+# the Free Software Foundation; either version 3 of the License, or
12 12
 # (at your option) any later version
13 13
 #
14 14
 # partrotate_unixtimestamp is distributed in the hope that it will be useful,
... ...
@@ -22,7 +22,7 @@
22 22
 
23 23
 use DBI;
24 24
 
25
-$version = "0.2.2";
25
+$version = "0.2.5";
26 26
 $mysql_table = "sip_capture";
27 27
 $mysql_dbname = "homer_db";
28 28
 $mysql_user = "mysql_login";
... ...
@@ -32,28 +32,36 @@ $maxparts = 6; #6 days How long keep the data in the DB
32 32
 $newparts = 2; #new partitions for 2 days. Anyway, start this script daily!
33 33
 @stepsvalues = (86400, 3600, 1800, 900); 
34 34
 $partstep = 0; # 0 - Day, 1 - Hour, 2 - 30 Minutes, 3 - 15 Minutes 
35
-# version 1 = auth_field is "authorization"
36
-$schema_version = 2;
37
-$auth_field = "auth";
35
+$engine = "MyISAM";
36
+$sql_schema_version = 2;
37
+$auth_column = "auth";
38
+$check_table = 1; #Check if table exists. For PostgreSQL change creation schema!
38 39
 
39 40
 #Check it
40 41
 $partstep=0 if(!defined $stepsvalues[$partstep]);
41 42
 #Mystep
42 43
 $mystep = $stepsvalues[$partstep];
43 44
 #Coof
45
+
46
+# Optionally load override configuration. perl format
47
+$rc = "/etc/sysconfig/partrotaterc";
48
+if (-e $rc) {
49
+  do $rc;
50
+}
51
+
44 52
 $coof=int(86400/$mystep);
45 53
 
46 54
 #How much partitions
47 55
 $maxparts*=$coof;
48 56
 $newparts*=$coof;
49
-$auth_field = "authorization" if($schema_version == 1);
50
-
51 57
 
52 58
 my $db = DBI->connect("DBI:mysql:$mysql_dbname:$mysql_host:3306", $mysql_user, $mysql_password);
53 59
 
60
+$auth_column = "authorization" if($sql_schema_version == 1);
61
+
54 62
 #$db->{PrintError} = 0;
55
-my $sth = $db->do("
56
-CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
63
+
64
+$sql = "CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
57 65
   `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
58 66
   `date` timestamp NOT NULL DEFAULT '0000-00-00 00:00:00',
59 67
   `micro_ts` bigint(18) NOT NULL DEFAULT '0',
... ...
@@ -67,7 +75,7 @@ CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
67 75
   `to_tag` varchar(64) NOT NULL,
68 76
   `pid_user` varchar(100) NOT NULL DEFAULT '',
69 77
   `contact_user` varchar(120) NOT NULL,
70
-  `auth_user` varchar(120) NOT NULL,
78
+  `".$auth_column."` varchar(120) NOT NULL,
71 79
   `callid` varchar(100) NOT NULL DEFAULT '',
72 80
   `callid_aleg` varchar(100) NOT NULL DEFAULT '',
73 81
   `via_1` varchar(256) NOT NULL,
... ...
@@ -76,11 +84,11 @@ CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
76 84
   `diversion` varchar(256) NOT NULL,
77 85
   `reason` varchar(200) NOT NULL,
78 86
   `content_type` varchar(256) NOT NULL,
79
-  `".$auth_field."` varchar(256) NOT NULL,
87
+  `authorization` varchar(256) NOT NULL,
80 88
   `user_agent` varchar(256) NOT NULL,
81
-  `source_ip` varchar(50) NOT NULL DEFAULT '',
89
+  `source_ip` varchar(60) NOT NULL DEFAULT '',
82 90
   `source_port` int(10) NOT NULL,
83
-  `destination_ip` varchar(50) NOT NULL DEFAULT '',
91
+  `destination_ip` varchar(60) NOT NULL DEFAULT '',
84 92
   `destination_port` int(10) NOT NULL,
85 93
   `contact_ip` varchar(60) NOT NULL,
86 94
   `contact_port` int(10) NOT NULL,
... ...
@@ -104,10 +112,21 @@ CREATE TABLE IF NOT EXISTS `".$mysql_table."` (
104 112
   KEY `method` (`method`),
105 113
   KEY `source_ip` (`source_ip`),
106 114
   KEY `destination_ip` (`destination_ip`)
107
-) ENGINE=MyISAM DEFAULT CHARSET=latin1
108
-PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`)) (PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = MyISAM);
109
-");
115
+) ENGINE=".$engine." DEFAULT CHARSET=latin1
116
+PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`)) (PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = ".$engine.")";
117
+
118
+my $sth = $db->do($sql) if($check_table == 1);
110 119
 
120
+#check if the table has partitions. If not, create one
121
+my $query = "SHOW TABLE STATUS FROM ".$mysql_dbname. " WHERE Name='".$mysql_table."'";
122
+$sth = $db->prepare($query);
123
+$sth->execute();
124
+my $tstatus = $sth->fetchrow_hashref()->{Create_options};
125
+if ($tstatus !~ /partitioned/) {
126
+   my $query = "ALTER TABLE ".$mysql_table. " PARTITION BY RANGE ( UNIX_TIMESTAMP(`date`)) (PARTITION pmax VALUES LESS THAN MAXVALUE)";
127
+   $sth = $db->prepare($query);
128
+   $sth->execute();
129
+}
111 130
 
112 131
 my $query = "SELECT UNIX_TIMESTAMP(CURDATE() - INTERVAL 1 DAY)";
113 132
 $sth = $db->prepare($query);
... ...
@@ -178,7 +197,7 @@ for(my $i=0; $i<$newparts; $i++) {
178 197
 
179 198
 	# Fix MAXVALUE. Thanks Dorn B. <djbinter@gmail.com> for report and fix.
180 199
         $query = "ALTER TABLE ".$mysql_table." REORGANIZE PARTITION pmax INTO (PARTITION ".$newpartname
181
-                                ."\n VALUES LESS THAN (".$curtstamp.") ENGINE = MyISAM, PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = MyISAM)";  
200
+                                ."\n VALUES LESS THAN (".$curtstamp.") ENGINE = ".$engine.", PARTITION pmax VALUES LESS THAN MAXVALUE ENGINE = ".$engine.")";  
182 201
 
183 202
         $db->do($query);
184 203
                     
... ...
@@ -93,7 +93,7 @@ MODULE_VERSION
93 93
 
94 94
 #define TABLE_LEN 256
95 95
 
96
-#define NR_KEYS 37
96
+#define NR_KEYS 36
97 97
 
98 98
 /* module function prototypes */
99 99
 static int mod_init(void);
... ...
@@ -113,8 +113,7 @@ static struct mi_root* sip_capture_mi(struct mi_root* cmd, void* param );
113 113
 static str db_url		= str_init(DEFAULT_RODB_URL);
114 114
 static str table_name		= str_init("sip_capture");
115 115
 static str hash_source		= str_init("call_id");
116
-static str mt_mode			= str_init("rand");
117
-static str id_column		= str_init("id");
116
+static str mt_mode		= str_init("rand");
118 117
 static str date_column		= str_init("date");
119 118
 static str micro_ts_column 	= str_init("micro_ts");
120 119
 static str method_column 	= str_init("method"); 	
... ...
@@ -227,7 +226,6 @@ static param_export_t params[] = {
227 226
 	{"table_name",       		STR_PARAM, &table_name.s	},
228 227
 	{"hash_source",				STR_PARAM, &hash_source.s	},
229 228
 	{"mt_mode",					STR_PARAM, &mt_mode.s	},
230
-	{"id_column",        		STR_PARAM, &id_column.s         },
231 229
 	{"date_column",        		STR_PARAM, &date_column.s       },	
232 230
 	{"micro_ts_column",     	STR_PARAM, &micro_ts_column.s	},
233 231
 	{"method_column",      		STR_PARAM, &method_column.s 	},
... ...
@@ -423,7 +421,6 @@ static int mod_init(void) {
423 421
 	hash_source.len = strlen (hash_source.s);
424 422
 	mt_mode.len = strlen(mt_mode.s);
425 423
 	date_column.len = strlen(date_column.s);
426
-	id_column.len = strlen(id_column.s);
427 424
 	micro_ts_column.len = strlen(micro_ts_column.s);
428 425
 	method_column.len = strlen(method_column.s); 	
429 426
 	reply_reason_column.len = strlen(reply_reason_column.s);        
... ...
@@ -717,189 +714,184 @@ static int sip_capture_store(struct _sipcapture_object *sco)
717 714
 		return -1;
718 715
 	}
719 716
 	
720
-	db_keys[0] = &id_column;			
721
-        db_vals[0].type = DB1_INT;
722
-        db_vals[0].nul = 0;
723
-        db_vals[0].val.int_val = 0;
724
-        
725
-	db_keys[1] = &date_column;
726
-	db_vals[1].type = DB1_DATETIME;
727
-	db_vals[1].nul = 0;
728
-	db_vals[1].val.time_val = time(NULL);
717
+	db_keys[0] = &date_column;
718
+	db_vals[0].type = DB1_DATETIME;
719
+	db_vals[0].nul = 0;
720
+	db_vals[0].val.time_val = time(NULL);
721
+	
722
+	db_keys[1] = &micro_ts_column;
723
+        db_vals[1].type = DB1_BIGINT;
724
+        db_vals[1].nul = 0;
725
+        db_vals[1].val.ll_val = sco->tmstamp;
729 726
 	
730
-	db_keys[2] = &micro_ts_column;
731
-        db_vals[2].type = DB1_BIGINT;
732
-        db_vals[2].nul = 0;
733
-        db_vals[2].val.ll_val = sco->tmstamp;
727
+	db_keys[2] = &method_column;
728
+	db_vals[2].type = DB1_STR;
729
+	db_vals[2].nul = 0;
730
+	db_vals[2].val.str_val = sco->method;
734 731
 	
735
-	db_keys[3] = &method_column;
732
+	db_keys[3] = &reply_reason_column;
736 733
 	db_vals[3].type = DB1_STR;
737 734
 	db_vals[3].nul = 0;
738
-	db_vals[3].val.str_val = sco->method;
735
+	db_vals[3].val.str_val = sco->reply_reason;
739 736
 	
740
-	db_keys[4] = &reply_reason_column;
737
+	db_keys[4] = &ruri_column;
741 738
 	db_vals[4].type = DB1_STR;
742 739
 	db_vals[4].nul = 0;
743
-	db_vals[4].val.str_val = sco->reply_reason;
740
+	db_vals[4].val.str_val = sco->ruri;
744 741
 	
745
-	db_keys[5] = &ruri_column;
742
+	db_keys[5] = &ruri_user_column;
746 743
 	db_vals[5].type = DB1_STR;
747 744
 	db_vals[5].nul = 0;
748
-	db_vals[5].val.str_val = sco->ruri;
745
+	db_vals[5].val.str_val = sco->ruri_user;
749 746
 	
750
-	db_keys[6] = &ruri_user_column;
747
+	db_keys[6] = &from_user_column;
751 748
 	db_vals[6].type = DB1_STR;
752 749
 	db_vals[6].nul = 0;
753
-	db_vals[6].val.str_val = sco->ruri_user;
750
+	db_vals[6].val.str_val = sco->from_user;
754 751
 	
755
-	db_keys[7] = &from_user_column;
752
+	db_keys[7] = &from_tag_column;
756 753
 	db_vals[7].type = DB1_STR;
757 754
 	db_vals[7].nul = 0;
758
-	db_vals[7].val.str_val = sco->from_user;
759
-	
760
-	db_keys[8] = &from_tag_column;
755
+	db_vals[7].val.str_val = sco->from_tag;
756
+
757
+	db_keys[8] = &to_user_column;
761 758
 	db_vals[8].type = DB1_STR;
762 759
 	db_vals[8].nul = 0;
763
-	db_vals[8].val.str_val = sco->from_tag;
760
+	db_vals[8].val.str_val = sco->to_user;
764 761
 
765
-	db_keys[9] = &to_user_column;
762
+	db_keys[9] = &to_tag_column;
766 763
 	db_vals[9].type = DB1_STR;
767 764
 	db_vals[9].nul = 0;
768
-	db_vals[9].val.str_val = sco->to_user;
769
-
770
-	db_keys[10] = &to_tag_column;
765
+	db_vals[9].val.str_val = sco->to_tag;
766
+	
767
+	db_keys[10] = &pid_user_column;
771 768
 	db_vals[10].type = DB1_STR;
772 769
 	db_vals[10].nul = 0;
773
-	db_vals[10].val.str_val = sco->to_tag;
774
-	
775
-	db_keys[11] = &pid_user_column;
770
+	db_vals[10].val.str_val = sco->pid_user;
771
+
772
+	db_keys[11] = &contact_user_column;
776 773
 	db_vals[11].type = DB1_STR;
777 774
 	db_vals[11].nul = 0;
778
-	db_vals[11].val.str_val = sco->pid_user;
775
+	db_vals[11].val.str_val = sco->contact_user;	
779 776
 
780
-	db_keys[12] = &contact_user_column;
777
+	db_keys[12] = &auth_user_column;
781 778
 	db_vals[12].type = DB1_STR;
782 779
 	db_vals[12].nul = 0;
783
-	db_vals[12].val.str_val = sco->contact_user;	
784
-
785
-	db_keys[13] = &auth_user_column;
780
+	db_vals[12].val.str_val = sco->auth_user;
781
+	
782
+	db_keys[13] = &callid_column;
786 783
 	db_vals[13].type = DB1_STR;
787 784
 	db_vals[13].nul = 0;
788
-	db_vals[13].val.str_val = sco->auth_user;
789
-	
790
-	db_keys[14] = &callid_column;
785
+	db_vals[13].val.str_val = sco->callid;
786
+
787
+	db_keys[14] = &callid_aleg_column;
791 788
 	db_vals[14].type = DB1_STR;
792 789
 	db_vals[14].nul = 0;
793
-	db_vals[14].val.str_val = sco->callid;
794
-
795
-	db_keys[15] = &callid_aleg_column;
790
+	db_vals[14].val.str_val = sco->callid_aleg;
791
+	
792
+	db_keys[15] = &via_1_column;
796 793
 	db_vals[15].type = DB1_STR;
797 794
 	db_vals[15].nul = 0;
798
-	db_vals[15].val.str_val = sco->callid_aleg;
795
+	db_vals[15].val.str_val = sco->via_1;
799 796
 	
800
-	db_keys[16] = &via_1_column;
797
+	db_keys[16] = &via_1_branch_column;
801 798
 	db_vals[16].type = DB1_STR;
802 799
 	db_vals[16].nul = 0;
803
-	db_vals[16].val.str_val = sco->via_1;
804
-	
805
-	db_keys[17] = &via_1_branch_column;
800
+	db_vals[16].val.str_val = sco->via_1_branch;
801
+
802
+	db_keys[17] = &cseq_column;
806 803
 	db_vals[17].type = DB1_STR;
807 804
 	db_vals[17].nul = 0;
808
-	db_vals[17].val.str_val = sco->via_1_branch;
809
-
810
-	db_keys[18] = &cseq_column;
805
+	db_vals[17].val.str_val = sco->cseq;	
806
+	
807
+	db_keys[18] = &reason_column;
811 808
 	db_vals[18].type = DB1_STR;
812 809
 	db_vals[18].nul = 0;
813
-	db_vals[18].val.str_val = sco->cseq;	
810
+	db_vals[18].val.str_val = sco->reason;
814 811
 	
815
-	db_keys[19] = &reason_column;
812
+	db_keys[19] = &content_type_column;
816 813
 	db_vals[19].type = DB1_STR;
817 814
 	db_vals[19].nul = 0;
818
-	db_vals[19].val.str_val = sco->reason;
819
-	
820
-	db_keys[20] = &content_type_column;
815
+	db_vals[19].val.str_val = sco->content_type;
816
+
817
+	db_keys[20] = &authorization_column;
821 818
 	db_vals[20].type = DB1_STR;
822 819
 	db_vals[20].nul = 0;
823
-	db_vals[20].val.str_val = sco->content_type;
820
+	db_vals[20].val.str_val = sco->authorization;
824 821
 
825
-	db_keys[21] = &authorization_column;
822
+	db_keys[21] = &user_agent_column;
826 823
 	db_vals[21].type = DB1_STR;
827 824
 	db_vals[21].nul = 0;
828
-	db_vals[21].val.str_val = sco->authorization;
829
-
830
-	db_keys[22] = &user_agent_column;
825
+	db_vals[21].val.str_val = sco->user_agent;
826
+	
827
+	db_keys[22] = &source_ip_column;
831 828
 	db_vals[22].type = DB1_STR;
832 829
 	db_vals[22].nul = 0;
833
-	db_vals[22].val.str_val = sco->user_agent;
830
+	db_vals[22].val.str_val = sco->source_ip;
834 831
 	
835
-	db_keys[23] = &source_ip_column;
836
-	db_vals[23].type = DB1_STR;
837
-	db_vals[23].nul = 0;
838
-	db_vals[23].val.str_val = sco->source_ip;
839
-	
840
-	db_keys[24] = &source_port_column;
841
-        db_vals[24].type = DB1_INT;
842
-        db_vals[24].nul = 0;
843
-        db_vals[24].val.int_val = sco->source_port;
832
+	db_keys[23] = &source_port_column;
833
+        db_vals[23].type = DB1_INT;
834
+        db_vals[23].nul = 0;
835
+        db_vals[23].val.int_val = sco->source_port;
844 836
         
845
-	db_keys[25] = &dest_ip_column;
846
-	db_vals[25].type = DB1_STR;
847
-	db_vals[25].nul = 0;
848
-	db_vals[25].val.str_val = sco->destination_ip;
837
+	db_keys[24] = &dest_ip_column;
838
+	db_vals[24].type = DB1_STR;
839
+	db_vals[24].nul = 0;
840
+	db_vals[24].val.str_val = sco->destination_ip;
849 841
 	
850
-	db_keys[26] = &dest_port_column;
851
-        db_vals[26].type = DB1_INT;
852
-        db_vals[26].nul = 0;
853
-        db_vals[26].val.int_val = sco->destination_port;        
842
+	db_keys[25] = &dest_port_column;
843
+        db_vals[25].type = DB1_INT;
844
+        db_vals[25].nul = 0;
845
+        db_vals[25].val.int_val = sco->destination_port;        
854 846
         
855
-	db_keys[27] = &contact_ip_column;
856
-	db_vals[27].type = DB1_STR;
857
-	db_vals[27].nul = 0;
858
-	db_vals[27].val.str_val = sco->contact_ip;
847
+	db_keys[26] = &contact_ip_column;
848
+	db_vals[26].type = DB1_STR;
849
+	db_vals[26].nul = 0;
850
+	db_vals[26].val.str_val = sco->contact_ip;
859 851
 	
860
-	db_keys[28] = &contact_port_column;
861
-        db_vals[28].type = DB1_INT;
862
-        db_vals[28].nul = 0;
863
-        db_vals[28].val.int_val = sco->contact_port;
852
+	db_keys[27] = &contact_port_column;
853
+        db_vals[27].type = DB1_INT;
854
+        db_vals[27].nul = 0;
855
+        db_vals[27].val.int_val = sco->contact_port;
864 856
         
865
-	db_keys[29] = &orig_ip_column;
866
-	db_vals[29].type = DB1_STR;
867
-	db_vals[29].nul = 0;
868
-	db_vals[29].val.str_val = sco->originator_ip;
857
+	db_keys[28] = &orig_ip_column;
858
+	db_vals[28].type = DB1_STR;
859
+	db_vals[28].nul = 0;
860
+	db_vals[28].val.str_val = sco->originator_ip;
869 861
 	
870
-	db_keys[30] = &orig_port_column;			
862
+	db_keys[29] = &orig_port_column;			
863
+        db_vals[29].type = DB1_INT;
864
+        db_vals[29].nul = 0;
865
+        db_vals[29].val.int_val = sco->originator_port;        
866
+        
867
+        db_keys[30] = &proto_column;			
871 868
         db_vals[30].type = DB1_INT;
872 869
         db_vals[30].nul = 0;
873
-        db_vals[30].val.int_val = sco->originator_port;        
874
-        
875
-        db_keys[31] = &proto_column;			
870
+        db_vals[30].val.int_val = sco->proto;        
871
+
872
+        db_keys[31] = &family_column;			
876 873
         db_vals[31].type = DB1_INT;
877 874
         db_vals[31].nul = 0;
878
-        db_vals[31].val.int_val = sco->proto;        
879
-
880
-        db_keys[32] = &family_column;			
881
-        db_vals[32].type = DB1_INT;
875
+        db_vals[31].val.int_val = sco->family;        
876
+        
877
+        db_keys[32] = &rtp_stat_column;			
878
+        db_vals[32].type = DB1_STR;
882 879
         db_vals[32].nul = 0;
883
-        db_vals[32].val.int_val = sco->family;        
880
+        db_vals[32].val.str_val = sco->rtp_stat;                
884 881
         
885
-        db_keys[33] = &rtp_stat_column;			
886
-        db_vals[33].type = DB1_STR;
882
+        db_keys[33] = &type_column;			
883
+        db_vals[33].type = DB1_INT;
887 884
         db_vals[33].nul = 0;
888
-        db_vals[33].val.str_val = sco->rtp_stat;                
889
-        
890
-        db_keys[34] = &type_column;			
891
-        db_vals[34].type = DB1_INT;
892
-        db_vals[34].nul = 0;
893
-        db_vals[34].val.int_val = sco->type;                
885
+        db_vals[33].val.int_val = sco->type;                
894 886
 
895
-	db_keys[35] = &node_column;
896
-	db_vals[35].type = DB1_STR;
897
-	db_vals[35].nul = 0;
898
-	db_vals[35].val.str_val = sco->node;
887
+	db_keys[34] = &node_column;
888
+	db_vals[34].type = DB1_STR;
889
+	db_vals[34].nul = 0;
890
+	db_vals[34].val.str_val = sco->node;
899 891
 	
900
-	db_keys[36] = &msg_column;
901
-	db_vals[36].type = DB1_BLOB;
902
-	db_vals[36].nul = 0;
892
+	db_keys[35] = &msg_column;
893
+	db_vals[35].type = DB1_BLOB;
894
+	db_vals[35].nul = 0;
903 895
 		
904 896
 	/* need to be removed in the future */
905 897
         /* if message was captured via hep skip trailing empty spaces(newlines) from the start of the buffer */
... ...
@@ -918,7 +910,7 @@ static int sip_capture_store(struct _sipcapture_object *sco)
918 910
 	tmp.s = sco->msg.s;
919 911
 	tmp.len = sco->msg.len;
920 912
 
921
-	db_vals[36].val.blob_val = tmp;
913
+	db_vals[35].val.blob_val = tmp;
922 914
 
923 915
 	if (no_tables > 0 ){
924 916
 		if ( mtmode == mode_hash ){
... ...
@@ -2,6 +2,8 @@
2 2
  * only for MYSQL >= 5.1.43
3 3
 */
4 4
 
5
+/* schema version 2 */
6
+
5 7
 /*!40101 SET @saved_cs_client     = @@character_set_client */;
6 8
 /*!40101 SET character_set_client = utf8 */;
7 9
 CREATE TABLE `sip_capture` (
... ...
@@ -27,7 +29,7 @@ CREATE TABLE `sip_capture` (
27 29
   `diversion` varchar(256) NOT NULL,
28 30
   `reason` varchar(200) NOT NULL,
29 31
   `content_type` varchar(256) NOT NULL,
30
-  `authorization` varchar(256) NOT NULL,
32
+  `auth` varchar(256) NOT NULL,
31 33
   `user_agent` varchar(256) NOT NULL,
32 34
   `source_ip` varchar(50) NOT NULL DEFAULT '',
33 35
   `source_port` int(10) NOT NULL,
34 36
new file mode 100644
... ...
@@ -0,0 +1,59 @@
1
+/*
2
+ * 
3
+ *   Postgress SQL Schema for Sipcapture
4
+ *   Author: Ovind Kolbu
5
+ *
6
+*/
7
+
8
+CREATE TABLE sip_capture (
9
+        id SERIAL NOT NULL,
10
+        date TIMESTAMP WITHOUT TIME ZONE DEFAULT '1900-01-01 00:00:01' NOT NULL,
11
+        micro_ts BIGINT NOT NULL DEFAULT '0',
12
+        method VARCHAR(50) NOT NULL DEFAULT '',
13
+        reply_reason VARCHAR(100) NOT NULL,
14
+        ruri VARCHAR(200) NOT NULL DEFAULT '',
15
+        ruri_user VARCHAR(100) NOT NULL DEFAULT '',
16
+        from_user VARCHAR(100) NOT NULL DEFAULT '',
17
+        from_tag VARCHAR(64) NOT NULL DEFAULT '',
18
+        to_user VARCHAR(100) NOT NULL DEFAULT '',
19
+        to_tag VARCHAR(64) NOT NULL,
20
+        pid_user VARCHAR(100) NOT NULL DEFAULT '',
21
+        contact_user VARCHAR(120) NOT NULL,
22
+        auth_user VARCHAR(120) NOT NULL,
23
+        callid VARCHAR(100) NOT NULL DEFAULT '',
24
+        callid_aleg VARCHAR(100) NOT NULL DEFAULT '',
25
+        via_1 VARCHAR(256) NOT NULL,
26
+        via_1_branch VARCHAR(80) NOT NULL,
27
+        cseq VARCHAR(25) NOT NULL,
28
+        diversion VARCHAR(256), /* MySQL: NOT NULL */
29
+        reason VARCHAR(200) NOT NULL,
30
+        content_type VARCHAR(256) NOT NULL,
31
+        auth VARCHAR(256) NOT NULL,
32
+        user_agent VARCHAR(256) NOT NULL,
33
+        source_ip VARCHAR(60) NOT NULL DEFAULT '',
34
+        source_port INTEGER NOT NULL,
35
+        destination_ip VARCHAR(60) NOT NULL DEFAULT '',
36
+        destination_port INTEGER NOT NULL,
37
+        contact_ip VARCHAR(60) NOT NULL,
38
+        contact_port INTEGER NOT NULL,
39
+        originator_ip VARCHAR(60) NOT NULL DEFAULT '',
40
+        originator_port INTEGER NOT NULL,
41
+        proto INTEGER NOT NULL,
42
+        family INTEGER NOT NULL,
43
+        rtp_stat VARCHAR(256) NOT NULL,
44
+        type INTEGER NOT NULL,
45
+        node VARCHAR(125) NOT NULL,
46
+        msg VARCHAR(1500) NOT NULL,
47
+        PRIMARY KEY (id,date)
48
+);
49
+
50
+CREATE INDEX sip_capture_ruri_user_idx ON sip_capture (ruri_user);
51
+CREATE INDEX sip_capture_from_user_idx ON sip_capture (from_user);
52
+CREATE INDEX sip_capture_to_user_idx ON sip_capture (to_user);
53
+CREATE INDEX sip_capture_pid_user_idx ON sip_capture (pid_user);
54
+CREATE INDEX sip_capture_auth_user_idx ON sip_capture (auth_user);
55
+CREATE INDEX sip_capture_callid_aleg_idx ON sip_capture (callid_aleg);
56
+CREATE INDEX sip_capture_date_idx ON sip_capture (date);
57
+CREATE INDEX sip_capture_callid_idx ON sip_capture (callid);
58
+
59
+