Linux 配置TRAP 的问题

java 代码 监控Linux主机 ,让Linux主机自动发送Trap的实现步骤

我刚接触不是很了解,求高人指点,以前不怎么使用这个
已在Linux 上 安装了 net-snmp
困惑:
我的java 程序跑在Windows上,我需要监控 Linux 主机,让Linux主机主动给我发Trap
1.我需要在Linux上怎样配置 trap,网上有很多,因为不明白,自己配置的稀里哗啦的,

2.我如何让Linux 主动发送报文给windows ,window 上需要怎么用配置 才能接收的到

  1. 求一篇java 能接收到Trap的代码,虚心学习,想看看效果 t r a p 操作:代理进程主动发出的报文,通知管理进程有某些事情发生。 要实现代理进程发给管理进程的

自己编写处理trap脚本

建立root/bin/traps文件,输入以下内容

#!/bin/sh
read host
read ip
vars=
while read oid val
do
if [ "$vars" = "" ]
then
vars="$oid = $val"
else
vars="$vars, $oid = $val"
fi
done
echo trap: $1 $host $ip $vars

在manager的snmptrapd.conf加入以下几行

traphandle SNMPv2-MIB::coldStart /root/bin/traps cold

traphandle SNMPv2-MIB::warmStart /root/bin/traps warm

traphandle IF-MIB::linkDown /root/bin/traps down

traphandle IF-MIB::linkUp /root/bin/traps up

traphandle SNMPv2-MIB::authenticationFailure /root/bin/traps auth

this one is deprecated

traphandle .1.3.6.1.6.3.1.1.5.6 /root/bin/traps egp-neighbor-loss

重启snmptrapd:snmptrapd –d –f –Lo 161这里要它监听161端口

在agent端输入命令:

snmptrap -v 1 -c public 192.168.213.64 TRAP-TEST-MIB::demotraps 192.168.213.64 2 0 ""IF-MIB::ifIndex i 1

manager端的反应:

Received 63 bytes from UDP: [192.168.213.64]:32812

0000: 30 3D 02 01 00 04 06 70 75 62 6C 69 63 A4 30 06 0=.....public.0.

0016: 0A 2B 06 01 04 01 8F 65 0D 87 5E 40 04 C0 A8 D5 .+.....e..^@....

0032: 40 02 01 02 02 01 00 43 04 03 F1 9E 99 30 10 30 @......C.....0.0

0048: 0E 06 09 2B 06 01 02 01 02 02 01 01 02 01 01 ...+...........

2007-08-07 12:54:43 192.168.213.64(via UDP: [192.168.213.64]:32812) TRAP, SNMP v1, community public

    UCD-SNMP-MIB::ucdExperimental.990 Link Down Trap (0) Uptime: 7 days, 15:47:44.25

    IF-MIB::ifIndex = INTEGER: 1

trap: down 192.168.213.64 UDP: [192.168.213.64]:32812 DISMAN-EVENT-MIB::sysUpTimeInstance = 7:15:47:44.25, SNMPv2-MIB::snmpTrapOID.0 = IF-MIB::linkDown, IF-MIB::ifIndex = 1, SNMP-COMMUNITY-MIB::snmpTrapAddress.0 = 192.168.213.64, SNMP-COMMUNITY-MIB::snmpTrapCommunity.0 = "public", SNMPv2-MIB::snmpTrapEnterprise.0 = UCD-SNMP-MIB::ucdExperimental.990