My code is finished.. Please give me some advise on what I did wrong(it is working code)... or what i didn't do it correctly or efficiently.. thanks guys!
#!/usr/bin/perl -w
use strict;
use diagnostics;
use Getopt::Long;
my @servers = qw(server1 sever2 server3 sever4);
my $help = 0;
my ($callid,$dn,$inbound);
sub usage {
print <<"NL";
usage: $0 sip/h323 [-h] -c <callid> -d <dialed number> -i <in
+bound id>
syntax:
--help -h
prints this help text and exists
--callid -c
allows searching in SBC by callid ; will output
+ of calls and siptool -v
--dn -d
allows searching in SBC by dialed number; will
+output last found call from each server if applicable
--inbound -i
allows searching in SBC by inbound ID ; will ou
+tput last found call from each server if applicable
--time -t { Future implementation }
allows searching callid/dn/inbound in SBC by ho
+ur ; in 00:00 to 23:59 format
To search between 2PM and 3PM, 14:00-15:00
example: $0 sip --dn 12125551212 or $0 sip -d 12125551212
$0 h323 --callid 12341234 or $0 h323 -c 12341234
$0 sip --inbound 333333 or $0 sip -i 33333
NL
exit 0;
}
sub san_check_arg {
usage () if $#ARGV != 0;
usage () if $ARGV[0] !~ /\bsip\b|\bh323\b/i;
return ('CALLID', $callid) if defined($callid);
return ('DN',$dn) if defined($dn);
return ('INBOUND ID',$inbound) if defined($inbound);
}
sub wr_temp {
my $wr_t = shift;
open FF, ">/tmp/file_123456";
print FF "$wr_t";
close FF;
}
sub proc_it {
my $proc = shift;
my @meth =
$_[0] eq 'CALLID' ? 'CALLID' :
$_[0] eq 'INBOUND ID' ? 'INBOUND ID' : '';
my $file_f;
my ($h323_r,$sip_r);
if ("$proc" eq 'h323') {
for (@servers) {
print "\t going through server $_\n";
if ($meth[0] eq 'INBOUND ID') {
$h323_r = `ssh "$_" grep "'|$_[1]|'" /process/hom
+e/h323cc.[12]/paccalls | tail -1`;
next;
} else {
$h323_r = `ssh "$_" grep "$_[1]" /process/home/h3
+23cc.[12]/paccalls | tail -1`;
}
if (($h323_r) && ($meth[0] eq 'CALLID')) {
$file_f = wr_temp("$h323_r");
system "/n2p/bin/siptool -v /tmp/file_123456";
last;
} elsif ($h323_r) {
print "Foudn at least one call at $_\n";
print "$h323_r\n";
next;
}
}
} elsif ("$proc" eq 'sip') {
for (@servers) {
print "\t going through server $_\n";
if ($meth[0] eq 'INBOUND ID') {
#my $yahoo = "\|$_[1]\|";
$sip_r = `ssh "$_" grep "'|$_[1]|'" /process/home
+/sipcc.[12]/sipcalls | tail -1`;
print "$sip_r\n";
next;
} else {
$sip_r = `ssh "$_" grep "$_[1]" /process/home/sip
+cc.[12]/sipcalls | tail -1`;
}
if (($sip_r) && ($meth[0] eq 'CALLID')) {
$file_f = wr_temp("$sip_r");
system("/n2p/bin/siptool -v /tmp/file_123456");
last;
} elsif ($sip_r) {
print "Found at least one call at $_\n";
print "$sip_r\n";
}
}
} else {
print "Do no understand your input\n";
usage();
}
}
my $val1 = eval { GetOptions (
"help" => sub { usage() },
"callid=s" => \$callid,
"dn=s" => \$dn,
"inbound=s" => \$inbound
)};
die usage() if $@; #alone
if (!$val1) {
usage();
}
my @ar = san_check_arg(); #check users input sanity
proc_it(@ARGV,@ar);