检测Asterisk通过AMI拒绝传入呼叫的方法

huangapple go评论55阅读模式
英文:

Detecting when Asterisk rejects an incoming call via AMI

问题

我们有一些Asterisk服务器;偶尔,由于人为错误,某人搞乱了拨号计划,导致呼入电话被拒绝:

> NOTICE[27927][C-00000188]: chan_sip.c:26826 handle_request_invite:
> 来自'upstream-peer' (192.168.1.1:5060) 到分机'44123123123'
> 被拒绝,因为在上下文'ourcontext'中找不到分机。

我想实现一小段代码,当发生这种情况时会触发某种警报,以便我们可以快速修复。

我可以(也确实)使用AMI从服务器获取各种事件 - 当通道创建时,当呼叫结束等等 - 但我似乎找不到任何事件或命令,可以在呼叫被拒绝时触发AMI事件。有人知道是否存在这样的东西吗?

英文:

We have a number of Asterisk servers; occasionally, human error means someone messes up the dialplan and incoming calls are rejected:

> NOTICE[27927][C-00000188]: chan_sip.c:26826 handle_request_invite:
> Call from 'upstream-peer' (192.168.1.1:5060) to extension '44123123123'
> rejected because extension not found in context 'ourcontext'.

I'd like to implement a small piece of code that will raise some kind of alert when this happens, so we can fix it quickly.

I can (and do) use AMI to get all sorts of events out of the server - when channels are created, when calls end etc - but I can't seem to find any event or command that will raise an AMI event when a call is rejected. Does anyone know if such a thing exists?

答案1

得分: 1

  1. 设置ami或ARI会话
  2. 捕获"NewChannel"事件
  3. 如果有其他拨号计划类型的事件(如NewExtension)-标记为正常。
  4. 捕获挂机事件,如果没有拨号计划标记-执行不正确拨号计划的程序。

另一个选项(低代码):
设置无效分机
exten => i,1,Noop(这里是一些内容,没有分机)
same => n,CelUserEvent(OOPS); 例如触发cel事件。

英文:
  1. Setup ami or ARI session

  2. Catch "NewChannel" event

  3. If any other dialplan-type event come(like NewExtension) - mark it is okay.

  4. Catch Hangup event, if no diaplan mark - fire your procedure for incorrect dialplan.

Another option(low-code):

Setup invalid extension

exten => i,1,Noop(something here, no extension)
same => n,CelUserEvent(OOPS); for example fire cel event.

答案2

得分: 0

感谢@arheops的启发:我将以下内容添加到上下文拨号计划的底部:

exten => _X.,1,UserEvent(InvalidExtn)
exten => _X.,2,Verbose(注意:传入呼叫尝试转到未配置的${EXTEN}。)
exten => _X.,3,Hangup

_X.将匹配任何号码;由于拨号计划按顺序解析,因此只有达到计划底部的(可能是无效的)号码才会被这个通配符匹配捕获。

然后,在我的监控应用程序中处理UserEvents事件:

manager.UserEvents += Manager_UserEvents;

使用以下简单的代码:

private static void Manager_UserEvents(object sender, UserEvent e)
{
  if (e.UserEventName=="InvalidExtn")
  {
     Console.WriteLine($"无效呼叫!到Asterisk服务器{e.Source.Hostname}的分机{e.Attributes["exten"]}。");
  }
}

虽然不是我希望的那么"干净",但似乎可以工作。

英文:

Thanks to @arheops for the inspiration: I'd added this to the bottom of the context dialplan:

exten => _X.,1,UserEvent(InvalidExtn)
exten => _X.,2,Verbose(ATTENTION: incoming call tried to go to ${EXTEN} which is not configured.)
exten => _X.,3,Hangup

_X. will catch any number; as the dialplan is parsed in order, then only (presumably invalid) numbers that have reached the bottom of the plan will be caught by this wildcard match.

Then, in my monitoring application I handle the UserEvents event:

manager.UserEvents += Manager_UserEvents;

with something simple like:

private static void Manager_UserEvents(object sender, UserEvent e)
{
  if (e.UserEventName=="InvalidExtn")
  {
     Console.WriteLine($"INVALID CALL! To extension {e.Attributes["exten"]} on Asterisk server {e.Source.Hostname}");
  }
}

Not as "clean" as I've have liked it, but it appears to work.

huangapple
  • 本文由 发表于 2023年8月8日 20:54:34
  • 转载请务必保留本文链接:https://go.coder-hub.com/76859777.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定