📄 master.cpp
字号:
OctetStr engineId(SnmpEngineID::create_engine_id(port)); // you may use your own methods to load/store this counter mib = new MasterAgentXMib(); status = mib->get_boot_counter(engineId, snmpEngineBoots); if ((status != SNMPv3_OK) && (status < SNMPv3_FILEOPEN_ERROR)) { LOG_BEGIN(ERROR_LOG | 0); LOG("main: Error loading snmpEngineBoots counter (status)"); LOG(status); LOG_END; exit(1); } snmpEngineBoots++; status = mib->set_boot_counter(engineId, snmpEngineBoots); if (status != SNMPv3_OK) { LOG_BEGIN(ERROR_LOG | 0); LOG("main: Error saving snmpEngineBoots counter (status)"); LOG(status); LOG_END; exit(1); } int stat; v3MP *v3mp = new v3MP(engineId, snmpEngineBoots, stat);#else mib = new MasterAgentXMib(); #endif init_signals(); reqList = new RequestList();#ifdef _SNMPv3 // register v3MP reqList->set_v3mp(v3mp);#endif // register requestList for outgoing requests mib->set_request_list(reqList); agentx = new AgentXMaster(); agentx->set_tcp_port(agentxPort);#ifdef AX_UNIX_SOCKET#ifndef WIN32 agentx->set_connect_mode(AX_USE_UNIX_SOCKET | AX_USE_TCP_SOCKET);#else agentx->set_connect_mode(AX_USE_TCP_SOCKET);#endif agentx->set_unix_port_loc("/var/agentx/");#else agentx->set_connect_mode(AX_USE_TCP_SOCKET);#endif mib->set_agentx(agentx); // enable auto context creation -> a subagent may register for a // context not yet known by the master mib->set_auto_context(TRUE); init(*mib); reqList->set_snmp(&snmp);#ifdef _SNMPv3 // add entrires in various tables to allow AgentX subagents // to connect to this master using its TCP port from all IPv4 ports // from the localhost (127.0.0.1) allow_agentx_tcp_from_localhost(); // register VACM Vacm* vacm = new Vacm(*mib); reqList->set_vacm(vacm); // initialize security information vacm->addNewContext(""); vacm->addNewContext("subagent"); // Add new entries to the SecurityToGroupTable. // Used to determine the group a given SecurityName belongs to. // User "new" of the USM belongs to newGroup vacm->addNewGroup(SecurityModel_USM, "unsecureUser", "newGroup", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "test", "testGroup", storageType_volatile); vacm->addNewGroup(SecurityModel_v2, "public", "v1v2group", storageType_volatile); vacm->addNewGroup(SecurityModel_v1, "public", "v1v2group", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "initial", "initial", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "unsecureUser", "initial", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "MD5", "newGroup", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "SHA", "testNoPrivGroup", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "MD5DES", "testGroup", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "SHADES", "testGroup", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "MD5IDEA", "testGroup", storageType_volatile); vacm->addNewGroup(SecurityModel_USM, "SHAIDEA", "testGroup", storageType_volatile); // remove a group with: //vacm->deleteGroup(SecurityModel_USM, "neu"); // Set access rights of groups. // The group "newGroup" (when using the USM with a security // level >= noAuthNoPriv within context "") would have full access // (read, write, notify) to all objects in view "newView". vacm->addNewAccessEntry("newGroup", "subagent", // context SecurityModel_USM, SecurityLevel_noAuthNoPriv, match_exact, // context must mach exactly // alternatively: match_prefix "newView", // readView "newView", // writeView "newView", // notifyView storageType_nonVolatile); vacm->addNewAccessEntry("newGroup", "subagent2", // context SecurityModel_USM, SecurityLevel_noAuthNoPriv, match_exact, // context must mach exactly // alternatively: match_prefix "newView", // readView "newView", // writeView "newView", // notifyView storageType_nonVolatile); vacm->addNewAccessEntry("newGroup", "", // context SecurityModel_USM, SecurityLevel_noAuthNoPriv, match_exact, // context must mach exactly // alternatively: match_prefix "newView", // readView "newView", // writeView "newView", // notifyView storageType_nonVolatile); vacm->addNewAccessEntry("testGroup", "", SecurityModel_USM, SecurityLevel_authPriv, match_prefix, "testView", "testView", "testView", storageType_nonVolatile); vacm->addNewAccessEntry("testNoPrivGroup", "", SecurityModel_USM, SecurityLevel_authNoPriv, match_prefix, "testView", "testView", "testView", storageType_nonVolatile); vacm->addNewAccessEntry("testGroup", "", SecurityModel_USM, SecurityLevel_noAuthNoPriv, match_prefix, "testView", "testView", "testView", storageType_nonVolatile); vacm->addNewAccessEntry("v1v2group", "", SecurityModel_v2, SecurityLevel_noAuthNoPriv, match_exact, "v1ReadView", "v1WriteView", "v1NotifyView", storageType_nonVolatile); vacm->addNewAccessEntry("v1v2group", "", SecurityModel_v1, SecurityLevel_noAuthNoPriv, match_exact, "v1ReadView", "v1WriteView", "v1NotifyView", storageType_nonVolatile); vacm->addNewAccessEntry("initial", "", SecurityModel_USM, SecurityLevel_noAuthNoPriv, match_exact, "restricted", "", "restricted", storageType_nonVolatile); vacm->addNewAccessEntry("initial", "", SecurityModel_USM, SecurityLevel_authNoPriv, match_exact, "internet", "internet", "internet", storageType_nonVolatile); vacm->addNewAccessEntry("initial", "", SecurityModel_USM, SecurityLevel_authPriv, match_exact, "internet", "internet", "internet", storageType_nonVolatile); // remove an AccessEntry with: // vacm->deleteAccessEntry("newGroup", // "", // SecurityModel_USM, // SecurityLevel_noAuthNoPriv); // Defining Views // View "v1ReadView" includes all objects starting with "1.3". // If the ith bit of the mask is not set (0), then also all objects // which have a different subid at position i are included in the // view. // For example: Oid "6.5.4.3.2.1", Mask(binary) 110111 // Then all objects with Oid with "6.5.<?>.3.2.1" // are included in the view, whereas <?> may be any // natural number. vacm->addNewView("v1ReadView", "1.3", "", // Mask "" is same as 0xFFFFFFFFFF... view_included, // alternatively: view_excluded storageType_nonVolatile); vacm->addNewView("v1WriteView", "1.3", "", // Mask "" is same as 0xFFFFFFFFFF... view_included, // alternatively: view_excluded storageType_nonVolatile); vacm->addNewView("v1NotifyView", "1.3", "", // Mask "" is same as 0xFFFFFFFFFF... view_included, // alternatively: view_excluded storageType_nonVolatile); vacm->addNewView("newView", "1.3", "", view_included, storageType_nonVolatile); vacm->addNewView("testView", "1.3.6", "", view_included, storageType_nonVolatile); vacm->addNewView("internet", "1.3.6.1","", view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.2.1.1","", view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.2.1.11","", view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.6.3.10.2.1","", view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.6.3.11.2.1","", view_included, storageType_nonVolatile); vacm->addNewView("restricted", "1.3.6.1.6.3.15.1.1","", view_included, storageType_nonVolatile); // add SNMPv1/v2c community to v3 security name mapping OctetStr co("public"); MibTableRow* row = snmpCommunityEntry::instance-> add_row(Oidx::from_string(co, FALSE)); OctetStr tag("v1v2cPermittedManagers"); snmpCommunityEntry::instance-> set_row(row, co, co, reqList->get_v3mp()->get_local_engine_id(), "", tag, 3, 1);#endif // start AgentX master mib->init(); Vbx* vbs = 0; coldStartOid coldOid; NotificationOriginator no; UdpAddress dest("127.0.0.1/162"); no.add_v1_trap_destination(dest); mib->notify("", coldOid, vbs, 0); Request* req; while (run) { req = reqList->receive(2); if (req) { mib->process_request(req); } else if ((reqList->size() == 0) && (mib->get_thread_pool()->is_idle())) { mib->cleanup(); } } mib->delete_thread_pool(); delete mib; delete reqList; delete agentx;#ifdef _SNMPv3 delete v3mp;#endif Snmp::socket_cleanup(); // Shut down socket subsystem return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -