现在的位置: 首页 > 综合 > 正文

FreeBSD snmptrapd.conf配置详解

2013年08月28日 ⁄ 综合 ⁄ 共 3783字 ⁄ 字号 评论关闭

这个文件在/usr/local/share/snmp/底下,如果我没有记错的话,默认应该没有这个文件的,你可以通过snmpconf命令来配置

snmptrapd.conf – configuration file for the NET-SNMP notification receiver

#################################################

#

# snmptrapd.conf

#

#   - created by the snmpconf configuration program

#

#################################################

# SECTION: Output formatting for traps received.

#

#   Output from snmptrapd is formatted according to the

#   rules defined by the formatting configuration directives.

 

# format1: How SNMPv1 traps are formatted.

#   See the snmptrapd.conf manual page for format string details.

#   arguments: formatstring

 

format1  "%02.2h:%02.2j Trap %w.%q from %A"

# 如果我发一个v1 trap,就会在log里面中出现:"15:40 Trap 2.0 from

#dumeifang.example.com.cn",%h就是当前的小时,%j就是当前的时间,%w trap type,我

#用的是2,%q trap sub-type,%A hostname

#发trap时用的命令:snmptrap -v 1 -c public 192.168.99.108 TRAP-TEST-MIB::

#demotraps 192.168.99.108 2 0 '' IF-MIB::ifIndex i 1

#TRAP-TEST-MIB是自定义的MIB

 

# format2: How SNMPv2 and SNMPv3 traps are formatted.

#   See the snmptrapd.conf manual page for format string details.

#   arguments: formatstring

 

format2  "%02.2h:%02.2j Trap %w.%q from %B"

#同样的,在log中会出现:"15:41 Trap 0.0 from 192.168.99.100(这是我发trap的IP)"

#snmptrap -v 2c -c public 192.168.99.108:162 "" .1.3.6.1.4.1.2021.13.990.0.17

#SNMPv2-MIB::sysLocation.0 s "just here"

#.1.3.6.1.4.1.2021.13.990.0.17 是自定义MIB的OID

 

#################################################

# SECTION: Trap Handlers

#

#   Here we define what programs are run when a trap is

#   received by the trap receiver.

 

# traphandle: When traps are received, a program can be run.

#   When traps are received, the list of configured trap

#   handles is consulted and any configured program is run.

#   If no handler is found, any handler with "default" as the

#   traphandle type is run instead.  The information contained

#   in trap is passed to the program via standard input (see

#   the snmptrapd.conf manual page for details).

#

#   arguments: oid|"default" program args

traphandle  SNMPv2-MIB::coldStart  /home/dumf/traps cold

#traps是在我自己用户目录下的一个脚本文件,源代码是在net-snmp官网上找的。

traphandle .1.3.6.1.4.1.2021.13.990.0.17 echo hello world

#.1.3.6.1.4.1.2021.13.990.0.17 是用snmptranslate翻译出来的自定义MIB

traphandle  default echo default handle

#默认的traphandle会打印出"default handle"

 

 

##################################################

# SECTION: Authentication options

#

#   Authentication options

# arguments: TYPES COMMUNITY [SOURCE [OID | -v VIEW]]

 

# There are currently three types of processing that can be specified, TYPES will be

# a (comma-separated) list of one or more of these tokens.

# log       log the details of the notification – either in a specified file, to standard

#           output (or stderr), or via syslog (or similar).

# execute  pass the details of the trap to a specified handler program, including

#           embedded perl.

# net       forward the trap to another notification receiver

 

authcommunity execute,log,net public

# This will let snmptrapd process notifications received using the “public”

# community string. Those notifications may be logged, allowed to trigger

# executable actions, and resend data to the network.

#这些大概的意思就是TYPES可以有log,execute,net这三个参数,可以只用一个,也可以通过逗号

#隔开使用多个,而上面的那句配置的意思就是,如果-c后面加的是"pubilc"的话,就可以log,可以

#使用脚本程序,可以把trap转到其他的接收者。

 

#################################################

# SECTION: Runtime options

#

#   Runtime options

 

# donotfork: Do not fork from the shell

#   arguments: (1|yes|true|0|no|false)

 

donotfork  yes

#意思就是说,snmptrapd是在前台下运行,而非后台,如果你用ps -aux|grep snmptrapd

#来看snmptrapd的进程信息的话,可以发现TT那一行是P0之类的,而不是??

 

# snmptrapd will run in the foreground other in the background

 

# pidfile: Store Process ID in file

#   arguments: PID file

 

pidfile  /tmp/trapdpro.txt

# defines a file in which to store the process ID of the notification receiver.

# By default, this ID is not saved.

#当snmptrapd启动时,会把它的PID写到trapdpro.txt文件里,如果没有这个文件,会新建一个再

#写入

 

##########################################################
# SECTION: Logging options
#
#   Logging options

# logoption: Set options controlling where to log to
#   See -L options in the snmptrapd.conf man page

logoption f /var/snmptrapd.log

 

#就这句还没验证成功,不过试过用-Lf之类的,但是会报错:

 #Unknown logging option passed to -L: ".

#根据这句话的意思,感觉不用加-L也不能用"",但是用这句话,它也不会在指定位置上建立指定的log文件

【上篇】
【下篇】

抱歉!评论已关闭.