<commit_before># gopatrol

[![Go Report Card](https://goreportcard.com/badge/github.com/AdhityaRamadhanus/gopatrol)](https://goreportcard.com/report/github.com/AdhityaRamadhanus/gopatrol)  

self-hosted endpoint monitoring daemon and status pages based on https://github.com/sourcegraph/checkup

<p>
  <a href="#installation">Installation |</a>
  <a href="#setting-up-gopatrol-with-fs">Setting FS |</a>
    <a href="#setting-up-gopatrol-with-s3">Setting S3 |</a>
  <a href="#setting-endpoints">Setting Endpoints |</a>
  <a href="#notifier-slack">Notifier |</a>
  <a href="#licenses">License</a>
  <br><br>
  <blockquote>
	gopatrol is self-hosted health checks and status pages, written in Go using checkup (instead of using them as dependency i decide to copy the file to this project) and grpc as backend.

  There is much work to do for this project to be complete. Use it carefully.

  gopatrol currently supports:

  - Checking HTTP endpoints
  - Checking TCP endpoints (TLS supported)
  - Checking of DNS services & record existence  
  - Storing results on S3 and local filesystem
  - Add and delete endpoints on the fly, you don't need to change the config file everytime you decide to add/delete an endpoint
  - Easy to setup and deploy minimalist status page (100% static)
  - Get notified via slack and email (soon)
  </blockquote>
</p>

Installation
----------- 
* git clone
* make
```bash
NAME:
   gopatrol-cli - Checkup server cli 

USAGE:
   gopatrol-cli [global options] command [command options] [arguments...]

VERSION:
   1.0.0

AUTHOR:
   <NAME> <<EMAIL>>

COMMANDS:
     add-http  Add endpoints to checkup
     add-tcp   Add tcp endpoints to checkup
     check     list and check endpoints
     list      list endpoint
     delete    delete endpoint
     help, h   Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version
```

```bash
NAME:
   gopatrol - gopatrol daemon 

USAGE:
   gopatrol [global options] command [command options] [arguments...]

VERSION:
   1.0.0

AUTHOR:
   <NAME> <<EMAIL>>

COMMANDS:
     setup    Setup statuspage
     daemon        run daemon
     help, h       Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version
```

### Setting up gopatrol with FS
All you need to do is setup configuration for daemon and status page

1. **Daemon Setup**
  ```bash
  $ gopatrol setup fs --url=<url to serve the page, with port ex: localhost:80, mycheckup.com:80>
  ```

  It will create three directories called caddy_config, checkup_config and statuspage. 

```
  └───statuspage
      └───css
          |   style.css
          |
      └───js
          |   app.min.js
          |
      └───images
          |
          |   ...
      └───logs
          |   ...
      |   index.html
      |
  └───caddy_config
      └───logs
          |   
          |   ...
      └───errors
          |   
          |   ...
      |   Caddyfile
      |
  └───checkup_config
      |   checkup.json
      |
  
```
  caddy_config contains Caddyfile, logs and errors folder for caddy webserver
  checkup_config contains checkup.json
  statuspage contains the status page web app

  Example of fs storage checkup.json generated by cli 
  ```json
  {
    "checkers": [],
    "storage": {
      "provider": "fs",
      "dir": "statuspage/logs/"
    }
  }
  ```

### Setting up gopatrol with S3
First you need S3 bucket for this and setting privileges for this bucket, unfortunately gopatrol doesn't support automatic provisioning like checkup so you have to do manual provision https://github.com/sourcegraph/checkup/wiki/Provisioning-S3-Manually

Then, just like with the FS, you need to setup configuration for daemon and status page
```bash
$ gopatrol setup s3 --i=<s3 AccessKeyID> --k=<s3 SecretKey> --r=<s3 Region> --b=<s3 Bucket Name> --url=<url to serve the page, with port ex: localhost:80, mycheckup.com:80>
```
It will create three directories called caddy_config, checkup_config and statuspage. 

```
  └───statuspage
      └───css
          |   style.css
          |
      └───js
          |   app.min.js
          |
      └───images
          |
          |   ...
      └───logs
          |   ...
      |   index.html
      |
  └───caddy_config
      └───logs
          |   
          |   ...
      └───errors
          |   
          |   ...
      |   Caddyfile
      |
  └───checkup_config
      |   checkup.json
      |
  
```
  caddy_config contains Caddyfile, logs and errors folder for caddy webserver
  checkup_config contains checkup.json
  statuspage contains the status page web app

  Example of s3 checkup.json generated by cli 
  ```json
  {
    "checkers":[],
    "storage": {
      "provider": "s3",
      "access_key_id": "<yours>",
      "secret_access_key": "<yours>",
      "bucket": "<yours>",
      "region": "us-east-1"
    }
  }
  ```

Running Daemon
---------------
```bash
$ gopatrol daemon
```

Serve Status Page
---------------
```bash
docker-compose up
```
![checkup](https://cloud.githubusercontent.com/assets/5761975/25096466/888ca154-23ca-11e7-910d-59be4c610989.png)

Setting Endpoints
----------------
You can manually add endpoints to the generated checkup.json (see Setting up gopatrol with FS or S3)

Example of such configuration

```json
{
	"checkers": [{<commit_msg>update readme for statuspage<commit_after># gopatrol

[![Go Report Card](https://goreportcard.com/badge/github.com/AdhityaRamadhanus/gopatrol)](https://goreportcard.com/report/github.com/AdhityaRamadhanus/gopatrol)  

self-hosted endpoint monitoring daemon and status pages based on https://github.com/sourcegraph/checkup

<p>
  <a href="#installation">Installation |</a>
  <a href="#setting-up-gopatrol-with-fs">Setting FS |</a>
    <a href="#setting-up-gopatrol-with-s3">Setting S3 |</a>
  <a href="#setting-endpoints">Setting Endpoints |</a>
  <a href="#notifier-slack">Notifier |</a>
  <a href="#licenses">License</a>
  <br><br>
  <blockquote>
	gopatrol is self-hosted health checks and status pages, written in Go using checkup (instead of using them as dependency i decide to copy the file to this project) and grpc as backend.

  There is much work to do for this project to be complete. Use it carefully.

  gopatrol currently supports:

  - Checking HTTP endpoints
  - Checking TCP endpoints (TLS supported)
  - Checking of DNS services & record existence  
  - Storing results on S3 and local filesystem
  - Add and delete endpoints on the fly, you don't need to change the config file everytime you decide to add/delete an endpoint
  - Easy to setup and deploy minimalist status page (100% static)
  - Get notified via slack and email (soon)
  </blockquote>
</p>

Installation
----------- 
* git clone
* make
```bash
NAME:
   gopatrol-cli - Checkup server cli 

USAGE:
   gopatrol-cli [global options] command [command options] [arguments...]

VERSION:
   1.0.0

AUTHOR:
   <NAME> <<EMAIL>>

COMMANDS:
     add-http  Add endpoints to checkup
     add-tcp   Add tcp endpoints to checkup
     check     list and check endpoints
     list      list endpoint
     delete    delete endpoint
     help, h   Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version
```

```bash
NAME:
   gopatrol - gopatrol daemon 

USAGE:
   gopatrol [global options] command [command options] [arguments...]

VERSION:
   1.0.0

AUTHOR:
   <NAME> <<EMAIL>>

COMMANDS:
     daemon       run daemon
     tls-daemon   run tls daemon
     setup        Setup Daemon and create status page
     status-page  Serve status page
     help, h      Shows a list of commands or help for one command

GLOBAL OPTIONS:
   --help, -h     show help
   --version, -v  print the version
```

### Setting up gopatrol with FS
All you need to do is setup configuration for daemon and status page

1. **Daemon Setup**
  ```bash
  $ gopatrol setup fs --url=<url to serve the page, with port ex: localhost:80, mycheckup.com:80>
  ```

  It will create three directories called caddy_config, checkup_config and statuspage. 

```
  └───statuspage
      └───css
          |   style.css
          |
      └───js
          |   app.min.js
          |
      └───images
          |
          |   ...
      └───logs
          |   ...
      |   index.html
      |
  └───caddy_config
      └───logs
          |   
          |   ...
      └───errors
          |   
          |   ...
      |   Caddyfile
      |
  └───checkup_config
      |   checkup.json
      |
  
```
  caddy_config contains Caddyfile, logs and errors folder for caddy webserver
  checkup_config contains checkup.json
  statuspage contains the status page web app

  Example of fs storage checkup.json generated by cli 
  ```json
  {
    "checkers": [],
    "storage": {
      "provider": "fs",
      "dir": "statuspage/logs/"
    }
  }
  ```

### Setting up gopatrol with S3
First you need S3 bucket for this and setting privileges for this bucket, unfortunately gopatrol doesn't support automatic provisioning like checkup so you have to do manual provision https://github.com/sourcegraph/checkup/wiki/Provisioning-S3-Manually

Then, just like with the FS, you need to setup configuration for daemon and status page
```bash
$ gopatrol setup s3 --i=<s3 AccessKeyID> --k=<s3 SecretKey> --r=<s3 Region> --b=<s3 Bucket Name> --url=<url to serve the page, with port ex: localhost:80, mycheckup.com:80>
```
It will create three directories called caddy_config, checkup_config and statuspage. 

```
  └───statuspage
      └───css
          |   style.css
          |
      └───js
          |   app.min.js
          |
      └───images
          |
          |   ...
      └───logs
          |   ...
      |   index.html
      |
  └───caddy_config
      └───logs
          |   
          |   ...
      └───errors
          |   
          |   ...
      |   Caddyfile
      |
  └───checkup_config
      |   checkup.json
      |
  
```
  caddy_config contains Caddyfile, logs and errors folder for caddy webserver
  checkup_config contains checkup.json
  statuspage contains the status page web app

  Example of s3 checkup.json generated by cli 
  ```json
  {
    "checkers":[],
    "storage": {
      "provider": "s3",
      "access_key_id": "<yours>",
      "secret_access_key": "<yours>",
      "bucket": "<yours>",
      "region": "us-east-1"
    }
  }
  ```

Running Daemon
---------------
```bash
$ gopatrol daemon 10s
```

Serve Status Page
---------------
```bash
$ gopatrol status-page --config=<Path to caddyfile, default to caddy_config/Caddyfile> 
```
![checkup](https://cloud.githubusercontent.com/assets/5761975/25096466/888ca154-23ca-11e7-910d-59be4c610989.png)

Setting Endpoints
----------------
You can manually add endpoints to the generated checkup.json (see Setting up gopatrol with FS or S3)

Example of such configuration

```json
{
	"checkers": [{
{'fraction_non_alphanumeric': 0.12244897959183673, 'fraction_numerical': 0.013178365516610231, 'mean_word_length': 2.4033011522890066, 'pattern_counts': {'":': 24, '<': 70, '<?xml version=': 0, '>': 70, 'https://': 10, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1579031', 'n_tokens_mistral': 3671, 'n_tokens_neox': 3528, 'n_words': 1092}