Distributed ping and service monitor using Python3 + Sanic
These instructions will get you a copy of the project up and running on your machine.
-
This project requires Python 3.5+.
-
The following pip packages are also required:
- sanic
- python-valve [v0.2.1 or later]
- aiohttp
- requests
- sanic-openapi
$ pip3 install sanic "python-valve>=0.2.1" aiohttp requests sanic-openapi
Within the pyPatrol config file are several parameters that need to be set:
- node_name - unique name of the pyPatrol node
- node_ip - ip or hostname of the pyPatrol node
- node_port - port that the pyPatrol service will bind to
- bind_protocol - which internet protocol to bind to ('ipv4' or 'ipv6')
- ipv4_capable - pyPatrol node ipv4 capable?
- ipv6_capable - pyPatrol node ipv6 capable?
- num_of_workers - number of async workers
- server_host - ip or hostname of the pyPatrol server
- server_port - port of the pyPatrol server
- server_secret - a secret string that authorizes the pyPatrol node with the server
- standalone - standalone mode or connect to pyPatrol server
- use_ssl - set if SSL (HTTPS) connections should be utilized
- ssl_cert - SSL certificate file path if use_ssl is True
- ssl_key - SSL key file path if use_ssl is True
- Clone the git repo
$ git clone https://github.com/masonr/pyPatrol
- Move the pyPatrol directory to /opt/
$ mv pyPatrol /opt/
- Copy the example configuration file
$ cp pypatrol.example pypatrol.conf
-
Configure the pyPatrol node using the parameters described above in the pypatrol.conf file
-
Run the unittests
$ cd /opt/pyPatrol
$ python3 test.py
After running all of the tests for each module, the final output should say - "OK".
- Navigate to the pyPatrol directory
$ cd /opt/pyPatrol
- Run the Sanic application
$ python3 app.py
- Navigate to the misc subdirectory
$ cd /opt/pyPatrol/misc
- Edit the pypatrol.service file and add the User to run the service as (suggested to be a non-root user). Then, copy the file into the systemd services directory
$ sudo cp pypatrol.service /etc/systemd/system/
- Start the pyPatrol service and verify that it is running correctly
$ sudo service pypatrol start
$ sudo service pypatrol status
- (Optional) Setup pyPatrol to start on boot
$ sudo systemctl enable pypatrol
- /status - Returns status of the pyPatrol node
- /ping - Pings (via IPv4) a specified IP/hostname
- /ping6 - Pings (via IPv6) a specified IP/hostname
- /http_response - Checks the HTTP response code of a given URL
- /cert - Checks if an SSL certificate is valid or will expire within a specified threshold
- /tcp_socket - Checks if a specified IP/hostname and port are listening for connections (TCP)
- /steam_server - Checks if a Steam Server running on a specified IP/hostname and port is online