FreeNAS Code
This project has moved to github - see https://github.com/freenas
Brought to you by:
cochard,
mattolander
#!/bin/sh # # $FreeBSD: src/etc/rc.d/bsnmpd,v 1.1 2005/04/17 10:47:58 glebius Exp $ # # Modified by Volker Theile (votdev@gmx.de) # # PROVIDE: bsnmpd # REQUIRE: NETWORKING syslogd # KEYWORD: nojail # XQUERY: -i "count(//snmpd/enable) > 0" -o "0" -b # RCVAR: bsnmpd . /etc/rc.subr . /etc/configxml.subr name="bsnmpd" rcvar=`set_rcvar` load_rc_config "$name" # Custom commands start_precmd="mkconf_cmd" mkconf_cmd="mkconf_cmd" extra_commands="mkconf" # Defaults bsnmpd_enable=${bsnmpd_enable:-"NO"} bsnmpd_config=${bsnmpd_config:-"/var/etc/${name}.config"} pidfile="/var/run/snmpd.pid" command="/usr/sbin/${name}" command_args="-c ${bsnmpd_config} -p ${pidfile}" mkconf_cmd() { # Get some system information hw_machine=`/sbin/sysctl -n hw.machine` hw_model=`/sbin/sysctl -n hw.model` hw_clockrate=`/sbin/sysctl -n hw.clockrate` kern_ostype=`/sbin/sysctl -n kern.ostype` kern_osrelease=`/sbin/sysctl -n kern.osrelease` kern_osrevision=`/sbin/sysctl -n kern.osrevision` /usr/local/bin/xml sel -t -m "//snmpd" \ -o "# Set some common variables" -n \ -v "concat('host := ',//system/hostname,'.',//system/domain)" -n \ -v "concat('location := "',location,'"')" -n \ -v "concat('contact := "',contact,'"')" -n \ -o "system := 1 # FreeBSD" -n \ -o "description := "Hardware: ${hw_machine} ${hw_model} running at ${hw_clockrate} Software: ${kern_ostype} ${kern_osrelease} (revision ${kern_osrevision})"" -n \ -v "concat('read := "',read,'"')" -n \ -i "count(trapenable) > 0" \ -n \ -o "# Trap settings" -n \ -v "concat('traphost := ',traphost)" -n \ -v "concat('trapport := ',trapport)" -n \ -v "concat('trap := "',trap,'"')" -n \ -b \ -n \ -o "# Configuration" -n \ -o "%snmpd" -n \ -o "begemotSnmpdDebugDumpPdus = 2" -n \ -o "begemotSnmpdDebugSyslogPri = 7" -n \ -n \ -o "# Set the read and write communities." -n \ -o "begemotSnmpdCommunityString.0.1 = \$(read)" -n \ -o "begemotSnmpdCommunityDisable = 1" -n \ -n \ -o "# open standard SNMP ports" -n \ -o "begemotSnmpdPortStatus.[\$(host)].161 = 1" -n \ -o "begemotSnmpdPortStatus.127.0.0.1.161 = 1" -n \ -n \ -o "# open a unix domain socket" -n \ -o "begemotSnmpdLocalPortStatus."/var/run/snmpd.sock" = 1" -n \ -o "begemotSnmpdLocalPortType."/var/run/snmpd.sock" = 4" -n \ -i "count(trapenable) > 0" \ -n \ -o "# send traps to the traphost" -n \ -o "begemotTrapSinkStatus.[\$(traphost)].\$(trapport) = 4" -n \ -o "begemotTrapSinkVersion.[\$(traphost)].\$(trapport) = 2" -n \ -o "begemotTrapSinkComm.[\$(traphost)].\$(trapport) = \$(trap)" -n \ -b \ -n \ -o "sysContact = \$(contact)" -n \ -o "sysLocation = \$(location)" -n \ -o "sysObjectId = 1.3.6.1.4.1.12325.1.1.2.1.\$(system)" -n \ -o "sysDescr = \$(description)" -n \ -n \ -o "snmpEnableAuthenTraps = 2" -n \ -n \ -i "count(modules/mibii) > 0" \ -o "#" -n \ -o "# Load MIB-2 module" -n \ -o "#" -n \ -o "begemotSnmpdModulePath."mibII" = "/usr/lib/snmp_mibII.so"" -n \ -n \ -b \ -i "count(modules/netgraph) > 0" \ -o "#" -n \ -o "# Netgraph module" -n \ -o "#" -n \ -o "begemotSnmpdModulePath."netgraph" = "/usr/lib/snmp_netgraph.so"" -n \ -n \ -o "#netgraph" -n \ -o "begemotNgControlNodeName = "snmpd"" -n \ -n \ -b \ -i "count(modules/hostres) > 0" \ -o "#" -n \ -o "# Host resources module snmp_hostres(3)." -n \ -o "# This requires the mibII module." -n \ -o "#" -n \ -o "begemotSnmpdModulePath."hostres" = "/usr/lib/snmp_hostres.so"" -n \ -n \ -b \ -n \ ${configxml_file} | /usr/local/bin/xml unesc > ${bsnmpd_config} } run_rc_command "$1"