From 4c6efb28969ad3c49e1ebdaf3ffc9aa2f164edcb Mon Sep 17 00:00:00 2001 From: paradizelost Date: Thu, 22 Jun 2017 19:59:56 -0500 Subject: [PATCH] Initial Commit --- docast.py | 12 +++++++++ logwatch.sh | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++++ sheet.py | 12 +++++++++ 3 files changed, 96 insertions(+) create mode 100644 docast.py create mode 100644 logwatch.sh create mode 100644 sheet.py diff --git a/docast.py b/docast.py new file mode 100644 index 0000000..e73bf3c --- /dev/null +++ b/docast.py @@ -0,0 +1,12 @@ +from __future__ import print_function +import time +import pychromecast +exroom=pychromecast.Chromecast('192.168.1.123') +lroom=pychromecast.Chromecast('192.168.1.107') +home=pychromecast.Chromecast('192.168.1.103') +emc=exroom.media_controller +lmc=lroom.media_controller +hmc=home.media_controller +home.wait() +time.sleep(5) +hmc.play_media('http://192.168.1.14/doorbell.mp3','audio/mpeg') diff --git a/logwatch.sh b/logwatch.sh new file mode 100644 index 0000000..3138152 --- /dev/null +++ b/logwatch.sh @@ -0,0 +1,72 @@ +#!/bin/bash +function procaplog(){ + while IFS=, read -r date mac; do + HOSTNAME=$(checkmac "$mac") + if [ "$HOSTNAME" ]; then + case $HOSTNAME in + AMAZON_IOT_BUTTON) + /root/bin/sheet.py "$date" "Diaper Change" + alert_dan "$date The button was pushed" + python /root/bin/docast.py + ;; + DAN_PIXEL) + alert_alli "Dan is home at $date" + /root/bin/sheet.py "$date" $HOSTNAME + ;; + *) + /root/bin/sheet.py "$date" $HOSTNAME + ;; + esac + else + alert_dan "$NOW - Unknown host $mac connected at $date" + /root/bin/sheet.py "$date" $mac + fi + done +}; +function procswitchlog(){ + 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 + fi +}; +function alert_alli(){ + nail -s "$1" -S from="Alerts@hamik.net" "$PHONE2" <<<"." +}; +function alert_dan(){ + nail -s "$1" -S from="Alerts@hamik.net" "$PHONE1" <<<"." + nail -s "$1" -S from="Alerts@hamik.net" "$PHONE3" <<<"." +}; +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)" +PHONE1="15555555555@vtext.com" +PHONE2="15555555555@vtext.com" +PHONE3="15555555555@vtext.com" + +if [ "$EVT" != "0" ]; then + cp "$LOG" "$LOG.old" + tail -n "$EVT" "$LOG" | awk '/WPA: pairwise key handshake completed/ {print $1 " " $2 " " $3 ", " $9 }'|procaplog +fi +if [ "$EVT2" != "0" ]; then + cp "$LOG2" "$LOG2.old" + tail -n "$EVT2" "$LOG2" | awk '/WPA: pairwise key handshake completed/ {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 + diff --git a/sheet.py b/sheet.py new file mode 100644 index 0000000..a62b9a0 --- /dev/null +++ b/sheet.py @@ -0,0 +1,12 @@ +#!/usr/bin/python +import gspread +import sys +toadd=sys.argv +toadd.pop(0) +from oauth2client.service_account import ServiceAccountCredentials +scope = "https://spreadsheets.google.com/feeds" +credentials = ServiceAccountCredentials.from_json_keyfile_name('/root/bin/credentials.json', scope) +gs = gspread.authorize(credentials) +gsheet = gs.open("testsheet") +wsheet = gsheet.worksheet("Sheet1") +wsheet.insert_row(toadd,index=2)