Revision
15377
Author
anthm
Date
2009-11-05 17:01:43 -0600 (Thu, 05 Nov 2009)

Log Message

add logger.pl a FS debug tool using ESL.pm

Added Paths

Diff

Added: freeswitch/trunk/libs/esl/perl/logger.pl (0 => 15377)


--- freeswitch/trunk/libs/esl/perl/logger.pl	                        (rev 0)
+++ freeswitch/trunk/libs/esl/perl/logger.pl	2009-11-05 23:01:43 UTC (rev 15377)
@@ -0,0 +1,122 @@
+use ESL;
+
+my $host = "localhost";
+my $port = "8021";
+my $pass = "ClueCon";
+my $profile = "internal";
+my $file = "";
+my $debug = "";
+my $paste = "";
+my $i;
+my $argc = @ARGV;
+my $e;
+my $running = 1;
+my $con;
+
+$SIG{INT} = sub { $running = 0 };
+
+sub parse(\$\$$) {
+    my ($index, $ref, $regex) = @_;
+
+    if ($ARGV[$$index] =~ $regex) {
+	die "missing arg!" if (!$ARGV[$$index+1]);
+	$$ref = $ARGV[++$$index];
+	return 1;
+    }
+    return 0;
+}
+
+for($i = 0; $i < $argc; $i++) {
+    if (! (parse($i, $host, '^-h$|^--host$') ||
+	   parse($i, $port, '^-p$|^--port$') ||
+	   parse($i, $pass, '^-P$|^--pass$') ||
+	   parse($i, $file, '^-f$|^--file$') ||
+	   parse($i, $paste, '^-pb$|^--paste-bin$') ||
+	   parse($i, $profile, '^-sp$|^--sip-profile$') ||
+	   parse($i, $debug, '^-sd$|^--sip-debug$')
+	   )) {
+	die "invalid arg!";
+    }
+}
+
+if ($paste) {
+    if (!$file) {
+	$file = "./logger_post.log";
+    }
+}
+
+if ($file) {
+    open (F, ">$file");
+    select F;
+}
+
+if ($paste) {
+    print F "paste=Send&remember=0&poster=${paste}&format=fslog&code2=";
+}
+
+$con = new ESL::ESLconnection($host, $port, $pass);
+
+sub do_api($) {
+    my ($cmd, $args) = split(" ", $_[0], 2);
+    my $e = $con->api($cmd, $args);
+    if ($e) {
+	print STDERR $e->getBody() . "\n";
+    }
+}
+
+foreach (split(",", $profile)) {
+    do_api("sofia profile $_ siptrace on");
+}
+
+if ($debug) {
+    do_api("sofia loglevel all $debug");
+}
+
+$e = $con->sendRecv("log 7");
+print STDERR $e->getBody() . "\n" if ($e);
+
+while($con->connected() && $running) {
+    $e = $con->recvEventTimed(100);
+    if ($e and $e->getHeader("content-type") eq "log/data") {
+	print $e->getBody();
+    }
+}
+print STDERR "Stopping\n";
+
+foreach (split(",", $profile)) {
+    do_api("sofia profile $_ siptrace off");
+}
+
+if ($debug) {
+    do_api("sofia loglevel all 0");
+}
+
+$e = $con->sendRecv("log 4");
+print STDERR $e->getBody() . "\n" if ($e);
+
+print STDERR "Done.....\n";
+
+if ($file) {
+    close F;
+    print STDERR "Data written to $file\n";
+}
+
+if ($paste) {
+    my $path;
+    system("mkdir -p .fs_logger");
+    chdir(".fs_logger") or die "I/O Error!";
+    
+    if ($file =~ /^\/.*/) {
+	$path = $file;
+    } else {
+	$path = "../$file";
+    }
+    
+    print STDERR "Posting to pastebin, please wait...\n";
+
+    system("wget --output-file=/dev/null --http-user=pastebin --http-password=freeswitch http://pastebin.freeswitch.org --post-file=$path");
+    $pb = `ls [0-9]*`;
+    print STDERR "Data posted to pastebin [$paste] http://pastebin.freeswitch.org/$pb\n";
+    chdir("..") or die "I/O Error!";
+    system("rm -fr .fs_logger");
+}