added support for system variables like sysLocation and for custom

scripts executed on SNMP read request.


git-svn-id: svn://svn.openwrt.org/openwrt/packages@14414 3c298f89-4303-0410-b956-a3cf2f4a3e73
This commit is contained in:
markus 2009-02-05 23:20:01 +00:00
parent 4c9918c037
commit f4db581ba1
2 changed files with 43 additions and 3 deletions

View File

@ -62,3 +62,17 @@ config access private_access
option read all option read all
option write all option write all
option notify all option notify all
config system
option sysLocaction 'office'
option sysContact 'bofh@example.com'
option sysName 'HeartOfGold'
# option sysServices 72
option sysDescr 'adult playground'
# option sysObjectID '1.2.3.4'
config exec filedescriptors
option prog /bin/cat
option args /proc/sys/fs/file-nr
# option miboid 1.2.3.4

View File

@ -9,6 +9,21 @@ RUN_D=/var/run
PID_F=$RUN_D/snmpd.pid PID_F=$RUN_D/snmpd.pid
RUN_C=$RUN_D/snmpd.conf RUN_C=$RUN_D/snmpd.conf
snmpd_system_add() {
local cfg="$1"
config_get syslocation "$cfg" sysLocation
[ -n "$syslocation" ] && echo "sysLocation $syslocation" >> $RUN_C
config_get syscontact "$cfg" sysContact
[ -n "$syscontact" ] && echo "sysContact $syscontact" >> $RUN_C
config_get sysname "$cfg" sysName
[ -n "$sysname" ] && echo "sysName $sysname" >> $RUN_C
config_get sysservice "$cfg" sysService
[ -n "$sysservice" ] && echo "sysService $sysservice" >> $RUN_C
config_get sysdescr "$cfg" sysDescr
[ -n "$sysdescr" ] && echo "sysDescr $sysdescr" >> $RUN_C
config_get sysobjectid "$cfg" sysObjectID
[ -n "$sysobjectid" ] && echo "sysObjectID $sysobjectid" >> $RUN_C
}
snmpd_com2sec_add() { snmpd_com2sec_add() {
local cfg="$1" local cfg="$1"
config_get secname "$cfg" secname config_get secname "$cfg" secname
@ -65,7 +80,7 @@ snmpd_access_add() {
snmpd_pass_add() { snmpd_pass_add() {
local cfg="$1" local cfg="$1"
local pass='pass' local pass='pass'
config_get miboid "$cfg" miboid config_get miboid "$cfg" miboid
[ -n "$miboid" ] || return 0 [ -n "$miboid" ] || return 0
config_get prog "$cfg" prog config_get prog "$cfg" prog
@ -76,19 +91,30 @@ snmpd_pass_add() {
priority=${priority:+-p $priority} priority=${priority:+-p $priority}
echo "$pass $priority $miboid $prog" >> $RUN_C echo "$pass $priority $miboid $prog" >> $RUN_C
} }
snmpd_exec_add() {
local cfg="$1"
config_get prog "$cfg" prog
[ -n "$prog" ] || return 0
config_get args "$cfg" args
config_get miboid "$cfg" miboid
echo "exec $cfg $miboid $prog $args" >> $RUN_C
}
start() { start() {
[ -d $LIB_D ] || mkdir -p $LIB_D [ -d $LIB_D ] || mkdir -p $LIB_D
[ -d $LOG_D ] || mkdir -p $LOG_D [ -d $LOG_D ] || mkdir -p $LOG_D
[ -d $RUN_D ] || mkdir -p $RUN_D [ -d $RUN_D ] || mkdir -p $RUN_D
[ -f $RUN_C ] && rm -f $RUN_C [ -f $RUN_C ] && rm -f $RUN_C
config_load snmpd config_load snmpd
config_foreach snmpd_system_add system
config_foreach snmpd_com2sec_add com2sec config_foreach snmpd_com2sec_add com2sec
config_foreach snmpd_group_add group config_foreach snmpd_group_add group
config_foreach snmpd_view_add view config_foreach snmpd_view_add view
config_foreach snmpd_access_add access config_foreach snmpd_access_add access
config_foreach snmpd_pass_add pass config_foreach snmpd_pass_add pass
config_foreach snmpd_exec_add exec
[ -f $DEFAULT ] && . $DEFAULT [ -f $DEFAULT ] && . $DEFAULT
$DEBUG /usr/sbin/snmpd $OPTIONS $DEBUG /usr/sbin/snmpd $OPTIONS