From f5f33c1aaba7e941a248996d45bb504e63694223 Mon Sep 17 00:00:00 2001 From: jim-p Date: Wed, 25 May 2011 13:34:48 -0400 Subject: Add initial SNMP UPS support. Version bump nut. --- config/nut/nut.inc | 123 ++++++++++++++++++++++++++++++++++++++++++++++ config/nut/nut.xml | 100 ++++++++++++++++++++++++++++++++++--- config/nut/status_nut.php | 7 ++- 3 files changed, 223 insertions(+), 7 deletions(-) (limited to 'config/nut') 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 = << '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 @@ -84,6 +84,10 @@ http://www.pfsense.com/packages/config/nut/status_nut.php + + General Settings + listtopic + UPS Monitoring monitor @@ -99,11 +103,24 @@ local + + + Power Down Instead of Halt + powerdown + checkbox + + + Local UPS Settings + listtopic + <strong>Local UPS Name</strong> name @@ -503,11 +520,6 @@ - - Power Down Instead of Halt - powerdown - checkbox - Local Remote Access Address <br>(ex: 192.168.1.0/24) allowaddr @@ -523,6 +535,10 @@ allowpass password + + Remote NUT UPS Settings + listtopic + <strong>Remote UPS Name</strong> remotename @@ -543,6 +559,77 @@ remotepass password + + Remote SNMP UPS Settings + listtopic + + + <strong>SNMP UPS Name</strong> + snmpname + input + + + <strong>SNMP UPS Address</strong> <br>(ex: 192.168.1.10) + snmpaddr + input + + + SNMP UPS Community<br>(Def: public) + snmpaddr + input + + + SNMP UPS Version<br>(Def: v2c) + snmpversion + select + + + + + + + SNMP UPS MIB<br>(Def: IETF) + snmpmib + select + + + + + + + + + + SNMP UPS Polling Freq<br>(Def: 30) + snmpfreq + input + + + Disable transfer OIDs<br>(use on APCC Symmetras) + snmpdisabletransfer + checkbox + before_form_nut(&$pkg); @@ -557,3 +644,4 @@ deinstall_package_nut(); + \ No newline at end of file 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!'); -- cgit v1.2.3