{"id":6711,"date":"2025-09-29T13:36:11","date_gmt":"2025-09-29T05:36:11","guid":{"rendered":"https:\/\/xinchewhd.com.cn\/?p=6711"},"modified":"2025-09-29T13:36:18","modified_gmt":"2025-09-29T05:36:18","slug":"spring-boot-%e5%ae%9e%e7%8e%b0-snmp-%e5%ba%94%e7%94%a8%e3%80%81%e5%8f%91%e9%80%81%e4%b8%8e%e8%a7%a3%e6%9e%90","status":"publish","type":"post","link":"https:\/\/xinchewhd.com.cn\/index.php\/spring-boot\/spring-boot-%e5%ae%9e%e7%8e%b0-snmp-%e5%ba%94%e7%94%a8%e3%80%81%e5%8f%91%e9%80%81%e4%b8%8e%e8%a7%a3%e6%9e%90\/","title":{"rendered":"Spring Boot \u5b9e\u73b0 SNMP \u5e94\u7528\u3001\u53d1\u9001\u4e0e\u89e3\u6790"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><strong>\u524d\u8a00<\/strong><strong><\/strong><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"522\" height=\"461\" data-src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png\" src=\"https:\/\/s.nmxc.ltd\/sakurairo_vision\/@2.6\/load_svg\/inload.svg\" onerror=\"imgError(this)\" alt=\"\" class=\"wp-image-6712 lazyload\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png 522w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234-300x265.png 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><noscript><img loading=\"lazy\" decoding=\"async\" width=\"522\" height=\"461\" src=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png\" alt=\"\" class=\"wp-image-6712\" srcset=\"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png 522w, https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234-300x265.png 300w\" sizes=\"auto, (max-width: 522px) 100vw, 522px\" \/><\/noscript><\/figure>\n\n\n\n<p>\u968f\u7740\u7f51\u7edc\u89c4\u6a21\u7684\u4e0d\u65ad\u6269\u5927\u4ee5\u53ca\u7f51\u7edc\u8bbe\u5907\u6570\u91cf\u7684\u6025\u5267\u589e\u52a0\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u76d1\u63a7\u548c\u7ba1\u7406\u8fd9\u4e9b\u8bbe\u5907\u6210\u4e3a\u4e86\u7f51\u7edc\u7ba1\u7406\u5458\u9762\u4e34\u7684\u4e00\u5927\u6311\u6218\u3002\u7b80\u5355\u7f51\u7edc\u7ba1\u7406\u534f\u8bae\uff08<code>Simple Network Management Protocol<\/code>\uff0c<code>SNMP<\/code>\uff09\u5e94\u8fd0\u800c\u751f\uff0c\u5b83\u4f5c\u4e3a\u4e00\u79cd\u5e94\u7528\u5c42\u534f\u8bae\uff0c\u4e3a\u7f51\u7edc\u7ba1\u7406\u63d0\u4f9b\u4e86\u6807\u51c6\u5316\u7684\u89e3\u51b3\u65b9\u6848\uff0c\u6781\u5927\u5730\u7b80\u5316\u4e86\u7f51\u7edc\u7ba1\u7406\u7684\u590d\u6742\u6027\u3002<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><\/strong><strong>\u57fa\u7840\u6982\u8ff0<\/strong><\/h4>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>\u534f\u8bae\u67b6\u6784<\/strong><\/h5>\n\n\n\n<p><code>SNMP<\/code>\u67b6\u6784\u4e3b\u8981\u7531\u4e09\u4e2a\u5173\u952e\u90e8\u5206\u7ec4\u6210\uff1a\u7f51\u7edc\u7ba1\u7406\u7cfb\u7edf\uff08<code>Network Management System<\/code>\uff0c<code>NMS<\/code>\uff09\u3001\u4ee3\u7406\uff08<code>Agent<\/code>\uff09\u4ee5\u53ca\u7ba1\u7406\u4fe1\u606f\u5e93\uff08<code>Management Information Base<\/code>\uff0c<code>MIB<\/code>\uff09\u3002<code>NMS<\/code>&nbsp;\u5728\u7f51\u7edc\u7ba1\u7406\u4e2d\u5145\u5f53\u7ba1\u7406\u8005\u7684\u89d2\u8272\uff0c\u901a\u5e38\u8fd0\u884c\u5728\u670d\u52a1\u5668\u4e0a\uff0c\u8d1f\u8d23\u5411\u5404\u4e2a\u8bbe\u5907\u4e0a\u7684<code>Agent<\/code>\u53d1\u9001\u7ba1\u7406\u8bf7\u6c42\uff0c\u4ee5\u67e5\u8be2\u6216\u4fee\u6539\u8bbe\u5907\u7684\u53c2\u6570\u503c\u3002\u540c\u65f6\uff0c<code>NMS<\/code>\u4e5f\u63a5\u6536\u6765\u81ea<code>Agent<\/code>\u4e3b\u52a8\u53d1\u9001\u7684<code>Trap<\/code>\u4fe1\u606f\uff0c\u4ece\u800c\u53ca\u65f6\u4e86\u89e3\u88ab\u7ba1\u7406\u8bbe\u5907\u7684\u72b6\u6001\u53d8\u5316\u3002<code>Agent<\/code>\u5219\u662f\u9a7b\u7559\u5728\u88ab\u7ba1\u7406\u8bbe\u5907\u4e2d\u7684\u4ee3\u7406\u8fdb\u7a0b\uff0c\u5176\u4e3b\u8981\u804c\u8d23\u662f\u7ef4\u62a4\u8bbe\u5907\u7684\u4fe1\u606f\u6570\u636e\uff0c\u5e76\u5bf9<code>NMS<\/code>\u53d1\u9001\u7684\u8bf7\u6c42\u505a\u51fa\u54cd\u5e94\uff0c\u5c06\u64cd\u4f5c\u7ed3\u679c\u53cd\u9988\u7ed9 NMS\u3002\u5f53\u8bbe\u5907\u53d1\u751f\u6545\u969c\u6216\u5176\u4ed6\u91cd\u8981\u4e8b\u4ef6\u65f6\uff0c<code>Agent<\/code>\u4f1a\u4e3b\u52a8\u5411<code>NMS<\/code>\u53d1\u9001<code>Trap<\/code>\u4fe1\u606f\u3002<code>MIB<\/code>\u5219\u662f\u7f51\u7edc\u8bbe\u5907\u4e0a\u88ab SNMP \u7ba1\u7406\u7684\u53c2\u6570\u96c6\u5408\uff0c\u5b83\u91c7\u7528\u5c42\u6b21\u5316\u7684\u7ed3\u6784\uff0c\u7c7b\u4f3c\u4e8e\u6587\u4ef6\u7cfb\u7edf\u7684\u76ee\u5f55\u7ed3\u6784\uff0c\u6bcf\u4e2a\u7ba1\u7406\u5bf9\u8c61\u5728<code>MIB<\/code>\u4e2d\u90fd\u6709\u5176\u552f\u4e00\u7684\u4f4d\u7f6e\u6807\u8bc6\uff0c\u5373\u5bf9\u8c61\u6807\u8bc6\u7b26\uff08<code>Object Identifier<\/code>\uff0c<code>OID<\/code>\uff09\u3002\u901a\u8fc7<code>OID<\/code>\uff0c<code>NMS<\/code>\u548c<code>Agent<\/code>\u80fd\u591f\u51c6\u786e\u5730\u5b9a\u4f4d\u548c\u64cd\u4f5c\u7279\u5b9a\u7684\u7ba1\u7406\u5bf9\u8c61\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>\u5de5\u4f5c\u539f\u7406<\/strong><\/h5>\n\n\n\n<p><code>SNMP<\/code>\u57fa\u4e8e<strong>\u8bf7\u6c42\/\u54cd\u5e94<\/strong>\u6a21\u578b\u8fdb\u884c\u5de5\u4f5c\u3002<code>NMS<\/code>\u901a\u8fc7\u5411<code>Agent<\/code>\u53d1\u9001\u4e0d\u540c\u7c7b\u578b\u7684\u8bf7\u6c42\u62a5\u6587\u6765\u5b9e\u73b0\u5bf9\u8bbe\u5907\u7684\u7ba1\u7406\u64cd\u4f5c\u3002\u5e38\u89c1\u7684\u8bf7\u6c42\u7c7b\u578b\u5305\u62ec&nbsp;<code>Get<\/code>&nbsp;\u8bf7\u6c42\uff0c\u7528\u4e8e\u4ece<code>Agent<\/code>\u83b7\u53d6\u4e00\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\u503c\uff1b<code>Set<\/code>\u8bf7\u6c42\uff0c\u7528\u4e8e\u4fee\u6539&nbsp;<code>Agent<\/code>&nbsp;\u4e0a\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u53c2\u6570\u503c\uff1b<code>GetNext<\/code>\u8bf7\u6c42\uff0c\u901a\u5e38\u7528\u4e8e\u904d\u5386 MIB \u4e2d\u7684\u8868\u7ed3\u6784\uff0c\u83b7\u53d6\u4e0b\u4e00\u4e2a\u5bf9\u8c61\u7684\u503c\uff1b<code>GetBulk<\/code>\u8bf7\u6c42\uff0c\u9002\u7528\u4e8e\u4e00\u6b21\u6027\u83b7\u53d6\u5927\u91cf\u6570\u636e\uff0c\u7279\u522b\u662f\u5728\u68c0\u7d22\u8868\u683c\u4fe1\u606f\u65f6\u80fd\u663e\u8457\u63d0\u9ad8\u6548\u7387\uff1b<code>Inform<\/code>\u8bf7\u6c42\uff0c<code>Agent<\/code>\u4f7f\u7528\u8be5\u8bf7\u6c42\u5411<code>NMS<\/code>\u53d1\u9001\u901a\u77e5\uff0c\u4e0e<code>Trap<\/code>\u7c7b\u4f3c\uff0c\u4f46<code>Inform<\/code>\u8bf7\u6c42\u9700\u8981<code>NMS<\/code>\u8fdb\u884c\u786e\u8ba4\u3002<code>Agent<\/code>\u5728\u63a5\u6536\u5230<code>NMS<\/code>\u7684\u8bf7\u6c42\u540e\uff0c\u4f1a\u6839\u636e\u8bf7\u6c42\u7c7b\u578b\u5728<code>MIB<\/code>\u4e2d\u67e5\u627e\u6216\u4fee\u6539\u76f8\u5e94\u7684\u7ba1\u7406\u5bf9\u8c61\uff0c\u5e76\u5c06\u7ed3\u679c\u5c01\u88c5\u5728\u54cd\u5e94\u62a5\u6587\u4e2d\u8fd4\u56de\u7ed9&nbsp;<code>NMS<\/code>\u3002\u5f53\u8bbe\u5907\u51fa\u73b0\u7279\u5b9a\u4e8b\u4ef6\uff08\u5982\u63a5\u53e3\u72b6\u6001\u6539\u53d8\u3001\u8bbe\u5907\u6545\u969c\u7b49\uff09\u65f6\uff0c<code>Agent<\/code>\u4f1a\u4e3b\u52a8\u5411<code>NMS<\/code>\u53d1\u9001<code>Trap<\/code>\u62a5\u6587\uff0c\u901a\u77e5<code>NMS<\/code>\u8bbe\u5907\u7aef\u53d1\u751f\u7684\u60c5\u51b5\u3002<\/p>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>\u7248\u672c\u6f14\u8fdb<\/strong><\/h5>\n\n\n\n<p><code>SNMP<\/code>\u7ecf\u5386\u4e86\u591a\u4e2a\u7248\u672c\u7684\u53d1\u5c55\uff0c\u6bcf\u4e2a\u7248\u672c\u90fd\u5728\u529f\u80fd\u548c\u5b89\u5168\u6027\u65b9\u9762\u6709\u6240\u6539\u8fdb\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>SNMPv1<\/code>\uff1a\u4f5c\u4e3a\u6700\u65e9\u7684\u7248\u672c\uff0c\u63d0\u4f9b\u4e86\u57fa\u672c\u7684\u7f51\u7edc\u7ba1\u7406\u529f\u80fd\u3002\u5b83\u91c7\u7528\u7b80\u5355\u7684\u56e2\u4f53\u540d\uff08<code>Community String<\/code>\uff09\u8fdb\u884c\u8ba4\u8bc1\uff0c\u5b89\u5168\u6027\u76f8\u5bf9\u8f83\u4f4e\uff0c\u4f46\u5728\u65e9\u671f\u7684\u7f51\u7edc\u73af\u5883\u4e2d\u53d1\u6325\u4e86\u91cd\u8981\u4f5c\u7528\u3002<\/li>\n\n\n\n<li><code>SNMPv2c<\/code>\uff1a\u662f<code>SNMPv1<\/code>\u7684\u589e\u5f3a\u7248\uff0c\u589e\u52a0\u4e86\u6539\u8fdb\u7684\u9519\u8bef\u5904\u7406\u673a\u5236\u548c\u6279\u91cf\u6570\u636e\u68c0\u7d22\u529f\u80fd\uff08\u5982<code>GetBulk<\/code>\u64cd\u4f5c\uff09\uff0c\u63d0\u9ad8\u4e86\u6570\u636e\u83b7\u53d6\u7684\u6548\u7387\u3002\u7136\u800c\uff0c\u5b83\u4ecd\u7136\u4f7f\u7528\u56e2\u4f53\u540d\u8fdb\u884c\u8ba4\u8bc1\uff0c\u5728\u5b89\u5168\u6027\u65b9\u9762\u5e76\u6ca1\u6709\u672c\u8d28\u7684\u63d0\u5347\u3002<\/li>\n\n\n\n<li><code>SNMPv3<\/code>\uff1a\u5728\u5b89\u5168\u6027\u65b9\u9762\u505a\u4e86\u663e\u8457\u6539\u8fdb\uff0c\u652f\u6301\u7528\u6237\u7ea7\u522b\u7684\u8ba4\u8bc1\u548c\u52a0\u5bc6\u3002\u5b83\u63d0\u4f9b\u4e86\u4e09\u79cd\u4e3b\u8981\u7684\u5b89\u5168\u529f\u80fd\uff1a\u8ba4\u8bc1\uff0c\u7528\u4e8e\u786e\u4fdd\u6d88\u606f\u7684\u53d1\u9001\u8005\u8eab\u4efd\u771f\u5b9e\u53ef\u9760\uff1b\u52a0\u5bc6\uff0c\u4fdd\u62a4\u6570\u636e\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u7684\u673a\u5bc6\u6027\uff0c\u9632\u6b62\u6570\u636e\u88ab\u7a83\u53d6\uff1b\u6d88\u606f\u5b8c\u6574\u6027\uff0c\u4fdd\u8bc1\u6d88\u606f\u5728\u4f20\u8f93\u8fc7\u7a0b\u4e2d\u672a\u88ab\u7be1\u6539\u3002\u901a\u8fc7\u8fd9\u4e9b\u5b89\u5168\u7279\u6027\uff0c<code>SNMPv3<\/code>\u80fd\u591f\u66f4\u597d\u5730\u6ee1\u8db3\u73b0\u4ee3\u7f51\u7edc\u5bf9\u5b89\u5168\u6027\u7684\u8981\u6c42\uff0c\u9002\u7528\u4e8e\u5bf9\u5b89\u5168\u8f83\u4e3a\u654f\u611f\u7684\u7f51\u7edc\u73af\u5883\u3002<\/li>\n<\/ul>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>SNMP \u5e94\u7528\u573a\u666f<\/strong><\/h5>\n\n\n\n<p><strong>\u7f51\u7edc\u8bbe\u5907\u76d1\u63a7<\/strong><\/p>\n\n\n\n<p><code>SNMP<\/code>\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5bf9\u8def\u7531\u5668\u3001\u4ea4\u6362\u673a\u3001\u65e0\u7ebf\u63a5\u5165\u70b9\u7b49\u5404\u7c7b\u7f51\u7edc\u8bbe\u5907\u7684\u72b6\u6001\u548c\u6027\u80fd\u76d1\u63a7\u3002\u901a\u8fc7<code>SNMP<\/code>\uff0c\u7f51\u7edc\u7ba1\u7406\u5458\u53ef\u4ee5\u5b9e\u65f6\u83b7\u53d6\u8bbe\u5907\u7684\u7cfb\u7edf\u4fe1\u606f\uff0c\u5982\u8bbe\u5907\u7c7b\u578b\u3001\u64cd\u4f5c\u7cfb\u7edf\u7248\u672c\u3001<code>IP<\/code>\u5730\u5740\u7b49\uff1b\u76d1\u63a7\u63a5\u53e3\u72b6\u6001\uff0c\u5305\u62ec\u63a5\u53e3\u7684\u8fde\u63a5\u72b6\u6001\u3001\u6d41\u91cf\u7edf\u8ba1\u3001\u5e26\u5bbd\u5229\u7528\u7387\u7b49\uff1b\u4e86\u89e3\u8bbe\u5907\u7684<code>CPU<\/code>\u548c\u5185\u5b58\u4f7f\u7528\u7387\u7b49\u5173\u952e\u6027\u80fd\u6307\u6807\u3002\u4f8b\u5982\uff0c\u901a\u8fc7\u6301\u7eed\u76d1\u6d4b\u8def\u7531\u5668\u63a5\u53e3\u7684\u6d41\u91cf\uff0c\u7ba1\u7406\u5458\u53ef\u4ee5\u53ca\u65f6\u53d1\u73b0\u7f51\u7edc\u62e5\u585e\u7684\u8ff9\u8c61\uff0c\u5e76\u91c7\u53d6\u76f8\u5e94\u7684\u63aa\u65bd\u8fdb\u884c\u4f18\u5316\uff0c\u5982\u8c03\u6574\u8def\u7531\u7b56\u7565\u6216\u589e\u52a0\u5e26\u5bbd\u3002<\/p>\n\n\n\n<p><strong>\u7f51\u7edc\u6027\u80fd\u7ba1\u7406<\/strong><\/p>\n\n\n\n<p>\u501f\u52a9<code>SNMP<\/code>\u6536\u96c6\u8bbe\u5907\u7684\u6d41\u91cf\u7edf\u8ba1\u548c\u6027\u80fd\u6307\u6807\uff0c\u7ba1\u7406\u5458\u53ef\u4ee5\u6df1\u5165\u5206\u6790\u7f51\u7edc\u6d41\u91cf\u7684\u5206\u5e03\u60c5\u51b5\u548c\u53d8\u5316\u8d8b\u52bf\u3002\u901a\u8fc7\u5bf9\u7f51\u7edc\u6d41\u91cf\u7684\u5206\u6790\uff0c\u80fd\u591f\u8bc6\u522b\u51fa\u7f51\u7edc\u4e2d\u7684\u74f6\u9888\u8282\u70b9\uff0c\u5373\u90a3\u4e9b\u5728\u7279\u5b9a\u65f6\u95f4\u6bb5\u5185\u7531\u4e8e\u8d1f\u8f7d\u8fc7\u9ad8\u800c\u5bfc\u81f4\u7f51\u7edc\u6027\u80fd\u4e0b\u964d\u7684\u8bbe\u5907\u6216\u94fe\u8def\u3002\u9488\u5bf9\u8fd9\u4e9b\u74f6\u9888\uff0c\u7ba1\u7406\u5458\u53ef\u4ee5\u91c7\u53d6\u9488\u5bf9\u6027\u7684\u4f18\u5316\u63aa\u65bd\uff0c\u5982\u5347\u7ea7\u786c\u4ef6\u8bbe\u5907\u3001\u4f18\u5316\u7f51\u7edc\u62d3\u6251\u7ed3\u6784\u6216\u8c03\u6574\u7f51\u7edc\u5e94\u7528\u7684\u6d41\u91cf\u5206\u914d\u7b56\u7565\uff0c\u4ece\u800c\u63d0\u5347\u6574\u4e2a\u7f51\u7edc\u7684\u6027\u80fd\u548c\u7528\u6237\u4f53\u9a8c\u3002<\/p>\n\n\n\n<p><strong>\u6545\u969c\u68c0\u6d4b\u548c\u544a\u8b66<\/strong><\/p>\n\n\n\n<p><code>SNMP<\/code>\u7684<code>Trap<\/code>\u529f\u80fd\u5728\u6545\u969c\u68c0\u6d4b\u548c\u544a\u8b66\u65b9\u9762\u53d1\u6325\u7740\u91cd\u8981\u4f5c\u7528\u3002\u5f53\u7f51\u7edc\u8bbe\u5907\u53d1\u751f\u6545\u969c\uff08\u5982\u786c\u4ef6\u6545\u969c\u3001\u94fe\u8def\u4e2d\u65ad\u3001\u8f6f\u4ef6\u9519\u8bef\u7b49\uff09\u65f6\uff0c\u8bbe\u5907\u4e0a\u7684<code>Agent<\/code>\u4f1a\u7acb\u5373\u5411<code>NMS<\/code>\u53d1\u9001<code>Trap<\/code>\u6d88\u606f\uff0c\u901a\u77e5\u7ba1\u7406\u5458\u8bbe\u5907\u51fa\u73b0\u7684\u5f02\u5e38\u60c5\u51b5\u3002\u7ba1\u7406\u5458\u53ef\u4ee5\u6839\u636e\u63a5\u6536\u5230\u7684<code>Trap<\/code>\u4fe1\u606f\u5feb\u901f\u5b9a\u4f4d\u6545\u969c\u8bbe\u5907\u548c\u6545\u969c\u7c7b\u578b\uff0c\u53ca\u65f6\u91c7\u53d6\u4fee\u590d\u63aa\u65bd\uff0c\u51cf\u5c11\u6545\u969c\u5bf9\u7f51\u7edc\u8fd0\u884c\u7684\u5f71\u54cd\u3002\u4f8b\u5982\uff0c\u5f53\u4ea4\u6362\u673a\u7684\u67d0\u4e2a\u7aef\u53e3\u51fa\u73b0\u94fe\u8def\u6545\u969c\u65f6\uff0c\u4ea4\u6362\u673a\u7684<code>Agent<\/code>\u4f1a\u5411<code>NMS<\/code>\u53d1\u9001\u76f8\u5e94\u7684<code>Trap<\/code>\u544a\u8b66\uff0c\u7ba1\u7406\u5458\u53ef\u4ee5\u8fc5\u901f\u6392\u67e5\u8be5\u7aef\u53e3\u7684\u8fde\u63a5\u60c5\u51b5\uff0c\u786e\u5b9a\u6545\u969c\u539f\u56e0\u5e76\u8fdb\u884c\u4fee\u590d\u3002<\/p>\n\n\n\n<p><strong>\u8bbe\u5907\u914d\u7f6e\u7ba1\u7406<\/strong><\/p>\n\n\n\n<p><code>SNMP<\/code>\u8fd8\u53ef\u4ee5\u7528\u4e8e\u8fdc\u7a0b\u914d\u7f6e\u8bbe\u5907\u53c2\u6570\uff0c\u5b9e\u73b0\u5bf9\u7f51\u7edc\u8bbe\u5907\u7684\u96c6\u4e2d\u7ba1\u7406\u3002\u7ba1\u7406\u5458\u53ef\u4ee5\u901a\u8fc7<code>NMS<\/code>\u5411<code>Agent<\/code>\u53d1\u9001<code>Set<\/code>\u8bf7\u6c42\uff0c\u4fee\u6539\u8bbe\u5907\u7684\u914d\u7f6e\u53c2\u6570\uff0c\u5982\u8c03\u6574\u7f51\u7edc\u8bbe\u5907\u7684<code>IP<\/code>\u5730\u5740\u3001\u5b50\u7f51\u63a9\u7801\u3001\u8def\u7531\u8868\u9879\u7b49\uff1b\u542f\u7528\u6216\u7981\u7528\u8bbe\u5907\u7684\u67d0\u4e9b\u7279\u6027\uff0c\u5982\u7aef\u53e3\u955c\u50cf\u3001<code>QoS<\/code>\u7b56\u7565\u7b49\u3002\u8fd9\u79cd\u8fdc\u7a0b\u914d\u7f6e\u7ba1\u7406\u65b9\u5f0f\u5927\u5927\u7b80\u5316\u4e86\u8bbe\u5907\u7ba1\u7406\u7684\u6d41\u7a0b\uff0c\u63d0\u9ad8\u4e86\u7ba1\u7406\u6548\u7387\uff0c\u5c24\u5176\u9002\u7528\u4e8e\u5927\u89c4\u6a21\u7f51\u7edc\u73af\u5883\u4e2d\u5bf9\u4f17\u591a\u8bbe\u5907\u7684\u7edf\u4e00\u7ba1\u7406\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong><\/strong><strong>SNMP \u96c6\u6210<\/strong><strong><\/strong><\/h2>\n\n\n\n<h4 class=\"wp-block-heading\"><strong><\/strong><strong>\u4ee3\u7801\u6848\u4f8b<\/strong><\/h4>\n\n\n\n<p>\u5728<code>pom.xml<\/code>\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u4f9d\u8d56\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;dependency&gt;<br>&nbsp; &nbsp; &lt;groupId&gt;org.snmp4j&lt;\/groupId&gt;<br>&nbsp; &nbsp; &lt;artifactId&gt;snmp4j&lt;\/artifactId&gt;<br>&nbsp; &nbsp; &lt;version&gt;2.8.4&lt;\/version&gt;<br>&lt;\/dependency&gt;<\/code><\/pre>\n\n\n\n<p><code>application.yml<\/code>\u914d\u7f6e\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>snmp:<br>&nbsp; target:<br>&nbsp; &nbsp; ip: 192.168.1.1<br>&nbsp; &nbsp; port: 161<br>&nbsp; version: v2c<br>&nbsp; community: public<br>&nbsp; timeout: 3000<br>&nbsp; retries: 2<br>&nbsp;&nbsp;trap:<br>&nbsp; &nbsp; listener-port: 162<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>\u914d\u7f6e\u7c7b\u5b9e\u73b0\uff1a<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>@Configuration<br>@ConfigurationProperties(prefix =&nbsp;\"snmp\")<br>public class SnmpConfig {<br>&nbsp; &nbsp; private TargetConfig target;<br>&nbsp; &nbsp; private String version;<br>&nbsp; &nbsp; private String community;<br>&nbsp; &nbsp; private int timeout;<br>&nbsp; &nbsp; private int retries;<br>&nbsp; &nbsp; private TrapConfig&nbsp;trap;<br><br>&nbsp; &nbsp; \/\/ \u5185\u90e8\u9759\u6001\u7c7b\u7528\u4e8e\u5c01\u88c5\u76ee\u6807\u8bbe\u5907\u914d\u7f6e<br>&nbsp; &nbsp; public static class TargetConfig {<br>&nbsp; &nbsp; &nbsp; &nbsp; private String ip;<br>&nbsp; &nbsp; &nbsp; &nbsp; private int port;<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ getters and setters<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; public static class TrapConfig {<br>&nbsp; &nbsp; &nbsp; &nbsp; private int listenerPort;<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ getters and setters<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; \/\/ getters and setters<br>}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>SNMP \u5ba2\u6237\u7aef\u521d\u59cb\u5316<\/strong><\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>@Configuration<br>public class SnmpClientConfig {<br><br>&nbsp; &nbsp; @Autowired<br>&nbsp; &nbsp; private SnmpConfig snmpConfig;<br><br>&nbsp; &nbsp; @Bean<br>&nbsp; &nbsp; public Snmp snmp() throws IOException {<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u521b\u5efa\u4f20\u8f93\u5c42\u5bf9\u8c61\uff08UDP\u534f\u8bae\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; TransportMapping&lt;?&gt; transport = new DefaultUdpTransportMapping();<br>&nbsp; &nbsp; &nbsp; &nbsp; Snmp snmp = new Snmp(transport);<br>&nbsp; &nbsp; &nbsp; &nbsp; transport.listen(); \/\/ \u542f\u52a8\u76d1\u542c\uff08\u7528\u4e8e\u63a5\u6536\u54cd\u5e94\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;snmp;<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; @Bean<br>&nbsp; &nbsp; public Target&nbsp;snmpTarget() {<br>&nbsp; &nbsp; &nbsp; &nbsp; Address targetAddress = GenericAddress.parse(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\"udp:\"&nbsp;+ snmpConfig.getTarget().getIp() +&nbsp;\"\/\"&nbsp;+ snmpConfig.getTarget().getPort()<br>&nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; CommunityTarget target = new CommunityTarget();<br>&nbsp; &nbsp; &nbsp; &nbsp; target.setCommunity(new OctetString(snmpConfig.getCommunity()));<br>&nbsp; &nbsp; &nbsp; &nbsp; target.setAddress(targetAddress);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u8bbe\u7f6eSNMP\u7248\u672c<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(\"v3\".equals(snmpConfig.getVersion())) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; target.setVersion(SnmpConstants.version3);<br>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;elseif&nbsp;(\"v2c\".equals(snmpConfig.getVersion())) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; target.setVersion(SnmpConstants.version2c);<br>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;else&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; target.setVersion(SnmpConstants.version1);<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; target.setTimeout(snmpConfig.getTimeout()); \/\/ \u8d85\u65f6\u65f6\u95f4\uff08\u6beb\u79d2\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp; target.setRetries(snmpConfig.getRetries()); \/\/ \u91cd\u8bd5\u6b21\u6570<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;target;<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Get \u8bf7\u6c42\u5b9e\u73b0<\/strong><\/h5>\n\n\n\n<p>\u901a\u8fc7\u5c01\u88c5<code>SNMP4J<\/code>\u7684<code>API<\/code>\uff0c\u5b9e\u73b0\u57fa\u4e8e<code>Spring Boot<\/code>\u7684<code>Get<\/code>\u8bf7\u6c42\u53d1\u9001\u529f\u80fd\uff0c\u7528\u4e8e\u83b7\u53d6\u8bbe\u5907\u7684\u6307\u5b9a<code>MIB<\/code>\u5bf9\u8c61\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Service<br>public class SnmpService {<br><br>&nbsp; &nbsp; @Autowired<br>&nbsp; &nbsp; private Snmp snmp;<br><br>&nbsp; &nbsp; @Autowired<br>&nbsp; &nbsp; private Target target;<br><br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u53d1\u9001Get\u8bf7\u6c42\u83b7\u53d6\u5355\u4e2aOID\u7684\u503c<br>&nbsp; &nbsp; &nbsp;* @param oid \u76ee\u6807\u5bf9\u8c61\u6807\u8bc6\u7b26<br>&nbsp; &nbsp; &nbsp;* @return&nbsp;\u89e3\u6790\u540e\u7684\u7ed3\u679c\u503c<br>&nbsp; &nbsp; &nbsp;*\/<br>&nbsp; &nbsp; public String get(String oid) throws IOException {<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u521b\u5efaGet\u8bf7\u6c42PDU<br>&nbsp; &nbsp; &nbsp; &nbsp; PDU pdu = new PDU();<br>&nbsp; &nbsp; &nbsp; &nbsp; pdu.add(new VariableBinding(new OID(oid)));<br>&nbsp; &nbsp; &nbsp; &nbsp; pdu.setType(PDU.GET);<br><br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u53d1\u9001\u8bf7\u6c42\u5e76\u83b7\u53d6\u54cd\u5e94<br>&nbsp; &nbsp; &nbsp; &nbsp; ResponseEvent event = snmp.send(pdu, target);<br>&nbsp; &nbsp; &nbsp; &nbsp; PDU response = event.getResponse();<br><br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(response == null) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new RuntimeException(\"\u672a\u6536\u5230SNMP\u54cd\u5e94\");<br>&nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;elseif&nbsp;(response.getErrorStatus() != PDU.noError) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; throw new RuntimeException(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\"SNMP\u9519\u8bef: \"&nbsp;+ response.getErrorStatusText() +&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;\" (\u9519\u8bef\u72b6\u6001\u7801: \"&nbsp;+ response.getErrorStatus() +&nbsp;\")\"<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; );<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br><br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u89e3\u6790\u54cd\u5e94\u7ed3\u679c<br>&nbsp; &nbsp; &nbsp; &nbsp; VariableBinding binding = response.get(0);<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;binding.getVariable().toString();<br>&nbsp; &nbsp; }<br><br>&nbsp; &nbsp; \/**<br>&nbsp; &nbsp; &nbsp;* \u6279\u91cf\u83b7\u53d6\u591a\u4e2aOID\u7684\u503c<br>&nbsp; &nbsp; &nbsp;* @param oids OID\u5217\u8868<br>&nbsp; &nbsp; &nbsp;* @return&nbsp;\u4ee5Map\u5f62\u5f0f\u8fd4\u56deOID\u4e0e\u5bf9\u5e94\u503c\u7684\u6620\u5c04<br>&nbsp; &nbsp; &nbsp;*\/<br>&nbsp; &nbsp; public Map&lt;String, String&gt; getBulk(List&lt;String&gt; oids) throws IOException {<br>&nbsp; &nbsp; &nbsp; &nbsp; PDU pdu = new PDU();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(String oid : oids) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pdu.add(new VariableBinding(new OID(oid)));<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; pdu.setType(PDU.GETBULK);<br>&nbsp; &nbsp; &nbsp; &nbsp; pdu.setMaxRepetitions(5); \/\/ \u8bbe\u7f6e\u6279\u91cf\u83b7\u53d6\u7684\u6700\u5927\u91cd\u590d\u6b21\u6570<br><br>&nbsp; &nbsp; &nbsp; &nbsp; ResponseEvent event = snmp.send(pdu, target);<br>&nbsp; &nbsp; &nbsp; &nbsp; PDU response = event.getResponse();<br>&nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u54cd\u5e94\u5904\u7406\u903b\u8f91\uff08\u7701\u7565\uff0c\u7c7b\u4f3c\u5355\u4e2aGet\u8bf7\u6c42\uff09<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String, String&gt; result = new HashMap&lt;&gt;();<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(VariableBinding binding : response.getVariableBindings()) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; result.put(binding.getOid().toString(), binding.getVariable().toString());<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;return&nbsp;result;<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Set \u8bf7\u6c42\u5b9e\u73b0<\/strong><\/h5>\n\n\n\n<p><code>Set<\/code>\u8bf7\u6c42\u7528\u4e8e\u4fee\u6539\u8bbe\u5907\u7684\u914d\u7f6e\u53c2\u6570\uff0c\u5b9e\u73b0\u65b9\u5f0f\u4e0e<code>Get<\/code>\u8bf7\u6c42\u7c7b\u4f3c\uff0c\u4f46\u9700\u8981\u6307\u5b9a\u4fee\u6539\u540e\u7684\u503c\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/**<br>&nbsp;* \u53d1\u9001Set\u8bf7\u6c42\u4fee\u6539\u8bbe\u5907\u53c2\u6570<br>&nbsp;* @param oid \u76ee\u6807OID<br>&nbsp;* @param value \u8981\u8bbe\u7f6e\u7684\u65b0\u503c<br>&nbsp;* @return&nbsp;\u662f\u5426\u8bbe\u7f6e\u6210\u529f<br>&nbsp;*\/<br>public boolean&nbsp;set(String oid, String value) throws IOException {<br>&nbsp; &nbsp; PDU pdu = new PDU();<br>&nbsp; &nbsp; Variable variable = new OctetString(value);<br>&nbsp; &nbsp; pdu.add(new VariableBinding(new OID(oid), variable));<br>&nbsp; &nbsp; pdu.setType(PDU.SET);<br><br>&nbsp; &nbsp; ResponseEvent event = snmp.send(pdu, target);<br>&nbsp; &nbsp; PDU response = event.getResponse();<br><br>&nbsp; &nbsp;&nbsp;return&nbsp;response != null &amp;&amp; response.getErrorStatus() == PDU.noError;<br>}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>Trap \u76d1\u542c\u4e0e\u5904\u7406<\/strong><\/h5>\n\n\n\n<p><code>Trap<\/code>\u662f\u8bbe\u5907\u4e3b\u52a8\u5411\u7ba1\u7406\u7aef\u53d1\u9001\u7684\u4e8b\u4ef6\u901a\u77e5\uff0c<code>Spring Boot<\/code>\u5e94\u7528\u53ef\u901a\u8fc7\u76d1\u542c\u6307\u5b9a\u7aef\u53e3\u63a5\u6536\u5e76\u5904\u7406<code>Trap<\/code>\u6d88\u606f\u3002https:\/\/wxa.wxs.qq.com\/tmpl\/oc\/base_tmpl.html<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@Slf4j<br>@Component<br>public class SnmpTrapReceiver implements ApplicationRunner, CommandResponder {<br><br>&nbsp; &nbsp; @Override<br>&nbsp; &nbsp; public void processPdu(CommandResponderEvent commandResponderEvent) {<br>&nbsp; &nbsp; &nbsp; &nbsp; try{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Map&lt;String,Object&gt; requestMap = new HashMap&lt;&gt;();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(commandResponderEvent.getPDU().getType() == PDU.TRAP || commandResponderEvent.getPDU().getType() == PDU.V1TRAP) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PDU pdu=commandResponderEvent.getPDU();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(pdu != null) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Vector&lt;? extends VariableBinding&gt; resVBs = pdu.getVariableBindings();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;for&nbsp;(int i = 0; i &lt; resVBs.size(); i++) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; VariableBinding recVB = resVBs.elementAt(i);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String oid = recVB.getOid().toString();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Variable variable = recVB.getVariable();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; String valueStr =&nbsp;\"\";<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if(variable instanceof OctetString){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; OctetString octetString = (OctetString) variable;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueStr = StrUtil.utf8Str(octetString.getValue());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }elseif&nbsp;(variable instanceof Gauge32) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Gauge32 gauge32 = (Gauge32) variable;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueStr = String.valueOf(gauge32.getValue());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }elseif&nbsp;(variable instanceof Integer32) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Integer32 integer32 = (Integer32) variable;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueStr = String.valueOf(integer32.getValue());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }else&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; valueStr = variable.toString();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.info(\"oid:\"&nbsp;+ oid +&nbsp;\" value:\"&nbsp;+ valueStr);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; }catch (Exception e){<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.error(\"\u5904\u7406Trap\u4fe1\u606f\u5f02\u5e38\uff0c\u5f02\u5e38\u4fe1\u606f\u4e3a\uff1a{}\", e.getMessage());<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br><br><br>&nbsp; &nbsp; @Override<br>&nbsp; &nbsp; public void run(ApplicationArguments args){<br>&nbsp; &nbsp; &nbsp; &nbsp; try {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ThreadPool threadPool = ThreadPool.create(\"snmptrap\", 10);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; MultiThreadedMessageDispatcher dispatcher = new MultiThreadedMessageDispatcher(threadPool, new MessageDispatcherImpl());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Address listenAddress = GenericAddress.parse(System.getProperty(\"snmp4j.listenAddress\",&nbsp;\"udp:192.168.1.1\/162\"));<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; TransportMapping transport;<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \/\/ \u5bf9TCP\u4e0eUDP\u534f\u8bae\u8fdb\u884c\u5904\u7406<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;if&nbsp;(listenAddress instanceof UdpAddress) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; transport = new DefaultUdpTransportMapping((UdpAddress) listenAddress);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.info(\"\u4f7f\u7528UDP\u534f\u8bae\");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp;else&nbsp;{<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; transport = new DefaultTcpTransportMapping((TcpAddress) listenAddress);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.info(\"\u4f7f\u7528TCP\u534f\u8bae\");<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; Snmp snmp = new Snmp(dispatcher, transport);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; snmp.getMessageDispatcher().addMessageProcessingModel(new MPv1());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; snmp.getMessageDispatcher().addMessageProcessingModel(new MPv2c());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; snmp.getMessageDispatcher().addMessageProcessingModel(new MPv3());<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; USM usm = new USM(SecurityProtocols.getInstance(), new OctetString(MPv3.createLocalEngineID()), 0);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; SecurityModels.getInstance().addSecurityModel(usm);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; snmp.listen();<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; snmp.addCommandResponder(this);<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.info(\"\u5f00\u59cb\u76d1\u542cTrap\u4fe1\u606f\");<br>&nbsp; &nbsp; &nbsp; &nbsp; } catch (IOException e) {<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; log.info(\"\u76d1\u542cTrap\u4fe1\u606f\u5f02\u5e38\uff0c\u5f02\u5e38\u4fe1\u606f\u4e3a\uff1a{}\", e.getMessage());<br>&nbsp; &nbsp; &nbsp; &nbsp; }<br>&nbsp; &nbsp; }<br>}<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\"><strong>\u5b89\u5168\u914d\u7f6e\uff08SNMPv3\uff09<\/strong><\/h5>\n\n\n\n<p>\u5bf9\u4e8e\u9700\u8981\u9ad8\u5b89\u5168\u6027\u7684\u573a\u666f\uff0c\u53ef\u914d\u7f6e<code>SNMPv3<\/code>\u7684\u8ba4\u8bc1\u4e0e\u52a0\u5bc6\u529f\u80fd\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public Target&nbsp;createV3Target() {<br>&nbsp; &nbsp; UserTarget target = new UserTarget();<br>&nbsp; &nbsp; target.setAddress(GenericAddress.parse(\"udp:192.168.1.1\/161\"));<br>&nbsp; &nbsp; target.setVersion(SnmpConstants.version3);<br>&nbsp; &nbsp; target.setSecurityLevel(SecurityLevel.AUTH_PRIV); \/\/ \u8ba4\u8bc1\u5e76\u52a0\u5bc6<br>&nbsp; &nbsp; target.setSecurityName(new OctetString(\"admin\")); \/\/ \u7528\u6237\u540d<br>&nbsp; &nbsp;&nbsp;return&nbsp;target;<br>}<br><br>\/\/ \u521d\u59cb\u5316SNMPv3\u7528\u6237<br>@Bean<br>public void initV3User() throws IOException {<br>&nbsp; &nbsp; USM usm = new USM(SecurityProtocols.getInstance(),&nbsp;<br>&nbsp; &nbsp; &nbsp; &nbsp; new OctetString(MPv3.createLocalEngineID()), 0);<br>&nbsp; &nbsp; SecurityModels.getInstance().addSecurityModel(usm);<br>&nbsp; &nbsp;&nbsp;<br>&nbsp; &nbsp; \/\/ \u6dfb\u52a0\u7528\u6237\uff08\u8ba4\u8bc1\u5bc6\u7801\u3001\u52a0\u5bc6\u5bc6\u7801\uff09<br>&nbsp; &nbsp; snmp.getUSM().addUser(<br>&nbsp; &nbsp; &nbsp; &nbsp; new OctetString(\"admin\"),<br>&nbsp; &nbsp; &nbsp; &nbsp; new UsmUser(<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; new OctetString(\"admin\"),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; AuthMD5.ID, new OctetString(\"authPass123\"),<br>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; PrivDES.ID, new OctetString(\"privPass123\")<br>&nbsp; &nbsp; &nbsp; &nbsp; )<br>&nbsp; &nbsp; );<br>}<\/code><\/pre>\n","raw":"","protected":false},"excerpt":{"rendered":"<p>\u524d\u8a00 \u968f\u7740\u7f51\u7edc\u89c4\u6a21\u7684\u4e0d\u65ad\u6269\u5927\u4ee5\u53ca\u7f51\u7edc\u8bbe\u5907\u6570\u91cf\u7684\u6025\u5267\u589e\u52a0\uff0c\u5982\u4f55\u9ad8\u6548\u5730\u76d1\u63a7\u548c\u7ba1\u7406\u8fd9\u4e9b\u8bbe\u5907\u6210\u4e3a\u4e86\u7f51\u7edc\u7ba1\u7406\u5458\u9762\u4e34\u7684\u4e00\u5927\u6311\u6218\u3002\u7b80\u5355\u7f51\u7edc\u7ba1\u7406\u534f &#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"emotion":"","emotion_color":"","title_style":"","license":"","footnotes":""},"categories":[7],"tags":[],"class_list":["post-6711","post","type-post","status-publish","format-standard","hentry","category-spring-boot"],"post_thumbnail_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","content_first_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","post_medium_image_300":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","post_thumbnail_image_624":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","post_frist_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","post_medium_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","post_large_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","post_full_image":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","post_all_images":[{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","id":"image0"},{"imagesurl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2025\/09\/20250929053606234.png","id":"image1"}],"videoAdId":"","listAd":"0","listAdId":"","listAdEvery":6,"total_comments":0,"category_name":"Spring Boot","post_date":"2025-09-29","like_count":"0","praiseWord":"\u9f13\u52b1","copyright_state":"","excitationAd":"0","rewardedVideoAdId":"","detailAdId":"","detailAd":"0","enterpriseMinapp":"0","audios":[],"postImageUrl":"https:\/\/wp-moto-1258805347.cos.ap-shanghai.myqcloud.com\/2023\/05\/20230519082947553.jpg","avatarurls":[],"related_posts":null,"pageviews":231,"next_post_id":6725,"next_post_title":"SpringBoot\u4e0eVector Search\u6574\u5408\uff0c\u5b9e\u73b0\u77ed\u89c6\u9891\u5185\u5bb9\u5b9e\u65f6\u63a8\u8350\u7cfb\u7edf","previous_post_id":6708,"previous_post_title":"SpringBoot \u65b9\u6cd5\u7ea7\u8017\u65f6\u76d1\u63a7\u5668","_links":{"self":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6711","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/comments?post=6711"}],"version-history":[{"count":1,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6711\/revisions"}],"predecessor-version":[{"id":6713,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/posts\/6711\/revisions\/6713"}],"wp:attachment":[{"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/media?parent=6711"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/categories?post=6711"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/xinchewhd.com.cn\/index.php\/wp-json\/wp\/v2\/tags?post=6711"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}