modules/sipcapture/doc/sipcapture_admin.xml
1f75be46
 <?xml version="1.0" encoding='ISO-8859-1'?>
 <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
 "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd" [
 
 <!-- Include general documentation entities -->
 <!ENTITY % docentities SYSTEM "../../../docbook/entities.xml">
 %docentities;
 
 ]>
 <!-- Module User's Guide -->
 
 <chapter>
 	
 	<title>&adminguide;</title>
 	
 	<section>
 	<title>Overview</title>
 	<para>
96830686
 		The sipcapture module stores incoming/outgoing SIP messages in database.
1f75be46
 	</para>
 	<para>
96830686
 		Kamailio can capture SIP messages in three modes
1f75be46
 		<itemizedlist>
 		<listitem>
 		<para>
 		IPIP encapsulation. (ETHHDR+IPHDR+IPHDR+UDPHDR).
 		</para>
 		</listitem>
 	        <listitem>
                 <para>
                 Monitoring/mirroring port.
                 </para>
                 </listitem>
 		<listitem>
 		<para>
680173cf
 		Homer encapsulation protocol mode (HEP v1, v2, v3). 
1f75be46
 		</para>
 		</listitem>
 		</itemizedlist>
 	</para>
 
 	<para>
8ebf2dbe
 	The capturing can be turned on/off using mi or rpc commands. Example:
1f75be46
 	</para>
 	<para>
 	&ctltool; fifo sip_capture on
 	</para>
 	<para>
 	&ctltool; fifo sip_capture off
 	</para>
 	</section>
 	<section>
 	<title>Dependencies</title>
 	<section>
 		<title>&kamailio; Modules</title>
 		<para>
 		The following modules must be loaded before this module:
 			<itemizedlist>
 			<listitem>
 			<para>
 				<emphasis>database module</emphasis> - mysql, postrgress,
 				dbtext, unixodbc...
 			</para>
 			</listitem>
 			</itemizedlist>
 		</para>
 	</section>
 	<section>
 		<title>External Libraries or Applications</title>
 		<para>
 		The following libraries or applications must be installed before running
 		&kamailio; with this module loaded:
 			<itemizedlist>
 			<listitem>
 			<para>
 				<emphasis>None</emphasis>.
 			</para>
 			</listitem>
 			</itemizedlist>
 		</para>
 	</section>
 	</section>
 	<section>
9114eebc
 	<title>Parameters</title>
7670fafb
 	<section id="sipcapture.p.db_url">
1f75be46
 		<title><varname>db_url</varname> (str)</title>
 		<para>
 		Database URL.
 		</para>
 		<para>
 		<emphasis>
 			Default value is "".
 		</emphasis>
 		</para>
 		<example>
 		<title>Set <varname>db_url</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
 modparam("sipcapture", "db_url", "mysql://user:passwd@host/dbname")
 ...
 </programlisting>
 		</example>
 	</section>
7670fafb
 	<section id="sipcapture.p.table_name">
1f75be46
 		<title><varname>table_name</varname> (str)</title>
 		<para>
96830686
 		Name of the table's name used to store the SIP messages. Can contain multiple tables, separated by "|".
1f75be46
 		</para>
 		<para>
 		<emphasis>
a588ced3
 			Default value is "sip_capture". Only for Homer 3. For Homer 5, please use an argument for the sip_capture function.
1f75be46
 		</emphasis>
 		</para>
 		<example>
 		<title>Set <varname>sip_capture</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
 modparam("sipcapture", "table_name", "homer_capture")
 ...
9a4b9061
 modparam("sipcapture", "table_name", "homer_capture1|homer_capture2");
 ...
 </programlisting>
 		</example>
 	</section>
7670fafb
 	<section id="sipcapture.p.mt_mode">
9a4b9061
 		<title><varname>mt_mode</varname> (str)</title>
 		<para>
 		Name of the mode used for storing data in multiple tables. Modes can be "rand" (random), "round_robin" (use a round_robin algorithm) or "hash" (use hashing to determine the table to store). These modes are only triggered if there is more than one table specified in table_name parameter, separated by "|". 
 		</para>
 		<para>
 		<emphasis>
 			Default value is "rand".
 		</emphasis>
 		</para>
 		<example>
 		<title>Set <varname>mt_mode</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
 modparam("sipcapture", "mt_mode", "hash")
 ...
 </programlisting>
 		</example>
 	</section>
7670fafb
 	<section id="sipcapture.p.hash_source">
9a4b9061
 		<title><varname>hash_source</varname> (str)</title>
 		<para>
 		The field of the SIP message used for hashing, when mt_mode is set to "hash". The value can be "call_id", "to_user" or "from_user".
 		</para>
 		<para>
 		<emphasis>
 			Default value is "call_id".
 		</emphasis>
 		</para>
 		<example>
 		<title>Set <varname>mt_mode</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
 modparam("sipcapture", "hash_source", "to_user")
 ...
1f75be46
 </programlisting>
 		</example>
 	</section>
7670fafb
 	<section id="sipcapture.p.db_insert_mode">
1f75be46
                 <title><varname>db_insert_mode</varname> (integer)</title>
                 <para>
                 If set to 1, use INSERT DELAYED to store sip message into capture table
                 when the DB driver has support for it. If no INSERT DELAYED support
                 is offered by DB driver, then standard INSERT is used.
                 </para>
                 <para>
fc90242d
                 If set to 2, use ASYNC INSERT to store sip message into capture table
                 when the DB driver has support for it. If no ASYNC INSERT support is
                 offered by DB driver, then standard INSERT is used.
                 </para>
                 <para>
1f75be46
                 Default value is 0 (no INSERT DELAYED).
                 </para>
                 <example>
                 <title>db_insert_mode example</title>
                 <programlisting format="linespecific">
 modparam("sipcapture", "db_insert_mode", 1)
 </programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.capture_on">
1f75be46
 		<title><varname>capture_on</varname> (integer)</title>
 		<para>
 		Parameter to enable/disable capture globaly (on(1)/off(0))
 		</para>
 		<para>
 		<emphasis>
 			Default value is "0".
 		</emphasis>
 		</para>
 		<example>
 		<title>Set <varname>capture_on</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
 modparam("sipcapture", "capture_on", 1)
 ...
 </programlisting>
 		</example>
 	</section>
da057e57
 
 	<section id="sipcapture.p.capture_mode">
                 <title><varname>capture_mode</varname> (integer)</title>
                 <para>
 				This parameter can be used for defining a capture mode which can be used in
 				the sip_capture calls as a parameter. A capture mode has a name and some parameters.
 				It must be defined in the format: name=>param1=val1;param2=val2;...
 				The parameters are db_url, table_name, mt_mode and hash_source (optional).
 				Multiple capture modes can be defined by using this parameter multiple times.
 				After this, the capture modes can be used like:
 				sip_capture ("", "CAPTURE_MODE");
 				</para>
                 <example>
                 <title>capture_mode example</title>
                 <programlisting format="linespecific">
 modparam("sipcapture", "capture_mode", "mode1=>db_url=mysql://user:passwd@host/dbname1;table_name=homer_capture1|homer_capture2;mt_mode=hash;hash_source=call_id;")
 modparam("sipcapture", "capture_mode", "mode2=>db_url=mysql://user:passwd@host/dbname2;table_name=homer_capture3|homer_capture4;mt_mode=rand;")
 </programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.hep_capture_on">
1f75be46
                 <title><varname>hep_capture_on</varname> (integer)</title>
                 <para>
                 Parameter to enable/disable capture of HEP (on(1)/off(0))
                 </para>
                 <para>
                 <emphasis>
                         Default value is "0".
                 </emphasis>
                 </para>
                 <example>
                 <title>Set <varname>hep_capture_on</varname> parameter</title>
                 <programlisting format="linespecific">
 ...
 modparam("sipcapture", "hep_capture_on", 1)
 ...
 </programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.raw_ipip_capture_on">
1f75be46
                 <title><varname>raw_ipip_capture_on</varname> (integer)</title>
                 <para>
                 Parameter to enable/disable IPIP capturing (on(1)/off(0))
                 </para>
                 <para>
                 <emphasis>
                         Default value is "0".
                 </emphasis>
                 </para>
                 <example>
                 <title>Set <varname>raw_ipip_capture_on</varname> parameter</title>
                 <programlisting format="linespecific">
 ...
 modparam("sipcapture", "raw_ipip_capture_on", 1)
 ...
 </programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.raw_moni_capture_on">
1f75be46
                 <title><varname>raw_moni_capture_on</varname> (integer)</title>
                 <para>
                 Parameter to enable/disable monitoring/mirroring port capturing (on(1)/off(0))
b7ed9c1e
 		Only one mode on raw socket can be enabled! Monitoring port capturing currently 
 		supported only on Linux.
1f75be46
                 </para>
                 <para>
                 <emphasis>
                         Default value is "0".
                 </emphasis>
                 </para>
                 <example>
                 <title>Set <varname>raw_moni_capture_on</varname> parameter</title>
                 <programlisting format="linespecific">
 ...
 modparam("sipcapture", "raw_moni_capture_on", 1)
 ...
 		</programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.raw_socket_listen">
1f75be46
                 <title><varname>raw_socket_listen</varname> (string)</title>
                 <para>
8c9681ac
                 Parameter indicate an listen IP address of RAW socket for IPIP capturing. 
                 You can also define a port/portrange for IPIP/Mirroring mode, to capture 
                 SIP messages in specific ports:
 		<para>
 		"10.0.0.1:5060" - the source/destination port of the SIP message must be equal 5060
 		</para>
 		<para>
 		"10.0.0.1:5060-5090" - the source/destination port of the SIP message must be 
 		equal or be between 5060 and 5090.
 		</para>
 		<para>
 		The port/portrange must be defined if you are planning to
 		use mirroring capture! In this case, the part with IP address will be
                 ignored, but to make parser happy, use i.e. 10.0.0.0
 		</para>
1f75be46
                 </para>
                 <para>
                 <emphasis>
                         Default value is "".
                 </emphasis>
                 </para>
                 <example>
                 <title>Set <varname>raw_socket_listen</varname> parameter</title>
                 <programlisting format="linespecific">
 ...
 modparam("sipcapture", "raw_socket_listen", "10.0.0.1:5060-5090")
 ...
 modparam("sipcapture", "raw_socket_listen", "10.0.0.1:5060")
 ...
 </programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.raw_interface">
1f75be46
                 <title><varname>raw_interface</varname> (string)</title>
 		<para>
 		Name of the interface to bind on the raw socket.
                 </para>
                 <para>
                 <emphasis>
                         Default value is "".
                 </emphasis>
                 </para>
                 <example>
7670fafb
                 <title>Set <varname>raw_interface</varname> parameter</title>
1f75be46
                 <programlisting format="linespecific">
 ...
 modparam("sipcapture", "raw_interface", "eth0")
 ...
 </programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.raw_sock_children">
1f75be46
                 <title><varname>raw_sock_children</varname> (integer)</title>
                 <para>
96830686
 		Parameter define how many children that must be created to listen the raw socket.
1f75be46
                 </para>
                 <para>
                 <emphasis>
                         Default value is "1".
                 </emphasis>
                 </para>
                 <example>
96830686
                 <title>Set <varname>raw_sock_children</varname> parameter</title>
1f75be46
                 <programlisting format="linespecific">
 ...
 modparam("sipcapture", "raw_sock_children", 6)
 ...
 </programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.promiscuous_on">
1f75be46
                 <title><varname>promiscuous_on</varname> (integer)</title>
                 <para>
                 Parameter to enable/disable promiscuous mode on the raw socket.
 		Linux only.
                 </para>
                 <para>
                 <emphasis>
                         Default value is "0".
                 </emphasis>
                 </para>
                 <example>
96830686
                 <title>Set <varname>promiscous_on</varname> parameter</title>
1f75be46
                 <programlisting format="linespecific">
 ...
 modparam("sipcapture", "promiscuous_on", 1)
 ...
 </programlisting>
                 </example>
         </section>
7670fafb
 	<section id="sipcapture.p.raw_moni_bpf_on">
81cd64fe
                 <title><varname>raw_moni_bpf_on</varname> (integer)</title>
                 <para>
b7ed9c1e
                 Activate Linux Socket Filter (LSF based on BPF) on the mirroring interface. 
8c9681ac
                 The structure is defined in linux/filter.h. The default LSF accept a port/portrange
b7ed9c1e
                 from the raw_socket_listen param. Currently LSF supported only on Linux.
81cd64fe
                 </para>
                 <para>
                 <emphasis>
                         Default value is "0".
                 </emphasis>
                 </para>
                 <example>
                 <title>Set <varname>raw_moni_bpf_on</varname> parameter</title>
                 <programlisting format="linespecific">
 ...
 modparam("sipcapture", "raw_moni_bpf_on", 1)
 ...
 </programlisting>
                 </example>
         </section>        
7670fafb
 	<section id="sipcapture.p.capture_node">
1f75be46
 		<title><varname>capture_node</varname> (str)</title>
 		<para>
 		Name of the capture node.
 		</para>
 		<para>
 		<emphasis>
 			Default value is "homer01".
 		</emphasis>
 		</para>
 		<example>
 		<title>Set <varname>capture_node</varname> parameter</title>
 		<programlisting format="linespecific">
 ...
 modparam("sipcapture", "capture_node", "homer03")
 ...
 </programlisting>
 		</example>
 	</section>
e88b500f
 	<section id="sipcapture.p.insert_retries">
 		<title><varname>insert_retries</varname> (integer)</title>
 		<para>
 		The number of times Kamailio should retry to write to the Homer database in case
 		the first attempt failed. The retry is also limited timewise by the
 		insert_retry_timeout parameter. Values allowed range from 0 to 500.
 		</para>
 		<para>
 		<emphasis>
 			Default value is 0 (no retries).
 		</emphasis>
 		</para>
 		<example>
 			<title>Set <varname>insert_retries</varname> parameter</title>
 			<programlisting format="linespecific">
 ...
 modparam("sipcapture", "insert_retries", 5)
 ...
 			</programlisting>
 		</example>
 	</section>
 	<section id="sipcapture.p.insert_retry_timeout">
 		<title><varname>insert_retry_timeout</varname> (integer)</title>
 		<para>
 		The time limit in seconds Kamailio retries to write to the Homer database in case
 		the first attempt failed. This parameter is only used together with the insert_retries
 		parameter. Values allowed range from 0 to 300.
 		</para>
 		<para>
 		<emphasis>
 			Default value is 60 seconds.
 		</emphasis>
 		</para>
 		<example>
 			<title>Set <varname>insert_retry_timeout</varname> parameter</title>
 			<programlisting format="linespecific">
 ...
 modparam("sipcapture", "insert_retry_timeout", 10)
e28d745d
 ...
 			</programlisting>
 		</example>
 	</section>
 	<section id="sipcapture.p.callid_aleg_header">
 		<title><varname>callid_aleg_header</varname> (str)</title>
 		<para>
 		Header name used to correlate A-leg with B-leg. It can take a list of headers,
 		separated by semicolon, e.g. "X-CID0;X-CID1". First match wins.
 		</para>
 		<para>
 		<emphasis>
 			Default value is "X-CID".
 		</emphasis>
 		</para>
 		<example>
 			<title>Set <varname>callid_aleg_header</varname> parameter</title>
 			<programlisting format="linespecific">
 ...
 modparam("sipcapture", "callid_aleg_header", "X-CallIDALeg")
41083531
 ...
 			</programlisting>
 		</example>
 	</section>
 	<section id="sipcapture.p.topoh_unmask">
 		<title><varname>topoh_unmask</varname> (int)</title>
 		<para>
 		If set to 1, call-id will be unmasked using topoh module api (topoh
 		module must be loaded in this case).
 		</para>
 		<para>
 			Default value is <emphasis>0</emphasis>.
 		</para>
 		<example>
 			<title>Set <varname>topoh_unmask</varname> parameter</title>
 			<programlisting format="linespecific">
 ...
 modparam("sipcapture", "topoh_unmask", 1)
e88b500f
 ...
 			</programlisting>
 		</example>
 	</section>
1f75be46
 </section>	
0688bed1
 <section>
 	<title>Functions</title>
 	<section id="sipcapture.f.sip_capture">
 		<title>
 		<function moreinfo="none">sip_capture([table])</function>
 		</title>
 		<para>
 		Store the current processed HEP/IPIP SIP message in database. It is stored in the
 		form prior applying changes made to it.
 		</para>
 		<para>Meaning of the parameters is as follows:</para>
 		<itemizedlist>
 		<listitem>
a2697207
 		<para><emphasis>table</emphasis> - The table where HEP SIP message will be stored. Homer 5 use now tables with datestamp. 
 		To generate an automatic table's name please use strftime parameters. I.e. $var(table) = "sip_capture_call_%Y%m%d" and set the variable
 		as an argument of the sip_capture function.
0688bed1
 		</para>
 		</listitem>
 		</itemizedlist>
 		<para>
 		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
 		ONREPLY_ROUTE, BRANCH_ROUTE.
 		</para>
 		<emphasis>
 			Default value is "NULL".
 		</emphasis>
 		<example>
 		<title><function>sip_capture()</function> usage</title>
 		<programlisting format="linespecific">
 ...
 sip_capture();
 ...
 sip_capture("sip_capture_call_20160124");
 ...
 </programlisting>
 		</example>
 	</section>
 	<section id="sipcapture.f.report_capture">
 		<title>
 		<function moreinfo="none">report_capture([table],[data])</function>
 		</title>
 		<para>
 		Store the current processed HEP REPORT message in database. 
 		</para>
 		<para>Meaning of the parameters is as follows:</para>
 		<itemizedlist>
 		<listitem>
 		<para><emphasis>table</emphasis> - The table where REPORT message will be stored.
 		</para>
 		<para><emphasis>data</emphasis> - The custom report data.
 		</para>
 		</listitem>
 		</itemizedlist>
 		<para>
 		This function can be used from REQUEST_ROUTE, FAILURE_ROUTE,
 		ONREPLY_ROUTE, BRANCH_ROUTE.
 		</para>
 		<emphasis>
 			Default value is "NULL".
 		</emphasis>
 		<example>
a2697207
 		<title><function>report_capture()</function> usage</title>
0688bed1
 		<programlisting format="linespecific">
 ...
 report_capture();
 ...
 report_capture("report_data");
 ...
 report_capture("report_data", "{\"MOS\":4.1,\"PACKET_LOST\":100"});
 ...
 </programlisting>
 		</example>
 	</section>
 	
 	</section>
 
 
1f75be46
     <section>
9114eebc
 	<title>MI Commands</title>
7670fafb
 	<section id="sipcapture.m.sip_capture">
1f75be46
 		<title>
 		<function moreinfo="none">sip_capture</function>
 		</title>
 		<para>
 
 		</para>
 		<para>
 		Name: <emphasis>sip_capture</emphasis>
 		</para>
 		<para>Parameters: </para>
 		<itemizedlist>
 			<listitem><para>capture_mode : turns on/off SIP message capturing.
 			Possible values are:</para>
 			<itemizedlist>
 				<listitem><para> on </para></listitem> 
 				<listitem><para> off </para></listitem>
 			</itemizedlist>
 			<para>The parameter is optional - if missing, the command will
 			return the status of the SIP message capturing (as string 
 			<quote>on</quote> or <quote>off</quote> ) without changing
 			anything.</para>
 			</listitem>
 		</itemizedlist>
 
 		<para>
 		MI FIFO Command Format:
 		</para>
 		<programlisting  format="linespecific">
 		:sip_capture:_reply_fifo_file_
 		capture_mode
 		_empty_line_
 		</programlisting>
 	</section>
8ebf2dbe
 	</section><!-- MI commands -->
     	<section>
 	<title>RPC Commands</title>
7670fafb
 	<section id="sipcapture.r.sipcapture.status">
8ebf2dbe
 		<title>
 		<function moreinfo="none">sipcapture.status param</function>
 		</title>
 		<para>
 
 		</para>
 		<para>
 		Name: <emphasis>sipcapture.status</emphasis>
 		</para>
 		<para>Parameters: </para>
 		<itemizedlist>
 			<listitem><para>on or off: turns on/off SIP message capturing.
 			Possible values are:</para>
 			<itemizedlist>
 				<listitem><para>on</para></listitem> 
 				<listitem><para>off</para></listitem>
 			</itemizedlist>
 			</listitem>
ba12e389
 			<listitem><para><quote>check</quote> does not change 
8ebf2dbe
 			sipcapture status, just reports the current status.</para>
 			</listitem>
 		</itemizedlist>
 
1f75be46
 	</section>
fd77c500
 	</section><!-- RPC commands -->
1f75be46
 	
 	<section>
 		<title>Database setup</title>
 		<para>
9af31f9c
 		Before running &kamailio; with the sipcapture module, you have to setup the database 
19d9cd97
 		tables where the module will store the data. For that, if the table were not 
 		created by the installation script or you choose to install everything by 
a2697207
 		yourself you can use the homer_databases.sql, <acronym>SQL</acronym> script 
19d9cd97
 		in the sql folder of sipcapture module as template. You can also find the 
 		complete database documentation on the project webpage, &kamailiodbdocslink;.
1f75be46
 		</para>
 	</section>
 	<section>
9af31f9c
         <title>Limitations</title>
 	<itemizedlist>
 		<listitem>
1f75be46
 		1. Only one capturing mode on RAW socket is supported: IPIP or monitoring/mirroring port. 
a2697207
 		   Don't activate both at the same time. Obsolete. Please use HEP mirroring now.
0688bed1
 		</listitem>
 		<listitem>
 		2. Mirroring port capturing works only on Linux.
9af31f9c
 		</listitem>
         </itemizedlist>
1f75be46
         </section>
 </chapter>