diff options
Diffstat (limited to 'lib/snmp/src')
-rw-r--r-- | lib/snmp/src/agent/snmp_community_mib.erl | 4 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmp_framework_mib.erl | 12 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmp_standard_mib.erl | 275 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmp_target_mib.erl | 13 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmp_user_based_sm_mib.erl | 60 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmp_view_based_acm_mib.erl | 189 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmpa.erl | 182 | ||||
-rw-r--r-- | lib/snmp/src/agent/snmpa_mib_lib.erl | 57 | ||||
-rw-r--r-- | lib/snmp/src/app/snmp.appup.src | 44 |
9 files changed, 798 insertions, 38 deletions
diff --git a/lib/snmp/src/agent/snmp_community_mib.erl b/lib/snmp/src/agent/snmp_community_mib.erl index 8f0f4cad73..5644a43345 100644 --- a/lib/snmp/src/agent/snmp_community_mib.erl +++ b/lib/snmp/src/agent/snmp_community_mib.erl @@ -336,6 +336,8 @@ get_target_addr_ext_mms(TDomain, TAddress, Key) -> get_target_addr_ext_mms(TDomain, TAddress, NextKey) end end. + + %%----------------------------------------------------------------- %% Instrumentation Functions %%----------------------------------------------------------------- @@ -347,7 +349,7 @@ snmpCommunityTable(print) -> PrintRow = fun(Prefix, Row) -> lists:flatten( - io_lib:format("~sIndex: ~p" + io_lib:format("~sIndex: ~p" "~n~sName: ~p" "~n~sSecurityName: ~p" "~n~sContextEngineID: ~p" diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl index d9bf7e8551..0d7866d94d 100644 --- a/lib/snmp/src/agent/snmp_framework_mib.erl +++ b/lib/snmp/src/agent/snmp_framework_mib.erl @@ -373,15 +373,27 @@ intAgentUDPPort(Op) -> intAgentIpAddress(Op) -> snmp_generic:variable_func(Op, db(intAgentIpAddress)). +snmpEngineID(print) -> + VarAndValue = [{snmpEngineID, snmpEngineID(get)}], + snmpa_mib_lib:print_variables(VarAndValue); snmpEngineID(Op) -> snmp_generic:variable_func(Op, db(snmpEngineID)). +snmpEngineMaxMessageSize(print) -> + VarAndValue = [{snmpEngineMaxMessageSize, snmpEngineMaxMessageSize(get)}], + snmpa_mib_lib:print_variables(VarAndValue); snmpEngineMaxMessageSize(Op) -> snmp_generic:variable_func(Op, db(snmpEngineMaxMessageSize)). +snmpEngineBoots(print) -> + VarAndValue = [{snmpEngineBoots, snmpEngineBoots(get)}], + snmpa_mib_lib:print_variables(VarAndValue); snmpEngineBoots(Op) -> snmp_generic:variable_func(Op, db(snmpEngineBoots)). +snmpEngineTime(print) -> + VarAndValue = [{snmpEngineTime, snmpEngineTime(get)}], + snmpa_mib_lib:print_variables(VarAndValue); snmpEngineTime(get) -> {value, get_engine_time()}. diff --git a/lib/snmp/src/agent/snmp_standard_mib.erl b/lib/snmp/src/agent/snmp_standard_mib.erl index 639172401d..b6834d278c 100644 --- a/lib/snmp/src/agent/snmp_standard_mib.erl +++ b/lib/snmp/src/agent/snmp_standard_mib.erl @@ -40,6 +40,28 @@ sys_object_id/1, sys_object_id/2, sys_or_table/3, variable_func/1, variable_func/2, inc/1, inc/2]). +-export([sysDescr/1, sysContact/1, sysName/1, sysLocation/1, + sysServices/1, sysUpTime/1, snmpEnableAuthenTraps/1, + sysObjectID/1, + snmpInPkts/1, snmpOutPkts/1, + snmpInBadVersions/1, + snmpInBadCommunityNames/1, snmpInBadCommunityUses/1, + snmpInASNParseErrs/1, + snmpInTooBigs/1, + snmpInNoSuchNames/1, snmpInBadValues/1, + snmpInReadOnlys/1, snmpInGenErrs/1, + snmpInTotalReqVars/1, snmpInTotalSetVars/1, + snmpInGetRequests/1, snmpInSetRequests/1, + snmpInGetNexts/1, + snmpInGetResponses/1, snmpInTraps/1, + snmpOutTooBigs/1, + snmpOutNoSuchNames/1, + snmpOutBadValues/1, + snmpOutGenErrs/1, + snmpOutGetRequests/1, snmpOutSetRequests/1, + snmpOutGetNexts/1, + snmpOutGetResponses/1, + snmpOutTraps/1]). -export([dummy/1, snmp_set_serial_no/1, snmp_set_serial_no/2]). -export([add_agent_caps/2, del_agent_caps/1, get_agent_caps/0]). -export([check_standard/1]). @@ -202,18 +224,257 @@ variable_func(get, Name) -> inc(Name) -> inc(Name, 1). inc(Name, N) -> ets:update_counter(snmp_agent_table, Name, N). + +sysDescr(print) -> + VarAndValue = [{sysDescr, sysDescr(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + +sysDescr(get) -> + VarDB = db(sysDescr), + snmp_generic:variable_get(VarDB). + + +sysContact(print) -> + VarAndValue = [{sysContact, sysContact(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + +sysContact(get) -> + VarDB = db(sysContact), + snmp_generic:variable_get(VarDB). + + +sysName(print) -> + VarAndValue = [{sysName, sysName(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + +sysName(get) -> + VarDB = db(sysName), + snmp_generic:variable_get(VarDB). + + +sysLocation(print) -> + VarAndValue = [{sysLocation, sysLocation(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + +sysLocation(get) -> + VarDB = db(sysLocation), + snmp_generic:variable_get(VarDB). + + +sysServices(print) -> + VarAndValue = [{sysServices, sysServices(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + +sysServices(get) -> + VarDB = db(sysServices), + snmp_generic:variable_get(VarDB). + + +snmpInPkts(print) -> + gen_counter(print, snmpInPkts); +snmpInPkts(get) -> + gen_counter(get, snmpInPkts). + + +snmpOutPkts(print) -> + gen_counter(print, snmpOutPkts); +snmpOutPkts(get) -> + gen_counter(get, snmpOutPkts). + + +snmpInASNParseErrs(print) -> + gen_counter(print, snmpInASNParseErrs); +snmpInASNParseErrs(get) -> + gen_counter(get, snmpInASNParseErrs). + + +snmpInBadCommunityNames(print) -> + gen_counter(print, snmpInBadCommunityNames); +snmpInBadCommunityNames(get) -> + gen_counter(get, snmpInBadCommunityNames). + + +snmpInBadCommunityUses(print) -> + gen_counter(print, snmpInBadCommunityUses); + +snmpInBadCommunityUses(get) -> + gen_counter(get, snmpInBadCommunityUses). + + +snmpInBadVersions(print) -> + gen_counter(print, snmpInBadVersions); +snmpInBadVersions(get) -> + gen_counter(get, snmpInBadVersions). + + +snmpInTooBigs(print) -> + gen_counter(print, snmpInTooBigs); +snmpInTooBigs(get) -> + gen_counter(get, snmpInTooBigs). + + +snmpInNoSuchNames(print) -> + gen_counter(print, snmpInNoSuchNames); +snmpInNoSuchNames(get) -> + gen_counter(get, snmpInNoSuchNames). + + +snmpInBadValues(print) -> + gen_counter(print, snmpInBadValues); +snmpInBadValues(get) -> + gen_counter(get, snmpInBadValues). + + +snmpInReadOnlys(print) -> + gen_counter(print, snmpInReadOnlys); +snmpInReadOnlys(get) -> + gen_counter(get, snmpInReadOnlys). + + +snmpInGenErrs(print) -> + gen_counter(print, snmpInGenErrs); +snmpInGenErrs(get) -> + gen_counter(get, snmpInGenErrs). + + +snmpInTotalReqVars(print) -> + gen_counter(print, snmpInTotalReqVars); +snmpInTotalReqVars(get) -> + gen_counter(get, snmpInTotalReqVars). + + +snmpInTotalSetVars(print) -> + gen_counter(print, snmpInTotalSetVars); +snmpInTotalSetVars(get) -> + gen_counter(get, snmpInTotalSetVars). + + +snmpInGetRequests(print) -> + gen_counter(print, snmpInGetRequests); +snmpInGetRequests(get) -> + gen_counter(get, snmpInGetRequests). + + +snmpInSetRequests(print) -> + gen_counter(print, snmpInSetRequests); +snmpInSetRequests(get) -> + gen_counter(get, snmpInSetRequests). + + +snmpInGetNexts(print) -> + gen_counter(print, snmpInGetNexts); +snmpInGetNexts(get) -> + gen_counter(get, snmpInGetNexts). + + +snmpInGetResponses(print) -> + gen_counter(print, snmpInGetResponses); +snmpInGetResponses(get) -> + gen_counter(get, snmpInGetResponses). + + +snmpInTraps(print) -> + gen_counter(print, snmpInTraps); +snmpInTraps(get) -> + gen_counter(get, snmpInTraps). + + +snmpOutTooBigs(print) -> + gen_counter(print, snmpOutTooBigs); +snmpOutTooBigs(get) -> + gen_counter(get, snmpOutTooBigs). + + +snmpOutNoSuchNames(print) -> + gen_counter(print, snmpOutNoSuchNames); +snmpOutNoSuchNames(get) -> + gen_counter(get, snmpOutNoSuchNames). + + +snmpOutBadValues(print) -> + gen_counter(print, snmpOutBadValues); +snmpOutBadValues(get) -> + gen_counter(get, snmpOutBadValues). + + +snmpOutGenErrs(print) -> + gen_counter(print, snmpOutGenErrs); +snmpOutGenErrs(get) -> + gen_counter(get, snmpOutGenErrs). + + +snmpOutGetRequests(print) -> + gen_counter(print, snmpOutGetRequests); +snmpOutGetRequests(get) -> + gen_counter(get, snmpOutGetRequests). + + +snmpOutSetRequests(print) -> + gen_counter(print, snmpOutSetRequests); +snmpOutSetRequests(get) -> + gen_counter(get, snmpOutSetRequests). + + +snmpOutGetNexts(print) -> + gen_counter(print, snmpOutGetNexts); +snmpOutGetNexts(get) -> + gen_counter(get, snmpOutGetNexts). + + +snmpOutGetResponses(print) -> + gen_counter(print, snmpOutGetResponses); +snmpOutGetResponses(get) -> + gen_counter(get, snmpOutGetResponses). + + +snmpOutTraps(print) -> + gen_counter(print, snmpOutTraps); +snmpOutTraps(get) -> + gen_counter(get, snmpOutTraps). + + +gen_counter(print, Counter) -> + Val = gen_counter(get, Counter), + VarAndValue = [{Counter, Val}], + snmpa_mib_lib:print_variables(VarAndValue); + +gen_counter(get, Counter) -> + variable_func(get, Counter). + + %%----------------------------------------------------------------- %% This is the instrumentation function for sysUpTime. %%----------------------------------------------------------------- +sysUpTime(print) -> + sys_up_time(print); +sysUpTime(get) -> + sys_up_time(get). + sys_up_time() -> snmpa:sys_up_time(). +sys_up_time(print) -> + VarAndValue = [{sysUpTime, sys_up_time(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + sys_up_time(get) -> {value, snmpa:sys_up_time()}. + %%----------------------------------------------------------------- %% This is the instrumentation function for snmpEnableAuthenTraps %%----------------------------------------------------------------- + +snmpEnableAuthenTraps(print) -> + snmp_enable_authen_traps(print); +snmpEnableAuthenTraps(get) -> + snmp_enable_authen_traps(get). + + +snmp_enable_authen_traps(print) -> + VarAndValue = [{snmpEnableAuthenTraps, snmp_enable_authen_traps(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + snmp_enable_authen_traps(new) -> snmp_generic:variable_func(new, db(snmpEnableAuthenTraps)); @@ -226,9 +487,19 @@ snmp_enable_authen_traps(get) -> snmp_enable_authen_traps(set, NewVal) -> snmp_generic:variable_func(set, NewVal, db(snmpEnableAuthenTraps)). + %%----------------------------------------------------------------- -%% This is the instrumentation function for sysObjectId +%% This is the instrumentation function for sysObjectID %%----------------------------------------------------------------- +sysObjectID(print) -> + sys_object_id(print); +sysObjectID(get) -> + sys_object_id(get). + +sys_object_id(print) -> + VarAndValue = [{sysObjectID, sys_object_id(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + sys_object_id(new) -> snmp_generic:variable_func(new, db(sysObjectID)); @@ -241,6 +512,7 @@ sys_object_id(get) -> sys_object_id(set, NewVal) -> snmp_generic:variable_func(set, NewVal, db(sysObjectID)). + %%----------------------------------------------------------------- %% This is a dummy instrumentation function for objects like %% snmpTrapOID, that is accessible-for-notify, with different @@ -249,6 +521,7 @@ sys_object_id(set, NewVal) -> %%----------------------------------------------------------------- dummy(_Op) -> ok. + %%----------------------------------------------------------------- %% This is the instrumentation function for snmpSetSerialNo. %% It is always volatile. diff --git a/lib/snmp/src/agent/snmp_target_mib.erl b/lib/snmp/src/agent/snmp_target_mib.erl index 3c32d1f59f..270a5fd5b6 100644 --- a/lib/snmp/src/agent/snmp_target_mib.erl +++ b/lib/snmp/src/agent/snmp_target_mib.erl @@ -511,6 +511,10 @@ set_target_engine_id(TargetAddrName, EngineId) -> %%----------------------------------------------------------------- %% Instrumentation Functions %%----------------------------------------------------------------- +snmpTargetSpinLock(print) -> + VarAndValue = [{snmpTargetSpinLock, snmpTargetSpinLock(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + snmpTargetSpinLock(new) -> snmp_generic:variable_func(new, {snmpTargetSpinLock, volatile}), {A1,A2,A3} = erlang:now(), @@ -591,12 +595,9 @@ snmpTargetAddrTable(print) -> ?'snmpTargetAddrRowStatus_active' -> active; _ -> undefined end, - Prefix, - element(?snmpTargetAddrEngineId, Row), - Prefix, - element(?snmpTargetAddrTMask, Row), - Prefix, - element(?snmpTargetAddrMMS, Row)])) + Prefix, element(?snmpTargetAddrEngineId, Row), + Prefix, element(?snmpTargetAddrTMask, Row), + Prefix, element(?snmpTargetAddrMMS, Row)])) end, snmpa_mib_lib:print_table(Table, DB, FOI, PrintRow); %% Op == new | delete diff --git a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl index f40bb1a5b9..69cebc858b 100644 --- a/lib/snmp/src/agent/snmp_user_based_sm_mib.erl +++ b/lib/snmp/src/agent/snmp_user_based_sm_mib.erl @@ -26,6 +26,12 @@ table_next/2, is_engine_id_known/1, get_user/2, get_user_from_security_name/2, mk_key_change/3, mk_key_change/5, extract_new_key/3, mk_random/1]). +-export([usmStatsUnsupportedSecLevels/1, + usmStatsNotInTimeWindows/1, + usmStatsUnknownUserNames/1, + usmStatsUnknownEngineIDs/1, + usmStatsWrongDigests/1, + usmStatsDecryptionErrors/1]). -export([add_user/1, add_user/13, delete_user/1]). %% Internal @@ -303,6 +309,54 @@ gc_tabs() -> %%----------------------------------------------------------------- %% Counter functions %%----------------------------------------------------------------- + +usmStatsUnsupportedSecLevels(print) -> + VarAndValue = [{usmStatsUnsupportedSecLevels, + usmStatsUnsupportedSecLevels(get)}], + snmpa_mib_lib:print_variables(VarAndValue); +usmStatsUnsupportedSecLevels(get) -> + get_counter(usmStatsUnsupportedSecLevels). + +usmStatsNotInTimeWindows(print) -> + VarAndValue = [{usmStatsNotInTimeWindows, usmStatsNotInTimeWindows(get)}], + snmpa_mib_lib:print_variables(VarAndValue); +usmStatsNotInTimeWindows(get) -> + get_counter(usmStatsNotInTimeWindows). + +usmStatsUnknownUserNames(print) -> + VarAndValue = [{usmStatsUnknownUserNames, usmStatsUnknownUserNames(get)}], + snmpa_mib_lib:print_variables(VarAndValue); +usmStatsUnknownUserNames(get) -> + get_counter(usmStatsUnknownUserNames). + +usmStatsUnknownEngineIDs(print) -> + VarAndValue = [{usmStatsUnknownEngineIDs, usmStatsUnknownEngineIDs(get)}], + snmpa_mib_lib:print_variables(VarAndValue); +usmStatsUnknownEngineIDs(get) -> + get_counter(usmStatsUnknownEngineIDs). + +usmStatsWrongDigests(print) -> + VarAndValue = [{usmStatsWrongDigests, usmStatsWrongDigests(get)}], + snmpa_mib_lib:print_variables(VarAndValue); +usmStatsWrongDigests(get) -> + get_counter(usmStatsWrongDigests). + +usmStatsDecryptionErrors(print) -> + VarAndValue = [{usmStatsDecryptionErrors, usmStatsDecryptionErrors(get)}], + snmpa_mib_lib:print_variables(VarAndValue); +usmStatsDecryptionErrors(get) -> + get_counter(usmStatsDecryptionErrors). + + +get_counter(Name) -> + case (catch ets:lookup(snmp_agent_table, Name)) of + [{_, Val}] -> + {value, Val}; + _ -> + genErr + end. + + init_vars() -> lists:map(fun maybe_create_var/1, vars()). maybe_create_var(Var) -> @@ -323,6 +377,7 @@ vars() -> usmStatsDecryptionErrors ]. + %%----------------------------------------------------------------- %% API functions %%----------------------------------------------------------------- @@ -374,6 +429,11 @@ get_user_from_security_name(EngineID, SecName) -> %%----------------------------------------------------------------- %% Instrumentation Functions %%----------------------------------------------------------------- + +usmUserSpinLock(print) -> + VarAndValue = [{usmUserSpinLock, usmUserSpinLock(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + usmUserSpinLock(new) -> snmp_generic:variable_func(new, {usmUserSpinLock, volatile}), {A1,A2,A3} = erlang:now(), diff --git a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl index 657207b36e..74acda2f21 100644 --- a/lib/snmp/src/agent/snmp_view_based_acm_mib.erl +++ b/lib/snmp/src/agent/snmp_view_based_acm_mib.erl @@ -133,7 +133,6 @@ check_vacm({vacmSecurityToGroup, SecModel, SecName, GroupName}) -> {ok, SecM} = snmp_conf:check_sec_model(SecModel, []), snmp_conf:check_string(SecName), snmp_conf:check_string(GroupName), - Vacm = {SecM, SecName, GroupName, ?'StorageType_nonVolatile', ?'RowStatus_active'}, {ok, {vacmSecurityToGroup, Vacm}}; @@ -188,8 +187,8 @@ init_tabs(Sec2Group, Access, View) -> init_view_table(View). init_sec2group_table([Row | T]) -> -% ?vtrace("init security-to-group table: " -% "~n Row: ~p",[Row]), +%% ?vtrace("init security-to-group table: " +%% "~n Row: ~p",[Row]), Key1 = element(1, Row), Key2 = element(2, Row), Key = [Key1, length(Key2) | Key2], @@ -198,12 +197,12 @@ init_sec2group_table([Row | T]) -> init_sec2group_table([]) -> true. init_access_table([{GN, Prefix, Model, Level, Row} | T]) -> -% ?vtrace("init access table: " -% "~n GN: ~p" -% "~n Prefix: ~p" -% "~n Model: ~p" -% "~n Level: ~p" -% "~n Row: ~p",[GN, Prefix, Model, Level, Row]), +%% ?vtrace("init access table: " +%% "~n GN: ~p" +%% "~n Prefix: ~p" +%% "~n Model: ~p" +%% "~n Level: ~p" +%% "~n Row: ~p",[GN, Prefix, Model, Level, Row]), Key = [length(GN) | GN] ++ [length(Prefix) | Prefix] ++ [Model, Level], snmpa_vacm:insert([{Key, Row}], false), init_access_table(T); @@ -211,8 +210,8 @@ init_access_table([]) -> snmpa_vacm:dump_table(). init_view_table([Row | T]) -> -% ?vtrace("init view table: " -% "~n Row: ~p",[Row]), +%% ?vtrace("init view table: " +%% "~n Row: ~p",[Row]), Key1 = element(1, Row), Key2 = element(2, Row), Key = [length(Key1) | Key1] ++ [length(Key2) | Key2], @@ -348,6 +347,49 @@ vacmContextTable(Op, Arg1, Arg2) -> snmp_framework_mib:intContextTable(Op, Arg1, Arg2). +vacmSecurityToGroupTable(print) -> + Table = vacmSecurityToGroupTable, + DB = db(Table), + FOI = foi(Table), + PrintRow = + fun(Prefix, Row) -> + lists:flatten( + io_lib:format("~sSecurityModel: ~p (~w)" + "~n~sSecurityName: ~p" + "~n~sGroupName: ~p" + "~n~sStorageType: ~p (~w)" + "~n~sStatus: ~p (~w)", + [Prefix, element(?vacmSecurityModel, Row), + case element(?vacmSecurityModel, Row) of + ?SEC_ANY -> any; + ?SEC_V1 -> v1; + ?SEC_V2C -> v2c; + ?SEC_USM -> usm; + _ -> undefined + end, + Prefix, element(?vacmSecurityName, Row), + Prefix, element(?vacmGroupName, Row), + Prefix, element(?vacmSecurityToGroupStorageType, Row), + case element(?vacmSecurityToGroupStorageType, Row) of + ?'vacmSecurityToGroupStorageType_readOnly' -> readOnly; + ?'vacmSecurityToGroupStorageType_permanent' -> permanent; + ?'vacmSecurityToGroupStorageType_nonVolatile' -> nonVolatile; + ?'vacmSecurityToGroupStorageType_volatile' -> volatile; + ?'vacmSecurityToGroupStorageType_other' -> other; + _ -> undefined + end, + Prefix, element(?vacmSecurityToGroupStatus, Row), + case element(?vacmSecurityToGroupStatus, Row) of + ?'vacmSecurityToGroupStatus_destroy' -> destroy; + ?'vacmSecurityToGroupStatus_createAndWait' -> createAndWait; + ?'vacmSecurityToGroupStatus_createAndGo' -> createAndGo; + ?'vacmSecurityToGroupStatus_notReady' -> notReady; + ?'vacmSecurityToGroupStatus_notInService' -> notInService; + ?'vacmSecurityToGroupStatus_active' -> active; + _ -> undefined + end])) + end, + snmpa_mib_lib:print_table(Table, DB, FOI, PrintRow); vacmSecurityToGroupTable(Op) -> snmp_generic:table_func(Op, db(vacmSecurityToGroupTable)). @@ -445,6 +487,49 @@ verify_vacmSecurityToGroupTable_col(_, Val) -> %% {RowIndex, {Col4, Col5, ..., Col9}} %% %%----------------------------------------------------------------- +vacmAccessTable(print) -> + %% M�ste jag g�ra om alla entrien till {RowIdx, Row}? + TableInfo = get_table(vacmAccessTable), + PrintRow = + fun(Prefix, Row) -> + lists:flatten( + io_lib:format("~sContextMatch: ~p (~w)" + "~n~sReadViewName: ~p" + "~n~sWriteViewName: ~p" + "~n~sNotifyViewName: ~p" + "~n~sStorageType: ~p (~w)" + "~n~sStatus: ~p (~w)", + [Prefix, element(?vacmAccessContextMatch-3, Row), + case element(?vacmAccessContextMatch-3, Row) of + ?vacmAccessContextMatch_exact -> exact; + ?vacmAccessContextMatch_prefix -> prefix; + _ -> undefined + end, + Prefix, element(?vacmAccessReadViewName-3, Row), + Prefix, element(?vacmAccessWriteViewName-3, Row), + Prefix, element(?vacmAccessNotifyViewName-3, Row), + Prefix, element(?vacmAccessStorageType-3, Row), + case element(?vacmAccessStorageType-3, Row) of + ?vacmAccessStorageType_other -> other ; + ?vacmAccessStorageType_volatile -> volatile; + ?vacmAccessStorageType_nonVolatile -> nonVolatile; + ?vacmAccessStorageType_permanent -> permanent; + ?vacmAccessStorageType_readOnly -> readOnly; + _ -> undefined + end, + Prefix, element(?vacmAccessStatus-3, Row), + case element(?vacmAccessStatus-3, Row) of + ?vacmAccessStatus_destroy -> destroy; + ?vacmAccessStatus_createAndWait -> createAndWait; + ?vacmAccessStatus_createAndGo -> createAndGo; + ?vacmAccessStatus_notReady -> notReady; + ?vacmAccessStatus_notInService -> notInService; + ?vacmAccessStatus_active -> active; + _ -> undefined + end + ])) + end, + snmpa_mib_lib:print_table(vacmAccessTable, {ok, TableInfo}, PrintRow); vacmAccessTable(_Op) -> ok. vacmAccessTable(get, RowIndex, Cols) -> @@ -664,6 +749,7 @@ do_get_next(RowIndex, Cols) -> end end. + %%----------------------------------------------------------------- %% Functions to manipulate vacmAccessRows. %%----------------------------------------------------------------- @@ -696,29 +782,76 @@ split_cols([Col | Cols], PreCols) when Col =< 3 -> split_cols(Cols, PreCols) -> {PreCols, Cols}. +vacmViewSpinLock(print) -> + VarAndValue = [{vacmViewSpinLock, vacmViewSpinLock(get)}], + snmpa_mib_lib:print_variables(VarAndValue); + vacmViewSpinLock(new) -> - snmp_generic:variable_func(new, {vacmViewSpinLock, volatile}), + snmp_generic:variable_func(new, volatile_db(vacmViewSpinLock)), {A1,A2,A3} = erlang:now(), random:seed(A1,A2,A3), Val = random:uniform(2147483648) - 1, - snmp_generic:variable_func(set, Val, {vacmViewSpinLock, volatile}); + snmp_generic:variable_func(set, Val, volatile_db(vacmViewSpinLock)); vacmViewSpinLock(delete) -> ok; vacmViewSpinLock(get) -> - snmp_generic:variable_func(get, {vacmViewSpinLock, volatile}). + snmp_generic:variable_func(get, volatile_db(vacmViewSpinLock)). vacmViewSpinLock(is_set_ok, NewVal) -> - case snmp_generic:variable_func(get, {vacmViewSpinLock, volatile}) of + case snmp_generic:variable_func(get, volatile_db(vacmViewSpinLock)) of {value, NewVal} -> noError; _ -> inconsistentValue end; vacmViewSpinLock(set, NewVal) -> snmp_generic:variable_func(set, (NewVal + 1) rem 2147483648, - {vacmViewSpinLock, volatile}). - - + volatile_db(vacmViewSpinLock)). + + +vacmViewTreeFamilyTable(print) -> + Table = vacmViewTreeFamilyTable, + DB = db(Table), + FOI = foi(Table), + PrintRow = + fun(Prefix, Row) -> + lists:flatten( + io_lib:format("~sViewName: ~p" + "~n~sSubtree: ~p" + "~n~sMask: ~p" + "~n~sType: ~p (~w)" + "~n~sStorageType: ~p (~w)" + "~n~sStatus: ~p (~w)", + [Prefix, element(?vacmViewTreeFamilyViewName, Row), + Prefix, element(?vacmViewTreeFamilySubtree, Row), + Prefix, element(?vacmViewTreeFamilyMask, Row), + Prefix, element(?vacmViewTreeFamilyType, Row), + case element(?vacmViewTreeFamilyType, Row) of + ?vacmViewTreeFamilyType_included -> included; + ?vacmViewTreeFamilyType_excluded -> excluded; + _ -> undefined + end, + Prefix, element(?vacmViewTreeFamilyStorageType, Row), + case element(?vacmViewTreeFamilyStorageType, Row) of + ?vacmViewTreeFamilyStorageType_readOnly -> readOnly; + ?vacmViewTreeFamilyStorageType_permanent -> permanent; + ?vacmViewTreeFamilyStorageType_nonVolatile -> nonVolatile; + ?vacmViewTreeFamilyStorageType_volatile -> volatile; + ?vacmViewTreeFamilyStorageType_other -> other; + _ -> undefined + end, + Prefix, element(?vacmViewTreeFamilyStatus, Row), + case element(?vacmViewTreeFamilyStatus, Row) of + ?vacmViewTreeFamilyStatus_destroy -> destroy; + ?vacmViewTreeFamilyStatus_createAndWait -> createAndWait; + ?vacmViewTreeFamilyStatus_createAndGo -> createAndGo; + ?vacmViewTreeFamilyStatus_notReady -> notReady; + ?vacmViewTreeFamilyStatus_notInService -> notInService; + ?vacmViewTreeFamilyStatus_active -> active; + _ -> undefined + end])) + end, + snmpa_mib_lib:print_table(Table, DB, FOI, PrintRow); vacmViewTreeFamilyTable(Op) -> snmp_generic:table_func(Op, db(vacmViewTreeFamilyTable)). vacmViewTreeFamilyTable(get_next, RowIndex, Cols) -> @@ -795,7 +928,25 @@ table_next(Name, RestOid) -> snmp_generic:table_next(db(Name), RestOid). -db(X) -> snmpa_agent:db(X). +get_table(vacmAccessTable) -> + do_get_vacmAccessTable([], []). + +do_get_vacmAccessTable(Key0, Acc) -> + case snmpa_vacm:get_next_row(Key0) of + {Key, _Row} = Entry -> + do_get_vacmAccessTable(Key, [Entry | Acc]); + false -> + lists:reverse(Acc) + end. + + +%%----------------------------------------------------------------- +%% Wrappers +%%----------------------------------------------------------------- + +db(X) -> snmpa_agent:db(X). +volatile_db(X) -> {X, volatile}. + fa(vacmSecurityToGroupTable) -> ?vacmGroupName; fa(vacmViewTreeFamilyTable) -> ?vacmViewTreeFamilyMask. diff --git a/lib/snmp/src/agent/snmpa.erl b/lib/snmp/src/agent/snmpa.erl index 87b191caed..22fbd33add 100644 --- a/lib/snmp/src/agent/snmpa.erl +++ b/lib/snmp/src/agent/snmpa.erl @@ -105,6 +105,8 @@ set_request_limit/1, set_request_limit/2 ]). +-export([print_mib_info/0, print_mib_tables/0, print_mib_variables/0]). + -include("snmpa_atl.hrl"). -define(EXTRA_INFO, undefined). @@ -283,6 +285,186 @@ whereis_mib(Agent, Mib) when is_atom(Mib) -> %% - +mibs_info() -> + [ + {snmp_standard_mib, + [], + [ + sysDescr, + sysObjectID, + sysContact, + sysName, + sysLocation, + sysServices, + snmpEnableAuthenTraps, + sysUpTime, + snmpInPkts, + snmpOutPkts, + snmpInBadVersions, + snmpInBadCommunityNames, + snmpInBadCommunityUses, + snmpInASNParseErrs, + snmpInTooBigs, + snmpInNoSuchNames, + snmpInBadValues, + snmpInReadOnlys, + snmpInGenErrs, + snmpInTotalReqVars, + snmpInTotalSetVars, + snmpInGetRequests, + snmpInSetRequests, + snmpInGetNexts, + snmpInGetResponses, + snmpInTraps, + snmpOutTooBigs, + snmpOutNoSuchNames, + snmpOutBadValues, + snmpOutGenErrs, + snmpOutGetRequests, + snmpOutSetRequests, + snmpOutGetNexts, + snmpOutGetResponses, + snmpOutTraps + ] + }, + {snmp_framework_mib, + [ + ], + [ + snmpEngineID, + snmpEngineBoots, + snmpEngineTime, + snmpEngineMaxMessageSize + ] + }, + {snmp_view_based_acm_mib, + [ + vacmAccessTable, + vacmSecurityToGroupTable, + vacmViewTreeFamilyTable + ], + [ + vacmViewSpinLock + ] + }, + {snmp_target_mib, + [ + snmpTargetAddrTable, + snmpTargetParamsTable + ], + [ + snmpTargetSpinLock + ] + }, + {snmp_community_mib, + [ + snmpCommunityTable + ], + [] + }, + {snmp_notification_mib, + [ + snmpNotifyTable + ], + []}, + {snmp_user_based_sm_mib, + [ + usmUserTable + ], + [ + usmUserSpinLock, + usmStatsUnsupportedSecLevels, + usmStatsNotInTimeWindows, + usmStatsUnknownUserNames, + usmStatsUnknownEngineIDs, + usmStatsWrongDigests, + usmStatsDecryptionErrors + ] + } + ]. + +print_mib_info() -> + MibsInfo = mibs_info(), + print_mib_info(MibsInfo). + +print_mib_info([]) -> + io:format("~n", []), + ok; +print_mib_info([{Mod, Tables, Variables} | MibsInfo]) -> + io:format("~n** ~s ** ~n~n", [make_pretty_mib(Mod)]), + print_mib_variables2(Mod, Variables), + print_mib_tables2(Mod, Tables), + io:format("~n", []), + print_mib_info(MibsInfo). + + +print_mib_tables() -> + Tables = [{Mod, Tabs} || {Mod, Tabs, _Vars} <- mibs_info()], + print_mib_tables(Tables). + +print_mib_tables([]) -> + ok; +print_mib_tables([{Mod, Tabs}|MibTabs]) + when is_atom(Mod) andalso is_list(Tabs) -> + print_mib_tables(Mod, Tabs), + print_mib_tables(MibTabs); +print_mib_tables([_|MibTabs]) -> + print_mib_tables(MibTabs). + +print_mib_tables(_Mod, [] = _Tables) -> + ok; +print_mib_tables(Mod, Tables) -> + io:format("~n** ~s ** ~n~n", [make_pretty_mib(Mod)]), + print_mib_tables2(Mod, Tables), + io:format("~n", []). + +print_mib_tables2(Mod, Tables) -> + [(catch Mod:Table(print)) || Table <- Tables]. + + +print_mib_variables() -> + Variables = [{Mod, Vars} || {Mod, _Tabs, Vars} <- mibs_info()], + print_mib_variables(Variables). + +print_mib_variables([]) -> + ok; +print_mib_variables([{Mod, Vars}|MibVars]) + when is_atom(Mod) andalso is_list(Vars) -> + print_mib_variables(Mod, Vars), + print_mib_variables(MibVars); +print_mib_variables([_|MibVars]) -> + print_mib_variables(MibVars). + +print_mib_variables(_Mod, [] = _Vars) -> + ok; +print_mib_variables(Mod, Vars) -> + io:format("~n** ~s ** ~n~n", [make_pretty_mib(Mod)]), + print_mib_variables2(Mod, Vars), + io:format("~n", []). + +print_mib_variables2(Mod, Variables) -> + Vars = [{Var, (catch Mod:Var(get))} || Var <- Variables], + snmpa_mib_lib:print_variables(Vars). + + +make_pretty_mib(snmp_view_based_acm_mib) -> + "SNMP-VIEW-BASED-ACM-MIB"; +make_pretty_mib(snmp_target_mib) -> + "SNMP-TARGET-MIB"; +make_pretty_mib(snmp_community_mib) -> + "SNMP-COMMUNITY-MIB"; +make_pretty_mib(snmp_notification_mib) -> + "SNMP-NOTIFICATION-MIB"; +make_pretty_mib(snmp_user_based_sm_mib) -> + "SNMP-USER-BASED-SM-MIB"; +make_pretty_mib(snmp_framework_mib) -> + "SNMP-FRAMEWORK-MIB"; +make_pretty_mib(Mod) -> + atom_to_list(Mod). + + +%% - + mib_of(Oid) -> snmpa_agent:mib_of(Oid). diff --git a/lib/snmp/src/agent/snmpa_mib_lib.erl b/lib/snmp/src/agent/snmpa_mib_lib.erl index 441228b9ee..cb96ff8056 100644 --- a/lib/snmp/src/agent/snmpa_mib_lib.erl +++ b/lib/snmp/src/agent/snmpa_mib_lib.erl @@ -19,7 +19,8 @@ -module(snmpa_mib_lib). -export([table_cre_row/3, table_del_row/2]). --export([get_table/2, print_table/3, print_table/4, print_tables/1]). +-export([get_table/2]). +-export([print_variables/1, print_table/3, print_table/4, print_tables/1]). -export([gc_tab/3, gc_tab/5]). -include("SNMPv2-TC.hrl"). @@ -81,31 +82,69 @@ get_table(NameDb, FOI, Oid, Acc) -> end. +print_variables(Variables) when is_list(Variables) -> + Variables2 = print_variables_prefixify(Variables), + lists:foreach(fun({Variable, ValueResult, Prefix}) -> + print_variable(Variable, ValueResult, Prefix) + end, Variables2), + ok. + +print_variable(Variable, {value, Val}, Prefix) when is_atom(Variable) -> + io:format("~w~s=> ~p~n", [Variable, Prefix, Val]); +print_variable(Variable, Error, Prefix) when is_atom(Variable) -> + io:format("~w~s=> [e] ~p~n", [Variable, Prefix, Error]). + +print_variables_prefixify(Variables) -> + MaxVarLength = print_variables_maxlength(Variables), + print_variables_prefixify(Variables, MaxVarLength, []). + +print_variables_prefixify([], _MaxVarLength, Acc) -> + lists:reverse(Acc); +print_variables_prefixify([{Var, Res}|Variables], MaxVarLength, Acc) -> + Prefix = make_variable_print_prefix(Var, MaxVarLength), + print_variables_prefixify(Variables, MaxVarLength, + [{Var, Res, Prefix}|Acc]). + +make_variable_print_prefix(Var, MaxVarLength) -> + lists:duplicate(MaxVarLength - length(atom_to_list(Var)) + 1, $ ). + +print_variables_maxlength(Variables) -> + print_variables_maxlength(Variables, 0). + +print_variables_maxlength([], MaxLength) -> + MaxLength; +print_variables_maxlength([{Var, _}|Variables], MaxLength) when is_atom(Var) -> + VarLen = length(atom_to_list(Var)), + if + VarLen > MaxLength -> + print_variables_maxlength(Variables, VarLen); + true -> + print_variables_maxlength(Variables, MaxLength) + end. + + print_tables(Tables) when is_list(Tables) -> lists:foreach(fun({Table, DB, FOI, PrintRow}) -> print_table(Table, DB, FOI, PrintRow) end, Tables), ok. -%% print_table(Table, DB, FOI, PrintRow) -> -%% TableInfo = get_table(DB(Table), FOI(Table)), -%% print_table(Table, TableInfo, PrintRow), -%% ok. - print_table(Table, DB, FOI, PrintRow) -> TableInfo = get_table(DB, FOI), print_table(Table, TableInfo, PrintRow). print_table(Table, TableInfo, PrintRow) when is_function(PrintRow, 2) -> - io:format("~w => ~n", [Table]), + io:format("~w =>", [Table]), do_print_table(TableInfo, PrintRow). +do_print_table({ok, [] = _TableInfo}, _PrintRow) -> + io:format(" -~n", []); do_print_table({ok, TableInfo}, PrintRow) when is_function(PrintRow, 2) -> + io:format("~n", []), lists:foreach(fun({RowIdx, Row}) -> io:format(" ~w => ~n~s~n", [RowIdx, PrintRow(" ", Row)]) - end, TableInfo), - io:format("~n", []); + end, TableInfo); do_print_table({error, {invalid_rowindex, BadRowIndex, []}}, _PrintRow) -> io:format("Error: Bad rowindex ~w~n", [BadRowIndex]); do_print_table({error, {invalid_rowindex, BadRowIndex, TableInfo}}, PrintRow) -> diff --git a/lib/snmp/src/app/snmp.appup.src b/lib/snmp/src/app/snmp.appup.src index ea39a7c30a..525093a256 100644 --- a/lib/snmp/src/app/snmp.appup.src +++ b/lib/snmp/src/app/snmp.appup.src @@ -24,7 +24,27 @@ [ {"4.18", [ - {load_module, snmp_misc, soft_purge, soft_purge, []} + {load_module, snmp_misc, soft_purge, soft_purge, []}, + {load_module, snmpa, soft_purge, soft_purge, + [snmp_community_mib, + snmp_framework_mib, + snmp_standard_mib, + snmp_target_mib, + snmp_user_based_sm_mib, + snmp_view_based_acm_mib]}, + {load_module, snmp_community_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_framework_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_standard_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_target_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_user_based_sm_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmpa_mib_lib, soft_purge, soft_purge, []} ] } ], @@ -34,7 +54,27 @@ [ {"4.18", [ - {load_module, snmp_misc, soft_purge, soft_purge, []} + {load_module, snmp_misc, soft_purge, soft_purge, []}, + {load_module, snmpa, soft_purge, soft_purge, + [snmp_community_mib, + snmp_framework_mib, + snmp_standard_mib, + snmp_target_mib, + snmp_user_based_sm_mib, + snmp_view_based_acm_mib]}, + {load_module, snmp_community_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_framework_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_standard_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_target_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_user_based_sm_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmp_view_based_acm_mib, soft_purge, soft_purge, + [snmpa_mib_lib]}, + {load_module, snmpa_mib_lib, soft_purge, soft_purge, []} ] } ] |