5

我被要求开发一个脚本,可以通过 H.323 拨打需要更好监控的语音邮件系统。(该设备以神秘的方式死机,并且提供的 snmp 功能很少)。这个想法是拨打一个号码,看看是否有人接听电话。如果出现问题,语音信箱系统会响铃或不接听。

我的问题在于我对 H.323 或可用库一无所知。(Perl 是我公司的首选语言,但对于这种特定的事情,我可能会使用 python 或使用一些二进制程序。)

在搜索 H.323 时,我发现了一个不同的黑暗兔子洞。我不知道 C 或想将 pbx 作为客户端运行,我找到了开源库,但没有“call()”函数之类的东西。我没有学习每一个进出的周期。

(如果这不是为了工作,我会连接几行 python 并使用 Twilio 来完成所有繁重的工作。)

我想我需要一些关于如何解决问题的指导。

谢谢

4

2 回答 2

3

要进行测试 H.323 呼叫,您无法击败 ohphone:

(sleep 30; echo q) | ohphone -s Default -n -u from_user to_user@gateway > /tmp/output.$$

你通常可以在你的 linux 发行版中找到 ohphone 作为一个包:

apt-get install ohphone

可以在voxgratia上找到源代码 虽然较旧,但它仍然可以出色地工作。

使用 ohphone 处理输出有点棘手,但您可以使用 perl 脚本之类的东西将其处理为 errno 值。

这是一个快速而肮脏的示例:

#!/usr/bin/env perl

$delay=$ARGV[0];
if(! $delay) { $delay = 10; }

$from=$ARGV[1];
if(! $from) { $from = "default_from_user"; }

$to=$ARGV[2];
if(! $to) { $to = "default_to_user"; }

$gateway=$ARGV[3];
if(! $gateway) { $gateway = "127.0.0.1"; }

print "Running: (sleep $delay; echo q ) | (ohphone -s Default -n -u $from $to\@$gateway)|\n";
open(IN,"(sleep $delay; echo q ) | (ohphone -s Default -n -u $from $to\@$gateway)|");

my $call_started=false;
my $call_completed=false;

my @results;

my $skip=1;
while($line=<IN>) {
 if($line=~/Listening interfaces/) {
  $skip=0;
  next;
 }
 if($skip) {
  next;
 }
 if($line=~/^Could not open sound device/) {
  next;
 }
 chomp($line);
 push(@results,$line);
 if($line=~/was busy$/) {
  print "$to: Called party busy\n";
  exit 1;
 }
 if($line=~/^Call with .* completed, duration (.*)$/) {
  print "$to: Completed duration $1 call.\n";
  exit 0;
 }
 if($line=~/has cleared the call, duration (.*)$/) {
  print "$to: Completed duration $1 call.\n";
  exit 0;
 }
 if($line=~/^Call with .* completed$/) {
  print "$to: No call duration.\n";
  exit 2;
 }
}

close(IN);

$result=join("\n",@results);
print "$ARGV[0]: Unknown results:\n$result\n";
exit 255;

这个脚本已经有好几年的历史了,但在那段时间里它对我们来说效果很好。

于 2012-10-17T21:47:33.147 回答
1

有 SIP 测试工具可让您生成 SIP 流量。我过去曾在大学项目中使用过 SIPp ,也许这对你有帮助

**EDIT:**

快速搜索给了Yate Seagull我没有使用过它们,但也许它们可以解决您的问题。如果您发现某些内容,请务必发布。

于 2010-11-10T15:41:31.487 回答