aboutsummaryrefslogtreecommitdiffstats
path: root/lib/snmp
diff options
context:
space:
mode:
Diffstat (limited to 'lib/snmp')
-rw-r--r--lib/snmp/src/agent/snmp_framework_mib.erl51
-rw-r--r--lib/snmp/src/agent/snmpa_conf.erl55
-rw-r--r--lib/snmp/src/agent/snmpa_net_if.erl14
-rw-r--r--lib/snmp/src/misc/snmp_conf.erl111
-rw-r--r--lib/snmp/src/misc/snmp_config.erl167
5 files changed, 254 insertions, 144 deletions
diff --git a/lib/snmp/src/agent/snmp_framework_mib.erl b/lib/snmp/src/agent/snmp_framework_mib.erl
index 51f8c46d19..0b439aa5f1 100644
--- a/lib/snmp/src/agent/snmp_framework_mib.erl
+++ b/lib/snmp/src/agent/snmp_framework_mib.erl
@@ -41,6 +41,7 @@
-compile({no_auto_import,[error/1]}).
-export([init/0, configure/1]).
-export([intContextTable/1, intContextTable/3,
+ intAgentTransportDomain/1,
intAgentUDPPort/1, intAgentIpAddress/1,
snmpEngineID/1,
snmpEngineBoots/1,
@@ -128,27 +129,20 @@ read_agent(Dir) ->
?vdebug("read agent config file", []),
FileName = "agent.conf",
File = filename:join(Dir, FileName),
- Agent =
+ Conf0 =
try
snmp_conf:read(File, fun order_agent/2, fun check_agent/2)
catch
throw:{error, Reason} ->
error({failed_reading_config_file, Dir, FileName, Reason})
end,
- sort_agent(Agent).
-
-
-%%-----------------------------------------------------------------
-%% Make sure that each mandatory agent attribute is present, and
-%% provide default values for the other non-present attributes.
-%%-----------------------------------------------------------------
-sort_agent(L) ->
- Mand = [{intAgentIpAddress, mandatory},
- {intAgentUDPPort, mandatory},
- {snmpEngineMaxMessageSize, mandatory},
- {snmpEngineID, mandatory}],
- {ok, L2} = snmp_conf:check_mandatory(L, Mand),
- lists:keysort(1, L2).
+ Mand =
+ [{intAgentIpAddress, mandatory},
+ {intAgentUDPPort, mandatory},
+ {snmpEngineMaxMessageSize, mandatory},
+ {snmpEngineID, mandatory}],
+ {ok, Conf} = snmp_conf:check_mandatory(Conf0, Mand),
+ Conf.
%%-----------------------------------------------------------------
@@ -198,14 +192,17 @@ check_context(Context) ->
%%-----------------------------------------------------------------
check_agent({intAgentTransportDomain, D}, Domain) ->
{snmp_conf:check_domain(D), D};
-check_agent({intAgentTransportAddress, Address}, Domain) ->
- {snmp_conf:check_address(Domain, Address), Domain};
+check_agent({intAgentIpAddress, Value}, D) ->
+ Domain =
+ case D of
+ undefined -> snmp_target_mib:default_domain();
+ _ -> D
+ end,
+ {snmp_conf:check_ip(Domain, Value), Domain};
check_agent(Entry, Domain) ->
{check_agent(Entry), Domain}.
-check_agent({intAgentIpAddress, Value}) -> % Obsoleted
- snmp_conf:check_ip(Value);
-check_agent({intAgentUDPPort, Value}) -> % Obsoleted
+check_agent({intAgentUDPPort, Value}) ->
snmp_conf:check_integer(Value);
%% This one is kept for backwards compatibility
check_agent({intAgentMaxPacketSize, Value}) ->
@@ -218,13 +215,14 @@ check_agent(X) ->
error({invalid_agent_attribute, X}).
%% Ordering function to sort intAgentTransportDomain first
-%% hence before intAgentTransportAddress
+%% hence before intAgentIpAddress
order_agent({Name, _}, {Name, _}) ->
true; %% Less than or equal
-order_agent(_, {intAgentTransportDomain, _}) ->
+order_agent({_, _}, {intAgentTransportDomain, _}) ->
false; %% Greater than
-order_agent(_, _) ->
- true. %% Less than or equal
+order_agent({A, _}, {B, _}) ->
+ A =< B.
+
maybe_create_table(Name) ->
@@ -398,6 +396,11 @@ intAgentUDPPort(Op) ->
intAgentIpAddress(Op) ->
snmp_generic:variable_func(Op, db(intAgentIpAddress)).
+intAgentTransportDomain(Op) ->
+ snmp_generic:variable_func(Op, db(intAgentTransportDomain)).
+
+
+
snmpEngineID(print) ->
VarAndValue = [{snmpEngineID, snmpEngineID(get)}],
snmpa_mib_lib:print_variables(VarAndValue);
diff --git a/lib/snmp/src/agent/snmpa_conf.erl b/lib/snmp/src/agent/snmpa_conf.erl
index f055f89880..b05590a504 100644
--- a/lib/snmp/src/agent/snmpa_conf.erl
+++ b/lib/snmp/src/agent/snmpa_conf.erl
@@ -154,6 +154,8 @@ write_agent_conf(Fd, [H|T]) ->
do_write_agent_conf(Fd, H),
write_agent_conf(Fd, T).
+do_write_agent_conf(Fd, {intAgentTransportDomain = Tag, Val}) ->
+ io:format(Fd, "{~w, ~w}.~n", [Tag, Val]);
do_write_agent_conf(Fd, {intAgentIpAddress = Tag, Val}) ->
io:format(Fd, "{~w, ~w}.~n", [Tag, Val]);
do_write_agent_conf(Fd, {intAgentUDPPort = Tag, Val} ) ->
@@ -566,29 +568,36 @@ write_target_addr_conf(Fd, Conf) ->
lists:foreach(Fun, Conf),
ok.
-do_write_target_addr_conf(Fd,
- {Name,
- Ip, Udp,
- Timeout, RetryCount, TagList,
- ParamsName, EngineId,
- TMask, MaxMessageSize}) ->
- Domain = snmp_target_mib:default_domain(),
- do_write_target_addr_conf(Fd,
- {Name,
- Domain, Ip, Udp,
- Timeout, RetryCount, TagList,
- ParamsName, EngineId,
- TMask, MaxMessageSize});
-do_write_target_addr_conf(Fd,
- {Name,
- Domain, Ip, Udp,
- Timeout, RetryCount, TagList,
- ParamsName, EngineId,
- TMask, MaxMessageSize}) ->
- io:format(Fd,
- "{\"~s\", ~w, ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n",
- [Name, Domain, Ip, Udp, Timeout, RetryCount, TagList,
- ParamsName, EngineId, TMask, MaxMessageSize]);
+do_write_target_addr_conf(
+ Fd,
+ {Name, Ip, Udp, Timeout, RetryCount, TagList,
+ ParamsName, EngineId, TMask, MaxMessageSize})
+ when is_integer(Udp) ->
+ Domain = snmp_target_mib:default_domain(),
+ Address = {Ip, Udp},
+ do_write_target_addr_conf(
+ Fd,
+ {Name, Domain, Address, Timeout, RetryCount, TagList,
+ ParamsName, EngineId, TMask, MaxMessageSize});
+do_write_target_addr_conf(
+ Fd,
+ {Name, Domain, Address, Timeout, RetryCount, TagList,
+ ParamsName, EngineId, TMask, MaxMessageSize})
+ when is_atom(Domain) ->
+ io:format(
+ Fd,
+ "{\"~s\", ~w, ~w, ~w, ~w, \"~s\", \"~s\", \"~s\", ~w, ~w}.~n",
+ [Name, Domain, Address, Timeout, RetryCount, TagList,
+ ParamsName, EngineId, TMask, MaxMessageSize]);
+do_write_target_addr_conf(
+ Fd,
+ {Name, Domain, Ip, Udp, Timeout, RetryCount, TagList,
+ ParamsName, EngineId, TMask, MaxMessageSize}) ->
+ Address = {Ip, Udp},
+ do_write_target_addr_conf(
+ Fd,
+ {Name, Domain, Address, Timeout, RetryCount, TagList,
+ ParamsName, EngineId, TMask, MaxMessageSize});
do_write_target_addr_conf(_Fd, Crap) ->
error({bad_target_addr_config, Crap}).
diff --git a/lib/snmp/src/agent/snmpa_net_if.erl b/lib/snmp/src/agent/snmpa_net_if.erl
index 59d88517c9..96211fc5f4 100644
--- a/lib/snmp/src/agent/snmpa_net_if.erl
+++ b/lib/snmp/src/agent/snmpa_net_if.erl
@@ -112,6 +112,14 @@ get_address() ->
{value, IPAddress} = snmp_framework_mib:intAgentIpAddress(get),
IPAddress.
+get_domain() ->
+ case snmp_framework_mib:intAgentTransportDomain(get) of
+ {value, Domain} ->
+ Domain;
+ genErr ->
+ snmpUDPDomain
+ end.
+
filter_reset(Pid) ->
Pid ! filter_reset.
@@ -155,6 +163,8 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) ->
?vlog("starting",[]),
%% -- Port and address --
+ Domain = get_domain(),
+ ?vdebug("domain: ~w",[Domain]),
UDPPort = get_port(),
?vdebug("port: ~w",[UDPPort]),
IPAddress = get_address(),
@@ -181,7 +191,9 @@ do_init(Prio, NoteStore, MasterAgent, Parent, Opts) ->
IPOpts2 = ip_opt_no_reuse_address(Opts),
IPOpts3 = ip_opt_recbuf(Opts),
IPOpts4 = ip_opt_sndbuf(Opts),
- IPOpts = [binary | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4],
+ IPOpts =
+ [binary, snmp_conf:tdomain_to_family(Domain)
+ | IPOpts1 ++ IPOpts2 ++ IPOpts3 ++ IPOpts4],
?vdebug("open socket with options: ~w",[IPOpts]),
case gen_udp_open(UDPPort, IPOpts) of
{ok, Sock} ->
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, []).