Giter Site home page Giter Site logo

pyhealthchecker's Introduction

PyHealthChecker

PyChecker is a Python 3.7 RESTful health-checker API using Flask, SQLite, and APScheduler.

Usage

  1. Clone this repository or its image;
  2. Follow the instructions below to have it running
  3. Send an HTTP Post to the http://server:port/application following the example:
POST /application HTTP/1.1
Host: localhost:5000
Content-Type: application/json

{
    "name":"My App",
    "check_interval": 20,
    "check_data":{
    	"method":"GET",
        "endpoint":"http://localhost:5000/check",
    	"headers":"",
    	"body":""
    },
    "expected":{
    	"code": "200",
    	"headers":"",
    	"body":""
    },
    "http_notification":{
    	"method":"POST",
    	"headers":{"Content-Type": "application/json","Authorization": "Bearer 12345678901234567890123456789"},
    	"endpoint":"https://some.notification.server",
    	"body":{"service": "${FAILING_SERVICE}","description": "${FAILING_SERVICE_DESCRIPTION}"}
    }
}

This POST will create an application entry, named "My App" and a task to verify it every X seconds, defined in the "check_interval" variable. Our PyHealthCheck then will try to reach "My App" by the means defined in the "check_data" using the response of that call to compare with the "expected" one. If there are more differences between the actual response and the expected data OR the service fails to answer, a notification will be sent over HTTP using the data on the "http_notification".

All other endpoints and its examples are covered in this read.me and the postman collection.

Installation on Dev Environment

Clone this repository and then run use the package manager pip to install it.

pip install -r ./requirements.txt

After packages installation , run ./app.py

python3 run app.py

Running in Docker

Clone this repository and then run:

docker build . -t pyhealthchecker

Once the image has been built, run

docker run -p 5000:5000 pyhealthchecker

Testing

There is a Postman Collection available for local and remote tests

You can also run the ./load.sh to make some initial requests and validations.

On Linux and MacOS environments, you will need to give permissions to the bash file:

chmod +x load.sh 

Now, run the curl initial file

./load.sh

All logs will be written on ./app.log .

Distributing

The docker image of this project is available at Docker Hub and can be pulled and executed independently:

 docker pull schulzwill/pyhealthchecker

Running on K8s

All files necessary are included in the k8s folder of this project.

To deploy this solution in an already existing Kubernetes cluster:

  1. Clone this repository and go to its root folder
  2. Create the namespace:
kubectl create -f ./k8s/ns-pyhealthchecker.yaml 
  1. Create the service for PyHealthChecker Application
kubectl create -f ./k8s/service-pyhealthchecker.yaml 
  1. Deploy it:
kubectl create -f ./k8s/deployment.yaml

To check if it is up and running:

kubectl get deployment pyhealthchecker -n pyhealthchecker

Contributing

Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

License

MIT

pyhealthchecker's People

Contributors

schulzwill avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.