• Stars
    star
    573
  • Rank 77,865 (Top 2 %)
  • Language
    Shell
  • License
    GNU Affero Genera...
  • Created almost 4 years ago
  • Updated over 3 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

HTTP(s) monitoring webpage via shell script

bash-http-monitoring

all is well image

HTTP(s) status dashboard webpage via shell script. Parallel checking, thus very fast, only dependencies are curl, coreutils and bash (version 4 or above). For all of you who want a simple script with a nice webpage to check a few websites. Perfect for a wall mounted monitoring display and a Raspberry Pi.

Installation and configuration is easy to do inside the script. It scales well, both on the checking side as the information display page (dense on purpose). Failed checks appear right on top for you to act on.

You can set an expected status code and a max timeout per check, so if you consider your site up when it returns a 302 (redirect) or 401 (unauthorized) the script consider that okay. If the status code is not what is configured or there is a timeout or another error, the script considers the check failed.

If a check fails, the script will check that specific one again after 5 seconds to prevent flapping.

Author: Remy van Elst

Website with more information

What this does not have:

  • Notifications
  • History

There however is the option to set a callback_url, whenever a check fails the script will send the status to that URL, allowing you to set up your own history logging or alerting.

Changelog

  • 27-12-2020: Initial release
  • 30-12-2020: Added cgi-bin/docker support
  • 11-01-2021: Added callback URL for failed checks

Installation & Configuration

Make sure you have curl installed (apt install curl). If you need a very simple webserver, try micro-httpd, by ACME. (apt install micro-httpd).

Clone the git repository:

git clone https://github.com/RaymiiOrg/bash-http-monitoring.git
cd bash-http-monitoring

Edit the srvmon script and add your sites. A few examples are provided. This is the syntax:

urls[gists]="https://gist.github.com"
urls[lobsters]="https://lobste.rs"
urls[raymii.org]="https://raymii.org"
urls[example]="http://example.org:3000/this/is/a/test"

The first part between the square brackets is the name, the second part between the quotes is the URL you want to monitor. It can be just a domain, an IP or an actual URL, including port and such.

If you want to override the default status code for a check, this is the syntax:

statuscode[gists]=302

The first part between the square brackets must match the urls[] part.

Further global configuration options include:

maxConcurrentCurls=12 # How many curl checks to run at the same time
defaultTimeOut=10 # Max timeout of a check in seconds
flapRetry=5 # After how many seconds should we re-check any failed checks? (To prevent flapping)
title="Status Dashboard" # Title of the webpage 
cgi=false # Enable or disable CGI header
callbackURL="" # leave empty to disable, otherwise see readme

Execute the script and send the output to a file in your webservers documentroot:

bash srvmon > /var/www/index.html

View that file in a web browser.

OS X specifics

On Mac OS X the builtin bash version is too old and the bsd date utility does not support the time in milliseconds option, so you have to use homebrew to install coreutils and bash:

brew install bash coreutils curl

Then you have to run the script with that bash version:

/usr/local/Cellar/bash/#VERSION#/bin/bash

Also in the cronjob if you choose to set that up.

Cronjob setup

If you want to set up a cronjob, send the output to a temp file and when finished, move that temp file over the "actual" file. Otherwise you might end up with an incomplete page when the checks are running. Like so:

* * * * * /bin/bash /opt/srvmon/srvmon > /var/www/index.html.tmp && /bin/mv /var/www/index.html.tmp /var/www/index.html

If the check fails for whatever reason, the "old" page will not be overridden.

CGI header

Some HTTP servers, like Apache, support CGI scripts. To make it brief, these are scripts which are handed a HTTP request to reply to.

The main advantage of using the script as a CGI script, is that the page is generated on demand and as such, provides a live-view on each page load.
If the page is public, this method should be avoided, as it can be easily abused.

If you want to set up CGI mode, you need to copy the script to your server CGI directory. You can use docker to try this out. Like so:

docker run -d -p 9090:80 -v $PWD/srvmon:/usr/local/apache2/cgi-bin/srvmon hypoport/httpd-cgi

Callback URL

This script does not provide other means of alerting or history. If you do want that, you must do a bit of work yourself. The script supports a callback url, whenever a check failed, it will do a POST request to a configurable URL with the status and error. This allows you to setup logging, history, graphs or otherwise alerting yourself. No examples are provided as of yet but feel free to open a merge request.

The JSON sent is in the following format:

{
	"url": "The configured URL, URL encoded",
	"name": "The configured name"
	"expected_status": "The configured expected status code", // as a string
	"actual_status": "The actual status code", // as a string
	"error": "descriptive error text (from curl mostly)"
} 

It also supports slack webhooks. See here on the Slack site how to set up a webhook. The callback URL looks like this:

https://hooks.slack.com/services/T00000000/B00000000/XXXXXXXXXXXXXXXXXXXXXXXX

When the callback URL contains hooks.slack.com, the JSON sent is formatted to match slack's webhook specification.

Each failed check results in its own request. No bundling is done.

You can use HTTPbin to test locally. HTTPbin is a so called echo server, anything that is sent to it is returned for debugging purposes. Set this in the config:

callbackURL="http://127.0.0.1:8888/post/"

Run httpbin in a local docker:

docker run -p 8888:80 kennethreitz/httpbin

Configure some failed checks, either a non matching status code or a non-existing domain:

Example json data:

{
	"url": "https%3A%2F%2Fgist.github.com",
	"name": "gist.github.com",
	"expected_status": "309",
	"actual_status": "302",
	"error": "Status code does not match expected code"
} 

Another example:

{
	"url": "https%3A%2F%2Fwww.buiekjhkjhkhkhkjhnradar.nl",
	"name": "www.buienradar.nl",
	"expected_status": "200",
	"actual_status": "000",
	"error": "curl: (6) Could not resolve host: www.buiekjhkjhkhkhkjhnradar.nl"
}

Screenshots

All checks are okay:

all is well image

A check has failed:

failed checks

Here is how it looks with many hosts (also note how fast it executes, 6 seconds):

many hosts

This is what the early version looked like:

beta

I had this script running at home for at least a year in that form, when I showed it to a friend he liked it, asked me to make it public, but before I did that I polished it up a bit.

More Repositories

1

ssl-decoder

Simple PHP script which decodes an SSL connection and displays the information.
PHP
449
star
2

certificate-expiry-monitor

https://certificatemonitor.org
PHP
432
star
3

NoPriv

NoPriv.py is a python script to backup any IMAP capable email account to a HTML archive, nicely browsable, instead of weird folders (Maildir), one huge file (mbox), only needing a web browser to view (thunderbird) and no propritary code, so you can make sure I don't steal your password.
Python
344
star
4

cipherli.st

Ciplerli.st - strong ciphers for NGINX, Apache and Lighttpd
HTML
315
star
5

ansible

My ansible playbooks
PHP
175
star
6

confluence-python-cli

A simple python script for interaction with a Atlassian Confluence Wiki
Python
121
star
7

simple-nagios-dashboard

Simple PHP 5 Nagios Dashboard.
PHP
57
star
8

to-text.py

Convert URL or RSS feed to text with readability
Python
49
star
9

ansible-vmware

Simple python script which uses PySphere to fill the Ansible inventory from VMWare vCenter.
Python
45
star
10

CertInfo

Which Root Certificates should you trust?
C++
42
star
11

openssl-modern-cpp

Examples showing OpenSSL C API usage with Modern C++ (smart pointers, RAII)
C++
39
star
12

cpp-qr-to-png

A bridge between two great libraries, QR-Code-Generator and Tiny-PNG-Out.
C++
31
star
13

boa-diminish-restricted-shell

A shell where you whitelist commands and only those commands can be executed. Either via ssh, as an interactive shell or launched with commands. Logs everything and escapes "dangerous" characters.
Python
24
star
14

nagios

My Nagios scripts and configs
Shell
20
star
15

restrict_ssh

This bash script restricts ssh to a set of commands via .ssh/authorized_keys
Shell
18
star
16

cpp-command-output

Execute commands and get exit status and stdout
C++
16
star
17

c_ookieclicker

c++ console cookie clicker (linux)
C++
15
star
18

raymiiorg.github.io

Raymii.org
HTML
14
star
19

librenms-api-alerts

Python script to talk to LibreNMS API and get alerts and hosts
Python
9
star
20

securecrt-arch-linux

VanDyke SecureCRT PKGBUILD for Arch Linux
Shell
9
star
21

qml-cpp-integration-example

QML
7
star
22

ScreenSaverStopper

Stop system from going to screensaver by sending F24 keystroke every 40 seconds.
C++
7
star
23

nutsmanager

Power/Water/Gas overview manager written in PHP/JSON
JavaScript
6
star
24

openstack-nova-snapshot

Easy OpenStack Nova snapshots from inside instances
Shell
5
star
25

rasplayer-fm

https://raymii.org/s/articles/Raspberry_Pi_FM_Radio_With_Buttons.html
C
5
star
26

ponify.nl

Lock your workstation or spread the Pony love!
Shell
4
star
27

browsa

Little Python script which browses random websites, to make it harder for spying entities to extract data points and signals from monitoring.
Python
4
star
28

log_vcs

Ansible callback plugin that creates a VCS branch every time you run Ansible. If you ever need to go back to a certain state or environment, check out that branch and be sure nothing has changed.
Python
4
star
29

lobsters-hn-post-compare

Hacker News vs Lobste.rs in C++, an exercise in parsing json http api's and date/time/timezones
C++
4
star
30

apt-update-mailer

This is a bash script which can be ran from a cronjob. It mails which packages can be updated, the current version you have installed, the version you are updating to and an URL to the Ubuntu package archive with more info on the update.
Shell
4
star
31

marktplaats-parser-with-filter

Marktplaats parser with filters
Python
3
star
32

CloudVPS-Boss

https://www.cloudvps.nl/blog/cloudvps-boss-linux-backup-naar-object-store
Shell
3
star
33

munin-plugins

My Munin Plugins, who doens't like nice graphs?
Shell
3
star
34

bind-gnuplot-reports

A very simple script which uses GNUplot to create graphs of Bind Query logs.
3
star
35

hash-check-mail

check-file.py - Python script to monitor a file for changes and then mail the report with the file attached.
Python
3
star
36

qt-http-get-request-qml-cpp

Example Qt code showing HTTP get request in C++ and Qml
C++
3
star
37

ansible-openstack-horizon-dashboard

Installs Horizon on Ubuntu
2
star
38

ckermit-snap

Snap package of Ubuntu 18.04's version of ckermit, because 20.04 repo doesn't have ckermit
Shell
2
star
39

QtQrcSourceCodeToDisk

Embed the source code directly in your application
C++
2
star
40

pygopherdstats

Simple log analyzer for pygopherd. Fun if you have a gopherhole and want statistics.
Shell
2
star
41

qml-responsive-layout-example

QML
2
star
42

WeatherTerminalPart1

QML
1
star
43

Win10KDESplashScreen

Windows 10 KDE Splash Screen
QML
1
star
44

qml_cpp_signal_example

QML
1
star
45

YouLessQt

Helpt de YouLess energiemeter goed op de analoge (draaischijf) meter plakken
QML
1
star
46

openscad

OpenSCAD
1
star
47

cookienumberprinter

C++ class to print idle / incremental style numbers.
C++
1
star