summaryrefslogtreecommitdiffstats
path: root/ext/solus
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2013-02-07 20:26:15 +0100
committermakefu <github@syntax-fehler.de>2013-02-07 20:26:15 +0100
commitdd6ad821a5a5bcb633b28a6d35e5e612d1f59094 (patch)
tree51a5281d1cbba3423eb5e9a86eb16d847fac5a6e /ext/solus
parent12fa3df06555c4ad6973602998a42446fbb52e70 (diff)
parent41fb505a5dc5c81965cc45dd00d14fe4150b8a42 (diff)
Merge branch 'master' of github.com:krebscode/painload
Diffstat (limited to 'ext/solus')
-rwxr-xr-xext/solus/bin/client28
-rwxr-xr-xext/solus/lib/parse-return-data20
2 files changed, 48 insertions, 0 deletions
diff --git a/ext/solus/bin/client b/ext/solus/bin/client
new file mode 100755
index 00000000..60b720d6
--- /dev/null
+++ b/ext/solus/bin/client
@@ -0,0 +1,28 @@
+#! /bin/sh
+# usage: client ACTION
+# ACTION: boot, info, reboot, shutdown, or status
+# environment:
+# api_url URL to the client API like https://<MASTER IP>:5656/api/client
+# api_key
+# api_hash
+set -euf
+
+url="$api_url/command.php"
+key="$api_key"
+hash="$api_hash"
+
+action="${1-$ACTION}"
+
+case "$action" in
+ (info)
+ # get all the information
+ action="$action&ipaddr=true&hdd=true&mem=true&bw=true";;
+esac
+
+abspath="`readlink -f "$0"`"
+bindir="`dirname "$abspath"`"
+libdir="`dirname "$bindir"`/lib"
+export PATH="$libdir:$PATH"
+
+curl -sS -d key="$key" -d hash="$hash" -d action="$action" "$url" |
+ parse-return-data
diff --git a/ext/solus/lib/parse-return-data b/ext/solus/lib/parse-return-data
new file mode 100755
index 00000000..85219727
--- /dev/null
+++ b/ext/solus/lib/parse-return-data
@@ -0,0 +1,20 @@
+#! /bin/sh
+set -euf
+sed '
+ # transform "XML" into lines {key}<tab>{value}-lines
+ s|</[^>]*>|\n|g
+ s|<\([^>]*\)>|\1\t|g
+' |
+sed '
+ # transform ipaddr list into multiple ipaddr_[46]<tab>{ipaddr}-lines
+ /^ipaddr\t/{
+ s|,|\nipaddr\t|g
+ s/\t\([0-9]*[.]\)/_4&/g
+ s/\t\([0-9]*[:]\)/_6&/g
+ }
+ # parse CSVs into multiple lines with proper labels
+ s:^\(hdd\|mem\|bw\)\t\([^,]*\),\([^,]*\),\([^,]*\),\([^,]*\)$:\1_total\t\2\
+\1_used\t\3\
+\1_free\t\4\
+\1_percentused\t\5:
+'