-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcoremon.sh
40 lines (34 loc) · 947 Bytes
/
coremon.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#!/usr/bin/env bash
URL="https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX"
PROXY="" # optional "http://proxy.host:port"
WATCH_DIR="/tmp"
PATTERN="*.core"
TIMEOUT=30 # seconds, limits frequency of reports
HOST=`hostname`
LAST_TS=0
COUNTER=0
function send_report()
{
if [ -n $PROXY ]; then
proxy_param="-x "$PROXY
fi
user=$1
fname=$2
text="Core $fname triggered by @$user on $HOST"
data='{"text": "'$text'"}'
curl $proxy_param -sH "Content-type: application/json" -d "$data" $URL
}
inotifywait -mqe create $WATCH_DIR |
while read path options name; do
if [[ $name = $PATTERN ]]; then
ts=`date +%s`
if [ $(($ts-$LAST_TS)) -ge $TIMEOUT ]; then
user=`ls -ld $path$name | awk '{print $3}'`
send_report $user $path$name $COUNTER
COUNTER=0
LAST_TS=$ts
else
((COUNTER++))
fi
fi
done