XML Output: libxo - provide single API to output TXT, XML, JSON and HTML
Garance A Drosehn
drosih at rpi.edu
Thu Jul 31 01:37:58 UTC 2014
On 25 Jul 2014, at 0:49, Simon Gerraty wrote:
>
> The following from Phil provides some idea of the functionality
> available and the API.
> The one shown here uses the default output handle (stdout), but there
> are variants that allow multiple output handles.
>
>> Here's some sample output (from my libxo-ified "w"):
>>
>> (This uses an environment variable to trigger the mode and options:
>> T X J and H are the modes (text, xml, json, html); [...etc...]
>>
>> % foreach i ( T XP JP HP HPIx )
>> echo === $i ===
>> env LIBXO_OPTIONS=$i ./xtest -n | head -10
>> end
>> === T ===
>> 6:47PM up 18 days, 2:01, 9 user%s, load averages: 0.00, 0.00, 0.00
>> USER TTY FROM LOGIN@ IDLE WHAT
>> phil pts/0 76.182.32.73 5:09PM 33 /bin/sh
>> phil pts/1 76.182.32.73 05Jul14 2
>> /usr/bin/perl /u/phil/bin/plum (
>> phil pts/2 76.182.32.73 05Jul14 1 /bin/tcsh
>> phil pts/3 76.182.32.73 05Jul14 2days ssh dent
>> phil pts/4 76.182.32.73 Tue02PM 2days ssh
>> svl-junos-d026.juniper.net
>> phil pts/5 76.182.32.73 Wed01AM 2days telnet
>> man-o-war 2006
>> phil pts/6 76.182.32.73 Fri10PM 2days ssh
>> 198.85.229.65
>> phil pts/7 76.182.32.73 Fri10PM 2days ssh zap
>> === XP ===
>> <uptime-information>
>> <time-of-day> 6:47PM</time-of-day>
>> <uptime seconds="1562436">18 days</uptime>
>> <uptime> 2:01</uptime>
>> <users>9</users>
>> <load-average-1>0.00</load-average-1>
>> <load-average-5>0.00</load-average-5>
>> <load-average-15>0.00</load-average-15>
>> <user-table>
>> <user-entry>
>> === JP ===
Do you have links to the library itself?
Over the years I've dabbled with doing something like this for the
lpr/lpc/lpq programs, so I've done a fair amount of thinking about
it. I didn't do as much *work* as either libxo or the GSOC project,
but I have done some thinking! Mind you, even that thinking is
based only on the lpr-programs, and not a larger set of utilities.
I'd suggest that the above isn't quite what one would want, either.
For the text version it's fine to have a time-of-day value as
'6:47PM', but if you're going for machine-readable output then
you'd want that in some format which was much more specific and
*standard* (as opposed to arbitrary pretty-printed strings).
Something like the ISO 8601 format used in obscure parts of lpd:
#define LPD_TIMESTAMP_PATTERN "%Y-%m-%dT%T%z %a"
(actually the %a part is not part of ISO 8601, but it is useful
for some programs which might want to process the time). Or you
might want to print it as a unix-epoch integer. Something that
makes it easy for a program to process it.
Or you could follow the example of EDN, and use rfc-3339-format
(see '#inst' at https://github.com/edn-format/edn). The nice
thing about standards is that there are so many to choose from.
It's hard to tell based on your sample output, but there's also
the question of truncating strings. In the text output of your
example, it obviously makes sense to truncate the 'WHAT' value
to 'ssh svl-junos-d026.juniper.net', but when printing the same
output in a machine-readable format you wouldn't want to truncate
it. Let the application which *reads* the data decide how many
characters *it* wants to use.
--
Garance Alistair Drosehn = drosih at rpi.edu
Senior Systems Programmer or gad at FreeBSD.org
Rensselaer Polytechnic Institute; Troy, NY; USA
More information about the freebsd-arch
mailing list