List your devices and their state
ondevice list [--options...] [filters...]
--json
{"id":"demo.7t91ta",state":"offline","stateTs":1490197318991,"version":"ondevice v0.4.3"}
--print-ids
--json
)--props
--state=<online/offline>
on:state=<online/offline>
(see below)
but filtered on the server (while filter expressions are processed on the client)With v0.5.3
, ondevice list
adds support for simple filter expressions.
These allow you to search for devices matching certain properties.
Filter expressions have the following syntax:
propertyName[operator[value]]
Supported operators:
=
, ==
: equality!=
: not equal<
, <<
: less than>
, >>
: greater than<=
: less than or equal (case sensitive string comparison)>=
: greater than or equal (case sensitive string comparison)For example (assuming you’ve set device properties accordingly):
arch
lists devices with the arch
property (equivalent to arch!=
)arch=
lists devices without the arch
property (read: where the arch
property is empty)arch=amd64
lists devices with architecture amd64
'version_foo<1.2.3'
lists devices with a foo package older than v1.2.3<
and >
)version_foo 'version_foo<1.2.3'
lists devices where the foo package is
installed but older than v.1.2.3This example lists online devices without the arch
property and tries to discover it.
We’re using Debian’s dpkg --print-architecure
here.
Similar commands can be used for other distros/OSs.
#!/bin/bash
# "discover.sh"
set -e
for devId in $(ondevice list --print-ids --state=online arch= | shuf); do
echo "=====\n Fetching device info: '$devId'\n====" >&2
# fetch arch and distro version
arch="$(ondevice ssh "user@$devId" dpkg --print-architecture)"
distro="$(ondevice ssh "user@$devId" lsb_release -s -c)"
if [ -z "$arch" -o -z "$distro" ]; then
echo "Failed to fetch device info for '$devId': arch='$arch' distro='$distro'" >&2
exit 1
fi
# set device properties
ondevice device "$devId" set arch="$arch" distro="$distro"
done
echo "~~~ all done ~~~" >&2
We’re using shuf
to randomise the list of matching devices (doing that prevents
us from getting stuck at a single misbehaving device in subsequent runs).
Also, we’re failing early (at the first error). This makes it easier to diagnose issues when running the script manually.
Extend this script to fit your needs and run it periodically (e.g. once an hour as cronjob) to automatically gather device infos.
Note that for long-running scripts, devices may go offline by the time it’s their turn. This will cause the script to fail (but since we run it relatively often, that shouldn’t be too big an issue)
Make sure you set up ssh-key based authentication for this to work noninteractively.
43<5
, hello>World
etc.on:
), no properties are
predefined. It is up to you to write scripts to annotate your devices with
themfoo=="=bar="
will look for the value =bar=
while foo="=bar="
would only match bar=
$ ondevice help list ondevice list List your devices Options: --json output JSON, one line/object per device --props include properties (only affects JSON output) --statelimit to devices that are on/offline Example: $ ondevice list ID State IP Version Name demo.7t91ta offline ondevice v0.4.3 demo.fbqh2p offline 192.168.1.23 ondevice v0.3.9 demo.q5dkpm online 127.0.0.1 ondevice v0.4.2 demo.thm7br offline 10.0.0.127 ondevice v0.4.3 $ ondevice list --json --props {"id":"demo.7t91ta",state":"offline","stateTs":1490197318991,"version":"ondevice v0.4.3"} {"id":"demo.fbqh2p","ip":"192.168.1.23","state":"offline","stateTs":1485721709598,"version":"ondevice v0.3.9"} {"id":"demo.q5dkpm","ip":"127.0.0.1","state":"offline","stateTs":1487068641353,"version":"ondevice v0.4.2","props":{"test":"1234"}} {"id":"demo.thm7br","ip":"10.0.0.127","state":"offline","stateTs":1490963689912,"version":"ondevice v0.4.3"} Keep in mind that JSON fields may be missing or null