[erlang-bugs] SNMP manager: strange behaviour

Денис Артёмов art_den@REDACTED
Tue Dec 9 13:29:16 CET 2008


This source code if work fine for me:

-module(test_snmp).

-behaviour(snmpm_user).

-export([
    start/1,
    handle_error/3, handle_agent/4, handle_pdu/5, handle_trap/4, handle_inform/4, handle_report/4
]).

-define(ENGINE_ID, [16#50, 16#6f, 16#6c, 16#79, 16#43, 16#6f, 16#6d, 16#2d, 16#33, 16#30, 16#30, 16#55, 16#2d, 16#31, 16#47, 16#54]).
-define(USER, lalala).
-define(USER_NAME, "username").

start(_Arg) ->
    catch start_safe(),
    snmpm:stop().

start_safe() ->
    ok = crypto:start(),
    
    ok = snmpm:start(),
    ok = snmpm:register_user(?USER, ?MODULE, undefined),
    
    AuthKey = snmp:passwd2localized_key(md5, "123456789", ?ENGINE_ID),
    PrivKey = snmp:passwd2localized_key(md5, "123456789", ?ENGINE_ID),
    
    ok = snmpm:register_usm_user(?ENGINE_ID, ?USER_NAME, 
        [
            {auth,     usmHMACMD5AuthProtocol},
            {sec_name, ?USER_NAME            },
            {auth_key, AuthKey               },
            {priv,     usmDESPrivProtocol    },
            {priv_key, PrivKey               }
        ]
    ),
    
    ok = snmpm:register_agent(
           ?USER, 
           [192,168,0,179], 
           [
                {version,   v3         },
                {engine_id, ?ENGINE_ID },
                {sec_model, usm        },
                {sec_name,  ?USER_NAME },
                {sec_level, authPriv   }
           ]
    ),
    
% If to uncomment code below, error occurs when calling snmpm:g!!!
%    ok = snmpm:register_agent(
%           ?USER, 
%           [192,168,0,180], 
%           [
%                {version,   v1      },
%                {community, "public"}
%           ]
%    ),
    
    Result1 = snmpm:g(?USER, {192,168,0,179}, [[1,3,6,1,2,1,1,1,0]]),
    io:format("Result1=~p~n", [Result1]),
    
    Result2 = snmpm:g(?USER, {192,168,0,179}, [[1,3,6,1,2,1,1,1,0]]),
    io:format("Result2=~p~n", [Result2]),
    
    ok. 
    

handle_error(ReqId, Reason, UserData) ->
    io:format
    (
        "handle_error(ReqId=~p, Reason=~p, UserData=~p)~n", 
        [ReqId, Reason, UserData]
       ),
    ignore.

handle_agent(Addr, Port, SnmpInfo, UserData) ->
    io:format
    (
        "handle_agent(Addr=~p, Port=~p, SnmpInfo=~p, UserData=~p)~n", 
        [Addr, Port, SnmpInfo, UserData]
    ),
    ignore.

handle_pdu(Addr, Port, ReqId, SnmpResponse, UserData) ->
    io:format
    (
        "handle_pdu(Addr=~p, Port=~p, ReqId=~p, SnmpResponse=~p, UserData=~p)~n", 
        [Addr, Port, ReqId, SnmpResponse, UserData]
       ),
    ignore.

handle_trap(Addr, Port, SnmpTrapInfo, UserData) ->
    io:format
    (
        "handle_trap(Addr=~p, Port=~p, SnmpTrapInfo=~p, UserData=~p)~n",
        [Addr, Port, SnmpTrapInfo, UserData]
    ),
    ignore.

handle_inform(Addr, Port, SnmpInfo, UserData) ->
    io:format
    (
        "handle_inform(Addr=~p, Port=~p, SnmpInfo=~p, UserData=~p)~n",
        [Addr, Port, SnmpInfo, UserData]
    ),
    ignore.

handle_report(Addr, Port, SnmpInfo, UserData) ->
    io:format
    (
        "handle_report(Addr=~p, Port=~p, SnmpInfo=~p, UserData=~p)~n",
        [Addr, Port, SnmpInfo, UserData]
    ),
    ignore.


but if to uncomment code where another agent is registered with SNMP v1, then info report appears in the screen after calling of snmpm:g function:

Eshell V5.6.5  (abort with ^G)
(snmpman_server@REDACTED)1> Result1={error,{send_failed,1628668040,unknownSecurityName}}
(snmpman_server@REDACTED)1> Result2={error,{send_failed,1628668041,unknownSecurityName}}
(snmpman_server@REDACTED)1>
=ERROR REPORT==== 9-Dec-2008::17:15:25 ===
[ snmp : manager : snmpm_mpd : <0.57.0> ]
MPD: CONFIG ERROR: unknownSecurityName (message: {message,'version-3',
                                                  {v3_hdr,1393084258,484,
                                                   [7],
                                                   3,undefined,undefined},
                                                  [48,50,4,16,80,111,108,121,
                                                   67,111,109,45,51,48,48,85,
                                                   45,49,71,84,4,0,160,28,2,4,
                                                   97,19,128,136,2,1,0,2,1,0,
                                                   48,14,48,12,6,8,43,6,1,2,1,
                                                   1,1,0,5,0]})

(snmpman_server@REDACTED)1>
=ERROR REPORT==== 9-Dec-2008::17:15:25 ===
[ snmp : manager : snmpm_mpd : <0.57.0> ]
MPD: CONFIG ERROR: unknownSecurityName (message: {message,'version-3',
                                                  {v3_hdr,1393084259,484,
                                                   [7],
                                                   3,undefined,undefined},
                                                  [48,50,4,16,80,111,108,121,
                                                   67,111,109,45,51,48,48,85,
                                                   45,49,71,84,4,0,160,28,2,4,
                                                   97,19,128,137,2,1,0,2,1,0,
                                                   48,14,48,12,6,8,43,6,1,2,1,
                                                   1,1,0,5,0]})

text of my manager.conf is:
{port,             162}.
{engine_id,        "manager id"}.
{max_message_size, 484}.

Is it bug in my code or in erlang SNMP library? How to force to register both snmp-v1 and snmp-v3 agents without errors?




More information about the erlang-bugs mailing list