diff options
author | Simon Rettberg | 2013-11-27 14:54:00 +0100 |
---|---|---|
committer | Simon Rettberg | 2013-11-27 14:54:00 +0100 |
commit | e323e44cfccc4bbb4352ec8f8fb4e94d643ef5cc (patch) | |
tree | 83a1cdb5ffcf99df386311619a042cccb079a3c1 /remote/rootfs/rootfs-stage32/data/opt/openslx/bin | |
parent | [rfs-stage32] Add curl, remove lots of required binaries which should come wi... (diff) | |
download | tm-scripts-e323e44cfccc4bbb4352ec8f8fb4e94d643ef5cc.tar.gz tm-scripts-e323e44cfccc4bbb4352ec8f8fb4e94d643ef5cc.tar.xz tm-scripts-e323e44cfccc4bbb4352ec8f8fb4e94d643ef5cc.zip |
[rfs-stage32] Improved slxlog a bit
Diffstat (limited to 'remote/rootfs/rootfs-stage32/data/opt/openslx/bin')
-rwxr-xr-x | remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog index 4df68cc0..236eabb3 100755 --- a/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog +++ b/remote/rootfs/rootfs-stage32/data/opt/openslx/bin/slxlog @@ -3,6 +3,9 @@ ################## # Remote logging # ################## +# +# Usage: slxlog "logtype" "Human readable string" ["file name which's contents should be sent too"] +# . /opt/openslx/config [ -z "$SLX_REMOTE_LOG" ] && exit 3 @@ -17,18 +20,21 @@ 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 + # Allow max 150 messages in total LINES=$(cat "$LOGCHECK" | wc -l) - [ "$LINES" -gt 500 ] && exit 1 + [ "$LINES" -gt "150" ] && 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 + LINES=$(grep "$TYPE" "$LOGCHECK" | wc -l) + if [ "$LINES" -ge "5" ]; then + 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 fi echo "$NOW $TYPE" >> "$LOGCHECK" -chmod 0666 "$LOGCHECK" +chmod 0666 "$LOGCHECK" 2>/dev/null if [ $# -lt 2 ]; then MSG="Missing text for $@" @@ -41,10 +47,10 @@ if [ $# -gt 2 ]; then EXTRA="$3" fi -if [ -r "$EXTRA" ]; then +if [ -r "$EXTRA" -a "$(stat -c %s "$EXTRA")" -lt "10000" ]; 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 + curl --data-urlencode "type=$TYPE" --data-urlencode "description=$MSG" --data-urlencode "longdesc=Missing/too large: $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 |