snmpa_supervisor.erl
来自「OTP是开放电信平台的简称」· ERL 代码 · 共 556 行 · 第 1/2 页
ERL
556 行
LocalDbSpec = worker_spec(snmpa_local_db, LdbArgs, Restart, 5000), ?vdebug("init VACM",[]), snmpa_vacm:init(DbDir, DbInitError), TargetCacheArgs = [Prio, TargetCacheOpts], TargetCacheSpec = worker_spec(snmpa_target_cache, TargetCacheArgs, transient, 2000, []), Rest = case AgentType of master -> % If we're starting the master, we must also % configure the tables. %% -- Config -- ConfOpts = get_opt(config, Opts, []), ?vdebug("[agent table] store config options: ~p",[ConfOpts]), ets:insert(snmp_agent_table, {config, ConfOpts}), ConfigArgs = [Vsns, ConfOpts], ConfigSpec = worker_spec(config, ?MODULE, config, ConfigArgs, transient, 2000, [?MODULE]), %% -- Agent verbosity -- AgentVerb = get_opt(agent_verbosity, Opts, silence), %% -- Mibs -- Mibs = get_mibs(get_opt(mibs, Opts, []), Vsns), ?vdebug("[agent table] store mibs: ~n ~p",[Mibs]), ets:insert(snmp_agent_table, {mibs, Mibs}), Ref = make_ref(), %% -- Set module -- SetModule = get_opt(set_mechanism, Opts, snmpa_set), ?vdebug("[agent table] store set-module: ~p",[SetModule]), ets:insert(snmp_agent_table, {set_mechanism, ConfOpts}), %% -- Authentication service -- AuthModule = get_opt(authentication_service, Opts, snmpa_acm), ?vdebug("[agent table] store authentication service: ~w", [AuthModule]), ets:insert(snmp_agent_table, {authentication_service, AuthModule}), %% -- Multi-threaded -- MultiT = get_opt(multi_threaded, Opts, false), ?vdebug("[agent table] store multi-threaded: ~p",[MultiT]), ets:insert(snmp_agent_table, {multi_threaded, MultiT}), %% -- Audit trail log -- case get_opt(audit_trail_log, Opts, not_found) of not_found -> ?vdebug("[agent table] no audit trail log",[]), ok; AtlOpts -> ?vdebug("[agent table] " "store audit trail log options: ~p", [AtlOpts]), ets:insert(snmp_agent_table, {audit_trail_log, AtlOpts}), ok end, %% -- MIB server -- MibsOpts = get_opt(mib_server, Opts, []), ?vdebug("[agent table] store mib-server options: " "~n ~p", [MibsOpts]), ets:insert(snmp_agent_table, {mib_server, MibsOpts}), %% -- Network interface -- NiOpts = get_opt(net_if, Opts, []), ?vdebug("[agent table] store net-if options: " "~n ~p", [NiOpts]), ets:insert(snmp_agent_table, {net_if, NiOpts}), %% -- Note store -- NsOpts = get_opt(note_store, Opts, []), ?vdebug("[agent table] store note-store options: " "~n ~p",[NsOpts]), ets:insert(snmp_agent_table, {note_store, NsOpts}), AgentOpts = [{verbosity, AgentVerb}, {mibs, Mibs}, {mib_storage, MibStorage}, {set_mechanism, SetModule}, {authentication_service, AuthModule}, {multi_threaded, MultiT}, {versions, Vsns}, {net_if, NiOpts}, {mib_server, MibsOpts}, {note_store, NsOpts}| get_opt(master_agent_options, Opts, [])], AgentSpec = worker_spec(snmpa_agent, [Prio,snmp_master_agent,none,Ref,AgentOpts], Restart, 15000), AgentSupSpec = sup_spec(snmpa_agent_sup, [AgentSpec], Restart, infinity), [ConfigSpec, AgentSupSpec]; _ -> ?vdebug("[sub agent] spec for the agent supervisor",[]), AgentSupSpec = sup_spec(snmpa_agent_sup, [], Restart, infinity), [AgentSupSpec] end, ?vdebug("init done",[]), {ok, {SupFlags, [MiscSupSpec, SymStoreSpec, LocalDbSpec, TargetCacheSpec | Rest]}}.get_mibs(Mibs, Vsns) -> MibDir = filename:join(code:priv_dir(snmp), "mibs"), StdMib = case (lists:member(v2, Vsns) or lists:member(v3, Vsns)) of true -> filename:join([MibDir, "SNMPv2-MIB"]); false -> filename:join([MibDir, "STANDARD-MIB"]) end, ?vdebug("add standard and v2 mibs",[]), NMibs = add_mib(StdMib, Mibs, ["SNMPv2-MIB", "STANDARD-MIB"]), case lists:member(v3, Vsns) of true -> ?vdebug("add v3 mibs",[]), add_v3_mibs(MibDir, NMibs); false -> NMibs end. add_v3_mibs(MibDir, Mibs) -> NMibs = add_mib(filename:join(MibDir, "SNMP-FRAMEWORK-MIB"), Mibs, ["SNMP-FRAMEWORK-MIB"]), add_mib(filename:join(MibDir, "SNMP-MPD-MIB"), NMibs, ["SNMP-MPD-MIB"]).add_mib(DefaultMib, [], _BaseNames) -> [DefaultMib];add_mib(DefaultMib, [Mib | T], BaseNames) -> case lists:member(filename:basename(Mib), BaseNames) of true -> [Mib | T]; % The user defined his own version of the mib false -> [Mib | add_mib(DefaultMib, T, BaseNames)] end.config(Vsns, Opts) -> ?d("config -> entry with" "~n Vsns. ~p" "~n Opts. ~p", [Vsns, Opts]), Verbosity = get_opt(verbosity, Opts, silence), put(sname, conf), put(verbosity, Verbosity), ?vlog("starting", []), ConfDir = get_opt(dir, Opts), ForceLoad = get_opt(force_load, Opts, false), case (catch conf(ConfDir, Vsns, ForceLoad)) of ok -> ?d("config -> done", []), ignore; {'EXIT', Reason} -> ?vlog("configure failed (exit) with reason: ~p",[Reason]), {error, {config_error, Reason}} end.conf(Dir, Vsns, true) -> conf1(Dir, Vsns, reconfigure);conf(Dir, Vsns, false) -> conf1(Dir, Vsns, configure).conf1(Dir, Vsns, Func) -> ?vlog("start ~w",[Func]), ?vdebug("~w snmp_standard_mib",[Func]), snmp_standard_mib:Func(Dir), ?vdebug("init snmp_framework_mib",[]), snmp_framework_mib:init(), ?vdebug("configure snmp_framework_mib",[]), snmp_framework_mib:configure(Dir), ?vdebug("~w snmp_target_mib",[Func]), snmp_target_mib:Func(Dir), ?vdebug("~w snmp_notification_mib",[Func]), snmp_notification_mib:Func(Dir), ?vdebug("~w snmp_view_based_acm_mib",[Func]), snmp_view_based_acm_mib:Func(Dir), case lists:member(v1, Vsns) or lists:member(v2, Vsns) of true -> ?vdebug("we need to handle v1 and/or v2 =>~n" " ~w snmp_community_mib",[Func]), snmp_community_mib:Func(Dir); false -> ?vdebug("no need to handle v1 or v2",[]), ok end, case lists:member(v3, Vsns) of true -> ?vdebug("we need to handle v3 =>~n" " ~w snmp_user_based_sm_mib",[Func]), snmp_user_based_sm_mib:Func(Dir); false -> ?vdebug("no need to handle v3",[]), ok end, ?vdebug("conf done",[]), ok.%% -------------------------------------sup_spec(Name, Args, Type, Time) -> ?d("sup_spec -> entry with" "~n Name: ~p" "~n Args: ~p" "~n Type: ~p" "~n Time: ~p", [Name, Args, Type, Time]), {Name, {Name, start_link, Args}, Type, Time, supervisor, [Name, supervisor]}.worker_spec(Name, Args, Type, Time) -> worker_spec(Name, Name, Args, Type, Time, []).worker_spec(Name, Args, Type, Time, Modules) -> worker_spec(Name, Name, Args, Type, Time, Modules).worker_spec(Name, Mod, Args, Type, Time, Modules) -> worker_spec(Name, Mod, start_link, Args, Type, Time, Modules).worker_spec(Name, Mod, Func, Args, Type, Time, Modules) when is_atom(Name) and is_atom(Mod) and is_atom(Func) and is_list(Args) and is_atom(Type) and is_list(Modules) -> ?d("worker_spec -> entry with" "~n Name: ~p" "~n Mod: ~p" "~n Func: ~p" "~n Args: ~p" "~n Type: ~p" "~n Time: ~p" "~n Modules: ~p", [Name, Mod, Func, Args, Type, Time, Modules]), {Name, {Mod, Func, Args}, Type, Time, worker, [Name] ++ Modules}.get_verbosity(Opts) -> SupOpts = get_opt(supervisor, Opts, []), get_opt(verbosity, SupOpts, silence).get_agent_type(Opts) -> get_opt(agent_type, Opts, master).get_opt(Key, Opts) -> snmp_misc:get_option(Key, Opts).get_opt(Key, Opts, Def) -> snmp_misc:get_option(Key, Opts, Def).key1search(Key, List) -> lists:keysearch(Key, 1, List).%%-----------------------------------------------------------------error_msg(F, A) -> ?snmpa_error(F, A).% i(F) ->% i(F, []).% i(F, A) ->% io:format("~p:~p: " ++ F ++ "~n", [node(),?MODULE|A]).
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?