From 6e4487e155682494cf72e59cf8423f60c05a35c0 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Sun, 26 Jan 2014 13:23:31 -0200 Subject: apcupsd - add script to send mail reports --- config/apcupsd/apcupsd_mail.php | 96 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) create mode 100755 config/apcupsd/apcupsd_mail.php (limited to 'config/apcupsd') diff --git a/config/apcupsd/apcupsd_mail.php b/config/apcupsd/apcupsd_mail.php new file mode 100755 index 00000000..3b1e40be --- /dev/null +++ b/config/apcupsd/apcupsd_mail.php @@ -0,0 +1,96 @@ + + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + 1. Redistributions of source code must retain the above copyright notice, + this list of conditions and the following disclaimer. + + 2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. + + THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, + INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY + AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE + AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + POSSIBILITY OF SUCH DAMAGE. +*/ + +require_once("pkg-utils.inc"); +require_once("globals.inc"); +require_once("phpmailer/class.phpmailer.php"); + +global $config, $g; + +$apcstatus[killpower] = "UPS now committed to shut down"; +$apcstatus[commfailure] = "Communications with UPS lost"; +$apcstatus[commok] = "Communciations with UPS restored"; +$apcstatus[onbattery] = "Power failure. Running on UPS batteries"; +$apcstatus[offbattery] = "Power has returned..."; +$apcstatus[failing] = "UPS battery power exhaused. Doing shutdown"; +$apcstatus[timeout] = "UPS battery runtime limit exceeded. Doing shutdown"; +$apcstatus[loadlimit] = "UPS battery discharge limit reached. Doing shutdown"; +$apcstatus[runlimit] = "UPS battery runtime percent reached. Doing shutdown"; +$apcstatus[doreboot] = "Beginning Reboot Sequence"; +$apcstatus[doshutdown] = "Beginning Shutdown Sequence"; +$apcstatus[annoyme] = "Power problems please logoff"; +$apcstatus[emergency] = "Emergency Shutdown. Possible UPS battery failure"; +$apcstatus[changeme] = "Emergency! UPS batteries have failed. Change them NOW"; +$apcstatus[remotedown] = "Remote Shutdown. Beginning Shutdown Sequence"; + +if (empty($argv[1]) || empty($apcstatus["$argv[1]"])) + return; + +$apcsubject = $apcstatus["$argv[1]"]; + +if (empty($config['notifications']['smtp']['ipaddress'])) + return; + +$mail = new PHPMailer(); +$mail->IsSMTP(); +$mail->Host = $config['notifications']['smtp']['ipaddress']; + +if ($config['notifications']['smtp']['ssl'] == "checked") + $mail->SMTPSecure = "ssl"; + +$mail->Port = empty($config['notifications']['smtp']['port']) ? 25 : $config['notifications']['smtp']['port']; + +if($config['notifications']['smtp']['username'] && + $config['notifications']['smtp']['password']) { + $mail->SMTPAuth = true; + $mail->Username = $config['notifications']['smtp']['username']; + $mail->Password = $config['notifications']['smtp']['password']; +} + +$mail->ContentType = 'text/html'; +$mail->IsHTML(true); +$mail->AddReplyTo($config['notifications']['smtp']['fromaddress'], "Apcupsd"); +$mail->SetFrom($config['notifications']['smtp']['fromaddress'], "Apcupsd"); +$address = $config['notifications']['smtp']['notifyemailaddress']; +$mail->AddAddress($address, "Apcupsd Recipient"); +$mail->Subject = "{$config['system']['hostname']}.{$config['system']['domain']} - {$apcsubject}"; + +putenv("PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin"); +$mail->Body = "
";
+$ph = popen('apcaccess status 2>&1', "r" );
+while ($line = fgets($ph)) $mail->Body .= htmlspecialchars($line);
+pclose($ph);
+$mail->Body .= "
"; + +if(!$mail->Send()) { + echo "Mailer Error: " . $mail->ErrorInfo; +} + +?> + -- cgit v1.2.3 From 4f0d3bd5e09fb8ff371a6b56830b155adc48fed1 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Sun, 26 Jan 2014 13:33:00 -0200 Subject: apcupsd - modifying default scripts to send mail reports on install package process --- config/apcupsd/apcupsd.inc | 33 ++++++++++++++++++++++++++++++++- config/apcupsd/apcupsd.xml | 7 ++++++- 2 files changed, 38 insertions(+), 2 deletions(-) (limited to 'config/apcupsd') diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc index 9abc23ba..08ddd17e 100644 --- a/config/apcupsd/apcupsd.inc +++ b/config/apcupsd/apcupsd.inc @@ -39,6 +39,7 @@ require_once("globals.inc"); function php_install_apcupsd(){ sync_package_apcupsd(); + apccontrol_scripts_install(); } function php_deinstall_apcupsd(){ @@ -185,7 +186,37 @@ function sync_package_apcupsd(){ unlink($apcupsd_rcfile); } } - + conf_mount_ro(); } + +function apccontrol_scripts_install(){ + + // check pfsense version + $pfs_version = substr(trim(file_get_contents("/etc/version")),0,3); + if ($pfs_version > 2.0){ + define('APCUPSD_BASE', '/usr/pbi/apcupsd-' . php_uname("m")); + } + else { + define('APCUPSD_BASE', '/usr/local'); + } + + $apccontrol_scripts = array("offbattery","onbattery","commfailure","commok","changeme"); + foreach($apccontrol_scripts as $apccontrol_script) { + + $apccontrol_script_file=<< /dev/null + +exit 0 + +EOF; + + file_put_contents(APCUPSD_BASE . "/etc/apcupsd/" . $apccontrol_script, $apccontrol_script_file, LOCK_EX); + } + +} + ?> + diff --git a/config/apcupsd/apcupsd.xml b/config/apcupsd/apcupsd.xml index 8674af61..ecd979f6 100644 --- a/config/apcupsd/apcupsd.xml +++ b/config/apcupsd/apcupsd.xml @@ -60,6 +60,11 @@ /usr/local/pkg/ 0755 + + http://www.pfsense.org/packages/config/apcupsd/apcupsd_mail.php + /usr/local/pkg/ + 0755 + Apcupsd Setup Apcupsd specific settings @@ -322,7 +327,7 @@ UPSTYPE DEVICE Description
- sync_package_apcupsd(); + php_install_apcupsd(); -- cgit v1.2.3 From e6510bf16633cd1198141fce80543a0bc983c133 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Wed, 5 Feb 2014 08:27:15 -0200 Subject: apcupsd - bump version --- config/apcupsd/apcupsd.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'config/apcupsd') diff --git a/config/apcupsd/apcupsd.xml b/config/apcupsd/apcupsd.xml index ecd979f6..239046e4 100644 --- a/config/apcupsd/apcupsd.xml +++ b/config/apcupsd/apcupsd.xml @@ -40,7 +40,7 @@ Apcupsd Services: Apcupsd (General) Monitoring - 0.1 + 0.2 /usr/local/pkg/apcupsd.inc Apcupsd has been created/modified. Apcupsd has been deleted. -- cgit v1.2.3 From 0bb5cb1d7b77b16b4c0ae9ab058ea2fc116dce58 Mon Sep 17 00:00:00 2001 From: "Danilo G. Baio (dbaio)" Date: Wed, 12 Feb 2014 08:33:03 -0200 Subject: apcupsd - added device field --- config/apcupsd/apcupsd.conf.php | 1 + config/apcupsd/apcupsd.inc | 1 + config/apcupsd/apcupsd.xml | 13 +++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) (limited to 'config/apcupsd') diff --git a/config/apcupsd/apcupsd.conf.php b/config/apcupsd/apcupsd.conf.php index 6a19b915..7a0340cd 100644 --- a/config/apcupsd/apcupsd.conf.php +++ b/config/apcupsd/apcupsd.conf.php @@ -109,6 +109,7 @@ UPSCABLE {$upscable} # default of 3052 will be used. # UPSTYPE {$upstype} +{$device} # POLLTIME # Interval (in seconds) at which apcupsd polls the UPS for status. This diff --git a/config/apcupsd/apcupsd.inc b/config/apcupsd/apcupsd.inc index 08ddd17e..a2b8d2ff 100644 --- a/config/apcupsd/apcupsd.inc +++ b/config/apcupsd/apcupsd.inc @@ -139,6 +139,7 @@ function sync_package_apcupsd(){ $upsname=$apcupsd_config['upsname']; $upscable=$apcupsd_config['upscable']; $upstype=$apcupsd_config['upstype']; + $device=($apcupsd_config['device'] != ''? "DEVICE {$apcupsd_config['device']}" : "#DEVICE"); $polltime=($apcupsd_config['polltime'] != ''? $apcupsd_config['polltime'] : "60"); $onbatterydelay=($apcupsd_config['onbatterydelay'] != ''? $apcupsd_config['onbatterydelay'] : "6"); $batterylevel=($apcupsd_config['batterylevel'] != ''? $apcupsd_config['batterylevel'] : "5"); diff --git a/config/apcupsd/apcupsd.xml b/config/apcupsd/apcupsd.xml index 239046e4..85148b2b 100644 --- a/config/apcupsd/apcupsd.xml +++ b/config/apcupsd/apcupsd.xml @@ -157,12 +157,6 @@ UPSTYPE DEVICE Description
catching; you usually want "APC". Port is usually 161. Community is usually "private".

-netsnmp hostname:port:vendor:community - OBSOLETE - Same as SNMP above but requires use of the - net-snmp library. Unless you have a specific need - for this old driver, you should use 'snmp' instead.
-
dumb /dev/tty** Old serial character device for use with simple-signaling UPSes.

@@ -182,6 +176,13 @@ UPSTYPE DEVICE Description
60 true + + Device + device + + input + 60 + Poll Time polltime -- cgit v1.2.3