AW: SNMP AgentX Problem <LONG MAIL>

"Stefan Mikuszeit" <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <F3901AB02822B34A97EDB74B8FEF9E06029736AF@hom02ex.hom-de.SYZYGY.INTERN>
Hello Thomas,

	yes, this was the issue :-)

	Now, i must look how i can put the collected data from my snmp-subagent (attached) to
	snmp-agent, I think there is only the set function not included, as Dave me telled, but i'm not a perl programer :-(

Regards
Stefan

-----Ursprüngliche Nachricht-----
Von: Thomas Anders [mailto:[email protected]]
Gesendet: Donnerstag, 5. Juli 2007 18:27
An: Stefan Mikuszeit
Cc: [email protected]
Betreff: Re: SNMP AgentX Problem <LONG MAIL>


Stefan Mikuszeit wrote:
> 	I used the Hello World example from `perldoc NetSNMP::agent` and started the SNMP Agent via:
> 		/usr/sbin/snmpd -Ls DAEMON -Lf /var/log/snmpd.log -u root -p /var/run/snmpd.pid -x tcp:localhost:705 -c /etc/snmp/snmpd.conf
> 
> 	and the subagent via:
> 		/usr/lib/net-snmp/agents/mysql_agent.pl
> 
> 	The agent conf:
> 		cat /etc/snmp/snmp/my_agent_name.conf
> agentxSocket tcp:localhost:705

What's the output of "net-snmp-config --snmpconfpath"? /etc/snmp/snmp
looks wrong. Since your subagent connects, this may just be a typo, though.

> 	I will become this message:
> 		NET-SNMP version 5.4 AgentX subagent connected
> 
> 	If i now start an snmpwalk, this will not work :-(
> 		snmpwalk localhost -c public -v2c .1.3.6.1.4.1.8072.9999.9999.7375.1.0
> 
> 	Errormessage:
> 		NET-SNMP-MIB::netSnmpPlaypen.7375.1.0 = No Such Object available on this agent at this OID

Try adding

use NetSNMP::ASN qw(ASN_OCTET_STR);

to the top of /usr/lib/net-snmp/agents/mysql_agent.pl. Does it help?


+Thomas

-- 
Thomas Anders (thomas.anders at blue-cable.de)

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/

_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users
mysql_agent.pl (application/octet-stream, 4.5 KB)
#!/usr/bin/perl --

use NetSNMP::ASN qw(ASN_OCTET_STR);
use NetSNMP::OID (':all');
use NetSNMP::agent(':all');
use NetSNMP::ASN(':all');
use DBI;
use Log::Logger;


$lh = new Log::Logger;

my $dsn  = "DBI:mysql:host=127.0.0.1;port=3306";
my $user = "root";
my $pass = "SK8Yyr9t";

my $LOGFILE = "/var/log/subagentx.log";

# set to 1 to get extra debugging information
my $DEBUGLEVEL = 4;

$subagent  = 0;

$refresh_interval    = 30;

$global_status       = ();
$global_last_refresh = 0;

###
### Called automatically now and then
### Refreshes the $global_status and $global_variables
### caches.
###

$lh->open_append("$LOGFILE");

sub refresh_status {
  my $now = time();

  # Check if we have been called quicker than once every $refresh_interval
  if (($now - $global_last_refresh) < $refresh_interval) {
    # if yes, do not do anything
    # print STDERR "Not refreshing\n" if ($debugging);
    $lh->log_print("Not refreshing\n");
    return;
  }

  # Connect database
  my $dbh = DBI->connect($dsn, $user, $pass);
  my $cmd = "show /*!50002 GLOBAL */ status";

  # Get status info
  my $sth = $dbh->prepare($cmd);
  $sth->execute();

  # 'status_data' becomes mysqlStatusData
  my $oldname = "";
  while (my $ref = $sth->fetchrow_hashref()) {
    my $name = $ref->{'Variable_name'};

    $name =~ s!_(.)!\U\1\E!g;
    $name = "mysql$name";
    $global_status{$name}{'value'}   = $ref->{'Value'};
    $global_status{$oldname}{'next'} = $name if ($oldname ne "");
    $oldname = $name;
  }

  # No next for the last
  $global_status{$name}{'next'} = '';

  # Fixes
  $global_status{'mysqlMIB'}{'value'} = "0";
  $global_status{'mysqlMIB'}{'next'}  = "mysqlMIBOBjects";

  $global_status{'mysqlMIBObjects'}{'value'} = "0";
  $global_status{'mysqlMIBObjects'}{'next'}  = "mysqlStatus";

  $global_status{'mysqlStatus'}{'value'} = "0";
  $global_status{'mysqlStatus'}{'next'}  = "mysqlAbortedClients";

  $dbh->disconnect();
  $global_last_refresh = $now;
  $lh->log_print("Refreshed at $now ", time()-$now, "\n");
  # print STDERR "Refreshed at $now ", time()-$now, "\n" if ($debugging);

  return;
}

my $regOID = new NetSNMP::OID("mysqlMIB");

if (!$agent) {
    $agent = new NetSNMP::agent('Name' => 'mysql_snmp', # reads mysqlsnmp.conf
                                'AgentX' => 1);         # make us a subagent
    $subagent = 1;
    # print STDERR "started us as a subagent ($agent)\n" if ($debugging);
    $lh->log_print("started us as a subagent ($agent)\n");
}

$agent->register("mysql_snmp", $regOID, &mysql_snmp_handler);

if ($subagent) {
    # We need to perform a loop here waiting for snmp requests.  We
    # also check for new STATUS data.
    $SIG{'INT'} = &shut_it_down;
    $SIG{'QUIT'} = &shut_it_down;
    $running = 1;
    while($running) {
        refresh_status();
        $agent->agent_check_and_process(1);  # 1 = block
    }
    $agent->shutdown();
}

sub shut_it_down {
  $running = 0;
  $lh->log_print("shutting down\n");
  #print STDERR "shutting down\n" if ($debugging);
}

sub mysql_snmp_handler {
  my ($handler, $registration_info, $request_info, $requests ) = @_;
  my ($request);

  # print STDERR "refs: ",join(", ", ref($handler), ref($registration_info), ref($request_info), ref($requests)),"\n" if ($debugging);
  $lh->log_print("refs: ",join(", ", ref($handler), ref($registration_info), ref($request_info), ref($requests)),"\n");

  for ($request = $requests; $request; $request = $request->next()) {
    # Process request for $oid (e.g. mysqlUptime)
    my $oid  = $request->getOID();
    my $mode = $request_info->getMode();
    my $value;
    my $next;

    # print STDERR "- asking for oid $oid (mode $mode)\n" if ($debugging);
    $lh->log_print(" - asking for oid $oid (mode $mode)\n");

    if ($mode == MODE_GET) {
      $value = $global_status{$oid}{'value'};
      $request->setValue(ASN_OCTET_STR, "$value");
      # print STDERR " - GET handling ($oid = $value)\n" if ($debugging);
      $lh->log_print(" - GET handling ($oid = $value)\n");
    }

    if ($mode == MODE_GETNEXT) {
      $next  = $global_status{$oid}{'next'};

      if ($next ne "") {
        $value = $global_status{$next}{'value'};

        $request->setOID($next);
        $request->setValue(ASN_OCTET_STR, "$value");
      } else {
        $request->setOID($oid);
      }
      # print STDERR " - GETNEXT handling ($oid: $next = $value)\n" if ($debugging);
      $lh->log_print(" - GETNEXT handling ($oid: $next = $value)\n");
    }
  }
  #print STDERR "- finished processing\n" if ($debugging);
  $lh->log_print(" - finished processing\n");
}
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.