You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
rtpengine/utils/rtpengine-ctl

77 lines
2.1 KiB

#!/usr/bin/perl
use IO::Socket::INET;
$num_args = $#ARGV + 1;
if ($num_args == 0) {
showusage();
exit;
}
# auto-flush on socket
$| = 1;
my $argumentstring = "";
my $ip = "127.0.0.1";
my $port = "9900";
for (my $argnum=0; $argnum <= $#ARGV; $argnum++) {
if ($ARGV[$argnum] eq "-ip") {
die "No argument after -ip\n" unless $argnum+1<=$#ARGV;
$argnum = $argnum+1;
$ip = $ARGV[$argnum];
} elsif ($ARGV[$argnum] eq "-port") {
die "No argument after -port\n" unless $argnum+1<=$#ARGV;
$argnum = $argnum+1;
$port = $ARGV[$argnum];
} else {
$argumentstring .= "$ARGV[$argnum] ";
}
}
# create a connecting socket
my $socket = new IO::Socket::INET (
PeerHost => $ip,
PeerPort => $port,
Proto => 'tcp',
);
die "Cannot connect to the rtpengine $!\n" unless $socket;
$argumentstring = trim($argumentstring);
my $size = $socket->send($argumentstring);
# notify server that request has been sent
shutdown($socket, 1);
# receive a response of up to 10MB
my $response = "";
$socket->recv($response, 1024*1024*10);
print $response;
$socket->close();
sub showusage {
print "\n";
print " rtpengine-ctl [ -ip <ipaddress> -port <port> ] <command>\n";
print "\n";
print " Supported commands are:\n";
print "\n";
print " list [ numsessions | sessions | session <callid> | totals ]\n";
print " numsessions : prints the number of sessions\n";
print " sessions : print one-liner session information\n";
print " session <callid> : print detail about one session\n";
print " totals : print total statistics\n";
print "\n";
print " terminate [ all | <callid> ]\n";
print " all : terminates all current sessions\n";
print " <callid> : session is immediately terminated\n";
print "\n";
print "\n";
print " Return Value:\n";
print " 0 on success with ouput from server side, other values for failure.\n";
print "\n";
}
sub trim { my $s = shift; $s =~ s/^\s+|\s+$//g; return $s };