Chinaunix

标题: 【snmp】snmp manager [打印本页]

作者: shijiang1130    时间: 2014-10-27 21:36
标题: 【snmp】snmp manager
本帖最后由 shijiang1130 于 2015-01-02 11:28 编辑

通过反复几次实验发现,其实是自己把事情弄点有点复杂了,只要定义一个manager.conf文件,启动snmp,以后就可以在code里动态注册
1. snmpm:register_user
2. snmpm:register_agent
再就可以用通常的方法:
1. snmpm:sync_get
2. snmpm:sync_get_bulk2
3. snmpm:sync_get_next
来获得你要的信息了。
作者: shijiang1130    时间: 2014-10-27 21:49
单个的你可以这么做:
作者: shijiang1130    时间: 2014-10-27 21:51
本帖最后由 shijiang1130 于 2014-10-27 21:52 编辑

1.  建个两个目录 manager/config 和 manager/db
2.  写个配置文件 my_snmp.config
  1. [{snmp,
  2.         [{manager,
  3.             [{config, [{dir, "manager/conf/"},
  4.                 {db_dir, "manager/db/"}]}]}]}].
复制代码

作者: shijiang1130    时间: 2014-10-27 21:53
3. 在manager/conf里建2个文件,这两个文件就是第二步中定义的两个文件。
  1)manager.conf
  2)agents.conf
作者: shijiang1130    时间: 2014-10-27 21:54
3.1 文件内容
  1. {port, 5000}.
  2. {engine_id, "my_snmp"}.
  3. {max_message_size, 484}.
复制代码

作者: shijiang1130    时间: 2014-10-27 21:55
3.2 文件内容
  1. {"my_snmp", "my_snmp", "public", [192,168,16,1], 161, "my_snmp",
  2.     infinity, 484, v2, v2c, "initial", noAuthNoPriv}.
复制代码

作者: shijiang1130    时间: 2014-10-27 21:57
启动时用参数 werl -config manager


作者: laputa73    时间: 2014-11-02 13:52
从erlang的思路看,应该起2个manager吧
作者: shijiang1130    时间: 2014-11-02 14:04
laputa73 发表于 2014-11-02 13:52
从erlang的思路看,应该起2个manager吧
一个对一个。不是一个对多个啊。还有一个问题就是为什么不能动态读取(community),hard coded觉得有点不安全
作者: laputa73    时间: 2014-11-02 17:54
回复 9# shijiang1130


    文档说
The information needed to handle agents should be stored in a file called agents.conf. It is also possible to add agents in run-time by calling the register_agent.

Each entry is a tuple:

{UserId, TargetName, Comm, Ip, Port, EngineID, Timeout, MaxMessageSize, Version, SecModel, SecName, SecLevel}.

   comm应该是可以通过agent.conf设置的
  只是例子程序是通过register_agent动态赋值的
作者: shijiang1130    时间: 2015-01-02 11:23
http://intronetworks.cs.luc.edu/current/html/netmgmt.html
这里提到了 snmpm:sync_get_bulk2 中的参数Nonrepeater  and Max-Repetitions,愣是没看懂
作者: shijiang1130    时间: 2015-01-02 11:59
比如:
http://tools.cisco.com/Support/S ... 15.3.1.9#oidContent
要得到所有peer的as号。
Nonrepeater=?  and Max-Repetitions= ?
作者: shijiang1130    时间: 2015-01-02 13:17

作者: shijiang1130    时间: 2015-01-02 13:18
  1. my %oids = (
  2.         "SysUptime"                        =>        "1.3.6.1.2.1.1.3.0",
  3.         "bgpVersion"                        =>        "1.3.6.1.2.1.15.1.0",
  4.         "bgpLocalAs"                        =>        "1.3.6.1.2.1.15.2.0",

  5. #        "bgpPeerTable"                        =>        "1.3.6.1.2.1.15.3",
  6.         "bgpPeerEntry"                        =>        "1.3.6.1.2.1.15.3.1",
  7.         "bgpPeerIdentifier"                =>        "1.3.6.1.2.1.15.3.1.1",
  8.         "bgpPeerState"                        =>        "1.3.6.1.2.1.15.3.1.2",
  9.         "bgpPeerAdminStatus"                =>        "1.3.6.1.2.1.15.3.1.3",
  10.         "bgpPeerNegotiatedVersion"        =>        "1.3.6.1.2.1.15.3.1.4",
  11.         "bgpPeerLocalAddr"                =>        "1.3.6.1.2.1.15.3.1.5",
  12.         "bgpPeerLocalPort"                =>        "1.3.6.1.2.1.15.3.1.6",
  13.         "bgpPeerRemoteAddr"                =>        "1.3.6.1.2.1.15.3.1.7",
  14.         "bgpPeerRemotePort"                =>        "1.3.6.1.2.1.15.3.1.8",
  15.         "bgpPeerRemoteAs"                =>        "1.3.6.1.2.1.15.3.1.9",
  16.         "bgpPeerInUpdates"                =>        "1.3.6.1.2.1.15.3.1.10",
  17.         "bgpPeerOutUpdates"                =>        "1.3.6.1.2.1.15.3.1.11",
  18.         "bgpPeerInTotalMessages"         =>        "1.3.6.1.2.1.15.3.1.12",
  19.         "bgpPeerOutTotalMessages"         =>        "1.3.6.1.2.1.15.3.1.13",
  20.         "bgpPeerLastError"                =>        "1.3.6.1.2.1.15.3.1.14",
  21.         "bgpPeerFsmEstablishedTransitions" =>        "1.3.6.1.2.1.15.3.1.15",
  22.         "bgpPeerFsmEstablishedTime"        =>        "1.3.6.1.2.1.15.3.1.16",
  23.         "bgpPeerConnectRetryInterval"        =>        "1.3.6.1.2.1.15.3.1.17",
  24.         "bgpPeerHoldTime"                =>        "1.3.6.1.2.1.15.3.1.18",
  25.         "bgpPeerKeepAlive"                =>        "1.3.6.1.2.1.15.3.1.19",
  26.         "bgpPeerHoldTimeConfigured"        =>        "1.3.6.1.2.1.15.3.1.20",
  27.         "bgpPeerKeepAliveConfigured"        =>        "1.3.6.1.2.1.15.3.1.21",
  28.         "bgpPeerMinASOriginationInterval" =>        "1.3.6.1.2.1.15.3.1.22",
  29.         "bgpPeerMinRouteAdvertisementInterval" => "1.3.6.1.2.1.15.3.1.23",
  30.         "bgpPeerInUpdateElapsedTime"         =>        "1.3.6.1.2.1.15.3.1.24",
  31.         "bgpIdentifier"                        =>        "1.3.6.1.2.1.15.4",
  32.         "bgpRcvdPathAttrTable"                =>        "1.3.6.1.2.1.15.5",
  33.         "bgp4PathAttrTable"                =>        "1.3.6.1.2.1.15.6",
  34.         "bgpPathAttrEntry"                =>        "1.3.6.1.2.1.15.5.1",
  35.         "bgpPathAttrPeer"                =>        "1.3.6.1.2.1.15.5.1.1",
  36.         "bgpPathAttrDestNetwork"        =>        "1.3.6.1.2.1.15.5.1.2",
  37.         "bgpPathAttrOrigin"                =>        "1.3.6.1.2.1.15.5.1.3",
  38.         "bgpPathAttrASPath"                =>        "1.3.6.1.2.1.15.5.1.4",
  39.         "bgpPathAttrNextHop"                =>        "1.3.6.1.2.1.15.5.1.5",
  40.         "bgpPathAttrInterASMetric"        =>        "1.3.6.1.2.1.15.5.1.6",
  41.         "bgp4PathAttrEntry"                =>        "1.3.6.1.2.1.15.6.1",
  42.         "bgp4PathAttrPeer"                =>        "1.3.6.1.2.1.15.6.1.1",
  43.         "bgp4PathAttrIpAddrPrefixLen"        =>        "1.3.6.1.2.1.15.6.1.2",
  44.         "bgp4PathAttrIpAddrPrefix"        =>        "1.3.6.1.2.1.15.6.1.3",
  45.         "bgp4PathAttrOrigin"                =>        "1.3.6.1.2.1.15.6.1.4",
  46.         "bgp4PathAttrASPathSegment"        =>        "1.3.6.1.2.1.15.6.1.5",
  47.         "bgp4PathAttrNextHop"                =>        "1.3.6.1.2.1.15.6.1.6",
  48.         "bgp4PathAttrMultiExitDisc"        =>        "1.3.6.1.2.1.15.6.1.7",
  49.         "bgp4PathAttrLocalPref"                =>        "1.3.6.1.2.1.15.6.1.8",
  50.         "bgp4PathAttrAtomicAggregate"        =>        "1.3.6.1.2.1.15.6.1.9",
  51.         "bgp4PathAttrAggregatorAS"        =>        "1.3.6.1.2.1.15.6.1.10",
  52.         "bgp4PathAttrAggregatorAddr"        =>        "1.3.6.1.2.1.15.6.1.11",
  53.         "bgp4PathAttrCalcLocalPref"        =>        "1.3.6.1.2.1.15.6.1.12",
  54.         "bgp4PathAttrBest"                =>        "1.3.6.1.2.1.15.6.1.13",
  55.         "bgp4PathAttrUnknown"                =>        "1.3.6.1.2.1.15.6.1.14",
  56.         );
复制代码





欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2