From: Markus Wigge Date: Thu, 5 Feb 2009 23:20:01 +0000 (+0000) Subject: added support for system variables like sysLocation and for custom X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=f16419bcba489c8a1cf5e88d0966fb160d14b9f9;p=openwrt%2Fsvn-archive%2Farchive.git added support for system variables like sysLocation and for custom scripts executed on SNMP read request. SVN-Revision: 14414 --- diff --git a/libs/net-snmp/files/snmpd.conf b/libs/net-snmp/files/snmpd.conf index 9d5b7cf205..12aec6dffc 100644 --- a/libs/net-snmp/files/snmpd.conf +++ b/libs/net-snmp/files/snmpd.conf @@ -62,3 +62,17 @@ config access private_access option read all option write 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 + diff --git a/libs/net-snmp/files/snmpd.init b/libs/net-snmp/files/snmpd.init index 8fffa9d3d8..f48e503aee 100644 --- a/libs/net-snmp/files/snmpd.init +++ b/libs/net-snmp/files/snmpd.init @@ -9,6 +9,21 @@ RUN_D=/var/run PID_F=$RUN_D/snmpd.pid 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() { local cfg="$1" config_get secname "$cfg" secname @@ -65,7 +80,7 @@ snmpd_access_add() { snmpd_pass_add() { local cfg="$1" local pass='pass' - + config_get miboid "$cfg" miboid [ -n "$miboid" ] || return 0 config_get prog "$cfg" prog @@ -76,19 +91,30 @@ snmpd_pass_add() { priority=${priority:+-p $priority} 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() { [ -d $LIB_D ] || mkdir -p $LIB_D [ -d $LOG_D ] || mkdir -p $LOG_D [ -d $RUN_D ] || mkdir -p $RUN_D [ -f $RUN_C ] && rm -f $RUN_C - + config_load snmpd - + + config_foreach snmpd_system_add system config_foreach snmpd_com2sec_add com2sec config_foreach snmpd_group_add group config_foreach snmpd_view_add view config_foreach snmpd_access_add access config_foreach snmpd_pass_add pass + config_foreach snmpd_exec_add exec [ -f $DEFAULT ] && . $DEFAULT $DEBUG /usr/sbin/snmpd $OPTIONS