aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorU-AD\carlsoan <carlsoan@gophersjos7275.ad.uc.edu>2018-05-30 09:41:00 -0400
committerU-AD\carlsoan <carlsoan@gophersjos7275.ad.uc.edu>2018-05-30 09:41:00 -0400
commit49a2d38f89eda25f520e60b9116eacee5fe4f507 (patch)
tree961ab2368fc63e1ee7d41681eb75b7a72d76b532
parent2148097814ca43b9b40c0e12277c417e31c515de (diff)
add caching to more checks
-rw-r--r--README.md6
-rwxr-xr-xchecks/snmpversion.sh.m433
-rwxr-xr-xchecks/sshversion.sh.m433
-rwxr-xr-xchecks/sslversion.sh.m433
-rwxr-xr-xchecks/tcversion.sh.m433
5 files changed, 105 insertions, 33 deletions
diff --git a/README.md b/README.md
index 5dabd4a..e1d8b0d 100644
--- a/README.md
+++ b/README.md
@@ -1,8 +1,4 @@
# playhooky
-Add caching functionality to the following checks :
-sshversion.sh.m4
-tcversion.sh.m4
-snmpversion.sh.m4
-sslversion.sh.m4
+
diff --git a/checks/snmpversion.sh.m4 b/checks/snmpversion.sh.m4
index 6ac2f70..495b0c9 100755
--- a/checks/snmpversion.sh.m4
+++ b/checks/snmpversion.sh.m4
@@ -1,16 +1,35 @@
#!/bin/bash
+##############################
+# sends the follows JSON to webhook:
+#
+# { "value1":"<snmp-version>" }
+##############################
+
CHECKDIR="BASEDIR"
CONFDIR="$CHECKDIR/conf"
IFTTTKEY="KEYTEXT"
-curl -s http://www.net-snmp.org/ | \
-awk '/Current release/ { print gensub(/^.*Current release:[ \t]*([0-9\.]+).*$/,"\\1","g",$0); }' > /tmp/snmpver
-diff /tmp/snmpver $CONFDIR/snmpver
-if [ $? -eq 1 ]; then
- mv /tmp/snmpver $CONFDIR/snmpver
- echo "{\"value1\":\"$(cat $CONFDIR/snmpver)\"}" |curl -X POST -d ''"$(cat -)"'' -H "Content-type: application/json" https://maker.ifttt.com/trigger/{snmpversion}/with/key/$IFTTTKEY
+snmpversiondata() {
+ curl -s http://www.net-snmp.org/ | \
+ awk '/Current release/ { print gensub(/^.*Current release:[ \t]*([0-9\.]+).*$/,"\\1","g",$0); }'
+}
+
+if [ "$1" == "cache" ]; then
+ snmpversiondata > $CONFDIR/snmpver
else
- echo "skipped"
+ if [ ! -f $CONFDIR/snmpver ]; then
+ echo "Caching Net-SNMP version"
+ $0 cache
+ else
+ snmpversiondata > /tmp/snmpver
+ diff /tmp/snmpver $CONFDIR/snmpver
+ if [ $? -eq 1 ]; then
+ mv /tmp/snmpver $CONFDIR/snmpver
+ echo "{\"value1\":\"$(cat $CONFDIR/snmpver)\"}" |curl -X POST -d ''"$(cat -)"'' -H "Content-type: application/json" https://maker.ifttt.com/trigger/{snmpversion}/with/key/$IFTTTKEY
+ else
+ echo "skipped"
+ fi
+ fi
fi
diff --git a/checks/sshversion.sh.m4 b/checks/sshversion.sh.m4
index 24f1940..f496f1c 100755
--- a/checks/sshversion.sh.m4
+++ b/checks/sshversion.sh.m4
@@ -1,16 +1,35 @@
#!/bin/bash
+##############################
+# sends the follows JSON to webhook:
+#
+# { "value1":"<openssh-version>" }
+##############################
+
CHECKDIR="BASEDIR"
CONFDIR="$CHECKDIR/conf"
IFTTTKEY="KEYTEXT"
-curl -s https://www.openssh.com/ | \
-awk '/released/ { print gensub(/^.*OpenSSH ([0-9\.]+)<.*$/,"\\1","1",$0); }' > /tmp/sshver
-diff /tmp/sshver $CONFDIR/sshver
-if [ $? -eq 1 ]; then
- mv /tmp/sshver $CONFDIR/sshver
- echo "{\"value1\":\"$(cat $CONFDIR/sshver)\"}" |curl -X POST -d ''"$(cat -)"'' -H "Content-type: application/json" https://maker.ifttt.com/trigger/{sshversion}/with/key/$IFTTTKEY
+sshversiondata() {
+ curl -s https://www.openssh.com/ | \
+ awk '/released/ { print gensub(/^.*OpenSSH ([0-9\.]+)<.*$/,"\\1","1",$0); }'
+}
+
+if [ "$1" == "cache" ]; then
+ sshversiondata > $CONFDIR/sshver
else
- echo "skipped"
+ if [ ! -f $CONFDIR/sshver ]; then
+ echo "Caching OpenSSH version"
+ $0 cache
+ else
+ sshversiondata > /tmp/sshver
+ diff /tmp/sshver $CONFDIR/sshver
+ if [ $? -eq 1 ]; then
+ mv /tmp/sshver $CONFDIR/sshver
+ echo "{\"value1\":\"$(cat $CONFDIR/sshver)\"}" |curl -X POST -d ''"$(cat -)"'' -H "Content-type: application/json" https://maker.ifttt.com/trigger/{sshversion}/with/key/$IFTTTKEY
+ else
+ echo "skipped"
+ fi
+ fi
fi
diff --git a/checks/sslversion.sh.m4 b/checks/sslversion.sh.m4
index 8fd8c5c..a6d4b1e 100755
--- a/checks/sslversion.sh.m4
+++ b/checks/sslversion.sh.m4
@@ -1,16 +1,35 @@
#!/bin/bash
+##############################
+# sends the follows JSON to webhook:
+#
+# { "value1":"<openssl-version>" }
+##############################
+
CHECKDIR="BASEDIR"
CONFDIR="$CHECKDIR/conf"
IFTTTKEY="KEYTEXT"
-curl -s https://www.openssl.org/source/ | \
-awk '/stable/ { print gensub(/^.* ([0-9\.]+) .*$/,"\\1","g",$0); }' > /tmp/sslver
-diff /tmp/sslver $CONFDIR/sslver
-if [ $? -eq 1 ]; then
- mv /tmp/sslver $CONFDIR/sslver
- echo "{\"value1\":\"$(cat $CONFDIR/sslver)\"}" |curl -X POST -d ''"$(cat -)"'' -H "Content-type: application/json" https://maker.ifttt.com/trigger/{sslversion}/with/key/$IFTTTKEY
+opensslversiondata() {
+ curl -s https://www.openssl.org/source/ | \
+ awk '/stable/ { print gensub(/^.* ([0-9\.]+) .*$/,"\\1","g",$0); }'
+}
+
+if [ "$1" == "cache" ]; then
+ opensslversiondata > $CONFDIR/sslver
else
- echo "skipped"
+ if [ ! -f $CONFDIR/sslver ]; then
+ echo "Caching OpenSSL version"
+ $0 cache
+ else
+ opensslversiondata > /tmp/sslver
+ diff /tmp/sslver $CONFDIR/sslver
+ if [ $? -eq 1 ]; then
+ mv /tmp/sslver $CONFDIR/sslver
+ echo "{\"value1\":\"$(cat $CONFDIR/sslver)\"}" |curl -X POST -d ''"$(cat -)"'' -H "Content-type: application/json" https://maker.ifttt.com/trigger/{sslversion}/with/key/$IFTTTKEY
+ else
+ echo "skipped"
+ fi
+ fi
fi
diff --git a/checks/tcversion.sh.m4 b/checks/tcversion.sh.m4
index 4f9208d..47dbe0f 100755
--- a/checks/tcversion.sh.m4
+++ b/checks/tcversion.sh.m4
@@ -1,16 +1,35 @@
#!/bin/bash
+##############################
+# sends the follows JSON to webhook:
+#
+# { "value1":"<openssl-version>" }
+##############################
+
CHECKDIR="BASEDIR"
CONFDIR="$CHECKDIR/conf"
IFTTTKEY="KEYTEXT"
-curl -s http://tinycorelinux.net/ | \
-awk '/The latest version:/ { print gensub(/^.*The latest version:[ \t]*<[\/]*[a-z]*[\/]*>([0-9\.]*)<.*$/,"\\1","g",$0); }' > /tmp/tcver
-diff /tmp/tcver $CONFDIR/tcver > /dev/null
-if [ $? -eq 1 ]; then
- mv /tmp/tcver $CONFDIR/tcver
- echo "{\"value1\":\"$(cat $CONFDIR/tcver)\"}" | curl -X POST -d ''"$(cat -)"'' -H "Content-type: application/json" https://maker.ifttt.com/trigger/{tcversion}/with/key/$IFTTTKEY
+tinycoreversiondata() {
+ curl -s http://tinycorelinux.net/ | \
+ awk '/The latest version:/ { print gensub(/^.*The latest version:[ \t]*<[\/]*[a-z]*[\/]*>([0-9\.]*)<.*$/,"\\1","g",$0); }'
+}
+
+if [ "$1" == "cache" ]; then
+ tinycoreversiondata > $CONFDIR/tcver
else
- echo "skipping"
+ if [ ! -f $CONFDIR/tcver ]; then
+ echo "Caching OpenSSL version"
+ $0 cache
+ else
+ tinycoreversiondata > /tmp/tcver
+ diff /tmp/tcver $CONFDIR/tcver > /dev/null
+ if [ $? -eq 1 ]; then
+ mv /tmp/tcver $CONFDIR/tcver
+ echo "{\"value1\":\"$(cat $CONFDIR/tcver)\"}" | curl -X POST -d ''"$(cat -)"'' -H "Content-type: application/json" https://maker.ifttt.com/trigger/{tcversion}/with/key/$IFTTTKEY
+ else
+ echo "skipping"
+ fi
+ fi
fi