我已经在我的系统上安装了 net-snmp5.7.2,我已经为我的应用程序编写了我的 app_agent.conf 并且
agentXSocket udp:X.X.X.X:1610
Run Code Online (Sandbox Code Playgroud)
并导出 SNMPCONFIGPATH=path_to_app_agent.conf
我还在 /usr/etc/snmp/snmp.conf 中写了 snmpd.conf
trap2sink X.X.X.Y
agentXSocket udp:X.X.X.X:1610
Run Code Online (Sandbox Code Playgroud)
我的 /etc/snmp/ 和 /var/net-snmp/ 中还有两个 snmpd.conf
来自 /etc/snmp 的配置:
com2sec notConfigUser default public
com2sec notConfigUser v1 notConfigUser
com2sec notConfigUser v1 notConfigUser
view systemview included .1.3.6.1.2.1.1
view systemview included .1.3.6.1.2.1.25.1.1
access notConfigGroup "" any noauth exact systemview none none
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat
Run Code Online (Sandbox Code Playgroud)
来自 /var/net-snmp 的配置:
setserialno 1322276014
ifXTable .1 14:0 18:0x $
ifXTable .2 14:0 18:0x $
ifXTable .3 14:0 18:0x $
engineBoots 14
oldEngineID 0x80001f888000e17f6964b28450
Run Code Online (Sandbox Code Playgroud)
我已经启动了 snmpd 和 snmptrapd。现在在我的代码中,我正在调用
netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
init_agent("app_agent");
init_snmp("app_agent");
Run Code Online (Sandbox Code Playgroud)
init_snmp 发出警告
警告:无法连接到 agentx 主代理 ([NIL]):
我不知道为什么??在此先感谢您的帮助
这基本上是说您编写的子代理无法连接到 NetSNMP 主代理,如消息所示。在 Linux 中,默认情况下,agentx 将尝试使用 /var/agentx/master 通过套接字建立连接。以下提示可能会有所帮助:
agentxsocket /var/agentx/master
和agentxperms 777 777
sudo service snmpd restart
;或者作为一个选项,您可以尝试停止服务sudo service snmpd stop
并以调试模式运行实例,snmpd -f -Lo -Dagentx
这很可能会输出有关子代理连接的有用信息。小智 5
我现在在使用 quagga 和 ospfd 时遇到了这个问题,在执行strace -f -p PID
完之后,在输出中注意到了这一点:
connect(14, {sa_family=AF_FILE, path="/var/agentx/master"}, 110) = -1 EACCES (Permission denied)
Run Code Online (Sandbox Code Playgroud)
所以我:
$ ls -al /var/agentx/
total 8
drwx------ 2 root root 4096 Sep 12 20:50 .
drwxr-xr-x. 27 root root 4096 Sep 12 20:13 ..
srwxrwxrwx 1 root root 0 Sep 12 20:50 master
Run Code Online (Sandbox Code Playgroud)
然后我:
$ chmod 755 /var/agentx/
Run Code Online (Sandbox Code Playgroud)
zebra 和 ospfd 立即连接了它们的 Agentx 子网。
$ tail -10f /var/log/quagga/zebra.log
2014/09/12 20:52:59 ZEBRA: snmp[info]: NET-SNMP version 5.5 AgentX subagent connected
$ tail -10f /var/log/quagga/ospfd.log
2014/09/12 20:52:59 OSPF: snmp[info]: NET-SNMP version 5.5 AgentX subagent connected
Run Code Online (Sandbox Code Playgroud)
这是在 RHEL6 上运行 quagga-0.99.23-2014062401。希望这可以帮助。