diff options
author | Raimo Niskanen <[email protected]> | 2014-05-08 16:16:03 +0200 |
---|---|---|
committer | Raimo Niskanen <[email protected]> | 2014-07-25 12:15:14 +0200 |
commit | 100b3345793043d50f90619c25123dc4d218e5cd (patch) | |
tree | fe3c11da9c4c905f1e7528b6079509bdeb10803c /lib/snmp/src/misc | |
parent | d2002049e348f1da8d011fe5f628484ec909ec41 (diff) | |
download | otp-100b3345793043d50f90619c25123dc4d218e5cd.tar.gz otp-100b3345793043d50f90619c25123dc4d218e5cd.tar.bz2 otp-100b3345793043d50f90619c25123dc4d218e5cd.zip |
fix agent configuration details
Diffstat (limited to 'lib/snmp/src/misc')
-rw-r--r-- | lib/snmp/src/misc/snmp_conf.erl | 111 | ||||
-rw-r--r-- | lib/snmp/src/misc/snmp_config.erl | 167 |
2 files changed, 182 insertions, 96 deletions
diff --git a/lib/snmp/src/misc/snmp_conf.erl b/lib/snmp/src/misc/snmp_conf.erl index 0d17c66455..0cad61e5c8 100644 --- a/lib/snmp/src/misc/snmp_conf.erl +++ b/lib/snmp/src/misc/snmp_conf.erl @@ -31,33 +31,34 @@ %% Basic (type) check functions -export([check_mandatory/2, check_integer/1, check_integer/2, - + check_string/1, check_string/2, - check_atom/2, + check_atom/2, check_timer/1, - all_domains/0, - check_domain/1, - all_tdomains/0, - check_tdomain/1, - mk_tdomain/1, - which_domain/1, + all_domains/0, + check_domain/1, + all_tdomains/0, + check_tdomain/1, + mk_tdomain/1, + tdomain_to_family/1, + which_domain/1, check_ip/1, check_ip/2, check_port/1, ip_port_to_domaddr/2, check_address/2, check_address/3, check_taddress/2, mk_taddress/2, - - check_packet_size/1, + + check_packet_size/1, check_oid/1, - check_imask/1, check_emask/1, - - check_mp_model/1, - check_sec_model/1, check_sec_model/2, check_sec_model/3, + check_imask/1, check_emask/1, + + check_mp_model/1, + check_sec_model/1, check_sec_model/2, check_sec_model/3, check_sec_level/1, all_integer/1 @@ -473,6 +474,22 @@ mk_tdomain(BadDomain) -> %% --------- +tdomain_to_family(snmpUDPDomain) -> + inet; +tdomain_to_family(transportDomainUdpIpv4) -> + inet; +tdomain_to_family(transportDomainUdpIpv6) -> + inet6; +tdomain_to_family(?transportDomainUdpIpv4) -> + inet; +tdomain_to_family(?transportDomainUdpIpv6) -> + inet6; +tdomain_to_family(BadDomain) -> + error({bad_domain, BadDomain}). + + +%% --------- + %% XXX remove %% check_taddress(X) -> %% check_taddress(snmpUDPDomain, X). @@ -716,35 +733,43 @@ which_domain({A0, A1, A2, A3, A4, A5, A6, A7}) %% --------- -%% XXX remove - check_ip(X) -> check_ip(snmpUDPDomain, X). -check_ip(snmpUDPDomain, X) -> - check_ip(transportDomainUdpIpv4, X); -check_ip(transportDomainUdpIpv4 = Domain, X) -> - case X of - [A,B,C,D] when ?is_ipv4_addr(A, B, C, D) -> - ok; - _ -> - error({bad_address, {Domain, X}}) - end; -check_ip(transportDomainUdpIpv6 = Domain, X) -> - case X of - [A,B,C,D,E,F,G,H] - when ?is_ipv6_addr(A, B, C, D, E, F, G, H) -> - ok; - [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P] - when ?is_ipv6_addr( - A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> +check_ip(Domain, IP) -> + case check_address_ip(Domain, IP) of + false -> + error({bad_address, {Domain, IP}}); + true -> ok; - _ -> - error({bad_address, {Domain, X}}) - end; -%% -check_ip(BadDomain, _X) -> - error({invalid_domain, BadDomain}). + FixedIP -> + {ok, FixedIP} + end. + +%% check_ip(snmpUDPDomain, X) -> +%% check_ip(transportDomainUdpIpv4, X); +%% check_ip(transportDomainUdpIpv4 = Domain, X) -> +%% case X of +%% [A,B,C,D] when ?is_ipv4_addr(A, B, C, D) -> +%% ok; +%% _ -> +%% error({bad_address, {Domain, X}}) +%% end; +%% check_ip(transportDomainUdpIpv6 = Domain, X) -> +%% case X of +%% [A,B,C,D,E,F,G,H] +%% when ?is_ipv6_addr(A, B, C, D, E, F, G, H) -> +%% ok; +%% [A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P] +%% when ?is_ipv6_addr( +%% A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P) -> +%% ok; +%% _ -> +%% error({bad_address, {Domain, X}}) +%% end; +%% %% +%% check_ip(BadDomain, _X) -> +%% error({invalid_domain, BadDomain}). %% --------- @@ -850,7 +875,9 @@ check_address_ip(transportDomainUdpIpv6, Address) -> mk_word(A12, A13), mk_word(A14, A15)}; _ -> false - end. + end; +check_address_ip(BadDomain, _) -> + error({bad_domain, BadDomain}). %% -> {IP, Port} check_address_ip_port(Domain, Address) @@ -907,7 +934,9 @@ check_address_ip_port(transportDomainUdpIpv6 = Domain, Address) -> mk_word(P0, P1)}; _ -> false - end. + end; +check_address_ip_port(BadDomain, _) -> + error({bad_domain, BadDomain}). diff --git a/lib/snmp/src/misc/snmp_config.erl b/lib/snmp/src/misc/snmp_config.erl index 12467a1abf..5dffed8068 100644 --- a/lib/snmp/src/misc/snmp_config.erl +++ b/lib/snmp/src/misc/snmp_config.erl @@ -30,6 +30,7 @@ read_config_file/3, read_config_file/4]). -export([write_agent_snmp_files/7, write_agent_snmp_files/12, + write_agent_snmp_files/6, write_agent_snmp_files/11, write_agent_snmp_conf/5, write_agent_snmp_context_conf/1, @@ -568,11 +569,9 @@ config_agent_snmp(Dir, Vsns) -> end, NT end, - case (catch write_agent_snmp_files(Dir, - Vsns, ManagerIP, TrapUdp, - AgentIP, AgentUDP, - SysName, NotifType, SecType, - Passwd, EngineID, MMS)) of + case (catch write_agent_snmp_files( + Dir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUDP, SysName, + NotifType, SecType, Passwd, EngineID, MMS)) of ok -> i("~n- - - - - - - - - - - - -"), i("Info: 1. SecurityName \"initial\" has noAuthNoPriv read access~n" @@ -1581,35 +1580,63 @@ remove_newline(Str) -> %% File generation %%====================================================================== +write_agent_snmp_files( + Dir, Vsns, Domain, ManagerAddr, AgentAddr, SysName) + when is_list(Dir), + is_list(Vsns), + is_atom(Domain), + is_list(SysName) -> + write_agent_snmp_files( + Dir, Vsns, Domain, ManagerAddr, AgentAddr, SysName, + "trap", none, "", "agentEngine", 484). + %%---------------------------------------------------------------------- %% Dir: string() (ex: "../conf/") %% ManagerIP, AgentIP: [int(),int(),int(),int()] %% TrapUdp, AgentUDP: integer() %% SysName: string() %%---------------------------------------------------------------------- -write_agent_snmp_files(Dir, Vsns, ManagerIP, TrapUdp, - AgentIP, AgentUDP, SysName) - when is_list(Dir) andalso - is_list(Vsns) andalso - is_list(ManagerIP) andalso - is_integer(TrapUdp) andalso - is_list(AgentIP) andalso - is_integer(AgentUDP) andalso +write_agent_snmp_files( + Dir, Vsns, ManagerIP, TrapUDP, AgentIP, AgentUDP, SysName) + when is_list(Dir) andalso + is_list(Vsns) andalso + is_list(ManagerIP) andalso + is_integer(TrapUDP) andalso + is_list(AgentIP) andalso + is_integer(AgentUDP) andalso is_list(SysName) -> - write_agent_snmp_files(Dir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUDP, - SysName, "trap", none, "", "agentEngine", 484). + write_agent_snmp_files( + Dir, Vsns, ManagerIP, TrapUDP, AgentIP, AgentUDP, SysName, + "trap", none, "", "agentEngine", 484). %% %% ----- Agent config files generator functions ----- %% -write_agent_snmp_files(Dir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUDP, - SysName, NotifType, SecType, Passwd, EngineID, MMS) -> +write_agent_snmp_files( + Dir, Vsns, Domain, ManagerAddr, AgentAddr, SysName, + NotifType, SecType, Passwd, EngineID, MMS) -> + write_agent_snmp_conf(Dir, Domain, AgentAddr, EngineID, MMS), + write_agent_snmp_context_conf(Dir), + write_agent_snmp_community_conf(Dir), + write_agent_snmp_standard_conf(Dir, SysName), + write_agent_snmp_target_addr_conf(Dir, Domain, ManagerAddr, Vsns), + write_agent_snmp_target_params_conf(Dir, Vsns), + write_agent_snmp_notify_conf(Dir, NotifType), + write_agent_snmp_usm_conf(Dir, Vsns, EngineID, SecType, Passwd), + write_agent_snmp_vacm_conf(Dir, Vsns, SecType), + ok. + +write_agent_snmp_files( + Dir, Vsns, ManagerIP, TrapUDP, AgentIP, AgentUDP, SysName, + NotifType, SecType, Passwd, EngineID, MMS) -> + Domain = snmp_target_mib:default_domain(), + ManagerAddr = {ManagerIP, TrapUDP}, write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS), write_agent_snmp_context_conf(Dir), write_agent_snmp_community_conf(Dir), write_agent_snmp_standard_conf(Dir, SysName), - write_agent_snmp_target_addr_conf(Dir, ManagerIP, TrapUdp, Vsns), + write_agent_snmp_target_addr_conf(Dir, Domain, ManagerAddr, Vsns), write_agent_snmp_target_params_conf(Dir, Vsns), write_agent_snmp_notify_conf(Dir, NotifType), write_agent_snmp_usm_conf(Dir, Vsns, EngineID, SecType, Passwd), @@ -1617,11 +1644,32 @@ write_agent_snmp_files(Dir, Vsns, ManagerIP, TrapUdp, AgentIP, AgentUDP, ok. + %% %% ------ [agent] agent.conf ------ %% -write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS) -> + +write_agent_snmp_conf(Dir, Domain, AgentAddr, EngineID, MMS) + when is_atom(Domain) -> + {AgentIP, AgentUDP} = AgentAddr, + Conf = + [{intAgentTransportDomain, Domain}, + {intAgentUDPPort, AgentUDP}, + {intAgentIpAddress, AgentIP}, + {snmpEngineID, EngineID}, + {snmpEngineMaxMessageSize, MMS}], + do_write_agent_snmp_conf(Dir, Conf); +write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS) + when is_integer(AgentUDP) -> + Conf = + [{intAgentUDPPort, AgentUDP}, + {intAgentIpAddress, AgentIP}, + {snmpEngineID, EngineID}, + {snmpEngineMaxMessageSize, MMS}], + do_write_agent_snmp_conf(Dir, Conf). + +do_write_agent_snmp_conf(Dir, Conf) -> Comment = "%% This file defines the Agent local configuration info\n" "%% The data is inserted into the snmpEngine* variables defined\n" @@ -1636,11 +1684,7 @@ write_agent_snmp_conf(Dir, AgentIP, AgentUDP, EngineID, MMS) -> "%% {snmpEngineID, \"agentEngine\"}.\n" "%% {snmpEngineMaxMessageSize, 484}.\n" "%%\n\n", - Hdr = header() ++ Comment, - Conf = [{intAgentUDPPort, AgentUDP}, - {intAgentIpAddress, AgentIP}, - {snmpEngineID, EngineID}, - {snmpEngineMaxMessageSize, MMS}], + Hdr = header() ++ Comment, write_agent_config(Dir, Hdr, Conf). write_agent_config(Dir, Hdr, Conf) -> @@ -1746,17 +1790,22 @@ update_agent_standard_config(Dir, Conf) -> %% ------ target_addr.conf ------ %% -write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, Vsns) -> +write_agent_snmp_target_addr_conf(Dir, Domain, Addr, Vsns) + when is_atom(Domain) -> Timeout = 1500, RetryCount = 3, - write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, - Timeout, RetryCount, - Vsns). - -write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, - Timeout, RetryCount, - Vsns) -> - Comment = + write_agent_snmp_target_addr_conf( + Dir, Domain, Addr, Timeout, RetryCount, Vsns); +write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, Vsns) + when is_integer(UDP) -> + Domain = snmp_target_mib:default_domain(), + Addr = {ManagerIp, UDP}, + write_agent_snmp_target_addr_conf(Dir, Domain, Addr, Vsns). + +write_agent_snmp_target_addr_conf( + Dir, Domain, Addr, Timeout, RetryCount, Vsns) + when is_atom(Domain) -> + Comment = "%% This file defines the target address parameters.\n" "%% The data is inserted into the snmpTargetAddrTable defined\n" "%% in SNMP-TARGET-MIB, and in the snmpTargetAddrExtTable defined\n" @@ -1776,35 +1825,37 @@ write_agent_snmp_target_addr_conf(Dir, ManagerIp, UDP, "%%\n\n", Hdr = header() ++ Comment, F = fun(v1 = Vsn, Acc) -> - [{mk_ip(ManagerIp, Vsn), - snmp_target_mib:default_domain(), - ManagerIp, UDP, Timeout, RetryCount, + [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}| Acc]; (v2 = Vsn, Acc) -> - [{mk_ip(ManagerIp, Vsn), - snmp_target_mib:default_domain(), - ManagerIp, UDP, Timeout, RetryCount, + [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten(io_lib:format("~s.2",[mk_ip(ManagerIp, Vsn)])), - ManagerIp, UDP, Timeout, RetryCount, + {lists:flatten(io_lib:format("~s.2",[mk_name(Addr, Vsn)])), + Domain, Addr, Timeout, RetryCount, "std_inform", mk_param(Vsn), "", [], 2048}| Acc]; (v3 = Vsn, Acc) -> - [{mk_ip(ManagerIp, Vsn), - snmp_target_mib:default_domain(), - ManagerIp, UDP, Timeout, RetryCount, + [{mk_name(Addr, Vsn), Domain, Addr, Timeout, RetryCount, "std_trap", mk_param(Vsn), "", [], 2048}, - {lists:flatten(io_lib:format("~s.3",[mk_ip(ManagerIp, Vsn)])), - ManagerIp, UDP, Timeout, RetryCount, + {lists:flatten(io_lib:format("~s.3",[mk_name(Addr, Vsn)])), + Domain, Addr, Timeout, RetryCount, "std_inform", mk_param(Vsn), "mgrEngine", [], 2048}| Acc] end, Conf = lists:foldl(F, [], Vsns), - write_agent_target_addr_config(Dir, Hdr, Conf). + write_agent_target_addr_config(Dir, Hdr, Conf); +write_agent_snmp_target_addr_conf( + Dir, ManagerIp, UDP, Timeout, RetryCount, Vsns) when is_integer(UDP) -> + Domain = snmp_target_mib:default_domain(), + Addr = {ManagerIp, UDP}, + write_agent_snmp_target_addr_conf( + Dir, Domain, Addr, Timeout, RetryCount, Vsns). mk_param(Vsn) -> lists:flatten(io_lib:format("target_~w", [Vsn])). -mk_ip([A,B,C,D], Vsn) -> - lists:flatten(io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn])). +mk_name({[A,B,C,D], _}, Vsn) -> + lists:flatten(io_lib:format("~w.~w.~w.~w ~w", [A,B,C,D,Vsn])); +mk_name(Address, Vsn) -> + lists:flatten(io_lib:format("~w ~w", [Address,Vsn])). write_agent_target_addr_config(Dir, Hdr, Conf) -> snmpa_conf:write_target_addr_config(Dir, Hdr, Conf). @@ -2438,14 +2489,20 @@ write_config_file(Dir, FileName, Verify, Write) is_list(FileName) andalso is_function(Verify) andalso is_function(Write)) -> - try - begin - do_write_config_file(Dir, FileName, Verify, Write) - end + try do_write_config_file(Dir, FileName, Verify, Write) of + ok -> + ok; + Other -> + d("File write of ~s returned: ~p~n", [FileName,Other]) catch throw:Error -> + S = erlang:get_stacktrace(), + d("File write of ~s throwed: ~p~n ~p~n", [FileName,Error,S]), Error; T:E -> + S = erlang:get_stacktrace(), + d("File write of ~s exception: ~p:~p~n ~p~n", + [FileName,T,E,S]), {error, {failed_write, Dir, FileName, {T, E, erlang:get_stacktrace()}}} @@ -2652,8 +2709,8 @@ ensure_started(App) -> %% ------------------------------------------------------------------------- -% d(F, A) -> -% i("DBG: " ++ F, A). +d(F, A) -> + i("DBG: " ++ F, A). i(F) -> i(F, []). |