APCUPSD (UPS daemon) Plugin

Posted on
Sun Sep 15, 2013 7:07 am
berkinet offline
User avatar
Posts: 2851
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

APCUPSD (UPS daemon) Plugin

An update (v0.3.3) of the apcupsd plugin is now available on dropbox. See the release notes at the bottom of this post for changes in v0.3.3

This plugin requires apcupsd (http://www.apcupsd.org) to be installed and running on whatever machine your UPS is connected to.

When you install the plugin you will need to configure it. In the Plugin configuration dialog set the frequency at which the Indigo devices should be updated, a connection timeout, and a debugging level.

Once configured plugin will allow you to create an Indigo device for each apcupsd instance (IP Address & Port) you have.

When creating an apcupsd plugin device, you need to:
  • Provide an IP Address. If you have apcupsd running on the same machine as your Indigo server, select the default local host. Otherwise select Will Specify and enter the IP Address in textfield that appears.
  • Enter the port number. The default of 3551 should be correct for most installations.
  • Select the UPS Report Fields you wish to use for states in this device. The default set contains the fields that are most likely to be of interest. Buttons are available to:
    • Select all states (fields)
    • Deselect all states (fields)
    • Reset default states list (i.e. Reset)
  • Specify the state (field) to be displayed for this device in Indigo's Devices window State column
  • Click Save

For release v0.3.1
This release contains a re-write of the query engine and several new features:
  • If the apcupsd server reports lost communications with the UPS, an error will be reported in the Devices window, States column and the device text color will change to red.
  • State names are now in lower case
  • The status state is now hard coded and will not appear in the states selection list
  • If apcupsd reports lost communication with the UPS, most state values will change to show "n/a"
    Values that are preserved when communications is lost will be marked with an *
  • Tooltips are available for all states listed in the ConfigUi
  • Clicking the ? in the ConfigUi will bring up a complete list of available states and their description. A link is also provided for the online apcupsd documentation.
  • Triggers are provided for every event the apcupsd daemon generates.
    Note: In order to receive events from the apcupsd daemon, you must install two programs that are included with the plugin AND make changes to the apcupsd configuration (See instructions below)
  • When querying the apcupsd server, the plugin now uses the /sbin/apcaccess program which is automatically installed by the apcaccess installer.
  • A new action is available to dump a full UPS query to the log.
  • A new menu item is available to dump a full config for all UPS devices to the log.

If you are upgrading from an earlier version of the plugin, you will need to do the following:
  • Disable the plugin
  • Delete the plugin from the Indigo 6 Plugins (Disabled) folder
  • Delete the file com.berkinet.apcupsd.indiPref from the Indigo 6, Preferences, Plugins folder
  • Delete all apcupsd plugin devices
  • Restart the Indigo server
  • Install, and configure, the v0.3.1 plugin
  • Create your UPS devices

Enabling event notification from the apcupsd daemon
  • Place the two enclosed files (apccmdex and apcupsAction) in /usr/local/bin.
  • Determine your numeric user ID (UID). In a terminal window just enter id
    The first bit of info will be uid=xxx that is the number you need. If you run the Indigo server as another user, you will need that user's UID.
  • Edit each of the user notification files in /etc/apcupsd that you wish to have notify you. By default apcupsd provides:
    commfailure, commok, changeme off battery and onbattery
    • On the first line change #!/bin/sh to #!/bin/ksh
    • Then, anywhere below the first line add the following line
      /usr/local/bin/apccmdex -u xxx -p /usr/local/bin/apcupsdAction -a `basename $0` -d yyy
      where xxx is your uid and yyy is the device from Indigo.
    • You can leave the rest of the file alone or comment (#) it out. All except the exit 0, that needs to stay.

Please use the apcupsd plugin discussion forum to post any issues, questions, ideas, etc.

Enjoy!

Release notes:
v 0.0.1 Sep 11, 2013
    Created the plugin from a previous script

v 0.1.0 Sep 12, 2013
    First public release
    Added state selection options (All, None, Default set)
    Added ability to display state descriptions from apcupsd.org
    Added option to select the state to be used for the Devices window state column
    Added error handling and reporting for connection errors
    Added action to update UPS device on demand
    Added Menu script to refresh all UPS devices

v 0.1.1 Sep 12, 2013
    Changed button text in Devices.xml

v 0.2.0 Sep 13, 2013
    Added error reporting in State column in case of lost communications to the UPS
    Changed the STATUS state to be hard coded - required to determine comms status
    Fixed several minor errors in rarely used methods
    Added deleting state values in case of lost comms (commLostStatesList)
    Added tooltips to states in ConfigUi
    Added Complete states list in support URL

v 0.3.0 Sep 14, 2013
    Finalized list of state values to keep if commlost
    Added notation (*) to state values that are preserved during a comm failure
    Improved error detection and retry login for status update polling
    Changed state names to lower case
    Switched query engine from native Python to call /sbin/apcaccess
    Added event triggers for all apcpusd events
    Added 2 utility programs to integrate with apcupsd events: apccmdex and apcupsdAction

v 0.3.1 Sep 15, 2013
    Added acton to dump full status report for a UPS device to the log
    Added menu item to log full status report for all UPSs

v 0.3.2 Sep 15, 2013
    Various small. but critical bug fixes

v 0.3.3 Sep 16, 2013
    Changed event names to show apcupsd event name + description
    Changed definition of status ONLINE to != COMMLOST
    Changed model name to "apcupsd UPS"
    Added apcupsdAction to readApcupsd - to let events force a status update
    Added documentation on creating event handlers

Posted on
Tue Oct 29, 2013 1:39 pm
berkinet offline
User avatar
Posts: 2851
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

APCUPSD (UPS daemon) Plugin v0.4.0 available

An update (v0.4.0) of the apcupsd plugin is now available on dropbox. See the release notes at the bottom of this post for changes since v0.3.3

Note: This plugin requires apcupsd (http://www.apcupsd.org) to be installed and running on the machine your UPS is connected to. Please see previous posts in this thread for installation information.

This release contains a built-in IP server to receive event notifications from the local apcupsd, and instances of apcupsd running on remote hardware. This feature is in addition to the Event Notification feature available in release 0.3.3, but is designed to ultimately replace that implementation.

To enable the new event server click the Use IP Socket for events? checkbox in the Plugin Config Dialog. Then enter the local IP port to listen on and a comma separated list of IP addresses from which incoming connections can be accepted. If you are running apcupsd on the local host, be sure to include 127.0.0.1. Here is a screenshot showing an example of the IP server config:
ss.png
ss.png (67.23 KiB) Viewed 4387 times

To send events to the event server, you need to edit the event handlers in /etc/apcupsd. The following handlers are supported:
    commfailure, commok, doreboot, doshutdown, emergency, endselftest, failing, loadlimit, mainsback, offbattery, onbattery, powerout, remotedown, runlimit, startselftest and timeout

Add the following text to each file you wish to have send events to the Indigo apcupsd plugin:
Code: Select all
#!/bin/sh

EVENT=`basename $0`
UPS=12345678

/bin/echo -n "${UPS}:${EVENT}" |/usr/bin/nc -w1 127.0.0.1 15006 &

Make sure you enter the Indigo device ID for your UPS device as the value of the UPS variable in the script.

If you are comfortable with the shell, you may wish to delete all but one of the handler files and then create them all again but as hard links to the one file you saved. In that way, you only need to edit one file to change all of the handlers.

Please use the apcupsd plugin discussion forum to post any issues, questions, ideas, etc.

Enjoy!

Release notes:
v 0.4.0 Oct 30, 2013
    Improved error handling when apcupsd is not available
    Added internal server to allow event communications from remote systems
    Fixed bug in trigger initialization
    Revised the polling model to query Indigo for all valid devices on each read (rather than maintaining an internal list)
    Complete re-write of the logging code

Posted on
Sat Nov 02, 2013 3:41 am
berkinet offline
User avatar
Posts: 2851
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

Re: APCUPSD (UPS daemon) Plugin v0.4.1 available

An update (v0.4.1) of the apcupsd plugin is now available on dropbox.

This release fixes a bug that prevented the plugin from loading if the plugin config file could not be located.

Release notes:
v 0.4.1 Nov 02, 2013
    Fixed a bug in plugin startup when upgrading without a plugin config file

Posted on
Sun Nov 03, 2013 7:00 am
berkinet offline
User avatar
Posts: 2851
Joined: Nov 18, 2008
Location: Berkeley, CA, USA & Mougins, France

APCUPSD (UPS daemon) Plugin v0.4.2 available

An update (v0.4.2) of the apcupsd plugin is now available on https://drive.google.com/open?id=0B3q1CEvta6R3Q05na2dtdGRId2M.

This release fixes a bug that that caused the plugin to crash when using debug level 2 or higher.

Release notes:
v 0.4.2 Nov 03, 2013
    Fixed a bug in the debugging and logging code

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 1 guest