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

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

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”;

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.”;

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
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):

secret = password
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=][/url]
url:[url=] … asterisk-pri-nagios[/url]


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



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



在线咨询: QQ交谈