#!/usr/bin/perl -w
use strict;
use IO::Socket;
use Getopt::Long;
$|=1;
my (
$host, $username, $password, $verbose, $help, $command, $mode,
$ipaddr, $respaddr, $sendto, $msg, $recvfrom,
$version, $response, $message, $line,
$sock, $port, $reply,
$warning, $critical,
%warnval, %critval,
%channels,
$runmode,
$key,
$s,
);
my $stop = 0;
my $mgr_port = 5038;
my $iax_port = 4569;
my $exitcode = 0;
my $cause = "";
my $iax_answer = 0;
my $iax_maxlen = 1024;
my $iax_timeout = 5;
my $iax_src_call = "8000"; #8000 most siginificant bit is IAX packet type full ... required for a poke etc...
my $iax_dst_call = "0000";
my $iax_timestamp = "00000000";
my $iax_outbound_seq = "00";
my $iax_inbound_seq = "00";
my $iax_type = "06"; #IAX_Control
sub ok {
$s = shift;
$s =~ s/[\r\n]//g;
print "OK: $s\n";
exit(0);
}
sub warning {
$s = shift;
$s =~ s/[\r\n]//g;
print "WARNING: $s\n";
exit(1);
}
sub error {
$s = shift;
$s =~ s/[\r\n]//g;
print "ERROR: $s\n";
exit(2);
}
sub unknown {
$s = shift;
$s =~ s/[\r\n]//g;
print "UNKNOWN: $s\n";
exit(3);
}
sub syntax {
$s = shift;
unless ($s =~ m/Help:/) {
$s = "Error: (".$s.")" or $s = 'Unknown';
}
print "$s\n" unless ($help);
print "Syntax: $0 -m mgr -h <host> -u <username> -p <password> [-cwv]\n";
print "Syntax: $0 -m iax -h <host> [-v]\n";
print "* --host -h Host\n";
print "* --mode -m Mode - eithr 'mgr' or 'iax'\n";
print " --username -u Username\n";
print " --password -p Password\n";
print " --port -P n Port (if not using $mgr_port for manager or $iax_port for IAX)\n";
print " --warning xxx=n Return warning if > n channels of type xxx.\n";
print " --critical xxx=n Return critical if > n channels of type xxx.\n";
print " --verbose -v Verbose\n";
print " --help -h This help\n";
exit(3);
}
Getopt::Long::Configure('bundling');
GetOptions
("p=s" => \$password, "password=s" => \$password,
"u=s" => \$username, "username=s" => \$username,
"h=s" => \$host, "host=s" => \$host,
"P=i" => \$port, "port=i" => \$port,
"H" => \$help, "help" => \$help,
"v" => \$verbose, "verbose" => \$verbose,
"m=s" => \$mode, "mode=s" => \$mode,
"critical=s" => \$critical, "warning=s" => \$warning);
syntax("Help:") if ($help);
syntax("Missing host") unless (defined($host));
syntax("Missing mode") unless (defined($mode));
if ($mode =~ /^iax$/i) {
print "Running in IAX mode\n" if ($verbose);
$runmode = 1;
=1= |