Skip to content

markroyer/python-server-check

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 

Repository files navigation

python-server-check

A simple Python script to see if a server is still alive. If the server does not respond after a specified number of attempts (default: 10), the script will email recipients indicated in the script.

Requirements

The python-server-check program requires Python and some email daemon is installed. On Debian-based systems, Exim4 is a reasonable choice. It can be installed and configured using the following commands.

sudo apt-get install exim4
sudo dpkg-reconfigure exim4-config

Building

No need to build anything. However, you will want to modify the script to send email to the appropriate people. After modifications, just run using the Python interpreter.

Basic Usage

The script can be executed in the following manner.

usage: checkServer.py [-h] [-a ATTEMPTS] [-w WAIT] [-g]
                      host sender [recipients [recipients ...]]

positional arguments:
  host                  host name to verify
  sender                email sender
  recipients            email recipients (default: sender)

optional arguments:
  -h, --help            show this help message and exit
  -a ATTEMPTS, --attempts ATTEMPTS
                        max attempts
  -w WAIT, --wait WAIT  wait time in seconds (default: 20)
  -g, --wget            use wget instead of icmp ping

As an example, invoking the script as

./checkServer.py foo.com a@email.com b@email.com

checks to see if foo.com reachable by ping. If foo.com is not reachable, an email is sent from a@email.com to b@email.com.

If no email recipients are specified, an email is sent to the sender email address.

Using the --wget option allows you to specify an alternative port if icmp traffic is blocked or ignored. Specify the port by appending it to the host name. For example, specify foo.com:8080 would use wget to check for the default page served on port 8080.

Using Cron

If you are using this script, then you probably want to use it with cron.

Typing

crontab -e

at a terminal will allow you to edit the local user's cron job file.

Adding a line such as

*/30 * * * * ~/checkServer.py foo.com a@email.com b@email.com

will check every 30 minutes that the server is still accessible. This assumes that the checkServer.py is placed in your home directory and is executable.

License

The project is licensed under the terms of the GPL3 license.

About

A Python script to see if a server is alive and send an email notification if unresponsive

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages