diff options
author | jim-p <jimp@pfsense.org> | 2011-05-25 13:34:48 -0400 |
---|---|---|
committer | jim-p <jimp@pfsense.org> | 2011-05-25 13:34:48 -0400 |
commit | f5f33c1aaba7e941a248996d45bb504e63694223 (patch) | |
tree | ea233c37ffe72fa1004f4c5f714bf41428e36a72 | |
parent | 7050a53970553f7ce153ee20d6554734118f2c22 (diff) | |
download | pfsense-packages-f5f33c1aaba7e941a248996d45bb504e63694223.tar.gz pfsense-packages-f5f33c1aaba7e941a248996d45bb504e63694223.tar.bz2 pfsense-packages-f5f33c1aaba7e941a248996d45bb504e63694223.zip |
Add initial SNMP UPS support. Version bump nut.
-rw-r--r-- | config/nut/nut.inc | 123 | ||||
-rw-r--r-- | config/nut/nut.xml | 100 | ||||
-rw-r--r-- | config/nut/status_nut.php | 7 | ||||
-rwxr-xr-x | pkg_config.7.xml | 2 | ||||
-rwxr-xr-x | pkg_config.8.xml | 2 | ||||
-rwxr-xr-x | pkg_config.8.xml.amd64 | 2 |
6 files changed, 226 insertions, 10 deletions
diff --git a/config/nut/nut.inc b/config/nut/nut.inc index 987dbe83..d300f999 100644 --- a/config/nut/nut.inc +++ b/config/nut/nut.inc @@ -343,6 +343,127 @@ EOD; return true; } + function sync_package_nut_snmp() { + $name = nut_config('snmpname'); + $driver = "snmp-ups"; + $port = nut_config('snmpaddr'); + $shutdownflag = (nut_config('powerdown') == 'on') ? '-p' : '-h'; + $snmpmib = nut_config('snmpmib'); + $snmpversion = nut_config('snmpversion'); + $snmpcommunity = nut_config('snmpcommunity'); + $snmpfreq = nut_config('snmpfreq'); + $snmpdisabletransfer = (nut_config('snmpdisabletransfer') == 'on'); + + if(!($name && $driver && $port)) + return false; + + /* ups.conf */ + $ups_conf = "user=root\n"; + $ovr_user = '-u root'; + $ups_conf .= "[{$name}]\n"; + $ups_conf .= "driver={$driver}\n"; + $ups_conf .= "port={$port}\n"; + if($snmpmib) + $ups_conf .= "mibs={$snmpmib}\n"; + if($snmpversion) + $ups_conf .= "snmp_version={$snmpversion}\n"; + if($snmpcommunity) + $ups_conf .= "community={$snmpcommunity}\n"; + if($snmpfreq) + $ups_conf .= "pollfreq={$snmpfreq}\n"; + if($snmpdisabletransfer) + $ups_conf .= "notransferoids=true\n"; + + /* upsd.conf */ + $upsd_conf = "ACL all 0.0.0.0/0\n"; + $upsd_conf .= "ACL localhost 127.0.0.1/32\n"; + if($allowaddr && $allowuser) { + $upsd_conf .= "ACL remote {$allowaddr}\n"; + $upsd_conf .= "ACCEPT remote\n"; + } + $upsd_conf .= "ACCEPT localhost\n"; + $upsd_conf .= "REJECT all\n"; + + /* upsd.users */ + $upsd_users = "[monuser]\n"; + $upsd_users .= "password = mypass\n"; + $upsd_users .= "allowfrom = localhost\n"; + $upsd_users .= "upsmon master\n"; + if($allowaddr && $allowuser) { + $upsd_users .= "\n[$allowuser]\n"; + $upsd_users .= "password = $allowpass\n"; + $upsd_users .= "allowfrom = remote\n"; + $upsd_users .= "upsmon master\n"; + } + + /* upsmon.conf */ + $upsmon_conf = <<<EOD +MONITOR {$name}@localhost 1 monuser mypass master +MINSUPPLIES 1 +SHUTDOWNCMD "/sbin/shutdown {$shutdownflag} +0" +POWERDOWNFLAG /etc/killpower +EOD; + + $stop = <<<EOD + if [ `pgrep upsmon | wc -l` != 0 ]; then + echo stopping upsmon + /usr/bin/killall upsmon + while [ `pgrep upsmon | wc -l` != 0 ]; do + sleep 1 + done + fi + if [ `pgrep upsd | wc -l` != 0 ]; then + echo stopping upsd + /usr/bin/killall upsd + fi + if [ `pgrep {$driver} | wc -l` != 0 ]; then + echo stopping {$driver} + /usr/local/libexec/nut/upsdrvctl stop + fi + sleep 1 + if [ `pgrep {$driver} | wc -l` != 0 ]; then + echo forcing {$driver} termination + /usr/bin/killall {$driver} + while [ `pgrep {$driver} | wc -l` != 0 ]; do + sleep 1 + done + fi + {$port_rel} +EOD; + + $start = <<<EOD +if [ `pgrep {$driver} | wc -l` != 0 ]; then + {$stop} + fi + {$port_set} + echo starting {$driver} + if /usr/local/libexec/nut/upsdrvctl start; then + echo starting upsd + /usr/local/sbin/upsd {$ovr_user} + echo starting upsmon + /usr/local/sbin/upsmon {$name}@localhost + else + echo {$driver} failed to start + fi +EOD; + + /* write out configuration */ + conf_mount_rw(); + nut_write_config(NUT_DIR.'/ups.conf', $ups_conf); + nut_write_config(NUT_DIR.'/upsd.conf', $upsd_conf, 0640, 'uucp'); + nut_write_config(NUT_DIR.'/upsd.users', $upsd_users, 0640, 'uucp'); + nut_write_config(NUT_DIR.'/upsmon.conf', $upsmon_conf, 0640, 'uucp'); + write_rcfile(array( + 'file' => 'nut.sh', + 'start' => $start, + 'stop' => $stop + ) + ); + conf_mount_ro(); + + return true; + } + function sync_package_nut() { global $config; global $input_errors; @@ -362,6 +483,8 @@ EOD; $return = sync_package_nut_remote(); elseif(nut_config('monitor') == 'local') $return = sync_package_nut_local(); + elseif(nut_config('monitor') == 'snmp') + $return = sync_package_nut_snmp(); if($return && $_POST['monitor']) { /* only start if changing settings as we have a startup script for system boot */ diff --git a/config/nut/nut.xml b/config/nut/nut.xml index 5390186f..aaad64ea 100644 --- a/config/nut/nut.xml +++ b/config/nut/nut.xml @@ -85,6 +85,10 @@ </additional_files_needed> <fields> <field> + <name>General Settings</name> + <type>listtopic</type> + </field> + <field> <fielddescr>UPS Monitoring</fielddescr> <fieldname>monitor</fieldname> <type>select</type> @@ -99,12 +103,25 @@ <value>local</value> </option> <option> - <name>Remote UPS</name> + <name>Remote NUT UPS</name> <value>remote</value> </option> + <option> + <name>Remote SNMP UPS</name> + <value>snmp</value> + </option> </options> </field> <field> + <fielddescr>Power Down Instead of Halt</fielddescr> + <fieldname>powerdown</fieldname> + <type>checkbox</type> + </field> + <field> + <name>Local UPS Settings</name> + <type>listtopic</type> + </field> + <field> <fielddescr><strong>Local UPS Name</strong></fielddescr> <fieldname>name</fieldname> <type>input</type> @@ -504,11 +521,6 @@ </options> </field> <field> - <fielddescr>Power Down Instead of Halt</fielddescr> - <fieldname>powerdown</fieldname> - <type>checkbox</type> - </field> - <field> <fielddescr>Local Remote Access Address <br>(ex: 192.168.1.0/24)</fielddescr> <fieldname>allowaddr</fieldname> <type>input</type> @@ -524,6 +536,10 @@ <type>password</type> </field> <field> + <name>Remote NUT UPS Settings</name> + <type>listtopic</type> + </field> + <field> <fielddescr><strong>Remote UPS Name</strong></fielddescr> <fieldname>remotename</fieldname> <type>input</type> @@ -543,6 +559,77 @@ <fieldname>remotepass</fieldname> <type>password</type> </field> + <field> + <name>Remote SNMP UPS Settings</name> + <type>listtopic</type> + </field> + <field> + <fielddescr><strong>SNMP UPS Name</strong></fielddescr> + <fieldname>snmpname</fieldname> + <type>input</type> + </field> + <field> + <fielddescr><strong>SNMP UPS Address</strong> <br>(ex: 192.168.1.10)</fielddescr> + <fieldname>snmpaddr</fieldname> + <type>input</type> + </field> + <field> + <fielddescr>SNMP UPS Community<br>(Def: public)</fielddescr> + <fieldname>snmpaddr</fieldname> + <type>input</type> + </field> + <field> + <fielddescr>SNMP UPS Version<br>(Def: v2c)</fielddescr> + <fieldname>snmpversion</fieldname> + <type>select</type> + <options> + <option> + <name>SNMP v2c</name> + <value>v2c</value> + </option> + <option> + <name>SNMP v1</name> + <value>v1</value> + </option> + </options> + </field> + <field> + <fielddescr>SNMP UPS MIB<br>(Def: IETF)</fielddescr> + <fieldname>snmpmib</fieldname> + <type>select</type> + <options> + <option> + <name>ietf</name> + <value>ietf</value> + </option> + <option> + <name>mge</name> + <value>mge</value> + </option> + <option> + <name>apcc</name> + <value>apcc</value> + </option> + <option> + <name>netvision</name> + <value>netvision</value> + </option> + <option> + <name>pw</name> + <value>pw</value> + </option> + </options> + </field> + <field> + <fielddescr>SNMP UPS Polling Freq<br>(Def: 30)</fielddescr> + <fieldname>snmpfreq</fieldname> + <type>input</type> + </field> + <field> + <fielddescr>Disable transfer OIDs<br>(use on APCC Symmetras)</fielddescr> + <fieldname>snmpdisabletransfer</fieldname> + <type>checkbox</type> + </field> </fields> <custom_php_command_before_form> before_form_nut(&$pkg); @@ -557,3 +644,4 @@ deinstall_package_nut(); </custom_php_deinstall_command> </packagegui> + diff --git a/config/nut/status_nut.php b/config/nut/status_nut.php index a181734f..5688e72a 100644 --- a/config/nut/status_nut.php +++ b/config/nut/status_nut.php @@ -146,13 +146,18 @@ include("head.inc"); if($nut_config['monitor'] == 'local') { tblrow('Monitoring:','Local UPS'); $cmd = "upsc {$nut_config['name']}@localhost"; - } else { + } elseif($nut_config['monitor'] == 'remote') { tblrow('Monitoring:','Remote UPS'); $cmd = "upsc {$nut_config['remotename']}@{$nut_config['remoteaddr']}"; + } elseif($nut_config['monitor'] == 'snmp') { + tblrow('Monitoring:','SNMP UPS'); + $cmd = "upsc {$nut_config['name']}@localhost"; } if($running) $handle = popen($cmd, 'r'); + elseif($nut_config['monitor'] == 'snmp') + tblrow('ERROR:','NUT is enabled, however the service is not running! The SNMP UPS may be unreachable.'); else tblrow('ERROR:','NUT is enabled, however the service is not running!'); diff --git a/pkg_config.7.xml b/pkg_config.7.xml index ede45e6c..2dec4b71 100755 --- a/pkg_config.7.xml +++ b/pkg_config.7.xml @@ -603,7 +603,7 @@ <descr>Network UPS Tools</descr> <website>http://www.networkupstools.org/</website> <category>Network Management</category> - <version>2.2.2b</version> + <version>2.2.2b pkg 1.1</version> <status>BETA</status> <required_version>1.2.1</required_version> <maintainer>rswagoner@gmail.com</maintainer> diff --git a/pkg_config.8.xml b/pkg_config.8.xml index 86f7dc07..a2ce7268 100755 --- a/pkg_config.8.xml +++ b/pkg_config.8.xml @@ -563,7 +563,7 @@ <descr>Network UPS Tools</descr> <website>http://www.networkupstools.org/</website> <category>Network Management</category> - <version>2.2.2_5</version> + <version>2.2.2_5 pkg 1.1</version> <status>BETA</status> <required_version>2.0</required_version> <maintainer>rswagoner@gmail.com</maintainer> diff --git a/pkg_config.8.xml.amd64 b/pkg_config.8.xml.amd64 index 019c58c1..4306457b 100755 --- a/pkg_config.8.xml.amd64 +++ b/pkg_config.8.xml.amd64 @@ -613,7 +613,7 @@ <descr>Network UPS Tools</descr> <website>http://www.networkupstools.org/</website> <category>Network Management</category> - <version>2.2.2_5</version> + <version>2.2.2_5 pkg 1.1</version> <status>BETA</status> <required_version>2.0</required_version> <maintainer>rswagoner@gmail.com</maintainer> |