Status-Push auf WebDAV-Share statt lokaler Datei

This commit is contained in:
Peter 2019-03-05 13:41:04 +01:00
parent d84ba6a6a4
commit a4eb236e48
Signed by: pludi
GPG Key ID: CFBA360E696EDC99
1 changed files with 13 additions and 2 deletions

View File

@ -3,10 +3,11 @@
[ ! -z "$DEBUG" ] && set -x [ ! -z "$DEBUG" ] && set -x
#set -eu #set -eu
STATUS_HTML=/var/tmp/spacestatus.html
STATUS_JSON=/var/tmp/spacestatus.json
function write_html { function write_html {
status=$1 status=$1
STATUS_HTML=/srv/www/spacestatus.html
TEMPLATE_HTML='<!DOCTYPE html><html><head><title>Status /usr/space: %s</title></head><body><p><code style="color: %s">%s</code></p></html>' TEMPLATE_HTML='<!DOCTYPE html><html><head><title>Status /usr/space: %s</title></head><body><p><code style="color: %s">%s</code></p></html>'
CLOSED_HTML='Closed darkred Closed' CLOSED_HTML='Closed darkred Closed'
OPEN_HTML='Open brightgreen Open' OPEN_HTML='Open brightgreen Open'
@ -21,7 +22,6 @@ function write_html {
function write_json { function write_json {
status=$1 status=$1
STATUS_JSON=/srv/www/spacestatus.json
TEMPLATE_JSON=$( cat /usr/local/etc/spacestatus.json ) TEMPLATE_JSON=$( cat /usr/local/etc/spacestatus.json )
CLOSED_JSON='false' CLOSED_JSON='false'
OPEN_JSON='true' OPEN_JSON='true'
@ -48,6 +48,15 @@ function write_json {
fi fi
} }
function publish {
CURL=/usr/bin/curl
WEBDAV=https://example.com
CREDS='user:pass'
${CURL} --user "${CREDS}" -T "${STATUS_HTML}" "${WEBDAV}"
${CURL} --user "${CREDS}" -T "${STATUS_JSON}" "${WEBDAV}"
}
tmpcount=$(mktemp) tmpcount=$(mktemp)
exec 3>$tmpcount exec 3>$tmpcount
/usr/sbin/dhcp-lease-list --parsable | awk '{print $4}' | while read ip /usr/sbin/dhcp-lease-list --parsable | awk '{print $4}' | while read ip
@ -63,4 +72,6 @@ leases=$( cat $tmpcount | wc -l )
write_html $leases write_html $leases
write_json $leases write_json $leases
publish
rm $tmpcount rm $tmpcount