SNMP

来源:百度文库 编辑:神马文学网 时间:2024/04/28 09:04:03
    最近的一个项目和Intel AMT 相关,开发操作iAMT的ASP组件,其中在接收订阅警报事件中碰到点问题,记下来,或者对朋友们有用处。
    我们知道支持iAMT的机器可以自定义事件过滤器(event filter),并指定事件过滤器是否在网络中广播事件发生的消息,如系统宕机,或者硬件故障。当指定广播消息时,我们可以通过侦听162 端口来接收事件警报消息. iAMT 广播使用SNMP 标准协议发送事件(Platform trap event). 也可以使用Windows SNMP 函数来接收 iAMT 事件,这样可以简化代码的复杂度。整个实现过程如下:      // 开始 SNMP Trap 侦听, 如果失败一般是由于没有安装 SNMP 服务造成的,请从控制面板Windows 组件中安装SNMP 服务。
      1, SnmpMgrTrapListen (&event);       // 等待SNMP Trap 事件产生, 如果有事件产生但又无法收到,可能是因为您使用了防火墙,请关闭防火墙或者打开 162端口.
   2, WaitForSingleObject (event, -1);      // 得到SNMP Trap 事件内容。
      3, SnmpMgrGetTrap (AsnObjectIdentifier, AsnNetworkAddress, GenericTrap, SpecificTrap, TimeStamp, SnmpVarBindList);
     
      格式化得到的 iAMT Trap 事件内容如下:
 
          Sensor Type  = (SpecificTrap >> 16) & 0xff;
          Event Type   = (SpecificTrap >> 8) & 0xff;;
          Event Offset = SpecificTrap & 0xff;          char * TrapData = SnmpVarBindList.list.value->asnValue.bits.stream;
          int    Length   = SnmpVarBindList.list.value->asnValue.bits.length;          TrapData 的数据按顺序排列为:                1, GUID              = 16 bytes
                2, Sequence Cookie   = 2 bytes
                3, Local Timestamp   = 4 bytes
                4, UTC Offset        = 2 bytes
                5, Trap Source Type  = 1 byte
                6, Event Source Type = 1 byte
                7, Event Severity    = 1 byte
                8, Sensor Device     = 1 byte
                9, Sensor Number     = 1 byte
                10, Entity           = 1 byte
                11, Entity Instance  = 1 byte
                12, Event Data       = 8 bytes
                13, LanguageCode     = 1 byte
                14, Manufacture ID   = 4 bytes
                15, System ID        = 2 bytes
                16, OEM Custom Field = (Length - 46) bytes
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/Treeyan/archive/2007/08/27/1760507.aspx