"Fossies" - the Fresh Open Source Software Archive

Member "opensips-3.0.1/test/23.sh" (16 Apr 2019, 4347 Bytes) of package /linux/misc/opensips-3.0.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the last Fossies "Diffs" side-by-side code changes report for "23.sh": 2.4.5_vs_3.0.0.

    1 #!/bin/bash
    2 # loads a carrierroute config for loadbalancing from postgres database
    3 
    4 # Copyright (C) 2007 1&1 Internet AG
    5 #
    6 # This file is part of opensips, a free SIP server.
    7 #
    8 # opensips is free software; you can redistribute it and/or modify
    9 # it under the terms of the GNU General Public License as published by
   10 # the Free Software Foundation; either version 2 of the License, or
   11 # (at your option) any later version
   12 #
   13 # opensips is distributed in the hope that it will be useful,
   14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16 # GNU General Public License for more details.
   17 #
   18 # You should have received a copy of the GNU General Public License
   19 # along with this program; if not, write to the Free Software
   20 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   21 
   22 source include/require
   23 
   24 if ! (check_opensips && check_module "carrierroute" && check_module "db_postgres"); then
   25     exit 0
   26 fi ;
   27 
   28 CFG=13.cfg
   29 
   30 cp $CFG $CFG.bak
   31 
   32 # setup config
   33 echo "loadmodule \"db_postgres/db_postgres.so\"" >> $CFG
   34 echo "modparam(\"carrierroute\", \"config_source\", \"db\")" >> $CFG
   35 echo "modparam(\"carrierroute\", \"db_url\", \"postgres://opensipsro:opensipsro@localhost/opensips\")" >> $CFG
   36 
   37 # setup database
   38 PGPASSWORD='opensipsrw' psql -A -t -n -q -h localhost -U opensips opensips -c "insert into route_tree (id, carrier) values ('1', 'carrier1');
   39 insert into route_tree (id, carrier) values ('2', 'default');
   40 insert into route_tree (id, carrier) values ('3', 'premium');
   41 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('1','1','49','0','0.5','0','host1.local.domain');
   42 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('2','1','49','0','0.5','0','host2.local.domain');
   43 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('3','1','42','0','0.3','0','host3.local');
   44 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('4','1','42','0','0.7','0','host4.local');
   45 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('5','1','1','0','0.5','0','host1-ca.local:5060');
   46 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('6','1','1','0','0.5','0','host2-ca.local.domain:5060');
   47 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('10','1','','0','0.1','0','host5.local');
   48 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('20','2','','0','1','0','host6');
   49 insert into carrierroute (id, carrier, scan_prefix, domain, prob, strip, rewrite_host) values ('21','3','','0','1','0','premium.host.local');"
   50 
   51 ../opensips -w . -f $CFG > /dev/null
   52 ret=$?
   53 
   54 sleep 1
   55 
   56 cd ../scripts
   57 
   58 TMPFILE=`mktemp -t opensips-test.XXXXXXXXXX`
   59 
   60 if [ "$ret" -eq 0 ] ; then
   61     opensips-cli -x mi cr_dump_routes > $TMPFILE
   62     ret=$?
   63 fi ;
   64 
   65 if [ "$ret" -eq 0 ] ; then
   66     tmp=`grep -v "Printing routing information:
   67 Printing tree for carrier premium (3)
   68 Printing tree for domain 0
   69       NULL: 100.000 %, 'premium.host.local': ON, '0', '', '', ''
   70 Printing tree for carrier default (2)
   71 Printing tree for domain 0
   72       NULL: 100.000 %, 'host6': ON, '0', '', '', ''
   73 Printing tree for carrier carrier1 (1)
   74 Printing tree for domain 0
   75          1: 50.000 %, 'host2-ca.local.domain:5060': ON, '0', '', '', ''
   76          1: 50.000 %, 'host1-ca.local:5060': ON, '0', '', '', ''
   77         42: 70.140 %, 'host4.local': ON, '0', '', '', ''
   78         42: 30.060 %, 'host3.local': ON, '0', '', '', ''
   79         49: 50.000 %, 'host2.local.domain': ON, '0', '', '', ''
   80         49: 50.000 %, 'host1.local.domain': ON, '0', '', '', ''
   81       NULL: 100.000 %, 'host5.local': ON, '0', '', '', ''" $TMPFILE`
   82     if [ "$tmp" = "" ] ; then
   83         ret=0
   84     else
   85         ret=1
   86     fi ;
   87 fi ;
   88 
   89 killall -9 opensips
   90 
   91 # cleanup database
   92 PGPASSWORD='opensipsrw' psql -A -t -n -q -h localhost -U opensips opensips -c "delete from route_tree where id = 1;
   93 delete from route_tree where id = 2;
   94 delete from route_tree where id = 3;
   95 delete from carrierroute where carrier=1;
   96 delete from carrierroute where carrier=2;
   97 delete from carrierroute where carrier=3;"
   98 
   99 cd ../test
  100 
  101 mv $CFG.bak $CFG
  102 rm $TMPFILE
  103 
  104 exit $ret