Nagios 检测系统如何检测asterisk pri 的状态

[i=s] 本帖最后由 8080 于 2010-9-8 12:21 编辑 [/i]

hi:
nagios 我已经有过介绍,它的功能已经相当丰富了,通过nagios 和asterisk 的结合,你可以做很多的解决方案,asterisk 不是呼叫中心,CRM, PBX。 asterisk 完全可以作为一个中间件为很多领域工作,系统报警,安防工程,工业控制系统。。下面只是一个例子,希望对业务的提升有所帮助。

I have a number of Asterisk implementations that I keep an eye on that have multiple PRI connections. Knowing if and when they ever go down has the obvious benefits of alerting me to a problem in near real time. But besides that, it allows my customers and I to verify SLAs, track and log issues, etc.

To this end, I have written a Nagios plugin which queries Asterisk’s manager interface and executes the pri show spans CLI command (this is Asterisk 1.4 by the way). The script then parses the output to ascertain whether a PRI is up or not.

The actual code to connect to the manager interface and execute the query is simply:

if( ( $astsock = fsockopen( $host, $port, $errno, $errstr, $timeout ) ) === false )
{
echo “Could not connect to Asterisk manager: $errstr”;
exit( STATUS_CRITICAL );
}

fputs( $astsock, “Action: Loginrn”);
fputs( $astsock, “UserName: $usernamern”);
fputs( $astsock, “Secret: $passwordrnrn”);

fputs( $astsock, “Action: Commandrn”);
fputs( $astsock, “Command: pri show spansrnrn”);

fputs( $astsock, “Action: Logoffrnrn”);

while( !feof( $astsock ) )
{
$asttext .= fread( $astsock, 8192 );
}

fclose( $astsock );

if( strpos( $asttext, “Authentication failed” ) !== false )
{
echo “Asterisk manager authentication failed.”;
exit( STATUS_CRITICAL );
}

This plugin is hard coded to English and expects to find Provisioned, Up, Active for a good PRI. For example, the Asterisk implementations that support the pri show spans command that I have access to return one of:

* PRI span 1/0: Provisioned, In Alarm, Down, Active
* PRI span 3/0: Provisioned, Up, Active

I’m actually running a slightly older version of Nagios at the moment, version 1.3. To integrate the plugin, first add the following command definition to an appropriate existing or new file under /etc/nagios-plugings/config/:

define command{
command_name check_asterisk_pri
command_line /usr/lib/nagios/plugins/check_asterisk_pri.php \
-H $HOSTADDRESS$ -U $ARG1$ -P $ARG2$ -w $ARG3$ \
-c $ARG4$ -n $ARG5$
}

where $ARG1$ is the Asterisk manager username and $ARG2$ is the password. $ARG3$ and $ARG4$ are the warning and critical thresholds respectively whereby if the number of available PRIs reaches one of these values, the appropriate error condition will be set. Lastly, $ARG5$ is the number of PRIs the plugin should expect to find.

NB: the command_line line above is split for readability but it should all be on the one line.

Now create a test for a host in an appropriate file in /etc/nagios/config/:

define service{
use core-service
host_name hostname.domain.ie
service_description Asterisk PRIs
check_command check_asterisk_pri!user!pass!2!1!4
}

Ensure that your Nagios server has permissions to access the Asterisk server via TCP on the Asterisk manager port (5038 by default). If on a public network, this should be done via stunnel or a VPN for security reasons.

Lastly, you’ll need a user with the appropriate permissions and host allow statements in your Asterisk configuration (/etc/asterisk/manager.conf):

[username]
secret = password
deny=0.0.0.0/0.0.0.0
permit=1.2.3.4/255.255.255.255
read = command
write = command

The next version may include support for BRI and Zap FXO ports also. I also plan on a Cacti plug in to show the channels on each PRI (up – on a call, down, etc). In any case, updates will be posted here.

The plug in can be download from: [url=http://www.opensolutions.ie/misc/check_asterisk_pri.php.txt]http://www.opensolutions.ie/misc/check_asterisk_pri.php.txt[/url]
url:[url=http://www.barryodonovan.com/index.php/2007/11/02/asterisk-pri-nagios]http://www.barryodonovan.com/ind … asterisk-pri-nagios[/url]

主题测试文章,只做测试使用。发布者:zhangyang,转转请注明出处:https://www.voip88.com/nagios-%e6%a3%80%e6%b5%8b%e7%b3%bb%e7%bb%9f%e5%a6%82%e4%bd%95%e6%a3%80%e6%b5%8basterisk-pri-%e7%9a%84%e7%8a%b6%e6%80%81/

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022年 8月 26日 下午3:27
下一篇 2022年 8月 26日 下午3:28

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
自6.2开始主题新增页头通知功能,购买用户可免费升级到最新版体验