[Nut-upsdev] NUT I-D (future RFC): XML encoded responses

Ted Mittelstaedt tedm at mittelstaedt.us
Fri Dec 31 02:07:45 GMT 2021


The following wrapper script works fine for the apcaccess program to 
cause it to spit out XML.  This could easily be adapted to a command 
line NUT program that queries values from a UPS.

This script wraps the output of apcaccess into XML.  NOTE: this script 
output is NOT completely usable for input into a database or other 
management logging because many of the parameter values from apcaccess 
include measurement units in them, for example instead of voltage being 
"120" the voltage is "120 Volts"

This is intended to be run as a CGI script so that there will not be any 
needed security auditing of the apcaccess program (since that program is 
not running as a daemon or otherwise directly exposed to the webserver)


Setup the webserver to serve the script output.  For Apache, use the 
following in it's config file:

ScriptAlias /apcupsd-xml/ "/usr/local/www/apache22/apcupsd-xml/"

<Directory "/usr/local/www/apache22/apcupsd-xml">
     AllowOverride None
     Options None
     Order allow,deny
     Allow from all
</Directory>

You may want to restrict this to specific subnets. Hit the webserver 
with a browser using this URL (for
example the webserver is foo.example.com the script is named status.sh

http://foo.example.com/apcupsd-xml/status.sh

should give you the following XML:

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<apcaccess_dump>
    <parameter name="APC">
                 <value>001,054,1280</value>
    </parameter>
    <parameter name="DATE">
                 <value>2016-01-18 21:00:10 -0800</value>
    </parameter>
    <parameter name="HOSTNAME">
                 <value>foo.example.com</value>
    </parameter>
    <parameter name="VERSION">
                 <value>3.14.12 (29 March 2014) freebsd</value>
    </parameter>

Here is the script:

#!/bin/sh
/usr/local/sbin/apcaccess > /tmp/apcaccess.list
echo "Content-type: text/plain; charset=iso-8859-1"
echo
header='<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<apcaccess_dump>'

fmt='   <parameter name="%s">
                 <value>%s</value>
    </parameter>
'
footer='</apcaccess_dump>'

{
printf "%s\n" "$header"
while read ParameterName Colon ValueName
do
         printf "$fmt" "$ParameterName" "$ValueName"
done < "/tmp/apcaccess.list"
printf "%s\n" "$footer"
}
/bin/rm /tmp/apcaccess.list
$

Ted

On 12/30/2021 8:26 AM, Roger Price wrote:
> On Thu, 30 Dec 2021, Greg Troxel wrote:
>
>>> I have received a comment asking me to add XML encoded responses from
>>> the server as an option.
>>
>> Do you mean
>>
>>  there is already XML and you are going to document it
>>
>> or
>>
>>  there is not XML, and someone is asking to draft a description of 
>> what XML
>>  might be for the document, in the hopes that somebody in some 
>> NUT-compliant
>>  implementation will implmenent it?
>
> The proposal is to create and document a simple XML encoding for the 
> responses from the Attachment Daemon, to facilitate the use of mobile 
> Management Daemons (clients on iPhone, Android, ...)
>
>> As I grep the sources to 2.7.4 (yes I know that's old, but it's the 
>> most recent release, and what is handy in pkgsrc), I see a driver 
>> that talks XML to Eaton units, but I don't see a user-to-nut XML 
>> interface.
>
> XML encoding of responses would be completely new.
>
>>> The comment proposed REST.  Is this the best choice?  Would SOAP be 
>>> better in an RFC?
>>
>> Posing that question makes it clear to me that the XML situation is 
>> not baked enough to put in an RFC, and I think it's much better to 
>> document what's already established, and then after the XML has 
>> settled down, create a revision that includes XML also, along with 
>> any other fixes.
>
> That's a likely path for a future RFC. A second text (which following 
> the IETF process, would have a new number) which corrects and extends 
> the first and which is carried along a standards track.  But in the 
> meantime is there a volunteer to write text and demonstration code for 
> the current I-D?
>
> Roger
>
> _______________________________________________
> Nut-upsdev mailing list
> Nut-upsdev at alioth-lists.debian.net
> https://alioth-lists.debian.net/cgi-bin/mailman/listinfo/nut-upsdev



More information about the Nut-upsdev mailing list