FreeNAS Code
This project has moved to github - see https://github.com/freenas
Brought to you by:
cochard,
mattolander
#!/bin/sh # Copyright (c) 2007 Volker Theile (votdev@gmx.de) # All rights reserved. # 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` # Custom commands start_precmd="create_conf" # Defaults snmpd_enable=${snmpd_enable:-"NO"} snmpd_config=${snmpd_config:-"/var/etc/snmpd.config"} pidfile="/var/run/snmpd.pid" command="/usr/sbin/${name}" command_args="-c ${snmpd_config} -p ${pidfile}" create_conf() { # Get some system informations. 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 > ${snmpd_config} } load_rc_config ${name} run_rc_command "$1"