Perl扩展net-snmp不运行数据库脚本

时间:2015-10-16 18:12:00

标签: perl net-snmp

我是初学者Perl程序员,我需要在NET_SNMP Perl扩展脚本中使用数据库调用(SQLite),但它失败了。

当我从终端调用我的数据库插入脚本时,它可以工作,但是当我从SNMP脚本调用它时,它什么都不做。

创建文件也是如此。

我的sql脚本返回表中的总条目

#!/usr/bin/perl

use DBI;

$driver   = "SQLite";
$database = "test.db";
$dsn = "DBI:$driver:dbname=$database";
$userid = "";
$password = "";

$dbh1 = DBI->connect($dsn, $userid, $password, { RaiseError => 1 }) or die         $DBI::errstr;

$stmt = qq(SELECT COUNT(*) FROM dcmIOboardConfig;);
$sth = $dbh1->prepare( $stmt ) or die "Can't prepare SQL statemen";
$rv = $sth->execute() or die "erro";

if($rv < 0){
    print 0;
}

while( @row = $sth->fetchrow_array()) {
  print $row[0];
}

$dbh1->disconnect();

当我打电话

 perl /var/www/count.pl

它运行,但是当它调用它介绍mu snmp客户端它失败

$sth = $dbh1->prepare( $stmt )

SNMP代码:

#!/usr/bin/perl


use NetSNMP::OID (':all'); 
use NetSNMP::agent (':all'); 
use NetSNMP::ASN (':all');


my $agent;
sub myhandler {

my $dcmNode = ".1.3.6.1.4.1.1206.4.2.9";

my  ($handler, $registration_info, $request_info, $requests) = @_;


for ($request = $requests; $request; $request = $request->next()) {
    my $oid           = $request->getOID();
    my $mode          = $request_info->getMode();
    my $isGet         = ($mode == MODE_GET);

    #  Trata o NTCIP - DCM

    if ( $isGet ) {


        @vOID = $oid->to_array();
        my $baseOID =  ".".@vOID[0].".".@vOID[1].".".@vOID[2].".".@vOID[3].".".@vOID[4].".".@vOID[5].".".@vOID[6].".".@vOID[7].".".@vOID[8].".".@vOID[9];

        if( $baseOID == $dcmNode ){

            # DCM - .1              
            if(@vOID[10] == "1"){

                $output = `perl /var/www/count.pl`;
                $request->setValue(ASN_INTEGER, $output);
                $request->setOID( $baseOID.".1.0" );
            }

0 个答案:

没有答案