add release
This commit is contained in:
parent
5901f4b29e
commit
3cef68a538
6 changed files with 421 additions and 1 deletions
82
README.md
82
README.md
|
|
@ -1,2 +1,82 @@
|
|||
# sclimon
|
||||

|
||||
|
||||
# SCLIMON
|
||||
The name sclimon stands for \[**S**\]imple \[**C**\]ommand \[**L**\]ine \[**I**\]nterface \[**Mon**\]itoring.
|
||||
Sclimon is a shell monitoring tool for websites, hosts and SSL certificates written in bash.
|
||||
You just need to drop a config file in the sclimon directory and run the script file in **list** mode or **alarm** mode.
|
||||
It's possible to configure the treshold how often the checks may fail until you get a notification mail.
|
||||
|
||||
## Example
|
||||

|
||||
|
||||
## Installation
|
||||
|
||||
Just clone this repository or download the script file and make it executable<br>
|
||||
|
||||
```
|
||||
$ chmod +x sclimon
|
||||
```
|
||||
and run the script file
|
||||
```
|
||||
./sclimon
|
||||
```
|
||||
|
||||
If you trust this repo and the script file, you can drop it into in your binary directory.
|
||||
```
|
||||
sudo curl sclimon -o /usr/bin/sclimon
|
||||
sudo chmod +x /usr/bin/sclimon
|
||||
```
|
||||
|
||||
and run it from enywhere with `$ sclimon`
|
||||
|
||||
|
||||
## How to configure
|
||||
The default configuration of sclimon is ```$HOME/.config/sclimon/config```. Sclimon will create a empty file, if it doesn't exists, but you must fill it on your own.
|
||||
|
||||
```
|
||||
FROMMAIL="foobar@example.com"
|
||||
MAILSERVER="example.com"
|
||||
PASSWORD="<my secret password>"
|
||||
TOMAIL="monitoring@example.com"
|
||||
DELAY="60"
|
||||
```
|
||||
|
||||
This file will be include by the script and set the mailserver (MAILSERVER) from where the mails should be send (FROMMAIL) to the receiver (TOMAIL). The delay option set in which intervals the checks should be run.
|
||||
|
||||
After the basic configuration you can create under ```$HOME/.config/sclimon/config/``` a text file with a ```.conf``` ending like ```$HOME/.config/sclimon/conf/example.conf```. Every `.conf` file will be included by sclimon and read in a loop. The `.conf` files need the following informations:
|
||||
|
||||
```
|
||||
TITLE="localhost"
|
||||
DOMAIN="example.com"
|
||||
HOST="127.0.0.1"
|
||||
PORT="8000"
|
||||
PROTOCOL="http|https"
|
||||
PATTERN="example"
|
||||
TYPE="Web|Ping|SSL"
|
||||
TRESHOLD="10"
|
||||
```
|
||||
|
||||
**TITLE** set the name in sclimon which will be shown in the interface.<br>
|
||||
**DOMAIN** is needed for the SSL and web check. <br>
|
||||
**HOST** set the IP adress for the ping check.<br>
|
||||
**PORT** The Port is needed for the SSL and web check. The default value is 443. If your Application runs on another port, please set it here.<br>
|
||||
**PROTOCOL** may be http or https. This option must be set for the webcheck and will be combine `PRTOCOL` and `DOMAIN` <br>
|
||||
**PATTERN** for the web check, sclimon will search on `DOMAIN` for a word pattern. If `PATTERN` could not be found, sclimon will mark the check as failed.<br>
|
||||
**TYPE** here you can set which kind of check should be run by sclimon. `WEB` checks on the webpage for a word or sentence from **PATTERN**. `PING` will test if `HOST` is reachable and `SSL` checks `DOMAIN`:`PORT` how long the SSL cert is valid and alarm it expires in less then 8 days or is already expired.<br>
|
||||
**TRESHOLD** set how often the ping and web check may fail, until you get a notification mail of the downtime.<br>
|
||||
|
||||
If the `DELAY` in ```$HOME/.config/sclimon/config``` is set to 60 and the `TRESHOLD` will be set to 5, it will take a check every minute until 5 fails are reached, so you get a notification of a downtime after 5 minutes. The `TRESHOLD` will be reset by a postive test. Please note, if you have a lot configurations this may increase the delay between the checks.
|
||||
|
||||
## run
|
||||
You can run sclimon with one of these options:
|
||||
|
||||
```
|
||||
Usage: check-if-online.sh [options]
|
||||
Options:
|
||||
-l List mode. Show all stats.
|
||||
-a Alarm mode. Show only alarms.
|
||||
-h Show this help page
|
||||
```
|
||||
|
||||
The `List mode` will show all configured checks in ```$HOME/.config/sclimon/conf/```<br>
|
||||
If you run sclimon with `-a` in `Alarm mode`, sclimon will only show failed checks <br>
|
||||
|
|
|
|||
5
config
Normal file
5
config
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
FROMMAIL="foo@example.com"
|
||||
MAILSERVER="example.com"
|
||||
PASSWORD="secret"
|
||||
TOMAIL="bar@example.com"
|
||||
DELAY="10"
|
||||
BIN
demo.gif
Normal file
BIN
demo.gif
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 269 KiB |
327
sclimon
Executable file
327
sclimon
Executable file
|
|
@ -0,0 +1,327 @@
|
|||
#!/bin/bash
|
||||
SCLIMONDIR="$HOME/.config/sclimon"
|
||||
PIDFILE=$HOME/.sclimon.pid
|
||||
|
||||
# Create $HOME-User directories and empty config file
|
||||
mkdir -p $SCLIMONDIR/{conf,flags}
|
||||
touch $SCLIMONDIR/config
|
||||
|
||||
# trap ctrl-c key stroke and call CTRL_C function to exit and clear Shell
|
||||
trap CTRL_C INT
|
||||
|
||||
function CTRL_C() {
|
||||
tput clear
|
||||
tput cnorm
|
||||
rm $PIDFILE
|
||||
exit 0
|
||||
}
|
||||
|
||||
usage()
|
||||
{
|
||||
cat <<EOF
|
||||
Usage: $(basename $0) [options]
|
||||
Options:
|
||||
-a Show all stats
|
||||
-d Show only failed checks
|
||||
-h Show this help page
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
while [ "$1" ]; do
|
||||
case "$1" in
|
||||
-a)
|
||||
shift
|
||||
file="$1"
|
||||
source="all"
|
||||
;;
|
||||
-d)
|
||||
shift
|
||||
host="$1"
|
||||
source="dashboard"
|
||||
;;
|
||||
-h)
|
||||
usage
|
||||
exit 0
|
||||
;;
|
||||
*)
|
||||
echo "see --help for usage"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
shift
|
||||
done
|
||||
|
||||
# Path to default configuration file
|
||||
source $SCLIMONDIR/config
|
||||
|
||||
# Text formating options
|
||||
padding=" "
|
||||
TXTYELLOW=$(tput setaf 3)
|
||||
TXTGREEN=$(tput setaf 2)
|
||||
TXTRED=$(tput setaf 1)
|
||||
TXTNORMAL=$(tput sgr0)
|
||||
TXTBLINK=$(tput blink)
|
||||
TXTBOLD=$(tput bold)
|
||||
TXTDIM=$(tput dim)
|
||||
|
||||
# Mail credentials from configuration file 'config'
|
||||
CREDENTIALS=$(echo -ne "\0$FROMMAIL\0$PASSWORD" | base64 | awk '{printf "AUTH PLAIN "$0}')
|
||||
LOGIN="$SCLIMONDIR/login.tmp"
|
||||
|
||||
# Sendmail via openssl client from $FROMMAIL to $TOMAIL from the configuration file 'config'
|
||||
SENDMAIL()
|
||||
{
|
||||
openssl s_client -brief -tls1_2 -connect $MAILSERVER:465 < $LOGIN
|
||||
}
|
||||
|
||||
# URL Check for *.conf files in conf/ with 'Web' TYPE
|
||||
URLCHECK() {
|
||||
curl -iL --silent "$PROTOCOL://$DOMAIN:$PORT" | grep -c "$PATTERN";
|
||||
}
|
||||
|
||||
PINGCHECK() {
|
||||
ping -c 1 $HOST &> /dev/null && echo 1 || echo 0
|
||||
}
|
||||
|
||||
SSLCHECK() {
|
||||
echo | openssl s_client -connect $DOMAIN:$PORT -servername $DOMAIN 2>/dev/null | openssl x509 -noout -text -certopt no_header,no_version,no_serial,no_signame,no_pubkey,no_sigdump,no_aux | grep Not\ After\ :| sed -e 's/.* : //g' -e 's/GMT//g';
|
||||
}
|
||||
|
||||
PINGCHECKPO() {
|
||||
printf "${TXTDIM}%s%s%s%s %s\n" "$TITLE" "${padding:${#TITLE}}" "${TXTBOLD}${TXTGREEN}[UP] ${TXTNORMAL}" "${padding:${#HEADLINE2}}" "$TYPE "
|
||||
if [ -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
rm "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
fi
|
||||
}
|
||||
|
||||
PINGCHECKNE() {
|
||||
printf "%s%s%s%s %s\n" "$TITLE" "${padding:${#TITLE}}" "${TXTBOLD}${TXTBLINK}${TXTRED}[DOWN]${TXTNORMAL}" "${padding:${#HEADLINE2}}" "$TYPE "
|
||||
if [ ! -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
touch "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
elif [ -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
if [[ $(wc -l < $SCLIMONDIR/flags/$TITLE.ALARM.flag) -lt $TRESHOLD ]]; then
|
||||
date >> $SCLIMONDIR/flags/$TITLE.ALARM.flag
|
||||
elif [[ $(wc -l < $SCLIMONDIR/flags/$TITLE.ALARM.flag) -eq $TRESHOLD ]]; then
|
||||
date >> $SCLIMONDIR/flags/$TITLE.ALARM.flag
|
||||
echo $CREDENTIALS > "$SCLIMONDIR/login.tmp"
|
||||
cat <<EOF >> "$SCLIMONDIR/login.tmp"
|
||||
MAIL FROM: $FROMMAIL
|
||||
rcpt to: $TOMAIL
|
||||
DATA
|
||||
From: $FROMMAIL
|
||||
Subject: [Monitoring] 🚨🚨🚨 Alarm $TITLE is down
|
||||
|
||||
FYI: $TITLE is down since $(head -n 1 "$SCLIMONDIR/flags/$TITLE.ALARM.flag")
|
||||
.
|
||||
QUIT
|
||||
EOF
|
||||
SENDMAIL 2&>1 >/dev/null
|
||||
rm "$SCLIMONDIR/login.tmp"
|
||||
elif [[ $(wc -l < $SCLIMONDIR/flags/$TITLE.ALARM.flag) -gt $TRESHOLD ]]; then
|
||||
:
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
WEBCHECKPO() {
|
||||
printf "${TXTDIM}%-20s%-36s%s%s %s\n" "$(echo $TITLE| cut -c1-20)" "${TXTBOLD}${TXTGREEN}[UP] ${TXTNORMAL}" "$TYPE "
|
||||
if [ -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
rm "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
fi
|
||||
}
|
||||
|
||||
WEBCHECKNE() {
|
||||
printf "${TXTDIM}%-20s%-40s%s%s %s\n" "$(echo $TITLE| cut -c1-20)" "${TXTBOLD}${TXTBLINK}${TXTRED}[DOWN]${TXTNORMAL}" "$TYPE "
|
||||
if [ ! -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
touch "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
elif [ -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
if [[ $(wc -l < $SCLIMONDIR/flags/$TITLE.ALARM.flag) -lt $TRESHOLD ]]; then
|
||||
date >> $SCLIMONDIR/flags/$TITLE.ALARM.flag
|
||||
elif [[ $(wc -l < $SCLIMONDIR/flags/$TITLE.ALARM.flag) -eq $TRESHOLD ]]; then
|
||||
date >> $SCLIMONDIR/flags/$TITLE.ALARM.flag
|
||||
echo $CREDENTIALS > "$SCLIMONDIR/login.tmp"
|
||||
cat <<EOF >> "$SCLIMONDIR/login.tmp"
|
||||
MAIL FROM: $FROMMAIL
|
||||
rcpt to: $TOMAIL
|
||||
DATA
|
||||
From: $FROMMAIL
|
||||
Subject: [Monitoring] 🚨🚨🚨 Alarm $TITLE is down
|
||||
|
||||
FYI: $TITLE is down since $(date)
|
||||
.
|
||||
QUIT
|
||||
EOF
|
||||
SENDMAIL 2&>1 >/dev/null
|
||||
rm "$SCLIMONDIR/login.tmp"
|
||||
elif [[ $(wc -l < $SCLIMONDIR/flags/$TITLE.ALARM.flag) -gt $TRESHOLD ]]; then
|
||||
:
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
SSLMAILWARN() {
|
||||
echo $CREDENTIALS > "$SCLIMONDIR/login.tmp"
|
||||
cat <<EOF >> "$SCLIMONDIR/login.tmp"
|
||||
MAIL FROM: $FROMMAIL
|
||||
rcpt to: $TOMAIL
|
||||
DATA
|
||||
From: $FROMMAIL
|
||||
Subject: [Monitoring] 🚨🚨🚨 Alarm CERT for $TITLE will expire
|
||||
|
||||
FYI: SSL Cert for $TITLE will expire in less than 8 days.
|
||||
.
|
||||
QUIT
|
||||
EOF
|
||||
SENDMAIL 2&>1 >/dev/null
|
||||
rm "$SCLIMONDIR/login.tmp"
|
||||
}
|
||||
|
||||
SSLMAILALARM() {
|
||||
echo $CREDENTIALS > "$SCLIMONDIR/login.tmp"
|
||||
cat <<EOF >> "$SCLIMONDIR/login.tmp"
|
||||
MAIL FROM: $FROMMAIL
|
||||
rcpt to: $TOMAIL
|
||||
DATA
|
||||
From: $FROMMAIL
|
||||
Subject: [Monitoring] 🚨🚨🚨 Alarm CERT for $TITLE is expired
|
||||
|
||||
FYI: SSL Cert for $TITLE is expired!
|
||||
.
|
||||
QUIT
|
||||
EOF
|
||||
SENDMAIL 2&>1 >/dev/null
|
||||
rm "$SCLIMONDIR/login.tmp"
|
||||
}
|
||||
# create Headline, run checks and format output to [HOST] [STATUS] [TYPE]. If check failed send email from mailbox in configured in config FROMMAIL to mailbox TOMAIL
|
||||
COMMAND() {
|
||||
HEADLINE1="HOST"
|
||||
HEADLINE2="STATUS"
|
||||
printf "%s%s%s%s %s\n" "$HEADLINE1" "${padding:${#HEADLINE1}}" "$HEADLINE2" "${padding:${#HEADLINE2}}" "TYPE"
|
||||
printf %"$COLUMNS"s |tr " " "-"
|
||||
|
||||
for i in $SCLIMONDIR/conf/*.conf; do
|
||||
source $i
|
||||
|
||||
if [ "$TYPE" == "Web" ]; then
|
||||
if [ "$source" == "all" ]; then
|
||||
if [ $(URLCHECK) == "1" ]; then
|
||||
WEBCHECKPO
|
||||
else
|
||||
WEBCHECKNE
|
||||
fi
|
||||
elif [ "$source" == "dashboard" ]; then
|
||||
if [ $(URLCHECK) == "1" ]; then
|
||||
if [ -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
rm "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
tput clear
|
||||
|
||||
fi
|
||||
else
|
||||
WEBCHECKNE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
if [ "$TYPE" == "Ping" ]; then
|
||||
if [ "$source" == "all" ]; then
|
||||
if [ $(PINGCHECK) == "1" ]; then
|
||||
PINGCHECKPO
|
||||
else
|
||||
PINGCHECKNE
|
||||
fi
|
||||
elif [ "$source" == "dashboard" ]; then
|
||||
if [ $(PINGCHECK) == "1" ]; then
|
||||
if [ -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
rm "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
tput clear
|
||||
fi
|
||||
else
|
||||
PINGCHECKNE
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$TYPE" == "SSL" ]; then
|
||||
EXPIRATION=$(echo $(( ($(date -d "$(SSLCHECK)" "+%s") - $(date +%s) )/(60*60*24) )) )
|
||||
if [ "$EXPIRATION" -le "1" ]; then
|
||||
EXPCHECK="3"
|
||||
elif [ "$EXPIRATION" -le "7" ]; then
|
||||
EXPCHECK="2"
|
||||
elif [ "$EXPIRATION" -ge "7" ]; then
|
||||
EXPCHECK="1"
|
||||
fi
|
||||
|
||||
if [ "$EXPCHECK" == "1" -a "$source" == "all" ]; then
|
||||
printf "${TXTDIM}%-20s%-36s%s%s %s\n" "$(echo $TITLE| cut -c1-20)" "${TXTBOLD}${TXTGREEN}[OK] ${TXTNORMAL}" "$TYPE "
|
||||
if [[ -f $SCLIMONDIR/flags/$TITLE.ALARM.flag || -f $SCLIMONDIR/flags/$TITLE.WARN.flag ]]; then
|
||||
rm "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
rm "$SCLIMONDIR/flags/$TITLE.WARN.flag"
|
||||
fi
|
||||
|
||||
elif [ "$EXPCHECK" == "2" ]; then
|
||||
printf "${TXTDIM}%-20s%-36s%s%s %s\n" "$(echo $TITLE| cut -c1-20)" "${TXTBOLD}${TXTYELLOW}[EXPIRES IN "$EXPIRATION"d] ${TXTNORMAL}" "$TYPE "
|
||||
if [ ! -f $SCLIMONDIR/flags/$TITLE.WARN.flag ]; then
|
||||
SSLMAILWARN
|
||||
fi
|
||||
touch "$SCLIMONDIR/flags/$TITLE.WARN.flag"
|
||||
|
||||
elif [ "$EXPCHECK" == "3" ]; then
|
||||
printf "%-20s%-40s%s%s %s\n" "$(echo $TITLE| cut -c1-20)" "${TXTBOLD}${TXTBLINK}${TXTRED}[EXPIRED]${TXTNORMAL}" "$TYPE "
|
||||
if [ ! -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
SSLMAILALARM
|
||||
fi
|
||||
touch "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
elif [ "$EXPCHECK" == "1" -a "$source" == "dashboard" ]; then
|
||||
if [ -f $SCLIMONDIR/flags/$TITLE.ALARM.flag ]; then
|
||||
rm "$SCLIMONDIR/flags/$TITLE.ALARM.flag"
|
||||
tput clear
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
done | sed -e 's/^.*\[DOWN/0&/' -e 's/^.*\[EXPIRED/0&/' -e t -e 's/^.*EXPIRES/1&/' -e 's/^.*\[GOOD/3&/' -e 't' -e 's/^/2/' | sort | sed 's/^.//'
|
||||
}
|
||||
|
||||
# Create PID File and check if process is running. In case Sclimon is already running show messages and exit.
|
||||
if [ -f $PIDFILE ]; then
|
||||
PID=$(cat $PIDFILE)
|
||||
ps -p $PID > /dev/null 2>&1
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Sclimon already running. Quit Sclimon or delete $PIDFILE"
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo $$ > $PIDFILE
|
||||
fi
|
||||
|
||||
# Check if the config file exists and Options are set. Delay will be default set to 10s if nothing is configured.
|
||||
# Also check if mail config are set and inform before start.
|
||||
# After the starup check run the monitoring tool in a loop and check again after the delay time.
|
||||
if [ ! -f $HOME/.config/sclimon/config ]; then
|
||||
echo -e "There is no $HOME/.config/sclimon/config file.\nPlease create config file and set options."
|
||||
else
|
||||
if [ -z "$DELAY" ]; then
|
||||
DELAY="10"
|
||||
fi
|
||||
if [ -z "$TRESHOLD" ]; then
|
||||
TRESHOLD="5"
|
||||
fi
|
||||
if [[ -z "$FROMMAIL" || -z "$MAILSERVER" || -z "$PASSWORD" || -z "$TOMAIL" ]]; then
|
||||
echo -e "Mail cofiguration are not set in $HOME/.config/sclimon/config.\nPlease set FROMMAIL, MAILSERVER, PASSWORD, TOMAIL to be informed about of downtimes.\nMonitoring will start in 10 seconds."
|
||||
sleep 10;
|
||||
fi
|
||||
if [ ! -f $SCLIMONDIR/conf/*.conf ]; then
|
||||
echo -e "There are no config files in $SCLIMONDIR/conf.\nPlease create a <name>.conf to be loaded."
|
||||
exit 0
|
||||
fi
|
||||
tput clear
|
||||
tput civis
|
||||
while true; do
|
||||
tput cup 0 0
|
||||
COMMAND
|
||||
sleep $DELAY
|
||||
done
|
||||
fi
|
||||
fi
|
||||
BIN
sclimon.png
Normal file
BIN
sclimon.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 87 KiB |
8
template-web.conf
Normal file
8
template-web.conf
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
TITLE="localhost"
|
||||
DOMAIN="localhost"
|
||||
HOST="127.0.0.1"
|
||||
PORT="8000"
|
||||
PROTOCOL="http"
|
||||
PATTERN="Foobar"
|
||||
TYPE="Web|Ping|SSL"
|
||||
TRESHOLD="10"
|
||||
Loading…
Add table
Add a link
Reference in a new issue