1、SNMP 的V3版本相对于V1,V2版本在登录时多了很多认证信息,包括认证协议类型、数据加密协议类型、安全级别、认证密码、数据加密密码等,其中ContextName和ContextEngineID可以指定为空,在 进行get操作时会进行获取,也可以通过串口进行获取,串口获取方法见:https://support.huawei.com/enterprise/zh/doc/EDOC1100135740/5db6fa06
v3版本的add_usm_user()函数中的参数较多,每个参数意义可参考见:https://support.huawei.com/enterprise/zh/doc/EDOC1100135740/e672caa3
2、snmp常用的函数可参考:https://blog.csdn.net/weixin_36340672/article/details/112820551
3、pdu.get_vb(Vb &vb,const int index)函数,vb参数为指向存储数据对象,index为第几个vb对象。例如:pdu.get(vb[1],1)为指向vb1,vb的第2个对象。(注:0是第一个vb,pdu.get(vb[0],0))
4、Snmp类中有一个成员函数notify_register(const OidCollection &trapids,const TargetCollection &targets,const snmp_callback callback,const void *callback_data=0);
(1) 该函数中OidCollection是要监听的oid,OidCollection类型是模板类,其类型是Oid类的实现,Oid类是对SMI中对象标识符类型的实现。
(2)TargetCollection类也是模板类的实现,是对SnmpTarget类的实现,SnmpTarget类是一次snmp通信活动的目标代理信息,也可看做网络设备运行中的代理,SnmpTarget类不仅封装了网络地址、端口信息,还封装了共同体字符串、重传次数,接收时时限等通信策略,目前SnmpTarget类有两个子类:CTarget类(SNMP V1,V2使用)和UTarget类(SNMPV3使用)。
(3)callback是用户回调函数。
(4)callbac_data是用户定义的数据指针。
例如:snmp.notify_register(traps,targets,callback,NULL)
回调函数 void callback(int reason,Snmp *snmp,Pdu *pdu,SnmpTarget &target,void *cd){//to do}
(5)get_bulk(Pdu &pdu,SnmpTarget &target,const int non_repeaters,const int max_reps);//non_repeaters:number of non repeaters,max_reps:maximum number of repetions.
注意在V2版本后面,max_repss上一次会最多获取到max_reps个数据,所以要特别注意若根据获取的对数据内容进行更新,要进行对应的调整,例子如下:
int index = -1;
while((status = snmp.get_bulk(pdu,*target,0,10)) == SNMP_CLASS_SUCCESS) //注意10
{
index++;
for{ int z = 0; z < pdu.get_vb_count();z++}
{
pdu.get_vb(vb,z);
string str = vb.get_printable_value();
data[index] = str; //index 若Version = 1;则index一直会按照获取的次数进行递增。若Version = 2,3,则index会一直重复10遍
}
}
5、trap的消息分析:snmp++ trap详解 - it610.com
后续在更新