snmp_config.erl

来自「OTP是开放电信平台的简称」· ERL 代码 · 共 2,125 行 · 第 1/5 页

ERL
2,125
字号
    TrapUdp    = ask("7. To what UDP port at the manager should traps ~n"		     "   be sent (standard 162)?", "5000", 		     fun verify_port_number/1),    SecType    = ask("8. Do you want a none- minimum- or semi-secure"		     " configuration? ~n"		     "   Note that if you chose v1 or v2, you won't get any"		     " security for these~n"		     "   requests (none, minimum, semi_des, semi_aes)", 		     "minimum", 		    fun verify_sec_type/1),    Passwd = 	case lists:member(v3, Vsns) and (SecType /= none) of	    true ->		ensure_crypto_started(),		ask("8b. Give a password of at least length 8. It is used to "		    "generate ~n"		    "    private keys for the configuration: ",		    mandatory, fun verify_passwd/1);	    false ->		""	end,    NotifType  =	case lists:member(v1, Vsns) of	    true ->		Overwrite = ask("9. Current configuration files will "				"now be overwritten. "				"Ok (y/n)?", "y", fun verify_yes_or_no/1),		case Overwrite of		    no ->			error(overwrite_not_allowed);		    yes ->			ok		end,		trap;	    false ->		NT = ask("9. Should notifications be sent as traps or informs "			 "(trap/inform)?", "trap", fun verify_notif_type/1),		Overwrite = ask("10. Current configuration files will "				"now be overwritten. "				"Ok (y/n)?", "y", fun verify_yes_or_no/1),		case Overwrite of		    no ->			error(overwrite_not_allowed);		    yes ->			ok		end,		NT	end,    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"	     "         and authenticated write access to the \"restricted\"~n"	     "         subtree."),	   i("      2. SecurityName \"all-rights\" has noAuthNoPriv "	     "read/write~n"	     "         access to the \"internet\" subtree."),	   i("      3. Standard traps are sent to the manager."),	   case lists:member(v1, Vsns) or lists:member(v2, Vsns) of	       true ->		   i("      4. Community \"public\" is mapped to security name"		     " \"initial\"."),		   i("      5. Community \"all-rights\" is mapped to security"		     " name \"all-rights\".");	       false ->		   ok	   end,	   i("The following agent files were written: agent.conf, "	     "community.conf,~n"	     "standard.conf, target_addr.conf, "	     "target_params.conf, ~n"	     "notify.conf" ++	     case lists:member(v3, Vsns) of		 true -> ", vacm.conf and usm.conf";		 false -> " and vacm.conf"	     end),	   i("- - - - - - - - - - - - -"),	   ok;	E -> 	    error({failed_writing_files, E})    end.%% -------------------config_manager_sys() ->    i("~nManager system config: "      "~n----------------------"),    Prio = ask("1. Manager process priority (low/normal/high)", 	       "normal", fun verify_prio/1),    Vsns = ask("2. What SNMP version(s) should be used "	       "(1,2,3,1&2,1&2&3,2&3)?", "3", fun verify_versions/1),    {ok, DefDir} = file:get_cwd(),    {DefConfDir, Warning} = default_manager_dir(DefDir),    ConfQ = 	if	    Warning == "" ->		"3. Configuration directory (absolute path)?";	    true ->		lists:flatten(		  io_lib:format("3. Configuration directory (absolute path)?" 				"~n   ~s", [Warning]))	end,    ConfigDir = ask(ConfQ, DefConfDir, fun verify_dir/1),    ConfigVerb = ask("4. Config verbosity "			"(silence/info/log/debug/trace)?", 			"silence",			fun verify_verbosity/1),    ConfigDbDir = ask("5. Database directory (absolute path)?", 		      DefDir, fun verify_dir/1),    ConfigDbRepair = ask("6. Database repair "			 "(true/false/force)?", "true",			 fun verify_dets_repair/1),    ConfigDbAutoSave = ask("7. Database auto save "			   "(infinity/milli seconds)?", 			   "5000", fun verify_dets_auto_save/1),    IRB = 	case ask("8. Inform request behaviour (auto/user)?", 		 "auto", fun verify_irb/1) of	    auto ->		auto;	    user ->		case ask("8b. Use default GC timeout"			 "(default/seconds)?",			 "default", fun verify_irb_user/1) of		    default ->			user;		    IrbGcTo ->			{user, IrbGcTo}		end	end,    ServerVerb = ask("9. Server verbosity "			"(silence/info/log/debug/trace)?", 			"silence",			fun verify_verbosity/1),    ServerTimeout = ask("10. Server GC timeout?", "30000",			   fun verify_timeout/1),        NoteStoreVerb = ask("11. Note store verbosity "			"(silence/info/log/debug/trace)?", 			"silence",			fun verify_verbosity/1),    NoteStoreTimeout = ask("12. Note store GC timeout?", "30000",			   fun verify_timeout/1),        NetIfMod = ask("13. Which network interface module shall be used?",		   "snmpm_net_if", fun verify_module/1),    NetIfVerb = ask("14. Network interface verbosity "		    "(silence/info/log/debug/trace)?", "silence",		    fun verify_verbosity/1),    NetIfBindTo = ask("15. Bind the manager IP address "		      "(true/false)?",		      "false", fun verify_bool/1),    NetIfNoReuse = ask("16. Shall the manager IP address and port "		       "be not reusable (true/false)?",		       "false", fun verify_bool/1),    NetIfRecbuf = 	case ask("17. Receive buffer size of the manager (in bytes) "		 "(default/pos integer)?", "default", 		 fun verify_netif_recbuf/1) of	    default ->		[];	    RecBufSz ->		[{recbuf, RecBufSz}]	end,    NetIfSndbuf = 	case ask("18. Send buffer size of the manager (in bytes) "		 "(default/pos integer)?", "default", 		 fun verify_netif_sndbuf/1) of	    default ->		[];	    SndBufSz ->		[{sndbuf, SndBufSz}]	end,    NetIfOpts = 	[{bind_to,   NetIfBindTo},	 {no_reuse,  NetIfNoReuse}] ++ NetIfRecbuf ++ NetIfSndbuf,    NetIf = 	[{module,    NetIfMod},	 {verbosity, NetIfVerb},	 {options,   NetIfOpts}],     ATL = 	case ask("19. Shall the manager use an audit trail log "		 "(y/n)?",		 "n", fun verify_yes_or_no/1) of	    yes ->		ATLDir = ask("19b. Where to store the "			     "audit trail log?",			     DefDir, fun verify_dir/1),		ATLMaxFiles = ask("19c. Max number of files?", 				  "10", 				  fun verify_pos_integer/1),		ATLMaxBytes = ask("19d. Max size (in bytes) "				  "of each file?", 				  "10240", 				  fun verify_pos_integer/1),		ATLSize = {ATLMaxBytes, ATLMaxFiles},		ATLRepair = ask("19e. Audit trail log repair "				"(true/false/truncate/snmp_repair)?", "true",				fun verify_atl_repair/1),		[{audit_trail_log, [{dir,    ATLDir},				    {size,   ATLSize},				    {repair, ATLRepair}]}];	    no ->		[]	end,    DefUser = 	case ask("20. Do you wish to assign a default user [yes] or use~n"		 "    the default settings [no] (y/n)?", "n", 		 fun verify_yes_or_no/1) of	    yes ->		DefUserMod = ask("20b. Default user module?", 				 "snmpm_user_default",				 fun verify_module/1),		DefUserData = ask("20c. Default user data?", "undefined",				  fun verify_user_data/1),		[{def_user_mod,  DefUserMod},		 {def_user_data, DefUserData}];	    no ->		[]	end,    SysConfig = 	[{priority,   Prio},	 {versions,   Vsns},	 {config,     [{dir,       ConfigDir}, 		       {verbosity, ConfigVerb},		       {db_dir,    ConfigDbDir},		       {repair,    ConfigDbRepair},		       {auto_save, ConfigDbAutoSave}]},	 {inform_request_behaviour, IRB},	 {mibs,       []},	 {server,     [{timeout,   ServerTimeout},		       {verbosity, ServerVerb}]},	 {note_store, [{timeout,   NoteStoreTimeout},		       {verbosity, NoteStoreVerb}]},	 {net_if,     NetIf}] ++ ATL ++ DefUser,    {Vsns, ConfigDir, SysConfig}.config_manager_snmp(Dir, Vsns) ->    i("~nManager snmp config: "      "~n--------------------"),    EngineName = guess_engine_name(),    EngineID   = ask("1. Engine ID (snmpEngineID standard variable)", 		      EngineName, fun verify_engine_id/1),    MMS        = ask("2. Max message size?", "484", 		     fun verify_max_message_size/1),    Host       = host(),    IP         = ask("3. IP address for the manager (only used as id ~n"		     "   when sending requests)",		     Host, fun verify_address/1),    Port       = ask("4. Port number (standard 162)?", "5000", 		     fun verify_port_number/1),    Users      = config_manager_snmp_users([]),    Agents     = config_manager_snmp_agents([]),    Usms       = config_manager_snmp_usms([]),    Overwrite = ask("8. Current configuration files will now be overwritten. "		    "Ok (y/n)?", "y", fun verify_yes_or_no/1),    case Overwrite of	no ->	    error(overwrite_not_allowed);	yes ->	    ok    end,    case (catch write_manager_snmp_files(Dir, 					 IP, Port, MMS, EngineID, 					 Users, Agents, Usms)) of	ok ->	   i("~n- - - - - - - - - - - - -"),	   i("The following manager files were written: "	     "manager.conf, agents.conf " ++ 	     case lists:member(v3, Vsns) of		 true ->		     ", users.conf and usm.conf";		 false ->		     " and users.conf"	     end),	   i("- - - - - - - - - - - - -"),	    ok;	E ->	    error({failed_writing_files, E})    end.	     config_manager_snmp_users(Users) ->    case ask("5. Configure a user of this manager (y/n)?",	     "y", fun verify_yes_or_no/1) of	yes ->	    User = config_manager_snmp_user(),	    config_manager_snmp_users([User|Users]);	no ->	    lists:reverse(Users)    end.config_manager_snmp_user() ->    UserId   = ask("5b. User id?", mandatory, 		   fun verify_user_id/1),    UserMod  = ask("5c. User callback module?", mandatory, 		   fun verify_module/1),    UserData = ask("5d. User (callback) data?", "undefined",		   fun verify_user_data/1),    {UserId, UserMod, UserData}.    config_manager_snmp_agents(Agents) ->    case ask("6. Configure an agent handled by this manager (y/n)?",	     "y", fun verify_yes_or_no/1) of	yes ->	    Agent = config_manager_snmp_agent(),	    config_manager_snmp_agents([Agent|Agents]);	no ->	    lists:reverse(Agents)    end.config_manager_snmp_agent() ->    UserId     = ask("6b. User id?", mandatory, 		     fun verify_user_id/1),    TargetName = ask("6c. Target name?", guess_agent_name(),		     fun verify_system_name/1),    Version    = ask("6d. Version (1/2/3)?", "1",	             fun verify_version/1),    Comm       = ask("6e. Community string ?", "public",	             fun verify_community/1),    EngineID   = ask("6f. Engine ID (snmpEngineID standard variable)", 	             guess_engine_name(), fun verify_engine_id/1),    IP         = ask("6g. IP address for the agent", host(), 	             fun verify_address/1),    Port       = ask("6h. The UDP port the agent listens to. "	             "(standard 161)", "4000", fun verify_port_number/1),    Timeout    = ask("6i. Retransmission timeout (infinity/pos integer)?",	             "infinity", fun verify_retransmission_timeout/1),        MMS        = ask("6j. Max message size?", "484", 	             fun verify_max_message_size/1),    SecModel   = ask("6k. Security model (any/v1/v2c/usm)?", "any", 	             fun verify_sec_model/1),    SecName    = ask("6l. Security name?", "\"initial\"", 	             fun verify_sec_name/1),    SecLevel   = ask("6m. Security level (noAuthNoPriv/authNoPriv/authPriv)?",	             "noAuthNoPriv", fun verify_sec_level/1),    {UserId,     TargetName, Comm, IP, Port, EngineID, Timeout, MMS,      Version, SecModel, SecName, SecLevel}.config_manager_snmp_usms(Usms) ->    case ask("7. Configure an usm user handled by this manager (y/n)?",	     "y", fun verify_yes_or_no/1) of	yes ->	    Usm = config_manager_snmp_usm(),	    config_manager_snmp_usms([Usm|Usms]);	no ->	    lists:reverse(Usms)    end.config_manager_snmp_usm() ->    EngineID = ask("7a. Engine ID", guess_engine_name(), 		   fun verify_engine_id/1),    UserName = ask("7b. User name?", mandatory, fun verify_usm_name/1),    SecName  = ask("7c. Security name?", UserName,		   fun verify_usm_sec_name/1),    AuthP    = ask("7d. Authentication protocol (no/sha/md5)?", "no",		   fun verify_usm_auth_protocol/1),    AuthKey  = ask_auth_key("7e", AuthP),     PrivP    = ask("7e. Priv protocol (no/des/aes)?", "no",		   fun verify_usm_priv_protocol/1),    PrivKey  = ask_priv_key("7f", PrivP),     {EngineID, UserName,     SecName, AuthP, AuthKey, PrivP, PrivKey}.%% ------------------------------------------------------------------is_members([], _Files) ->    true;is_members([H|T], Files) ->    lists:member(H, Files) andalso is_members(T, Files).default_agent_dir(DefDir) ->    default_dir("agent", DefDir).default_manager_dir(DefDir) ->    default_dir("manager", DefDir).default_dir(Component, DefDir) ->    %% Look for the component dir, if found use that as default    {ok, Files} = file:list_dir(DefDir),    case lists:member(Component, Files) of	true ->	    {filename:join(DefDir, Component), ""};	false ->	    %% No luck, 	    %% so check if cwd contains either agent and/or 	    %% manager config files. If it does, issue a warning	    %% Check for presence of agent config files	    %% If all the agent config files are present,	    %% issue a warning	    AgentConfs = 		[		 "agent.conf",		 "context.conf",		 "community.conf",		 "notify.conf",		 "standard.conf",		 "target_params.conf",		 "target_addr.conf",		 "usm.conf",	 		 "vacm.conf"		],	    IsAgentDir = is_members(AgentConfs, Files),	    %% Check for presence of manager config files	    %% If all the manager config files are present,	    %% issue a warning	    ManagerConfs = 		[		 "agents.conf",		 "manager.conf",		 "users.conf",		 "usm.conf"		],	    IsManagerDir = is_members(ManagerConfs, Files),	    Warning = 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?