From 4117d3e80c581dfe5e6daa9b16e9fe78b168f24e Mon Sep 17 00:00:00 2001 From: bryan Date: Mon, 28 Dec 2020 01:58:43 +0000 Subject: [PATCH] rename files, add readme, add empty .service file --- .readme.md.kate-swp | Bin 0 -> 232 bytes arp-check => arpcheck | 21 ++++++++++++--------- arpcheck-default.conf | 24 ++++++++++++++++++++++++ arpcheck@.service | 0 readme.md | 21 +++++++++++++++++++++ 5 files changed, 57 insertions(+), 9 deletions(-) create mode 100644 .readme.md.kate-swp rename arp-check => arpcheck (66%) create mode 100644 arpcheck-default.conf create mode 100644 arpcheck@.service create mode 100644 readme.md diff --git a/.readme.md.kate-swp b/.readme.md.kate-swp new file mode 100644 index 0000000000000000000000000000000000000000..fede7ac43415458cc941597d2edd510303df6397 GIT binary patch literal 232 zcmZQzU=Z?7EJ;-eE>A2_aLdd|RWQ;sU|?VnseU(&$!2#({!h>M`<3}Q_KUI|J{%kb zl;HznZ6MZh4faIhGRC-4BCQY6EdVr86^PX!hQqjwNYa`>X)S~_h>I+32;>_fq(NMu FGyo0R9|iyb literal 0 HcmV?d00001 diff --git a/arp-check b/arpcheck similarity index 66% rename from arp-check rename to arpcheck index 25cdb1e..800bf2f 100755 --- a/arp-check +++ b/arpcheck @@ -1,10 +1,13 @@ #! /bin/bash +if [ ! -e "$1" ]; then + exit 2 +fi -TOKEN="A9jDrGFO6Ob-m88" -IP="172.16.1.82" -COUNT_TO_AWAY=900 +. "$1" + +countToAway=`expr $SECONDS_TO_AWAY / $INTERVAL` startedTimeout="n" away="n" alertedHome="y" @@ -28,24 +31,24 @@ do else let "counter += 1" echo "******** $counter" - if [ $counter -eq $COUNT_TO_AWAY ]; then - alert "Status" "Away" + if [ $counter -eq $countToAway ]; then + alert "$ALERT_TITLE" "$ALERT_MESSAGE_AWAY" alertedHome="n" alertedAway="y" fi fi else if [ "$startedTimeout" = "y" ]; then - if [ "$counter" -ge 100 ]; then - echo "$counter" >> count.hayleyiphone + if [ "$counter" -ge `expr 600 / $INTERVAL` && "$counter" -le `expr 1800 / $INTERVAL ]; then + echo "$counter" >> "$LOGFILE" fi startedTimeout="n" counter=0 if [ "$alertedHome" = "n" ]; then - alert "Status" "Home" + alert "$ALERT_TITLE" "$ALERT_MESSAGE_HOME" alertedHome="y" fi fi fi -done < <(stdbuf -oL arping -W 1 "$IP") +done < <(stdbuf -oL arping -W "$INTERVAL" "$IP") diff --git a/arpcheck-default.conf b/arpcheck-default.conf new file mode 100644 index 0000000..4bcaf16 --- /dev/null +++ b/arpcheck-default.conf @@ -0,0 +1,24 @@ +#! /bin/bash + +# ip to arp ping +IP="172.16.1.82" + +# alternatively, MAC to ping +MAC="86:51:F8:EF:D1:8C" + +# number of seconds for ping to timeout before device is considered to not be present +SECONDS_TO_AWAY=900 + +# number of seconds between pings +INTERVAL=1 + +# app token for gotify +TOKEN="A9jDrGFO6Ob-m88" + +# logfile +LOGFILE="/var/log/arp-check/$IP" + +# alert configuration: +ALERT_TITLE="Status" +ALERT_MESSAGE_HOME="Home" +ALERT_MESSAGE_AWAY="Away" diff --git a/arpcheck@.service b/arpcheck@.service new file mode 100644 index 0000000..e69de29 diff --git a/readme.md b/readme.md new file mode 100644 index 0000000..7bee960 --- /dev/null +++ b/readme.md @@ -0,0 +1,21 @@ +# ARPCHECK # +## Uses `arping` utility to check for presence of device on network. ## + +## Installation + +1. Copy arpcheck to `/usr/local/bin` + +2. Create `/var/log/arpcheck directory` (or directory to match log directory in conf file) + +3. Copy `arpcheck-default.conf` to device specific configuration file. ex.: `arpcheck-johndoe.conf` + You may make as many individual configuartion files as you want. + +4. Create `/etc/arpcheck directory` + +5. Copy arpcheck config files you made to `/etc/arpcheck` directory + +6. Copy `arpcheck@.service` file to `\etc\systemd\system` + +7. Enable service: `systemctl enable arpcheck@.service` + +8. Start service: `systemctl start arpcheck@.service`