]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
add logger.pl a FS debug tool using ESL.pm
authorAnthony Minessale <anthony.minessale@gmail.com>
Thu, 5 Nov 2009 23:01:43 +0000 (23:01 +0000)
committerAnthony Minessale <anthony.minessale@gmail.com>
Thu, 5 Nov 2009 23:01:43 +0000 (23:01 +0000)
git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@15377 d0543943-73ff-0310-b7d9-9358b9ac24b2

libs/esl/perl/logger.pl [new file with mode: 0644]

diff --git a/libs/esl/perl/logger.pl b/libs/esl/perl/logger.pl
new file mode 100644 (file)
index 0000000..2e26cfd
--- /dev/null
@@ -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");
+}