-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogwatch.sh
143 lines (142 loc) · 4.16 KB
/
logwatch.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
PHONE1="[email protected]"
PHONE2="[email protected]"
PHONE3="[email protected]"
LOG="/var/log/logs/192.168.1.113.log"
LOG2="/var/log/logs/192.168.1.104.log"
LOG3="/var/log/logs/192.168.1.252-1.log"
EVT="$(comm --nocheck-order -23 "$LOG" "$LOG.old" | wc -l)"
EVT2="$(comm --nocheck-order -23 "$LOG2" "$LOG2.old" | wc -l)"
EVT3="$(comm --nocheck-order -23 "$LOG3" "$LOG3.old" | wc -l)"
function procaplog(){
while IFS=, read -r date mac; do
SENDALERT=$(checkdisconnects "$date" $mac)
echo "starting mac check"
echo "starting mac check" >> /var/log/logwatch.log
HOSTNAME=$(/root/bin/hostlookup.py $mac "$date")
if [ "$HOSTNAME" ]; then
echo "__ $HOSTNAME __"
echo "__ $HOSTNAME __" >> /var/log/logwatch.log
case $HOSTNAME in
AMAZON_IOT_BUTTON)
/root/bin/sheet.py "$date" "Diaper Change"
if [ $SENDALERT -eq 1 ]; then
alert_dan "$date The button was pushed"
else
echo "Not alerting, Reconnection of $HOSTNAME" >> /var/log/logwatch.log
fi
python /root/bin/button1.py "$HOSTNAME" "$date"
#castnow --address 192.168.1.103 http://192.168.1.14/doorbell.mp3 --exit
;;
HEFTY)
/root/bin/sleeptracker.py "$date"
;;
COLGATE)
/root/bin/sleeptracker.py "$date"
;;
AMAZON_BASICS_BATTERIES)
/root/bin/sleeptracker.py "$date"
;;
CASCADE)
/root/bin/sleeptracker.py "$date"
;;
Charmin_1)
/root/bin/feedings.py "$date"
;;
CHARMIN_2)
/root/bin/feedings.py "$date"
;;
DIRTY_DIAPER)
/root/bin/diaper.py "$date" soiled
;;
WET_DIAPER)
/root/bin/diaper.py "$date" wet
;;
DAN_PIXEL)
if [ $SENDALERT -eq 1 ]; then
echo "Alerting Alli"
echo "Alerting Alli" >> /var/log/logwatch.log
alert_alli "Dan is home at $date"
else
echo "Not alerting, Reconnection of $HOSTNAME" >> /var/log/logwatch.log
fi
/root/bin/sheet.py "$date" $HOSTNAME
;;
ALLI_S7)
if [ $SENDALERT -eq 1 ]; then
echo "Alerting Dan"
echo "Alerting Dan" >> /var/log/logwatch.log
alert_dan "Alli is home at $date"
else
echo "Not alerting, Reconnection of $HOSTNAME" >> /var/log/logwatch.log
fi
/root/bin/sheet.py "$date" $HOSTNAME
;;
*)
echo "No Match with -$HOSTNAME- alerting"
echo "No Match with -$HOSTNAME- alerting">> /var/log/logwatch.log
/root/bin/sheet.py "$date" $HOSTNAME
;;
esac
else
echo "$mac"
if [ $SENDALERT -eq 1 ]; then
alert_dan "$NOW - Unknown host $mac connected at $date"
else
echo "Not alerting, Reconnection of $mac" >> /var/log/logwatch.log
fi
/root/bin/sheet.py "$date" $mac
fi
done
};
function checkdisconnects(){
THISCHECK=$(date -d "$1" +%s)
if [ "$(tail -n 30 "$LOG2" "$LOG" | grep "$(date +"%b %e")" | grep "$2" | grep "disassociated" |wc -l)" -gt 0 ]; then
echo 0
else
echo 1
fi
}
function procswitchlog(){
echo "$1" >> /var/log/logwatch.log
echo "$1"
while IFS=, read -r date device port state; do
if [ "$state" == "Up:" ]; then
alert_dan "Port $port on switch $device came up at $date"
else
alert_dan "Port $port on switch $device went down at $date"
fi
done
}
function checkmac(){
LINE=$(grep "$1" /root/bin/test.txt )
if [ "$LINE" ]; then
read -r mac hostname <<< $LINE
echo "$hostname"
echo "$hostname" >> /var/log/logwatch.log
fi
};
function alert_alli(){
echo "$1"
echo "$1" >> /var/log/logwatch.log
nail -s "$1" -S from="[email protected]" "$PHONE2" <<<"."
};
function alert_dan(){
echo "$1"
echo "$1" >> /var/log/logwatch.log
nail -s "$1" -S from="[email protected]" "$PHONE1" <<<"."
nail -s "$1" -S from="[email protected]" "$PHONE3" <<<"."
};
if [ "$EVT" != "0" ]; then
cp "$LOG" "$LOG.old"
tail -n "$EVT" "$LOG" | awk '/IEEE 802.11: associated/ {print $1 " " $2 " " $3 ", " $9 }'|procaplog
fi
if [ "$EVT2" != "0" ]; then
cp "$LOG2" "$LOG2.old"
tail -n "$EVT2" "$LOG2" | awk '/IEEE 802.11: associated/ {print $1 " " $2 " " $3 ", " $9 }'|procaplog
fi
if [ "$EVT3" != "0" ]; then
cp "$LOG3" "$LOG3.old"
#tail -n "$EVT3" "$LOG3" | awk '/Link Up:/ {print $1 " " $2 " " $3 "," $4 "," $11 "," $10 }'|procswitchlog
#tail -n "$EVT3" "$LOG3" | awk '/Link Down:/ {print $1 " " $2 " " $3 "," $4 "," $11 "," $10}'|procswitchlog
fi