From 99966645c5398cc4f992c3b62a01aaf33116843b Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Mon, 30 Apr 2018 17:18:36 +0100 Subject: [PATCH] Add server status script --- i3/blocks/serverStatus | 48 ++++++++++++++++++++++++++++++++++++++++++ i3/i3blocks.conf | 29 +++++++++++++++++++++++++ 2 files changed, 77 insertions(+) create mode 100755 i3/blocks/serverStatus diff --git a/i3/blocks/serverStatus b/i3/blocks/serverStatus new file mode 100755 index 00000000..34bce4c2 --- /dev/null +++ b/i3/blocks/serverStatus @@ -0,0 +1,48 @@ +#!/usr/bin/bash + + + +SCRIPTPATH="$( cd "$(dirname "$0")" ; pwd -P )" +source $SCRIPTPATH/servers.private + +checkAllSites(){ + eval server=( \${$1[@]} ) + for site in ${server[@]}; do + printf "%-35s | %s \n" "$site" "$(checkURL $site)" + done +} + +# This function takes 1 parameter, the name of an array in which to check a random URL +checkRandomSite(){ + #The server variable will be equal to whichever server array we are looking at + eval server=( \${$1[@]} ) + random=$(( ( RANDOM % (${#server[@]} - 1) ) + 1 )) + urlToCheck=${server[$random]} + echo $urlToCheck + echo $(checkURL $urlToCheck) +} + +checkURL(){ + responce=$(curl -s --head -w %{http_code} $1 -L -o /dev/null --connect-timeout 60) + echo $responce +} + +if [ ! -z "$1" ]; then + if [ -z "$2" ]; then + checked=$(eval checkRandomSite $1) + checked=(${checked// / }) + #echo ${checked[0]} + #echo ${checked[1]} + echo $1 + echo "" + if [ "${checked[1]}" = "200" ]; then + echo "#00FF00" + else + echo "#FF8000" + fi + elif [ "$2" = "all" ]; then + checkAllSites $1 + fi +else + echo Please specify a server name +fi diff --git a/i3/i3blocks.conf b/i3/i3blocks.conf index 6b329f57..ea115701 100644 --- a/i3/i3blocks.conf +++ b/i3/i3blocks.conf @@ -39,6 +39,35 @@ instance=CAPS interval=once signal=11 +[vps01status] +command=~/.dotfiles/i3/blocks/serverStatus VPS01 +interval=30 +separator=false + +[vps02status] +command=~/.dotfiles/i3/blocks/serverStatus VPS02 +interval=30 +separator=false + +[vps03status] +command=~/.dotfiles/i3/blocks/serverStatus VPS03 +interval=30 +separator=false + +[freightlinerstatus] +command=~/.dotfiles/i3/blocks/serverStatus Freightliner +interval=30 +separator=false + +[nhsstatus] +command=~/.dotfiles/i3/blocks/serverStatus NHS +interval=30 +separator=false + +[vapourtecstatus] +command=~/.dotfiles/i3/blocks/serverStatus Vapourtec +interval=30 + [apachestatus] command=~/.dotfiles/i3/blocks/apache interval=5