summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2013-11-26 19:08:35 +0100
committerSimon Rettberg2013-11-26 19:08:35 +0100
commit3f386cf5f3cfa703464cdb8b3eca823ed1f2acc6 (patch)
tree5a9871fc1e0c640a2fe019592f767ead80b136c4
parent[vmware] fix wrong permissions for /tmp/vmware (diff)
downloadtm-scripts-3f386cf5f3cfa703464cdb8b3eca823ed1f2acc6.tar.gz
tm-scripts-3f386cf5f3cfa703464cdb8b3eca823ed1f2acc6.tar.xz
tm-scripts-3f386cf5f3cfa703464cdb8b3eca823ed1f2acc6.zip
[rfs-stage32] Add 'slxlog', a utility for remote logging
-rwxr-xr-xremote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog53
1 files changed, 53 insertions, 0 deletions
diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog
new file mode 100755
index 00000000..4df68cc0
--- /dev/null
+++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog
@@ -0,0 +1,53 @@
+#!/opt/openslx/bin/ash
+
+##################
+# Remote logging #
+##################
+
+. /opt/openslx/config
+[ -z "$SLX_REMOTE_LOG" ] && exit 3
+
+LOGCHECK="/tmp/remote_log_check"
+NOW=$(date +%s)
+
+[ $# -eq 0 ] && exit 0
+
+TYPE="$1"
+
+# Simple spamcheck. Not very tamper-proof, but if you'd want to spam the server
+# you could do it anyways. This is to protect from accidental loops calling this.
+if [ -r "$LOGCHECK" ]; then
+ # Allow max 500 messages in total
+ LINES=$(cat "$LOGCHECK" | wc -l)
+ [ "$LINES" -gt 500 ] && exit 1
+ # Allow max 5 of same type messages in 30 seconds
+ LAST=$(grep "$TYPE" "$LOGCHECK" | tail -n 5 | head -n 1 | awk '{print $1}')
+ if [ -n "$LAST" ]; then
+ DIFF="$[ $NOW - $LAST ]"
+ [ "$DIFF" -lt "30" ] && exit 2
+ fi
+fi
+echo "$NOW $TYPE" >> "$LOGCHECK"
+chmod 0666 "$LOGCHECK"
+
+if [ $# -lt 2 ]; then
+ MSG="Missing text for $@"
+else
+ MSG="$2"
+fi
+MSG="[$(whoami)] $MSG"
+
+if [ $# -gt 2 ]; then
+ EXTRA="$3"
+fi
+
+if [ -r "$EXTRA" ]; then
+ curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" --data-urlencode "longdesc@$EXTRA" "$SLX_REMOTE_LOG" > /dev/null 2>&1
+elif [ -n "$EXTRA" ]; then
+ curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" --data-urlencode "longdesc=Missing $EXTRA" "$SLX_REMOTE_LOG" > /dev/null 2>&1
+else
+ curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" "$SLX_REMOTE_LOG" > /dev/null 2>&1
+fi
+
+exit 0
+