mon: Add command line livestatus wrappers
This adds two brand new sub modules to the mon command called "mon api ls"
and "mon api lsq". Both scripts are handling livestatus queries via the
command line, but in different ways.
"mon api lsq" is a tiny wrapper of the unixcat program. The wrapper
accepts a raw livestatus query either at stdin or as the first command
line argument. This means that an LS query that previously was run like:
printf 'GET hosts\n...' | unixcat /opt/monitor/var/rw/live
Can now be run as simply as this:
mon api lsq $'GET hosts\n...'
"mon api ls" on the other hand, is a much larger script that accepts
ordinary command line switches to generate an LS query for you. The
script also allows you to list the available tables and describe the
columns of a table. Specifying filter definitions can be done in two
different ways, the quick LQL-style syntax or the Shell-style syntax
that is much safer for command line usage. Have a look at "--help".
These wrappers comes in very handy as troubleshooting utils. One
might send an email to a customer in a support case, asking them
to run an LS query on all of their nodes at the same time, such as:
mon node ctrl --self -- mon api ls hostgroups -c name,num_hosts
The same thing using printf etc. would need some additional quoting,
a pipe, and so on. Those things are always quite error-prone.
And, yup. It's all bash. Haters gonna hate. If you can't deal with it,
just rewrite it later into something else that still accepts the same
command line arguments.
Change-Id: I834f5a234aa8b70c4b74c3b94f04dda9d1aeb3d6
Signed-off-by: Philip Eklöf <peklof@op5.com>