Distributed ping and service monitor node using Python + Sanic
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs/REST_API
misc
modules
.gitignore
LICENSE
README.md
app.py
pypatrol.example
routes.py
test.py
utils.py

README.md

pyPatrol

Distributed ping and service monitor using Python3 + Sanic

Getting Started

These instructions will get you a copy of the project up and running on your machine.

Prerequisites

  $ pip3 install sanic "python-valve>=0.2.1" aiohttp requests sanic-openapi

Configuration

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

Installing

  1. Clone the git repo
  $ git clone https://github.com/masonr/pyPatrol
  1. Move the pyPatrol directory to /opt/
  $ mv pyPatrol /opt/
  1. Copy the example configuration file
  $ cp pypatrol.example pypatrol.conf
  1. Configure the pyPatrol node using the parameters described above in the pypatrol.conf file

  2. Run the unittests

  $ cd /opt/pyPatrol
  $ python3 test.py

After running all of the tests for each module, the final output should say - "OK".

How To Run

  1. Navigate to the pyPatrol directory
  $ cd /opt/pyPatrol
  1. Run the Sanic application
  $ python3 app.py

Running As A Service

systemd

  1. Navigate to the misc subdirectory
  $ cd /opt/pyPatrol/misc
  1. 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/
  1. Start the pyPatrol service and verify that it is running correctly
  $ sudo service pypatrol start
  $ sudo service pypatrol status
  1. (Optional) Setup pyPatrol to start on boot
  $ sudo systemctl enable pypatrol

Capabilities / Documentation

REST API Specifications

  • /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