Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bc381b356 | ||
|
|
18420c2d60 | ||
|
|
0b4dc34c57 | ||
|
|
030212c156 | ||
|
|
63b0ac8b35 | ||
|
|
263b2f0f94 | ||
|
|
db23bd9073 | ||
|
|
40dc1cc270 | ||
|
|
67c3bf6e5e | ||
|
|
57ef931d38 | ||
|
|
e3038f0e80 | ||
|
|
8106832d69 | ||
|
|
758428b312 | ||
|
|
77de4c4742 | ||
|
|
a85c5d5486 | ||
|
|
c7d554efa5 | ||
|
|
f3afdf2977 | ||
|
|
19a0ba7271 | ||
|
|
4a4c88ae17 | ||
|
|
253e6f8338 | ||
|
|
1d412678ff | ||
|
|
48c7514fa5 | ||
|
|
d7b437595c | ||
|
|
50f530a05c | ||
|
|
2a632e8f87 | ||
|
|
857ad584e7 | ||
|
|
8b3b2f70bf | ||
|
|
4308f2c1ef | ||
|
|
425c93ed8f | ||
|
|
752e82d80b | ||
|
|
e91462ce41 | ||
|
|
347297a8ea | ||
|
|
56dbe2fea0 | ||
|
|
ebcca4317d | ||
|
|
e6355dfee8 | ||
|
|
7309888db5 | ||
|
|
f60eee86ee | ||
|
|
e46acb885c | ||
|
|
24da853820 | ||
|
|
4e5a86031f | ||
|
|
7f6f127f4f | ||
|
|
12c352254f | ||
|
|
2b9d986932 | ||
|
|
cdbf5f6c6f | ||
|
|
33562e97f4 | ||
|
|
c9acc83141 | ||
|
|
8c4c360472 | ||
|
|
2c8714f1fa | ||
|
|
8ec256edbf | ||
|
|
a48ec41bca | ||
|
|
541e0264ab | ||
|
|
f945e4b8a2 | ||
|
|
076b92a2b4 | ||
|
|
02e9f74a04 | ||
|
|
b37dd5e819 | ||
|
|
1775f80ffe | ||
|
|
3187db1e9a | ||
|
|
932eab00a0 | ||
|
|
c842ac2343 | ||
|
|
6320237326 | ||
|
|
8fe9d013b5 | ||
|
|
c094c06e56 | ||
|
|
f961bf961e | ||
|
|
404a3cea64 | ||
|
|
d000460a99 | ||
|
|
455fae05c1 | ||
|
|
85dff34350 | ||
|
|
99fa632021 | ||
|
|
cafcc9d45b | ||
|
|
dc929dac70 | ||
|
|
42825b62fb | ||
|
|
a89bb392ed | ||
|
|
e7c4d03c22 | ||
|
|
4e6bf91651 | ||
|
|
de31a7a62e | ||
|
|
7f0543ebd2 | ||
|
|
9b893aa4e0 | ||
|
|
50435f4030 | ||
|
|
9649d80388 | ||
|
|
8c3ab1eac2 | ||
|
|
cdb5ba080a | ||
|
|
0a145da912 | ||
|
|
b603cdb0ea | ||
|
|
11d1f24ceb | ||
|
|
c74472d332 | ||
|
|
78a1262e7c | ||
|
|
7ff8907eda | ||
|
|
1d21f5889d | ||
|
|
d7d904ae5f | ||
|
|
7390895514 | ||
|
|
2873d96b9f | ||
|
|
ea9623f695 | ||
|
|
9cdef02bdc | ||
|
|
16229592a2 | ||
|
|
52ad4ee9e5 | ||
|
|
b47c6dc408 | ||
|
|
8e2a2c4dbc | ||
|
|
8698736e7d |
No files matched your search
Binary file not shown.
|
After Width: | Height: | Size: 37 KiB |
@@ -14,10 +14,10 @@ jobs:
|
|||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 5
|
timeout-minutes: 5
|
||||||
steps:
|
steps:
|
||||||
- name: Set up Go 1.15
|
- name: Set up Go
|
||||||
uses: actions/setup-go@v2
|
uses: actions/setup-go@v2
|
||||||
with:
|
with:
|
||||||
go-version: 1.15
|
go-version: 1.16
|
||||||
- name: Check out code into the Go module directory
|
- name: Check out code into the Go module directory
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
- name: Build binary to make sure it works
|
- name: Build binary to make sure it works
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ jobs:
|
|||||||
build:
|
build:
|
||||||
name: Publish
|
name: Publish
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
steps:
|
steps:
|
||||||
- name: Check out code
|
- name: Check out code
|
||||||
uses: actions/checkout@v2
|
uses: actions/checkout@v2
|
||||||
|
|||||||
@@ -1,3 +1,5 @@
|
|||||||
.idea
|
.idea
|
||||||
.vscode
|
.vscode
|
||||||
gatus
|
gatus
|
||||||
|
db.db
|
||||||
|
config/config.yml
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 TwinProduction
|
Copyright (c) 2021 TwinProduction
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
|||||||
@@ -11,4 +11,4 @@ run-frontend:
|
|||||||
npm --prefix web/app run serve
|
npm --prefix web/app run serve
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test -mod=vendor ./... -cover
|
go test ./alerting/... ./client/... ./config/... ./controller/... ./core/... ./jsonpath/... ./pattern/... ./security/... ./storage/... ./util/... ./watchdog/... -cover
|
||||||
@@ -7,8 +7,10 @@
|
|||||||
[](https://cloud.docker.com/repository/docker/twinproduction/gatus)
|
[](https://cloud.docker.com/repository/docker/twinproduction/gatus)
|
||||||
[](https://github.com/TwinProduction)
|
[](https://github.com/TwinProduction)
|
||||||
|
|
||||||
A service health dashboard in Go that is meant to be used as a docker
|
Gatus is a health dashboard that gives you the ability to monitor your services using HTTP, ICMP, TCP, and even DNS
|
||||||
image with a custom configuration file.
|
queries as well as evaluate the result of said queries by using a list of conditions on values like the status code,
|
||||||
|
the response time, the certificate expiration, the body and many others. The icing on top is that each of these health
|
||||||
|
checks can be paired with alerting via Slack, PagerDuty and even Twilio.
|
||||||
|
|
||||||
I personally deploy it in my Kubernetes cluster and let it monitor the status of my
|
I personally deploy it in my Kubernetes cluster and let it monitor the status of my
|
||||||
core applications: https://status.twinnation.org/
|
core applications: https://status.twinnation.org/
|
||||||
@@ -16,18 +18,21 @@ core applications: https://status.twinnation.org/
|
|||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
|
- [Why Gatus?](#why-gatus)
|
||||||
- [Features](#features)
|
- [Features](#features)
|
||||||
- [Usage](#usage)
|
- [Usage](#usage)
|
||||||
- [Configuration](#configuration)
|
- [Configuration](#configuration)
|
||||||
- [Conditions](#conditions)
|
- [Conditions](#conditions)
|
||||||
- [Placeholders](#placeholders)
|
- [Placeholders](#placeholders)
|
||||||
- [Functions](#functions)
|
- [Functions](#functions)
|
||||||
- [Alerting](#alerting)
|
- [Alerting](#alerting)
|
||||||
- [Configuring Slack alerts](#configuring-slack-alerts)
|
- [Configuring Slack alerts](#configuring-slack-alerts)
|
||||||
|
- [Configuring Discord alerts](#configuring-discord-alerts)
|
||||||
- [Configuring PagerDuty alerts](#configuring-pagerduty-alerts)
|
- [Configuring PagerDuty alerts](#configuring-pagerduty-alerts)
|
||||||
- [Configuring Twilio alerts](#configuring-twilio-alerts)
|
- [Configuring Twilio alerts](#configuring-twilio-alerts)
|
||||||
- [Configuring Mattermost alerts](#configuring-mattermost-alerts)
|
- [Configuring Mattermost alerts](#configuring-mattermost-alerts)
|
||||||
- [Configuring Messagebird alerts](#configuring-messagebird-alerts)
|
- [Configuring Messagebird alerts](#configuring-messagebird-alerts)
|
||||||
|
- [Configuring Telegram alerts](#configuring-telegram-alerts)
|
||||||
- [Configuring custom alerts](#configuring-custom-alerts)
|
- [Configuring custom alerts](#configuring-custom-alerts)
|
||||||
- [Kubernetes (ALPHA)](#kubernetes-alpha)
|
- [Kubernetes (ALPHA)](#kubernetes-alpha)
|
||||||
- [Auto Discovery](#auto-discovery)
|
- [Auto Discovery](#auto-discovery)
|
||||||
@@ -44,9 +49,30 @@ core applications: https://status.twinnation.org/
|
|||||||
- [Monitoring a service using DNS queries](#monitoring-a-service-using-dns-queries)
|
- [Monitoring a service using DNS queries](#monitoring-a-service-using-dns-queries)
|
||||||
- [Basic authentication](#basic-authentication)
|
- [Basic authentication](#basic-authentication)
|
||||||
- [disable-monitoring-lock](#disable-monitoring-lock)
|
- [disable-monitoring-lock](#disable-monitoring-lock)
|
||||||
|
- [Reloading configuration on the fly](#reloading-configuration-on-the-fly)
|
||||||
- [Service groups](#service-groups)
|
- [Service groups](#service-groups)
|
||||||
- [Exposing Gatus on a custom port](#exposing-gatus-on-a-custom-port)
|
- [Exposing Gatus on a custom port](#exposing-gatus-on-a-custom-port)
|
||||||
- [Uptime Badges (ALPHA)](#uptime-badges)
|
- [Uptime Badges (ALPHA)](#uptime-badges)
|
||||||
|
- [API](#API)
|
||||||
|
|
||||||
|
|
||||||
|
## Why Gatus?
|
||||||
|
|
||||||
|
Before getting into the specifics, I want to address the most common question:
|
||||||
|
> Why would I use Gatus when I can just use Prometheus’ Alertmanager, Cloudwatch or even Splunk?
|
||||||
|
|
||||||
|
Neither of these can tell you that there’s a problem if there are no clients actively calling the endpoint.
|
||||||
|
In other words, it's because monitoring metrics mostly rely on existing traffic, which effectively means that unless
|
||||||
|
your clients are already experiencing a problem, you won't be notified.
|
||||||
|
|
||||||
|
Gatus, on the other hand, allows you to configure health checks for each of your features, which in turn allows it to
|
||||||
|
monitor these features and potentially alert you before any clients are impacted.
|
||||||
|
|
||||||
|
A sign you may want to look into Gatus is by simply asking yourself whether you'd receive an alert if your load balancer
|
||||||
|
was to go down right now. Will any of your existing alerts by triggered? Your metrics won’t report an increase in errors
|
||||||
|
if there’s no traffic that makes it to your applications. This puts you in a situation where your clients are the ones
|
||||||
|
that will notify you about the degradation of your services rather than you reassuring them that you're working on
|
||||||
|
fixing the issue before they even know about it.
|
||||||
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
@@ -82,7 +108,7 @@ services:
|
|||||||
- "[RESPONSE_TIME] < 300" # Response time must be under 300ms
|
- "[RESPONSE_TIME] < 300" # Response time must be under 300ms
|
||||||
- name: example
|
- name: example
|
||||||
url: "https://example.org/"
|
url: "https://example.org/"
|
||||||
interval: 30s
|
interval: 5m
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
```
|
```
|
||||||
@@ -91,10 +117,10 @@ This example would look like this:
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
Note that you can also add environment variables in the configuration file (i.e. `$DOMAIN`, `${DOMAIN}`)
|
Note that you can also use environment variables in the configuration file (e.g. `$DOMAIN`, `${DOMAIN}`)
|
||||||
|
|
||||||
|
|
||||||
### Configuration
|
## Configuration
|
||||||
|
|
||||||
| Parameter | Description | Default |
|
| Parameter | Description | Default |
|
||||||
|:---------------------------------------- |:----------------------------------------------------------------------------- |:-------------- |
|
|:---------------------------------------- |:----------------------------------------------------------------------------- |:-------------- |
|
||||||
@@ -108,53 +134,33 @@ Note that you can also add environment variables in the configuration file (i.e.
|
|||||||
| `services[].url` | URL to send the request to | Required `""` |
|
| `services[].url` | URL to send the request to | Required `""` |
|
||||||
| `services[].method` | Request method | `GET` |
|
| `services[].method` | Request method | `GET` |
|
||||||
| `services[].insecure` | Whether to skip verifying the server's certificate chain and host name | `false` |
|
| `services[].insecure` | Whether to skip verifying the server's certificate chain and host name | `false` |
|
||||||
| `services[].conditions` | Conditions used to determine the health of the service | `[]` |
|
| `services[].conditions` | Conditions used to determine the health of the service. See [Conditions](#conditions). | `[]` |
|
||||||
| `services[].interval` | Duration to wait between every status check | `60s` |
|
| `services[].interval` | Duration to wait between every status check | `60s` |
|
||||||
| `services[].graphql` | Whether to wrap the body in a query param (`{"query":"$body"}`) | `false` |
|
| `services[].graphql` | Whether to wrap the body in a query param (`{"query":"$body"}`) | `false` |
|
||||||
| `services[].body` | Request body | `""` |
|
| `services[].body` | Request body | `""` |
|
||||||
| `services[].headers` | Request headers | `{}` |
|
| `services[].headers` | Request headers | `{}` |
|
||||||
| `services[].dns` | Configuration for a service of type DNS. See [Monitoring using DNS queries](#monitoring-using-dns-queries) | `""` |
|
| `services[].dns` | Configuration for a service of type DNS. See [Monitoring a service using DNS queries](#monitoring-a-service-using-dns-queries). | `""` |
|
||||||
| `services[].dns.query-type` | Query type for DNS service | `""` |
|
| `services[].dns.query-type` | Query type for DNS service | `""` |
|
||||||
| `services[].dns.query-name` | Query name for DNS service | `""` |
|
| `services[].dns.query-name` | Query name for DNS service | `""` |
|
||||||
| `services[].alerts[].type` | Type of alert. Valid types: `slack`, `pagerduty`, `twilio`, `mattermost`, `messagebird`, `custom` | Required `""` |
|
| `services[].alerts[].type` | Type of alert. Valid types: `slack`, `discord`, `pagerduty`, `twilio`, `mattermost`, `messagebird`, `custom` | Required `""` |
|
||||||
| `services[].alerts[].enabled` | Whether to enable the alert | `false` |
|
| `services[].alerts[].enabled` | Whether to enable the alert | `false` |
|
||||||
| `services[].alerts[].failure-threshold` | Number of failures in a row needed before triggering the alert | `3` |
|
| `services[].alerts[].failure-threshold` | Number of failures in a row needed before triggering the alert | `3` |
|
||||||
| `services[].alerts[].success-threshold` | Number of successes in a row before an ongoing incident is marked as resolved | `2` |
|
| `services[].alerts[].success-threshold` | Number of successes in a row before an ongoing incident is marked as resolved | `2` |
|
||||||
| `services[].alerts[].send-on-resolved` | Whether to send a notification once a triggered alert is marked as resolved | `false` |
|
| `services[].alerts[].send-on-resolved` | Whether to send a notification once a triggered alert is marked as resolved | `false` |
|
||||||
| `services[].alerts[].description` | Description of the alert. Will be included in the alert sent | `""` |
|
| `services[].alerts[].description` | Description of the alert. Will be included in the alert sent | `""` |
|
||||||
| `alerting` | Configuration for alerting | `{}` |
|
| `alerting` | Configuration for alerting. See [Alerting](#alerting). | `{}` |
|
||||||
| `alerting.slack` | Configuration for alerts of type `slack` | `{}` |
|
|
||||||
| `alerting.slack.webhook-url` | Slack Webhook URL | Required `""` |
|
|
||||||
| `alerting.pagerduty` | Configuration for alerts of type `pagerduty` | `{}` |
|
|
||||||
| `alerting.pagerduty.integration-key` | PagerDuty Events API v2 integration key. | Required `""` |
|
|
||||||
| `alerting.twilio` | Settings for alerts of type `twilio` | `{}` |
|
|
||||||
| `alerting.twilio.sid` | Twilio account SID | Required `""` |
|
|
||||||
| `alerting.twilio.token` | Twilio auth token | Required `""` |
|
|
||||||
| `alerting.twilio.from` | Number to send Twilio alerts from | Required `""` |
|
|
||||||
| `alerting.twilio.to` | Number to send twilio alerts to | Required `""` |
|
|
||||||
| `alerting.mattermost` | Configuration for alerts of type `mattermost` | `{}` |
|
|
||||||
| `alerting.mattermost.webhook-url` | Mattermost Webhook URL | Required `""` |
|
|
||||||
| `alerting.mattermost.insecure` | Whether to skip verifying the server's certificate chain and host name | `false` |
|
|
||||||
| `alerting.messagebird` | Settings for alerts of type `messagebird` | `{}` |
|
|
||||||
| `alerting.messagebird.access-key` | Messagebird access key | Required `""` |
|
|
||||||
| `alerting.messagebird.originator` | The sender of the message | Required `""` |
|
|
||||||
| `alerting.messagebird.recipients` | The recipients of the message | Required `""` |
|
|
||||||
| `alerting.custom` | Configuration for custom actions on failure or alerts | `{}` |
|
|
||||||
| `alerting.custom.url` | Custom alerting request url | Required `""` |
|
|
||||||
| `alerting.custom.method` | Request method | `GET` |
|
|
||||||
| `alerting.custom.insecure` | Whether to skip verifying the server's certificate chain and host name | `false` |
|
|
||||||
| `alerting.custom.body` | Custom alerting request body. | `""` |
|
|
||||||
| `alerting.custom.headers` | Custom alerting request headers | `{}` |
|
|
||||||
| `security` | Security configuration | `{}` |
|
| `security` | Security configuration | `{}` |
|
||||||
| `security.basic` | Basic authentication security configuration | `{}` |
|
| `security.basic` | Basic authentication security configuration | `{}` |
|
||||||
| `security.basic.username` | Username for Basic authentication | Required `""` |
|
| `security.basic.username` | Username for Basic authentication | Required `""` |
|
||||||
| `security.basic.password-sha512` | Password's SHA512 hash for Basic authentication | Required `""` |
|
| `security.basic.password-sha512` | Password's SHA512 hash for Basic authentication | Required `""` |
|
||||||
| `disable-monitoring-lock` | Whether to [disable the monitoring lock](#disable-monitoring-lock) | `false` |
|
| `disable-monitoring-lock` | Whether to [disable the monitoring lock](#disable-monitoring-lock) | `false` |
|
||||||
|
| `skip-invalid-config-update` | Whether to ignore invalid configuration update. See [Reloading configuration on the fly](#reloading-configuration-on-the-fly).
|
||||||
| `web` | Web configuration | `{}` |
|
| `web` | Web configuration | `{}` |
|
||||||
| `web.address` | Address to listen on | `0.0.0.0` |
|
| `web.address` | Address to listen on | `0.0.0.0` |
|
||||||
| `web.port` | Port to listen on | `8080` |
|
| `web.port` | Port to listen on | `8080` |
|
||||||
|
|
||||||
For Kubernetes configuration, see [Kubernetes](#kubernetes-alpha)
|
- For Kubernetes configuration, see [Kubernetes](#kubernetes-alpha).
|
||||||
|
- For alerting configuration, see [Alerting](#alerting).
|
||||||
|
|
||||||
|
|
||||||
### Conditions
|
### Conditions
|
||||||
@@ -167,7 +173,7 @@ Here are some examples of conditions you can use:
|
|||||||
| `[STATUS] < 300` | Status must lower than 300 | 200, 201, 299 | 301, 302, ... |
|
| `[STATUS] < 300` | Status must lower than 300 | 200, 201, 299 | 301, 302, ... |
|
||||||
| `[STATUS] <= 299` | Status must be less than or equal to 299 | 200, 201, 299 | 301, 302, ... |
|
| `[STATUS] <= 299` | Status must be less than or equal to 299 | 200, 201, 299 | 301, 302, ... |
|
||||||
| `[STATUS] > 400` | Status must be greater than 400 | 401, 402, 403, 404 | 400, 200, ... |
|
| `[STATUS] > 400` | Status must be greater than 400 | 401, 402, 403, 404 | 400, 200, ... |
|
||||||
| `[STATUS] == any(200, 429)` | Status must be either 200 or 420 | 200, 429 | 201, 400, ... |
|
| `[STATUS] == any(200, 429)` | Status must be either 200 or 429 | 200, 429 | 201, 400, ... |
|
||||||
| `[CONNECTED] == true` | Connection to host must've been successful | true, false | |
|
| `[CONNECTED] == true` | Connection to host must've been successful | true, false | |
|
||||||
| `[RESPONSE_TIME] < 500` | Response time must be below 500ms | 100ms, 200ms, 300ms | 500ms, 501ms |
|
| `[RESPONSE_TIME] < 500` | Response time must be below 500ms | 100ms, 200ms, 300ms | 500ms, 501ms |
|
||||||
| `[IP] == 127.0.0.1` | Target IP must be 127.0.0.1 | 127.0.0.1 | 0.0.0.0 |
|
| `[IP] == 127.0.0.1` | Target IP must be 127.0.0.1 | 127.0.0.1 | 0.0.0.0 |
|
||||||
@@ -177,6 +183,8 @@ Here are some examples of conditions you can use:
|
|||||||
| `[BODY].age == [BODY].id` | JSONPath value of `$.age` is equal JSONPath `$.id` | `{"age":1,"id":1}` | |
|
| `[BODY].age == [BODY].id` | JSONPath value of `$.age` is equal JSONPath `$.id` | `{"age":1,"id":1}` | |
|
||||||
| `len([BODY].data) < 5` | Array at JSONPath `$.data` has less than 5 elements | `{"data":[{"id":1}]}` | |
|
| `len([BODY].data) < 5` | Array at JSONPath `$.data` has less than 5 elements | `{"data":[{"id":1}]}` | |
|
||||||
| `len([BODY].name) == 8` | String at JSONPath `$.name` has a length of 8 | `{"name":"john.doe"}` | `{"name":"bob"}` |
|
| `len([BODY].name) == 8` | String at JSONPath `$.name` has a length of 8 | `{"name":"john.doe"}` | `{"name":"bob"}` |
|
||||||
|
| `has([BODY].errors) == false` | JSONPath `$.errors` does not exist | `{"name":"john.doe"}` | `{"errors":[]}` |
|
||||||
|
| `has([BODY].users) == true` | JSONPath `$.users` exists | `{"users":[]}` | `{}` |
|
||||||
| `[BODY].name == pat(john*)` | String at JSONPath `$.name` matches pattern `john*` | `{"name":"john.doe"}` | `{"name":"bob"}` |
|
| `[BODY].name == pat(john*)` | String at JSONPath `$.name` matches pattern `john*` | `{"name":"john.doe"}` | `{"name":"bob"}` |
|
||||||
| `[BODY].id == any(1, 2)` | Value at JSONPath `$.id` is equal to `1` or `2` | 1, 2 | 3, 4, 5 |
|
| `[BODY].id == any(1, 2)` | Value at JSONPath `$.id` is equal to `1` or `2` | 1, 2 | 3, 4, 5 |
|
||||||
| `[CERTIFICATE_EXPIRATION] > 48h` | Certificate expiration is more than 48h away | 49h, 50h, 123h | 1h, 24h, ... |
|
| `[CERTIFICATE_EXPIRATION] > 48h` | Certificate expiration is more than 48h away | 49h, 50h, 123h | 1h, 24h, ... |
|
||||||
@@ -200,6 +208,7 @@ Here are some examples of conditions you can use:
|
|||||||
| Function | Description | Example |
|
| Function | Description | Example |
|
||||||
|:-----------|:---------------------------------------------------------------------------------------------------------------- |:-------------------------- |
|
|:-----------|:---------------------------------------------------------------------------------------------------------------- |:-------------------------- |
|
||||||
| `len` | Returns the length of the object/slice. Works only with the `[BODY]` placeholder. | `len([BODY].username) > 8`
|
| `len` | Returns the length of the object/slice. Works only with the `[BODY]` placeholder. | `len([BODY].username) > 8`
|
||||||
|
| `has` | Returns `true` or `false` based on whether a given path is valid. Works only with the `[BODY]` placeholder. | `has([BODY].errors) == false`
|
||||||
| `pat` | Specifies that the string passed as parameter should be evaluated as a pattern. Works only with `==` and `!=`. | `[IP] == pat(192.168.*)`
|
| `pat` | Specifies that the string passed as parameter should be evaluated as a pattern. Works only with `==` and `!=`. | `[IP] == pat(192.168.*)`
|
||||||
| `any` | Specifies that any one of the values passed as parameters is a valid value. Works only with `==` and `!=`. | `[BODY].ip == any(127.0.0.1, ::1)`
|
| `any` | Specifies that any one of the values passed as parameters is a valid value. Works only with `==` and `!=`. | `[BODY].ip == any(127.0.0.1, ::1)`
|
||||||
|
|
||||||
@@ -208,6 +217,47 @@ Here are some examples of conditions you can use:
|
|||||||
|
|
||||||
### Alerting
|
### Alerting
|
||||||
|
|
||||||
|
Gatus supports multiple alerting providers, such as Slack and PagerDuty, and supports different alerts for each
|
||||||
|
individual services with configurable descriptions and thresholds.
|
||||||
|
|
||||||
|
Note that if an alerting provider is not configured properly, all alerts configured with the provider's type will be
|
||||||
|
ignored.
|
||||||
|
|
||||||
|
| Parameter | Description | Default |
|
||||||
|
|:---------------------------------------- |:----------------------------------------------------------------------------- |:-------------- |
|
||||||
|
| `alerting.slack` | Configuration for alerts of type `slack` | `{}` |
|
||||||
|
| `alerting.slack.webhook-url` | Slack Webhook URL | Required `""` |
|
||||||
|
| `alerting.discord` | Configuration for alerts of type `discord` | `{}` |
|
||||||
|
| `alerting.discord.webhook-url` | Discord Webhook URL | Required `""` |
|
||||||
|
| `alerting.pagerduty` | Configuration for alerts of type `pagerduty` | `{}` |
|
||||||
|
| `alerting.pagerduty.integration-key` | PagerDuty Events API v2 integration key. | Required `""` |
|
||||||
|
| `alerting.twilio` | Settings for alerts of type `twilio` | `{}` |
|
||||||
|
| `alerting.twilio.sid` | Twilio account SID | Required `""` |
|
||||||
|
| `alerting.twilio.token` | Twilio auth token | Required `""` |
|
||||||
|
| `alerting.twilio.from` | Number to send Twilio alerts from | Required `""` |
|
||||||
|
| `alerting.twilio.to` | Number to send twilio alerts to | Required `""` |
|
||||||
|
| `alerting.mattermost` | Configuration for alerts of type `mattermost` | `{}` |
|
||||||
|
| `alerting.mattermost.webhook-url` | Mattermost Webhook URL | Required `""` |
|
||||||
|
| `alerting.mattermost.insecure` | Whether to skip verifying the server's certificate chain and host name | `false` |
|
||||||
|
| `alerting.messagebird` | Settings for alerts of type `messagebird` | `{}` |
|
||||||
|
| `alerting.messagebird.access-key` | Messagebird access key | Required `""` |
|
||||||
|
| `alerting.messagebird.originator` | The sender of the message | Required `""` |
|
||||||
|
| `alerting.messagebird.recipients` | The recipients of the message | Required `""` |
|
||||||
|
| `alerting.telegram` | Configuration for alerts of type `telegram` | `{}` |
|
||||||
|
| `alerting.telegram.token` | Telegram Bot Token | Required `""` |
|
||||||
|
| `alerting.telegram.id` | Telegram User ID | Required `""` |
|
||||||
|
| `alerting.custom` | Configuration for custom actions on failure or alerts | `{}` |
|
||||||
|
| `alerting.custom.url` | Custom alerting request url | Required `""` |
|
||||||
|
| `alerting.custom.method` | Request method | `GET` |
|
||||||
|
| `alerting.custom.insecure` | Whether to skip verifying the server's certificate chain and host name | `false` |
|
||||||
|
| `alerting.custom.body` | Custom alerting request body. | `""` |
|
||||||
|
| `alerting.custom.headers` | Custom alerting request headers | `{}` |
|
||||||
|
| `alerting.*.default-alert.enabled` | Whether to enable the alert | N/A |
|
||||||
|
| `alerting.*.default-alert.failure-threshold` | Number of failures in a row needed before triggering the alert | N/A |
|
||||||
|
| `alerting.*.default-alert.success-threshold` | Number of successes in a row before an ongoing incident is marked as resolved | N/A |
|
||||||
|
| `alerting.*.default-alert.send-on-resolved` | Whether to send a notification once a triggered alert is marked as resolved | N/A |
|
||||||
|
| `alerting.*.default-alert.description` | Description of the alert. Will be included in the alert sent | N/A |
|
||||||
|
|
||||||
|
|
||||||
#### Configuring Slack alerts
|
#### Configuring Slack alerts
|
||||||
|
|
||||||
@@ -215,6 +265,7 @@ Here are some examples of conditions you can use:
|
|||||||
alerting:
|
alerting:
|
||||||
slack:
|
slack:
|
||||||
webhook-url: "https://hooks.slack.com/services/**********/**********/**********"
|
webhook-url: "https://hooks.slack.com/services/**********/**********/**********"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
@@ -240,6 +291,29 @@ Here's an example of what the notifications look like:
|
|||||||

|

|
||||||
|
|
||||||
|
|
||||||
|
#### Configuring Discord alerts
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
alerting:
|
||||||
|
discord:
|
||||||
|
webhook-url: "https://discord.com/api/webhooks/**********/**********"
|
||||||
|
|
||||||
|
services:
|
||||||
|
- name: twinnation
|
||||||
|
url: "https://twinnation.org/health"
|
||||||
|
interval: 30s
|
||||||
|
alerts:
|
||||||
|
- type: discord
|
||||||
|
enabled: true
|
||||||
|
description: "healthcheck failed"
|
||||||
|
send-on-resolved: true
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
- "[RESPONSE_TIME] < 300"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
#### Configuring PagerDuty alerts
|
#### Configuring PagerDuty alerts
|
||||||
|
|
||||||
It is highly recommended to set `services[].alerts[].send-on-resolved` to `true` for alerts
|
It is highly recommended to set `services[].alerts[].send-on-resolved` to `true` for alerts
|
||||||
@@ -251,6 +325,7 @@ PagerDuty instead.
|
|||||||
alerting:
|
alerting:
|
||||||
pagerduty:
|
pagerduty:
|
||||||
integration-key: "********************************"
|
integration-key: "********************************"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
@@ -261,7 +336,7 @@ services:
|
|||||||
failure-threshold: 3
|
failure-threshold: 3
|
||||||
success-threshold: 5
|
success-threshold: 5
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
description: "healthcheck failed 3 times in a row"
|
description: "healthcheck failed"
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
- "[BODY].status == UP"
|
- "[BODY].status == UP"
|
||||||
@@ -278,6 +353,7 @@ alerting:
|
|||||||
token: "..."
|
token: "..."
|
||||||
from: "+1-234-567-8901"
|
from: "+1-234-567-8901"
|
||||||
to: "+1-234-567-8901"
|
to: "+1-234-567-8901"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: twinnation
|
||||||
interval: 30s
|
interval: 30s
|
||||||
@@ -287,7 +363,7 @@ services:
|
|||||||
enabled: true
|
enabled: true
|
||||||
failure-threshold: 5
|
failure-threshold: 5
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
description: "healthcheck failed 5 times in a row"
|
description: "healthcheck failed"
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
- "[BODY].status == UP"
|
- "[BODY].status == UP"
|
||||||
@@ -302,6 +378,7 @@ alerting:
|
|||||||
mattermost:
|
mattermost:
|
||||||
webhook-url: "http://**********/hooks/**********"
|
webhook-url: "http://**********/hooks/**********"
|
||||||
insecure: true
|
insecure: true
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: "https://twinnation.org/health"
|
url: "https://twinnation.org/health"
|
||||||
@@ -309,7 +386,7 @@ services:
|
|||||||
alerts:
|
alerts:
|
||||||
- type: mattermost
|
- type: mattermost
|
||||||
enabled: true
|
enabled: true
|
||||||
description: "healthcheck failed 3 times in a row"
|
description: "healthcheck failed"
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
@@ -341,7 +418,7 @@ services:
|
|||||||
enabled: true
|
enabled: true
|
||||||
failure-threshold: 3
|
failure-threshold: 3
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
description: "healthcheck failed 3 times in a row"
|
description: "healthcheck failed"
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
- "[BODY].status == UP"
|
- "[BODY].status == UP"
|
||||||
@@ -349,6 +426,32 @@ services:
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
|
#### Configuring Telegram alerts
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
alerting:
|
||||||
|
telegram:
|
||||||
|
token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11"
|
||||||
|
id: "0123456789"
|
||||||
|
|
||||||
|
services:
|
||||||
|
- name: twinnation
|
||||||
|
url: "https://twinnation.org/health"
|
||||||
|
interval: 30s
|
||||||
|
alerts:
|
||||||
|
- type: telegram
|
||||||
|
enabled: true
|
||||||
|
send-on-resolved: true
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
- "[BODY].status == UP"
|
||||||
|
```
|
||||||
|
|
||||||
|
Here's an example of what the notifications look like:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
|
||||||
#### Configuring custom alerts
|
#### Configuring custom alerts
|
||||||
|
|
||||||
While they're called alerts, you can use this feature to call anything.
|
While they're called alerts, you can use this feature to call anything.
|
||||||
@@ -358,14 +461,15 @@ leveraging Gatus, you could have Gatus call that application endpoint when a ser
|
|||||||
would then check if the service that started failing was recently deployed, and if it was, then automatically
|
would then check if the service that started failing was recently deployed, and if it was, then automatically
|
||||||
roll it back.
|
roll it back.
|
||||||
|
|
||||||
The values `[ALERT_DESCRIPTION]` and `[SERVICE_NAME]` are automatically substituted for the alert description and the
|
The placeholders `[ALERT_DESCRIPTION]` and `[SERVICE_NAME]` are automatically substituted for the alert description and
|
||||||
service name respectively in the body (`alerting.custom.body`) as well as the url (`alerting.custom.url`).
|
the service name. These placeholders can be used in the body (`alerting.custom.body`) and in the url (`alerting.custom.url`).
|
||||||
|
|
||||||
If you have `send-on-resolved` set to `true`, you may want to use `[ALERT_TRIGGERED_OR_RESOLVED]` to differentiate
|
If you have an alert using the `custom` provider with `send-on-resolved` set to `true`, you can use the
|
||||||
the notifications. It will be replaced for either `TRIGGERED` or `RESOLVED`, based on the situation.
|
`[ALERT_TRIGGERED_OR_RESOLVED]` placeholder to differentiate the notifications.
|
||||||
|
The aforementioned placeholder will be replaced by `TRIGGERED` or `RESOLVED` accordingly, though it can be modified
|
||||||
|
(details at the end of this section).
|
||||||
|
|
||||||
For all intents and purpose, we'll configure the custom alert with a Slack webhook, but you can call anything you want.
|
For all intents and purpose, we'll configure the custom alert with a Slack webhook, but you can call anything you want.
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
alerting:
|
alerting:
|
||||||
custom:
|
custom:
|
||||||
@@ -386,13 +490,79 @@ services:
|
|||||||
failure-threshold: 10
|
failure-threshold: 10
|
||||||
success-threshold: 3
|
success-threshold: 3
|
||||||
send-on-resolved: true
|
send-on-resolved: true
|
||||||
description: "healthcheck failed 10 times in a row"
|
description: "healthcheck failed"
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
- "[BODY].status == UP"
|
- "[BODY].status == UP"
|
||||||
- "[RESPONSE_TIME] < 300"
|
- "[RESPONSE_TIME] < 300"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Note that you can customize the resolved values for the `[ALERT_TRIGGERED_OR_RESOLVED]` placeholder like so:
|
||||||
|
```yaml
|
||||||
|
alerting:
|
||||||
|
custom:
|
||||||
|
placeholders:
|
||||||
|
ALERT_TRIGGERED_OR_RESOLVED:
|
||||||
|
TRIGGERED: "partial_outage"
|
||||||
|
RESOLVED: "operational"
|
||||||
|
```
|
||||||
|
As a result, the `[ALERT_TRIGGERED_OR_RESOLVED]` in the body of first example of this section would be replaced by
|
||||||
|
`partial_outage` when an alert is triggered and `operational` when an alert is resolved.
|
||||||
|
|
||||||
|
|
||||||
|
#### Setting a default provider alert
|
||||||
|
|
||||||
|
While you can specify the alert configuration directly in the service definition, it's tedious and may lead to a very
|
||||||
|
long configuration file.
|
||||||
|
|
||||||
|
To avoid such problem, you can use the `default-alert` parameter present in each provider configuration:
|
||||||
|
```yaml
|
||||||
|
alerting:
|
||||||
|
slack:
|
||||||
|
webhook-url: "https://hooks.slack.com/services/**********/**********/**********"
|
||||||
|
default-alert:
|
||||||
|
enabled: true
|
||||||
|
description: "healthcheck failed"
|
||||||
|
send-on-resolved: true
|
||||||
|
failure-threshold: 5
|
||||||
|
success-threshold: 5
|
||||||
|
```
|
||||||
|
|
||||||
|
As a result, your service configuration looks a lot tidier:
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
- name: example
|
||||||
|
url: "https://example.org"
|
||||||
|
alerts:
|
||||||
|
- type: slack
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
|
||||||
|
- name: other-example
|
||||||
|
url: "https://example.com"
|
||||||
|
alerts:
|
||||||
|
- type: slack
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
```
|
||||||
|
|
||||||
|
It also allows you to do things like this:
|
||||||
|
```yaml
|
||||||
|
services:
|
||||||
|
- name: twinnation
|
||||||
|
url: "https://twinnation.org/health"
|
||||||
|
alerts:
|
||||||
|
- type: slack
|
||||||
|
failure-threshold: 5
|
||||||
|
- type: slack
|
||||||
|
failure-threshold: 10
|
||||||
|
- type: slack
|
||||||
|
failure-threshold: 15
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Kubernetes (ALPHA)
|
### Kubernetes (ALPHA)
|
||||||
|
|
||||||
> **WARNING**: This feature is in ALPHA. This means that it is very likely to change in the near future, which means that
|
> **WARNING**: This feature is in ALPHA. This means that it is very likely to change in the near future, which means that
|
||||||
@@ -471,6 +641,11 @@ If you're on Windows, replace `"$(pwd)"` by the absolute path to your current di
|
|||||||
docker run -p 8080:8080 --mount type=bind,source=C:/Users/Chris/Desktop/config.yaml,target=/config/config.yaml --name gatus twinproduction/gatus
|
docker run -p 8080:8080 --mount type=bind,source=C:/Users/Chris/Desktop/config.yaml,target=/config/config.yaml --name gatus twinproduction/gatus
|
||||||
```
|
```
|
||||||
|
|
||||||
|
To build the image locally:
|
||||||
|
```
|
||||||
|
docker build . -t twinproduction/gatus
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
## Running the tests
|
## Running the tests
|
||||||
|
|
||||||
@@ -493,29 +668,27 @@ By setting `services[].graphql` to true, the body will automatically be wrapped
|
|||||||
For instance, the following configuration:
|
For instance, the following configuration:
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
- name: filter users by gender
|
- name: filter-users-by-gender
|
||||||
url: http://localhost:8080/playground
|
url: http://localhost:8080/playground
|
||||||
method: POST
|
method: POST
|
||||||
graphql: true
|
graphql: true
|
||||||
body: |
|
body: |
|
||||||
{
|
{
|
||||||
user(gender: "female") {
|
users(gender: "female") {
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
gender
|
gender
|
||||||
avatar
|
avatar
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
headers:
|
|
||||||
Content-Type: application/json # XXX: as of v1.9.2, this header is automatically added when graphql is set to true
|
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
- "[BODY].data.user[0].gender == female"
|
- "[BODY].data.users[0].gender == female"
|
||||||
```
|
```
|
||||||
|
|
||||||
will send a `POST` request to `http://localhost:8080/playground` with the following body:
|
will send a `POST` request to `http://localhost:8080/playground` with the following body:
|
||||||
```json
|
```json
|
||||||
{"query":" {\n user(gender: \"female\") {\n id\n name\n gender\n avatar\n }\n }"}
|
{"query":" {\n users(gender: \"female\") {\n id\n name\n gender\n avatar\n }\n }"}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
@@ -587,7 +760,7 @@ commonly known as "ping" or "echo":
|
|||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
- name: ICMP
|
- name: ping-example
|
||||||
url: "icmp://example.com"
|
url: "icmp://example.com"
|
||||||
conditions:
|
conditions:
|
||||||
- "[CONNECTED] == true"
|
- "[CONNECTED] == true"
|
||||||
@@ -602,7 +775,7 @@ You can specify a domain prefixed by `icmp://`, or an IP address prefixed by `ic
|
|||||||
Defining a `dns` configuration in a service will automatically mark that service as a service of type DNS:
|
Defining a `dns` configuration in a service will automatically mark that service as a service of type DNS:
|
||||||
```yaml
|
```yaml
|
||||||
services:
|
services:
|
||||||
- name: example dns query
|
- name: example-dns-query
|
||||||
url: "8.8.8.8" # Address of the DNS server to use
|
url: "8.8.8.8" # Address of the DNS server to use
|
||||||
interval: 30s
|
interval: 30s
|
||||||
dns:
|
dns:
|
||||||
@@ -647,6 +820,30 @@ technically, if you create 100 services with a 1 seconds interval, Gatus will se
|
|||||||
- You want to test multiple services at very short interval (< 5s)
|
- You want to test multiple services at very short interval (< 5s)
|
||||||
|
|
||||||
|
|
||||||
|
### Reloading configuration on the fly
|
||||||
|
|
||||||
|
For the sake on convenience, Gatus automatically reloads the configuration on the fly if the loaded configuration file
|
||||||
|
is updated while Gatus is running.
|
||||||
|
|
||||||
|
By default, the application will exit if the updating configuration is invalid, but you can configure
|
||||||
|
Gatus to continue running if the configuration file is updated with an invalid configuration by
|
||||||
|
setting `skip-invalid-config-update` to `true`.
|
||||||
|
|
||||||
|
Keep in mind that it is in your best interest to ensure the validity of the configuration file after each update you
|
||||||
|
apply to the configuration file while Gatus is running by looking at the log and making sure that you do not see the
|
||||||
|
following message:
|
||||||
|
```
|
||||||
|
The configuration file was updated, but it is not valid. The old configuration will continue being used.
|
||||||
|
```
|
||||||
|
Failure to do so may result in Gatus being unable to start if the application is restarted for whatever reason.
|
||||||
|
|
||||||
|
I recommend not setting `skip-invalid-config-update` to `true` to avoid a situation like this, but the choice is yours
|
||||||
|
to make.
|
||||||
|
|
||||||
|
Note that if you are not using a file storage, updating the configuration while Gatus is running is effectively
|
||||||
|
the same as restarting the application.
|
||||||
|
|
||||||
|
|
||||||
### Service groups
|
### Service groups
|
||||||
|
|
||||||
Service groups are used for grouping multiple services together on the dashboard.
|
Service groups are used for grouping multiple services together on the dashboard.
|
||||||
@@ -742,3 +939,25 @@ Example: 
|
||||||
Type AlertType `yaml:"type"`
|
Type Type `yaml:"type"`
|
||||||
|
|
||||||
// Enabled defines whether or not the alert is enabled
|
// Enabled defines whether or not the alert is enabled
|
||||||
Enabled bool `yaml:"enabled"`
|
//
|
||||||
|
// This is a pointer, because it is populated by YAML and we need to know whether it was explicitly set to a value
|
||||||
|
// or not for provider.ParseWithDefaultAlert to work.
|
||||||
|
Enabled *bool `yaml:"enabled"`
|
||||||
|
|
||||||
// FailureThreshold is the number of failures in a row needed before triggering the alert
|
// FailureThreshold is the number of failures in a row needed before triggering the alert
|
||||||
FailureThreshold int `yaml:"failure-threshold"`
|
FailureThreshold int `yaml:"failure-threshold"`
|
||||||
|
|
||||||
// Description of the alert. Will be included in the alert sent.
|
// Description of the alert. Will be included in the alert sent.
|
||||||
Description string `yaml:"description"`
|
//
|
||||||
|
// This is a pointer, because it is populated by YAML and we need to know whether it was explicitly set to a value
|
||||||
|
// or not for provider.ParseWithDefaultAlert to work.
|
||||||
|
Description *string `yaml:"description"`
|
||||||
|
|
||||||
// SendOnResolved defines whether to send a second notification when the issue has been resolved
|
// SendOnResolved defines whether to send a second notification when the issue has been resolved
|
||||||
SendOnResolved bool `yaml:"send-on-resolved"`
|
//
|
||||||
|
// This is a pointer, because it is populated by YAML and we need to know whether it was explicitly set to a value
|
||||||
|
// or not for provider.ParseWithDefaultAlert to work. Use Alert.IsSendingOnResolved() for a non-pointer
|
||||||
|
SendOnResolved *bool `yaml:"send-on-resolved"`
|
||||||
|
|
||||||
// SuccessThreshold defines how many successful executions must happen in a row before an ongoing incident is marked as resolved
|
// SuccessThreshold defines how many successful executions must happen in a row before an ongoing incident is marked as resolved
|
||||||
SuccessThreshold int `yaml:"success-threshold"`
|
SuccessThreshold int `yaml:"success-threshold"`
|
||||||
@@ -35,26 +44,26 @@ type Alert struct {
|
|||||||
Triggered bool
|
Triggered bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// AlertType is the type of the alert.
|
// GetDescription retrieves the description of the alert
|
||||||
// The value will generally be the name of the alert provider
|
func (alert Alert) GetDescription() string {
|
||||||
type AlertType string
|
if alert.Description == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return *alert.Description
|
||||||
|
}
|
||||||
|
|
||||||
const (
|
// IsEnabled returns whether an alert is enabled or not
|
||||||
// SlackAlert is the AlertType for the slack alerting provider
|
func (alert Alert) IsEnabled() bool {
|
||||||
SlackAlert AlertType = "slack"
|
if alert.Enabled == nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
return *alert.Enabled
|
||||||
|
}
|
||||||
|
|
||||||
// MattermostAlert is the AlertType for the mattermost alerting provider
|
// IsSendingOnResolved returns whether an alert is sending on resolve or not
|
||||||
MattermostAlert AlertType = "mattermost"
|
func (alert Alert) IsSendingOnResolved() bool {
|
||||||
|
if alert.SendOnResolved == nil {
|
||||||
// MessagebirdAlert is the AlertType for the messagebird alerting provider
|
return false
|
||||||
MessagebirdAlert AlertType = "messagebird"
|
}
|
||||||
|
return *alert.SendOnResolved
|
||||||
// PagerDutyAlert is the AlertType for the pagerduty alerting provider
|
}
|
||||||
PagerDutyAlert AlertType = "pagerduty"
|
|
||||||
|
|
||||||
// TwilioAlert is the AlertType for the twilio alerting provider
|
|
||||||
TwilioAlert AlertType = "twilio"
|
|
||||||
|
|
||||||
// CustomAlert is the AlertType for the custom alerting provider
|
|
||||||
CustomAlert AlertType = "custom"
|
|
||||||
)
|
|
||||||
@@ -0,0 +1,36 @@
|
|||||||
|
package alert
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestAlert_IsEnabled(t *testing.T) {
|
||||||
|
if (Alert{Enabled: nil}).IsEnabled() {
|
||||||
|
t.Error("alert.IsEnabled() should've returned false, because Enabled was set to nil")
|
||||||
|
}
|
||||||
|
if value := false; (Alert{Enabled: &value}).IsEnabled() {
|
||||||
|
t.Error("alert.IsEnabled() should've returned false, because Enabled was set to false")
|
||||||
|
}
|
||||||
|
if value := true; !(Alert{Enabled: &value}).IsEnabled() {
|
||||||
|
t.Error("alert.IsEnabled() should've returned true, because Enabled was set to true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlert_GetDescription(t *testing.T) {
|
||||||
|
if (Alert{Description: nil}).GetDescription() != "" {
|
||||||
|
t.Error("alert.GetDescription() should've returned an empty string, because Description was set to nil")
|
||||||
|
}
|
||||||
|
if value := "description"; (Alert{Description: &value}).GetDescription() != value {
|
||||||
|
t.Error("alert.GetDescription() should've returned false, because Description was set to 'description'")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlert_IsSendingOnResolved(t *testing.T) {
|
||||||
|
if (Alert{SendOnResolved: nil}).IsSendingOnResolved() {
|
||||||
|
t.Error("alert.IsSendingOnResolved() should've returned false, because SendOnResolved was set to nil")
|
||||||
|
}
|
||||||
|
if value := false; (Alert{SendOnResolved: &value}).IsSendingOnResolved() {
|
||||||
|
t.Error("alert.IsSendingOnResolved() should've returned false, because SendOnResolved was set to false")
|
||||||
|
}
|
||||||
|
if value := true; !(Alert{SendOnResolved: &value}).IsSendingOnResolved() {
|
||||||
|
t.Error("alert.IsSendingOnResolved() should've returned true, because SendOnResolved was set to true")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
package alert
|
||||||
|
|
||||||
|
// Type is the type of the alert.
|
||||||
|
// The value will generally be the name of the alert provider
|
||||||
|
type Type string
|
||||||
|
|
||||||
|
const (
|
||||||
|
// TypeCustom is the Type for the custom alerting provider
|
||||||
|
TypeCustom Type = "custom"
|
||||||
|
|
||||||
|
// TypeDiscord is the Type for the discord alerting provider
|
||||||
|
TypeDiscord Type = "discord"
|
||||||
|
|
||||||
|
// TypeMattermost is the Type for the mattermost alerting provider
|
||||||
|
TypeMattermost Type = "mattermost"
|
||||||
|
|
||||||
|
// TypeMessagebird is the Type for the messagebird alerting provider
|
||||||
|
TypeMessagebird Type = "messagebird"
|
||||||
|
|
||||||
|
// TypePagerDuty is the Type for the pagerduty alerting provider
|
||||||
|
TypePagerDuty Type = "pagerduty"
|
||||||
|
|
||||||
|
// TypeSlack is the Type for the slack alerting provider
|
||||||
|
TypeSlack Type = "slack"
|
||||||
|
|
||||||
|
// TypeTelegram is the Type for the telegram alerting provider
|
||||||
|
TypeTelegram Type = "telegram"
|
||||||
|
|
||||||
|
// TypeTwilio is the Type for the twilio alerting provider
|
||||||
|
TypeTwilio Type = "twilio"
|
||||||
|
)
|
||||||
+71
-6
@@ -1,18 +1,25 @@
|
|||||||
package alerting
|
package alerting
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/discord"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/mattermost"
|
"github.com/TwinProduction/gatus/alerting/provider/mattermost"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/telegram"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is the configuration for alerting providers
|
// Config is the configuration for alerting providers
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// Slack is the configuration for the slack alerting provider
|
// Custom is the configuration for the custom alerting provider
|
||||||
Slack *slack.AlertProvider `yaml:"slack"`
|
Custom *custom.AlertProvider `yaml:"custom"`
|
||||||
|
|
||||||
|
// Discord is the configuration for the discord alerting provider
|
||||||
|
Discord *discord.AlertProvider `yaml:"discord"`
|
||||||
|
|
||||||
// Mattermost is the configuration for the mattermost alerting provider
|
// Mattermost is the configuration for the mattermost alerting provider
|
||||||
Mattermost *mattermost.AlertProvider `yaml:"mattermost"`
|
Mattermost *mattermost.AlertProvider `yaml:"mattermost"`
|
||||||
@@ -20,12 +27,70 @@ type Config struct {
|
|||||||
// Messagebird is the configuration for the messagebird alerting provider
|
// Messagebird is the configuration for the messagebird alerting provider
|
||||||
Messagebird *messagebird.AlertProvider `yaml:"messagebird"`
|
Messagebird *messagebird.AlertProvider `yaml:"messagebird"`
|
||||||
|
|
||||||
// Pagerduty is the configuration for the pagerduty alerting provider
|
// PagerDuty is the configuration for the pagerduty alerting provider
|
||||||
PagerDuty *pagerduty.AlertProvider `yaml:"pagerduty"`
|
PagerDuty *pagerduty.AlertProvider `yaml:"pagerduty"`
|
||||||
|
|
||||||
|
// Slack is the configuration for the slack alerting provider
|
||||||
|
Slack *slack.AlertProvider `yaml:"slack"`
|
||||||
|
|
||||||
|
// Telegram is the configuration for the telegram alerting provider
|
||||||
|
Telegram *telegram.AlertProvider `yaml:"telegram"`
|
||||||
|
|
||||||
// Twilio is the configuration for the twilio alerting provider
|
// Twilio is the configuration for the twilio alerting provider
|
||||||
Twilio *twilio.AlertProvider `yaml:"twilio"`
|
Twilio *twilio.AlertProvider `yaml:"twilio"`
|
||||||
|
}
|
||||||
// Custom is the configuration for the custom alerting provider
|
|
||||||
Custom *custom.AlertProvider `yaml:"custom"`
|
// GetAlertingProviderByAlertType returns an provider.AlertProvider by its corresponding alert.Type
|
||||||
|
func (config Config) GetAlertingProviderByAlertType(alertType alert.Type) provider.AlertProvider {
|
||||||
|
switch alertType {
|
||||||
|
case alert.TypeCustom:
|
||||||
|
if config.Custom == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.Custom
|
||||||
|
case alert.TypeDiscord:
|
||||||
|
if config.Discord == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.Discord
|
||||||
|
case alert.TypeMattermost:
|
||||||
|
if config.Mattermost == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.Mattermost
|
||||||
|
case alert.TypeMessagebird:
|
||||||
|
if config.Messagebird == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.Messagebird
|
||||||
|
case alert.TypePagerDuty:
|
||||||
|
if config.PagerDuty == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.PagerDuty
|
||||||
|
case alert.TypeSlack:
|
||||||
|
if config.Slack == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.Slack
|
||||||
|
case alert.TypeTelegram:
|
||||||
|
if config.Telegram == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.Telegram
|
||||||
|
case alert.TypeTwilio:
|
||||||
|
if config.Twilio == nil {
|
||||||
|
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return config.Twilio
|
||||||
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/client"
|
"github.com/TwinProduction/gatus/client"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
@@ -16,11 +17,15 @@ import (
|
|||||||
// AlertProvider is the configuration necessary for sending an alert using a custom HTTP request
|
// AlertProvider is the configuration necessary for sending an alert using a custom HTTP request
|
||||||
// Technically, all alert providers should be reachable using the custom alert provider
|
// Technically, all alert providers should be reachable using the custom alert provider
|
||||||
type AlertProvider struct {
|
type AlertProvider struct {
|
||||||
URL string `yaml:"url"`
|
URL string `yaml:"url"`
|
||||||
Method string `yaml:"method,omitempty"`
|
Method string `yaml:"method,omitempty"`
|
||||||
Insecure bool `yaml:"insecure,omitempty"`
|
Insecure bool `yaml:"insecure,omitempty"`
|
||||||
Body string `yaml:"body,omitempty"`
|
Body string `yaml:"body,omitempty"`
|
||||||
Headers map[string]string `yaml:"headers,omitempty"`
|
Headers map[string]string `yaml:"headers,omitempty"`
|
||||||
|
Placeholders map[string]map[string]string `yaml:"placeholders,omitempty"`
|
||||||
|
|
||||||
|
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
|
||||||
|
DefaultAlert *alert.Alert `yaml:"default-alert"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid returns whether the provider's configuration is valid
|
// IsValid returns whether the provider's configuration is valid
|
||||||
@@ -29,14 +34,29 @@ func (provider *AlertProvider) IsValid() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *AlertProvider {
|
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *alert.Alert, result *core.Result, resolved bool) *AlertProvider {
|
||||||
return provider
|
return provider
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetAlertStatePlaceholderValue returns the Placeholder value for ALERT_TRIGGERED_OR_RESOLVED if configured
|
||||||
|
func (provider *AlertProvider) GetAlertStatePlaceholderValue(resolved bool) string {
|
||||||
|
status := "TRIGGERED"
|
||||||
|
if resolved {
|
||||||
|
status = "RESOLVED"
|
||||||
|
}
|
||||||
|
if _, ok := provider.Placeholders["ALERT_TRIGGERED_OR_RESOLVED"]; ok {
|
||||||
|
if val, ok := provider.Placeholders["ALERT_TRIGGERED_OR_RESOLVED"][status]; ok {
|
||||||
|
return val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|
||||||
func (provider *AlertProvider) buildHTTPRequest(serviceName, alertDescription string, resolved bool) *http.Request {
|
func (provider *AlertProvider) buildHTTPRequest(serviceName, alertDescription string, resolved bool) *http.Request {
|
||||||
body := provider.Body
|
body := provider.Body
|
||||||
providerURL := provider.URL
|
providerURL := provider.URL
|
||||||
method := provider.Method
|
method := provider.Method
|
||||||
|
|
||||||
if strings.Contains(body, "[ALERT_DESCRIPTION]") {
|
if strings.Contains(body, "[ALERT_DESCRIPTION]") {
|
||||||
body = strings.ReplaceAll(body, "[ALERT_DESCRIPTION]", alertDescription)
|
body = strings.ReplaceAll(body, "[ALERT_DESCRIPTION]", alertDescription)
|
||||||
}
|
}
|
||||||
@@ -45,9 +65,9 @@ func (provider *AlertProvider) buildHTTPRequest(serviceName, alertDescription st
|
|||||||
}
|
}
|
||||||
if strings.Contains(body, "[ALERT_TRIGGERED_OR_RESOLVED]") {
|
if strings.Contains(body, "[ALERT_TRIGGERED_OR_RESOLVED]") {
|
||||||
if resolved {
|
if resolved {
|
||||||
body = strings.ReplaceAll(body, "[ALERT_TRIGGERED_OR_RESOLVED]", "RESOLVED")
|
body = strings.ReplaceAll(body, "[ALERT_TRIGGERED_OR_RESOLVED]", provider.GetAlertStatePlaceholderValue(true))
|
||||||
} else {
|
} else {
|
||||||
body = strings.ReplaceAll(body, "[ALERT_TRIGGERED_OR_RESOLVED]", "TRIGGERED")
|
body = strings.ReplaceAll(body, "[ALERT_TRIGGERED_OR_RESOLVED]", provider.GetAlertStatePlaceholderValue(false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if strings.Contains(providerURL, "[ALERT_DESCRIPTION]") {
|
if strings.Contains(providerURL, "[ALERT_DESCRIPTION]") {
|
||||||
@@ -58,9 +78,9 @@ func (provider *AlertProvider) buildHTTPRequest(serviceName, alertDescription st
|
|||||||
}
|
}
|
||||||
if strings.Contains(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]") {
|
if strings.Contains(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]") {
|
||||||
if resolved {
|
if resolved {
|
||||||
providerURL = strings.ReplaceAll(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]", "RESOLVED")
|
providerURL = strings.ReplaceAll(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]", provider.GetAlertStatePlaceholderValue(true))
|
||||||
} else {
|
} else {
|
||||||
providerURL = strings.ReplaceAll(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]", "TRIGGERED")
|
providerURL = strings.ReplaceAll(providerURL, "[ALERT_TRIGGERED_OR_RESOLVED]", provider.GetAlertStatePlaceholderValue(false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(method) == 0 {
|
if len(method) == 0 {
|
||||||
@@ -96,3 +116,8 @@ func (provider *AlertProvider) Send(serviceName, alertDescription string, resolv
|
|||||||
}
|
}
|
||||||
return ioutil.ReadAll(response.Body)
|
return ioutil.ReadAll(response.Body)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
func (provider AlertProvider) GetDefaultAlert() *alert.Alert {
|
||||||
|
return provider.DefaultAlert
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -60,11 +61,51 @@ func TestAlertProvider_buildHTTPRequestWhenTriggered(t *testing.T) {
|
|||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProvider(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProvider(t *testing.T) {
|
||||||
provider := AlertProvider{URL: "http://example.com"}
|
provider := AlertProvider{URL: "http://example.com"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if customAlertProvider != customAlertProvider {
|
if customAlertProvider.URL != "http://example.com" {
|
||||||
t.Error("customAlertProvider should've been equal to customAlertProvider")
|
t.Error("expected URL to be http://example.com, got", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlertProvider_buildHTTPRequestWithCustomPlaceholder(t *testing.T) {
|
||||||
|
const (
|
||||||
|
ExpectedURL = "http://example.com/service-name?event=test&description=alert-description"
|
||||||
|
ExpectedBody = "service-name,alert-description,test"
|
||||||
|
)
|
||||||
|
customAlertProvider := &AlertProvider{
|
||||||
|
URL: "http://example.com/[SERVICE_NAME]?event=[ALERT_TRIGGERED_OR_RESOLVED]&description=[ALERT_DESCRIPTION]",
|
||||||
|
Body: "[SERVICE_NAME],[ALERT_DESCRIPTION],[ALERT_TRIGGERED_OR_RESOLVED]",
|
||||||
|
Headers: nil,
|
||||||
|
Placeholders: map[string]map[string]string{
|
||||||
|
"ALERT_TRIGGERED_OR_RESOLVED": {
|
||||||
|
"RESOLVED": "test",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
request := customAlertProvider.buildHTTPRequest("service-name", "alert-description", true)
|
||||||
|
if request.URL.String() != ExpectedURL {
|
||||||
|
t.Error("expected URL to be", ExpectedURL, "was", request.URL.String())
|
||||||
|
}
|
||||||
|
body, _ := ioutil.ReadAll(request.Body)
|
||||||
|
if string(body) != ExpectedBody {
|
||||||
|
t.Error("expected body to be", ExpectedBody, "was", string(body))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlertProvider_GetAlertStatePlaceholderValueDefaults(t *testing.T) {
|
||||||
|
customAlertProvider := &AlertProvider{
|
||||||
|
URL: "http://example.com/[SERVICE_NAME]?event=[ALERT_TRIGGERED_OR_RESOLVED]&description=[ALERT_DESCRIPTION]",
|
||||||
|
Body: "[SERVICE_NAME],[ALERT_DESCRIPTION],[ALERT_TRIGGERED_OR_RESOLVED]",
|
||||||
|
Headers: nil,
|
||||||
|
Placeholders: nil,
|
||||||
|
}
|
||||||
|
if customAlertProvider.GetAlertStatePlaceholderValue(true) != "RESOLVED" {
|
||||||
|
t.Error("expected RESOLVED, got", customAlertProvider.GetAlertStatePlaceholderValue(true))
|
||||||
|
}
|
||||||
|
if customAlertProvider.GetAlertStatePlaceholderValue(false) != "TRIGGERED" {
|
||||||
|
t.Error("expected TRIGGERED, got", customAlertProvider.GetAlertStatePlaceholderValue(false))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,72 @@
|
|||||||
|
package discord
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
|
"github.com/TwinProduction/gatus/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AlertProvider is the configuration necessary for sending an alert using Discord
|
||||||
|
type AlertProvider struct {
|
||||||
|
WebhookURL string `yaml:"webhook-url"`
|
||||||
|
|
||||||
|
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
|
||||||
|
DefaultAlert *alert.Alert `yaml:"default-alert"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid returns whether the provider's configuration is valid
|
||||||
|
func (provider *AlertProvider) IsValid() bool {
|
||||||
|
return len(provider.WebhookURL) > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
|
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *alert.Alert, result *core.Result, resolved bool) *custom.AlertProvider {
|
||||||
|
var message, results string
|
||||||
|
var colorCode int
|
||||||
|
if resolved {
|
||||||
|
message = fmt.Sprintf("An alert for **%s** has been resolved after passing successfully %d time(s) in a row", service.Name, alert.SuccessThreshold)
|
||||||
|
colorCode = 3066993
|
||||||
|
} else {
|
||||||
|
message = fmt.Sprintf("An alert for **%s** has been triggered due to having failed %d time(s) in a row", service.Name, alert.FailureThreshold)
|
||||||
|
colorCode = 15158332
|
||||||
|
}
|
||||||
|
for _, conditionResult := range result.ConditionResults {
|
||||||
|
var prefix string
|
||||||
|
if conditionResult.Success {
|
||||||
|
prefix = ":white_check_mark:"
|
||||||
|
} else {
|
||||||
|
prefix = ":x:"
|
||||||
|
}
|
||||||
|
results += fmt.Sprintf("%s - `%s`\\n", prefix, conditionResult.Condition)
|
||||||
|
}
|
||||||
|
return &custom.AlertProvider{
|
||||||
|
URL: provider.WebhookURL,
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Body: fmt.Sprintf(`{
|
||||||
|
"content": "",
|
||||||
|
"embeds": [
|
||||||
|
{
|
||||||
|
"title": ":helmet_with_white_cross: Gatus",
|
||||||
|
"description": "%s:\n> %s",
|
||||||
|
"color": %d,
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"name": "Condition results",
|
||||||
|
"value": "%s",
|
||||||
|
"inline": false
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}`, message, alert.GetDescription(), colorCode, results),
|
||||||
|
Headers: map[string]string{"Content-Type": "application/json"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
func (provider AlertProvider) GetDefaultAlert() *alert.Alert {
|
||||||
|
return provider.DefaultAlert
|
||||||
|
}
|
||||||
@@ -0,0 +1,66 @@
|
|||||||
|
package discord
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
|
"github.com/TwinProduction/gatus/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAlertProvider_IsValid(t *testing.T) {
|
||||||
|
invalidProvider := AlertProvider{WebhookURL: ""}
|
||||||
|
if invalidProvider.IsValid() {
|
||||||
|
t.Error("provider shouldn't have been valid")
|
||||||
|
}
|
||||||
|
validProvider := AlertProvider{WebhookURL: "http://example.com"}
|
||||||
|
if !validProvider.IsValid() {
|
||||||
|
t.Error("provider should've been valid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
|
provider := AlertProvider{WebhookURL: "http://example.com"}
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
||||||
|
if customAlertProvider == nil {
|
||||||
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if !strings.Contains(customAlertProvider.Body, "resolved") {
|
||||||
|
t.Error("customAlertProvider.Body should've contained the substring resolved")
|
||||||
|
}
|
||||||
|
if customAlertProvider.URL != "http://example.com" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "http://example.com", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
|
provider := AlertProvider{WebhookURL: "http://example.com"}
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false)
|
||||||
|
if customAlertProvider == nil {
|
||||||
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if !strings.Contains(customAlertProvider.Body, "triggered") {
|
||||||
|
t.Error("customAlertProvider.Body should've contained the substring triggered")
|
||||||
|
}
|
||||||
|
if customAlertProvider.URL != "http://example.com" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "http://example.com", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
@@ -12,6 +13,9 @@ import (
|
|||||||
type AlertProvider struct {
|
type AlertProvider struct {
|
||||||
WebhookURL string `yaml:"webhook-url"`
|
WebhookURL string `yaml:"webhook-url"`
|
||||||
Insecure bool `yaml:"insecure,omitempty"`
|
Insecure bool `yaml:"insecure,omitempty"`
|
||||||
|
|
||||||
|
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
|
||||||
|
DefaultAlert *alert.Alert `yaml:"default-alert"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid returns whether the provider's configuration is valid
|
// IsValid returns whether the provider's configuration is valid
|
||||||
@@ -20,7 +24,7 @@ func (provider *AlertProvider) IsValid() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *custom.AlertProvider {
|
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *alert.Alert, result *core.Result, resolved bool) *custom.AlertProvider {
|
||||||
var message string
|
var message string
|
||||||
var color string
|
var color string
|
||||||
if resolved {
|
if resolved {
|
||||||
@@ -38,7 +42,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
} else {
|
} else {
|
||||||
prefix = ":x:"
|
prefix = ":x:"
|
||||||
}
|
}
|
||||||
results += fmt.Sprintf("%s - `%s`\n", prefix, conditionResult.Condition)
|
results += fmt.Sprintf("%s - `%s`\\n", prefix, conditionResult.Condition)
|
||||||
}
|
}
|
||||||
return &custom.AlertProvider{
|
return &custom.AlertProvider{
|
||||||
URL: provider.WebhookURL,
|
URL: provider.WebhookURL,
|
||||||
@@ -69,7 +73,12 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}`, message, message, alert.Description, color, service.URL, results),
|
}`, message, message, alert.GetDescription(), color, service.URL, results),
|
||||||
Headers: map[string]string{"Content-Type": "application/json"},
|
Headers: map[string]string{"Content-Type": "application/json"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
func (provider AlertProvider) GetDefaultAlert() *alert.Alert {
|
||||||
|
return provider.DefaultAlert
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package mattermost
|
package mattermost
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -19,23 +22,45 @@ func TestAlertProvider_IsValid(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
provider := AlertProvider{WebhookURL: "http://example.com"}
|
provider := AlertProvider{WebhookURL: "http://example.org"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "resolved") {
|
if !strings.Contains(customAlertProvider.Body, "resolved") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring resolved")
|
t.Error("customAlertProvider.Body should've contained the substring resolved")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "http://example.org" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "http://example.org", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
provider := AlertProvider{WebhookURL: "http://example.com"}
|
provider := AlertProvider{WebhookURL: "http://example.org"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "triggered") {
|
if !strings.Contains(customAlertProvider.Body, "triggered") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring triggered")
|
t.Error("customAlertProvider.Body should've contained the substring triggered")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "http://example.org" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "http://example.org", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
@@ -17,6 +18,9 @@ type AlertProvider struct {
|
|||||||
AccessKey string `yaml:"access-key"`
|
AccessKey string `yaml:"access-key"`
|
||||||
Originator string `yaml:"originator"`
|
Originator string `yaml:"originator"`
|
||||||
Recipients string `yaml:"recipients"`
|
Recipients string `yaml:"recipients"`
|
||||||
|
|
||||||
|
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
|
||||||
|
DefaultAlert *alert.Alert `yaml:"default-alert"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid returns whether the provider's configuration is valid
|
// IsValid returns whether the provider's configuration is valid
|
||||||
@@ -26,12 +30,12 @@ func (provider *AlertProvider) IsValid() bool {
|
|||||||
|
|
||||||
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
// Reference doc for messagebird https://developers.messagebird.com/api/sms-messaging/#send-outbound-sms
|
// Reference doc for messagebird https://developers.messagebird.com/api/sms-messaging/#send-outbound-sms
|
||||||
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, _ *core.Result, resolved bool) *custom.AlertProvider {
|
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *alert.Alert, _ *core.Result, resolved bool) *custom.AlertProvider {
|
||||||
var message string
|
var message string
|
||||||
if resolved {
|
if resolved {
|
||||||
message = fmt.Sprintf("RESOLVED: %s - %s", service.Name, alert.Description)
|
message = fmt.Sprintf("RESOLVED: %s - %s", service.Name, alert.GetDescription())
|
||||||
} else {
|
} else {
|
||||||
message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.Description)
|
message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.GetDescription())
|
||||||
}
|
}
|
||||||
|
|
||||||
return &custom.AlertProvider{
|
return &custom.AlertProvider{
|
||||||
@@ -48,3 +52,8 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
func (provider AlertProvider) GetDefaultAlert() *alert.Alert {
|
||||||
|
return provider.DefaultAlert
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package messagebird
|
package messagebird
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -28,13 +31,24 @@ func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
|||||||
Originator: "1",
|
Originator: "1",
|
||||||
Recipients: "1",
|
Recipients: "1",
|
||||||
}
|
}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "RESOLVED") {
|
if !strings.Contains(customAlertProvider.Body, "RESOLVED") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring RESOLVED")
|
t.Error("customAlertProvider.Body should've contained the substring RESOLVED")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "https://rest.messagebird.com/messages" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "https://rest.messagebird.com/messages", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
@@ -43,11 +57,22 @@ func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
|||||||
Originator: "1",
|
Originator: "1",
|
||||||
Recipients: "1",
|
Recipients: "1",
|
||||||
}
|
}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, false)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{}, false)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "TRIGGERED") {
|
if !strings.Contains(customAlertProvider.Body, "TRIGGERED") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring TRIGGERED")
|
t.Error("customAlertProvider.Body should've contained the substring TRIGGERED")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "https://rest.messagebird.com/messages" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "https://rest.messagebird.com/messages", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
@@ -11,6 +12,9 @@ import (
|
|||||||
// AlertProvider is the configuration necessary for sending an alert using PagerDuty
|
// AlertProvider is the configuration necessary for sending an alert using PagerDuty
|
||||||
type AlertProvider struct {
|
type AlertProvider struct {
|
||||||
IntegrationKey string `yaml:"integration-key"`
|
IntegrationKey string `yaml:"integration-key"`
|
||||||
|
|
||||||
|
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
|
||||||
|
DefaultAlert *alert.Alert `yaml:"default-alert"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid returns whether the provider's configuration is valid
|
// IsValid returns whether the provider's configuration is valid
|
||||||
@@ -21,14 +25,14 @@ func (provider *AlertProvider) IsValid() bool {
|
|||||||
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
//
|
//
|
||||||
// relevant: https://developer.pagerduty.com/docs/events-api-v2/trigger-events/
|
// relevant: https://developer.pagerduty.com/docs/events-api-v2/trigger-events/
|
||||||
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, _ *core.Result, resolved bool) *custom.AlertProvider {
|
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *alert.Alert, _ *core.Result, resolved bool) *custom.AlertProvider {
|
||||||
var message, eventAction, resolveKey string
|
var message, eventAction, resolveKey string
|
||||||
if resolved {
|
if resolved {
|
||||||
message = fmt.Sprintf("RESOLVED: %s - %s", service.Name, alert.Description)
|
message = fmt.Sprintf("RESOLVED: %s - %s", service.Name, alert.GetDescription())
|
||||||
eventAction = "resolve"
|
eventAction = "resolve"
|
||||||
resolveKey = alert.ResolveKey
|
resolveKey = alert.ResolveKey
|
||||||
} else {
|
} else {
|
||||||
message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.Description)
|
message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.GetDescription())
|
||||||
eventAction = "trigger"
|
eventAction = "trigger"
|
||||||
resolveKey = ""
|
resolveKey = ""
|
||||||
}
|
}
|
||||||
@@ -50,3 +54,8 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
func (provider AlertProvider) GetDefaultAlert() *alert.Alert {
|
||||||
|
return provider.DefaultAlert
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package pagerduty
|
package pagerduty
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,22 +23,44 @@ func TestAlertProvider_IsValid(t *testing.T) {
|
|||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
provider := AlertProvider{IntegrationKey: "00000000000000000000000000000000"}
|
provider := AlertProvider{IntegrationKey: "00000000000000000000000000000000"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "RESOLVED") {
|
if !strings.Contains(customAlertProvider.Body, "RESOLVED") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring RESOLVED")
|
t.Error("customAlertProvider.Body should've contained the substring RESOLVED")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "https://events.pagerduty.com/v2/enqueue" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "https://events.pagerduty.com/v2/enqueue", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
provider := AlertProvider{IntegrationKey: "00000000000000000000000000000000"}
|
provider := AlertProvider{IntegrationKey: "00000000000000000000000000000000"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, false)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{}, false)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "TRIGGERED") {
|
if !strings.Contains(customAlertProvider.Body, "TRIGGERED") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring TRIGGERED")
|
t.Error("customAlertProvider.Body should've contained the substring TRIGGERED")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "https://events.pagerduty.com/v2/enqueue" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "https://events.pagerduty.com/v2/enqueue", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,11 +1,14 @@
|
|||||||
package provider
|
package provider
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/discord"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/mattermost"
|
"github.com/TwinProduction/gatus/alerting/provider/mattermost"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/telegram"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
@@ -16,15 +19,42 @@ type AlertProvider interface {
|
|||||||
IsValid() bool
|
IsValid() bool
|
||||||
|
|
||||||
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *custom.AlertProvider
|
ToCustomAlertProvider(service *core.Service, alert *alert.Alert, result *core.Result, resolved bool) *custom.AlertProvider
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
GetDefaultAlert() *alert.Alert
|
||||||
|
}
|
||||||
|
|
||||||
|
// ParseWithDefaultAlert parses a service alert by using the provider's default alert as a baseline
|
||||||
|
func ParseWithDefaultAlert(providerDefaultAlert, serviceAlert *alert.Alert) {
|
||||||
|
if providerDefaultAlert == nil || serviceAlert == nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if serviceAlert.Enabled == nil {
|
||||||
|
serviceAlert.Enabled = providerDefaultAlert.Enabled
|
||||||
|
}
|
||||||
|
if serviceAlert.SendOnResolved == nil {
|
||||||
|
serviceAlert.SendOnResolved = providerDefaultAlert.SendOnResolved
|
||||||
|
}
|
||||||
|
if serviceAlert.Description == nil {
|
||||||
|
serviceAlert.Description = providerDefaultAlert.Description
|
||||||
|
}
|
||||||
|
if serviceAlert.FailureThreshold == 0 {
|
||||||
|
serviceAlert.FailureThreshold = providerDefaultAlert.FailureThreshold
|
||||||
|
}
|
||||||
|
if serviceAlert.SuccessThreshold == 0 {
|
||||||
|
serviceAlert.SuccessThreshold = providerDefaultAlert.SuccessThreshold
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
// Validate interface implementation on compile
|
// Validate interface implementation on compile
|
||||||
_ AlertProvider = (*custom.AlertProvider)(nil)
|
_ AlertProvider = (*custom.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*twilio.AlertProvider)(nil)
|
_ AlertProvider = (*discord.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*slack.AlertProvider)(nil)
|
|
||||||
_ AlertProvider = (*mattermost.AlertProvider)(nil)
|
_ AlertProvider = (*mattermost.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*messagebird.AlertProvider)(nil)
|
_ AlertProvider = (*messagebird.AlertProvider)(nil)
|
||||||
_ AlertProvider = (*pagerduty.AlertProvider)(nil)
|
_ AlertProvider = (*pagerduty.AlertProvider)(nil)
|
||||||
|
_ AlertProvider = (*slack.AlertProvider)(nil)
|
||||||
|
_ AlertProvider = (*telegram.AlertProvider)(nil)
|
||||||
|
_ AlertProvider = (*twilio.AlertProvider)(nil)
|
||||||
)
|
)
|
||||||
@@ -0,0 +1,153 @@
|
|||||||
|
package provider
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestParseWithDefaultAlert(t *testing.T) {
|
||||||
|
type Scenario struct {
|
||||||
|
Name string
|
||||||
|
DefaultAlert, ServiceAlert, ExpectedOutputAlert *alert.Alert
|
||||||
|
}
|
||||||
|
enabled := true
|
||||||
|
disabled := false
|
||||||
|
firstDescription := "description-1"
|
||||||
|
secondDescription := "description-2"
|
||||||
|
scenarios := []Scenario{
|
||||||
|
{
|
||||||
|
Name: "service-alert-type-only",
|
||||||
|
DefaultAlert: &alert.Alert{
|
||||||
|
Enabled: &enabled,
|
||||||
|
SendOnResolved: &enabled,
|
||||||
|
Description: &firstDescription,
|
||||||
|
FailureThreshold: 5,
|
||||||
|
SuccessThreshold: 10,
|
||||||
|
},
|
||||||
|
ServiceAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeDiscord,
|
||||||
|
},
|
||||||
|
ExpectedOutputAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeDiscord,
|
||||||
|
Enabled: &enabled,
|
||||||
|
SendOnResolved: &enabled,
|
||||||
|
Description: &firstDescription,
|
||||||
|
FailureThreshold: 5,
|
||||||
|
SuccessThreshold: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "service-alert-overwrites-default-alert",
|
||||||
|
DefaultAlert: &alert.Alert{
|
||||||
|
Enabled: &disabled,
|
||||||
|
SendOnResolved: &disabled,
|
||||||
|
Description: &firstDescription,
|
||||||
|
FailureThreshold: 5,
|
||||||
|
SuccessThreshold: 10,
|
||||||
|
},
|
||||||
|
ServiceAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeTelegram,
|
||||||
|
Enabled: &enabled,
|
||||||
|
SendOnResolved: &enabled,
|
||||||
|
Description: &secondDescription,
|
||||||
|
FailureThreshold: 6,
|
||||||
|
SuccessThreshold: 11,
|
||||||
|
},
|
||||||
|
ExpectedOutputAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeTelegram,
|
||||||
|
Enabled: &enabled,
|
||||||
|
SendOnResolved: &enabled,
|
||||||
|
Description: &secondDescription,
|
||||||
|
FailureThreshold: 6,
|
||||||
|
SuccessThreshold: 11,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "service-alert-partially-overwrites-default-alert",
|
||||||
|
DefaultAlert: &alert.Alert{
|
||||||
|
Enabled: &enabled,
|
||||||
|
SendOnResolved: &enabled,
|
||||||
|
Description: &firstDescription,
|
||||||
|
FailureThreshold: 5,
|
||||||
|
SuccessThreshold: 10,
|
||||||
|
},
|
||||||
|
ServiceAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeDiscord,
|
||||||
|
Enabled: nil,
|
||||||
|
SendOnResolved: nil,
|
||||||
|
FailureThreshold: 6,
|
||||||
|
SuccessThreshold: 11,
|
||||||
|
},
|
||||||
|
ExpectedOutputAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeDiscord,
|
||||||
|
Enabled: &enabled,
|
||||||
|
SendOnResolved: &enabled,
|
||||||
|
Description: &firstDescription,
|
||||||
|
FailureThreshold: 6,
|
||||||
|
SuccessThreshold: 11,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "default-alert-type-should-be-ignored",
|
||||||
|
DefaultAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeTelegram,
|
||||||
|
Enabled: &enabled,
|
||||||
|
SendOnResolved: &enabled,
|
||||||
|
Description: &firstDescription,
|
||||||
|
FailureThreshold: 5,
|
||||||
|
SuccessThreshold: 10,
|
||||||
|
},
|
||||||
|
ServiceAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeDiscord,
|
||||||
|
},
|
||||||
|
ExpectedOutputAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeDiscord,
|
||||||
|
Enabled: &enabled,
|
||||||
|
SendOnResolved: &enabled,
|
||||||
|
Description: &firstDescription,
|
||||||
|
FailureThreshold: 5,
|
||||||
|
SuccessThreshold: 10,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "no-default-alert",
|
||||||
|
DefaultAlert: &alert.Alert{
|
||||||
|
Type: alert.TypeDiscord,
|
||||||
|
Enabled: nil,
|
||||||
|
SendOnResolved: nil,
|
||||||
|
Description: &firstDescription,
|
||||||
|
FailureThreshold: 2,
|
||||||
|
SuccessThreshold: 5,
|
||||||
|
},
|
||||||
|
ServiceAlert: nil,
|
||||||
|
ExpectedOutputAlert: nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, scenario := range scenarios {
|
||||||
|
t.Run(scenario.Name, func(t *testing.T) {
|
||||||
|
ParseWithDefaultAlert(scenario.DefaultAlert, scenario.ServiceAlert)
|
||||||
|
if scenario.ExpectedOutputAlert == nil {
|
||||||
|
if scenario.ServiceAlert != nil {
|
||||||
|
t.Fail()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if scenario.ServiceAlert.IsEnabled() != scenario.ExpectedOutputAlert.IsEnabled() {
|
||||||
|
t.Errorf("expected ServiceAlert.IsEnabled() to be %v, got %v", scenario.ExpectedOutputAlert.IsEnabled(), scenario.ServiceAlert.IsEnabled())
|
||||||
|
}
|
||||||
|
if scenario.ServiceAlert.IsSendingOnResolved() != scenario.ExpectedOutputAlert.IsSendingOnResolved() {
|
||||||
|
t.Errorf("expected ServiceAlert.IsSendingOnResolved() to be %v, got %v", scenario.ExpectedOutputAlert.IsSendingOnResolved(), scenario.ServiceAlert.IsSendingOnResolved())
|
||||||
|
}
|
||||||
|
if scenario.ServiceAlert.GetDescription() != scenario.ExpectedOutputAlert.GetDescription() {
|
||||||
|
t.Errorf("expected ServiceAlert.GetDescription() to be %v, got %v", scenario.ExpectedOutputAlert.GetDescription(), scenario.ServiceAlert.GetDescription())
|
||||||
|
}
|
||||||
|
if scenario.ServiceAlert.FailureThreshold != scenario.ExpectedOutputAlert.FailureThreshold {
|
||||||
|
t.Errorf("expected ServiceAlert.FailureThreshold to be %v, got %v", scenario.ExpectedOutputAlert.FailureThreshold, scenario.ServiceAlert.FailureThreshold)
|
||||||
|
}
|
||||||
|
if scenario.ServiceAlert.SuccessThreshold != scenario.ExpectedOutputAlert.SuccessThreshold {
|
||||||
|
t.Errorf("expected ServiceAlert.SuccessThreshold to be %v, got %v", scenario.ExpectedOutputAlert.SuccessThreshold, scenario.ServiceAlert.SuccessThreshold)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,13 +4,17 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AlertProvider is the configuration necessary for sending an alert using Slack
|
// AlertProvider is the configuration necessary for sending an alert using Slack
|
||||||
type AlertProvider struct {
|
type AlertProvider struct {
|
||||||
WebhookURL string `yaml:"webhook-url"`
|
WebhookURL string `yaml:"webhook-url"` // Slack webhook URL
|
||||||
|
|
||||||
|
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
|
||||||
|
DefaultAlert *alert.Alert `yaml:"default-alert"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid returns whether the provider's configuration is valid
|
// IsValid returns whether the provider's configuration is valid
|
||||||
@@ -19,7 +23,7 @@ func (provider *AlertProvider) IsValid() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, result *core.Result, resolved bool) *custom.AlertProvider {
|
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *alert.Alert, result *core.Result, resolved bool) *custom.AlertProvider {
|
||||||
var message, color, results string
|
var message, color, results string
|
||||||
if resolved {
|
if resolved {
|
||||||
message = fmt.Sprintf("An alert for *%s* has been resolved after passing successfully %d time(s) in a row", service.Name, alert.SuccessThreshold)
|
message = fmt.Sprintf("An alert for *%s* has been resolved after passing successfully %d time(s) in a row", service.Name, alert.SuccessThreshold)
|
||||||
@@ -35,7 +39,7 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
} else {
|
} else {
|
||||||
prefix = ":x:"
|
prefix = ":x:"
|
||||||
}
|
}
|
||||||
results += fmt.Sprintf("%s - `%s`\n", prefix, conditionResult.Condition)
|
results += fmt.Sprintf("%s - `%s`\\n", prefix, conditionResult.Condition)
|
||||||
}
|
}
|
||||||
return &custom.AlertProvider{
|
return &custom.AlertProvider{
|
||||||
URL: provider.WebhookURL,
|
URL: provider.WebhookURL,
|
||||||
@@ -57,7 +61,12 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}`, message, alert.Description, color, results),
|
}`, message, alert.GetDescription(), color, results),
|
||||||
Headers: map[string]string{"Content-Type": "application/json"},
|
Headers: map[string]string{"Content-Type": "application/json"},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
func (provider AlertProvider) GetDefaultAlert() *alert.Alert {
|
||||||
|
return provider.DefaultAlert
|
||||||
|
}
|
||||||
@@ -1,9 +1,12 @@
|
|||||||
package slack
|
package slack
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -20,22 +23,44 @@ func TestAlertProvider_IsValid(t *testing.T) {
|
|||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
provider := AlertProvider{WebhookURL: "http://example.com"}
|
provider := AlertProvider{WebhookURL: "http://example.com"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "resolved") {
|
if !strings.Contains(customAlertProvider.Body, "resolved") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring resolved")
|
t.Error("customAlertProvider.Body should've contained the substring resolved")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "http://example.com" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "http://example.com", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
provider := AlertProvider{WebhookURL: "http://example.com"}
|
provider := AlertProvider{WebhookURL: "http://example.com"}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false)
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "triggered") {
|
if !strings.Contains(customAlertProvider.Body, "triggered") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring triggered")
|
t.Error("customAlertProvider.Body should've contained the substring triggered")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "http://example.com" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "http://example.com", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package telegram
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
|
"github.com/TwinProduction/gatus/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
// AlertProvider is the configuration necessary for sending an alert using Telegram
|
||||||
|
type AlertProvider struct {
|
||||||
|
Token string `yaml:"token"`
|
||||||
|
ID string `yaml:"id"`
|
||||||
|
|
||||||
|
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
|
||||||
|
DefaultAlert *alert.Alert `yaml:"default-alert"`
|
||||||
|
}
|
||||||
|
|
||||||
|
// IsValid returns whether the provider's configuration is valid
|
||||||
|
func (provider *AlertProvider) IsValid() bool {
|
||||||
|
return len(provider.Token) > 0 && len(provider.ID) > 0
|
||||||
|
}
|
||||||
|
|
||||||
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
|
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *alert.Alert, result *core.Result, resolved bool) *custom.AlertProvider {
|
||||||
|
var message, results string
|
||||||
|
if resolved {
|
||||||
|
message = fmt.Sprintf("An alert for *%s* has been resolved:\\n—\\n _healthcheck passing successfully %d time(s) in a row_\\n— ", service.Name, alert.FailureThreshold)
|
||||||
|
} else {
|
||||||
|
message = fmt.Sprintf("An alert for *%s* has been triggered:\\n—\\n _healthcheck failed %d time(s) in a row_\\n— ", service.Name, alert.FailureThreshold)
|
||||||
|
}
|
||||||
|
for _, conditionResult := range result.ConditionResults {
|
||||||
|
var prefix string
|
||||||
|
if conditionResult.Success {
|
||||||
|
prefix = "✅"
|
||||||
|
} else {
|
||||||
|
prefix = "❌"
|
||||||
|
}
|
||||||
|
results += fmt.Sprintf("%s - `%s`\\n", prefix, conditionResult.Condition)
|
||||||
|
}
|
||||||
|
var text string
|
||||||
|
if len(alert.GetDescription()) > 0 {
|
||||||
|
text = fmt.Sprintf("⛑ *Gatus* \\n%s \\n*Description* \\n_%s_ \\n\\n*Condition results*\\n%s", message, alert.GetDescription(), results)
|
||||||
|
} else {
|
||||||
|
text = fmt.Sprintf("⛑ *Gatus* \\n%s \\n*Condition results*\\n%s", message, results)
|
||||||
|
}
|
||||||
|
return &custom.AlertProvider{
|
||||||
|
URL: fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", provider.Token),
|
||||||
|
Method: http.MethodPost,
|
||||||
|
Body: fmt.Sprintf(`{"chat_id": "%s", "text": "%s", "parse_mode": "MARKDOWN"}`, provider.ID, text),
|
||||||
|
Headers: map[string]string{"Content-Type": "application/json"},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
func (provider AlertProvider) GetDefaultAlert() *alert.Alert {
|
||||||
|
return provider.DefaultAlert
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package telegram
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
|
"github.com/TwinProduction/gatus/core"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestAlertProvider_IsValid(t *testing.T) {
|
||||||
|
invalidProvider := AlertProvider{Token: "", ID: ""}
|
||||||
|
if invalidProvider.IsValid() {
|
||||||
|
t.Error("provider shouldn't have been valid")
|
||||||
|
}
|
||||||
|
validProvider := AlertProvider{Token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", ID: "12345678"}
|
||||||
|
if !validProvider.IsValid() {
|
||||||
|
t.Error("provider should've been valid")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
|
provider := AlertProvider{Token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", ID: "12345678"}
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "SUCCESSFUL_CONDITION", Success: true}}}, true)
|
||||||
|
if customAlertProvider == nil {
|
||||||
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if !strings.Contains(customAlertProvider.Body, "resolved") {
|
||||||
|
t.Error("customAlertProvider.Body should've contained the substring resolved")
|
||||||
|
}
|
||||||
|
if customAlertProvider.URL != fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", provider.Token) {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", provider.Token), customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
//_, err := json.Marshal(customAlertProvider.Body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
|
provider := AlertProvider{Token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", ID: "0123456789"}
|
||||||
|
description := "Healthcheck Successful"
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{Description: &description}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false)
|
||||||
|
if customAlertProvider == nil {
|
||||||
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if !strings.Contains(customAlertProvider.Body, "triggered") {
|
||||||
|
t.Error("customAlertProvider.Body should've contained the substring triggered")
|
||||||
|
}
|
||||||
|
if customAlertProvider.URL != fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", provider.Token) {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", provider.Token), customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAlertProvider_ToCustomAlertProviderWithDescription(t *testing.T) {
|
||||||
|
provider := AlertProvider{Token: "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", ID: "0123456789"}
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &alert.Alert{}, &core.Result{ConditionResults: []*core.ConditionResult{{Condition: "UNSUCCESSFUL_CONDITION", Success: false}}}, false)
|
||||||
|
if customAlertProvider == nil {
|
||||||
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if !strings.Contains(customAlertProvider.Body, "triggered") {
|
||||||
|
t.Error("customAlertProvider.Body should've contained the substring triggered")
|
||||||
|
}
|
||||||
|
if customAlertProvider.URL != fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", provider.Token) {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", fmt.Sprintf("https://api.telegram.org/bot%s/sendMessage", provider.Token), customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
body := make(map[string]interface{})
|
||||||
|
err := json.Unmarshal([]byte(customAlertProvider.Body), &body)
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected body to be valid JSON, got error:", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
@@ -16,6 +17,9 @@ type AlertProvider struct {
|
|||||||
Token string `yaml:"token"`
|
Token string `yaml:"token"`
|
||||||
From string `yaml:"from"`
|
From string `yaml:"from"`
|
||||||
To string `yaml:"to"`
|
To string `yaml:"to"`
|
||||||
|
|
||||||
|
// DefaultAlert is the default alert configuration to use for services with an alert of the appropriate type
|
||||||
|
DefaultAlert *alert.Alert `yaml:"default-alert"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsValid returns whether the provider's configuration is valid
|
// IsValid returns whether the provider's configuration is valid
|
||||||
@@ -24,12 +28,12 @@ func (provider *AlertProvider) IsValid() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
// ToCustomAlertProvider converts the provider into a custom.AlertProvider
|
||||||
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *core.Alert, _ *core.Result, resolved bool) *custom.AlertProvider {
|
func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, alert *alert.Alert, _ *core.Result, resolved bool) *custom.AlertProvider {
|
||||||
var message string
|
var message string
|
||||||
if resolved {
|
if resolved {
|
||||||
message = fmt.Sprintf("RESOLVED: %s - %s", service.Name, alert.Description)
|
message = fmt.Sprintf("RESOLVED: %s - %s", service.Name, alert.GetDescription())
|
||||||
} else {
|
} else {
|
||||||
message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.Description)
|
message = fmt.Sprintf("TRIGGERED: %s - %s", service.Name, alert.GetDescription())
|
||||||
}
|
}
|
||||||
return &custom.AlertProvider{
|
return &custom.AlertProvider{
|
||||||
URL: fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json", provider.SID),
|
URL: fmt.Sprintf("https://api.twilio.com/2010-04-01/Accounts/%s/Messages.json", provider.SID),
|
||||||
@@ -45,3 +49,8 @@ func (provider *AlertProvider) ToCustomAlertProvider(service *core.Service, aler
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetDefaultAlert returns the provider's default alert configuration
|
||||||
|
func (provider AlertProvider) GetDefaultAlert() *alert.Alert {
|
||||||
|
return provider.DefaultAlert
|
||||||
|
}
|
||||||
@@ -1,9 +1,11 @@
|
|||||||
package twilio
|
package twilio
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -26,31 +28,51 @@ func TestTwilioAlertProvider_IsValid(t *testing.T) {
|
|||||||
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithResolvedAlert(t *testing.T) {
|
||||||
provider := AlertProvider{
|
provider := AlertProvider{
|
||||||
SID: "1",
|
SID: "1",
|
||||||
Token: "1",
|
Token: "2",
|
||||||
From: "1",
|
From: "3",
|
||||||
To: "1",
|
To: "4",
|
||||||
}
|
}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, true)
|
description := "alert-description"
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "service-name"}, &alert.Alert{Description: &description}, &core.Result{}, true)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "RESOLVED") {
|
if !strings.Contains(customAlertProvider.Body, "RESOLVED") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring RESOLVED")
|
t.Error("customAlertProvider.Body should've contained the substring RESOLVED")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "https://api.twilio.com/2010-04-01/Accounts/1/Messages.json" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "https://api.twilio.com/2010-04-01/Accounts/1/Messages.json", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Body != "Body=RESOLVED%3A+service-name+-+alert-description&From=3&To=4" {
|
||||||
|
t.Errorf("expected body to be %s, got %s", "Body=RESOLVED%3A+service-name+-+alert-description&From=3&To=4", customAlertProvider.Body)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
func TestAlertProvider_ToCustomAlertProviderWithTriggeredAlert(t *testing.T) {
|
||||||
provider := AlertProvider{
|
provider := AlertProvider{
|
||||||
SID: "1",
|
SID: "4",
|
||||||
Token: "1",
|
Token: "3",
|
||||||
From: "1",
|
From: "2",
|
||||||
To: "1",
|
To: "1",
|
||||||
}
|
}
|
||||||
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{}, &core.Alert{}, &core.Result{}, false)
|
description := "alert-description"
|
||||||
|
customAlertProvider := provider.ToCustomAlertProvider(&core.Service{Name: "service-name"}, &alert.Alert{Description: &description}, &core.Result{}, false)
|
||||||
if customAlertProvider == nil {
|
if customAlertProvider == nil {
|
||||||
t.Error("customAlertProvider shouldn't have been nil")
|
t.Fatal("customAlertProvider shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if !strings.Contains(customAlertProvider.Body, "TRIGGERED") {
|
if !strings.Contains(customAlertProvider.Body, "TRIGGERED") {
|
||||||
t.Error("customAlertProvider.Body should've contained the substring TRIGGERED")
|
t.Error("customAlertProvider.Body should've contained the substring TRIGGERED")
|
||||||
}
|
}
|
||||||
|
if customAlertProvider.URL != "https://api.twilio.com/2010-04-01/Accounts/4/Messages.json" {
|
||||||
|
t.Errorf("expected URL to be %s, got %s", "https://api.twilio.com/2010-04-01/Accounts/4/Messages.json", customAlertProvider.URL)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Method != http.MethodPost {
|
||||||
|
t.Errorf("expected method to be %s, got %s", http.MethodPost, customAlertProvider.Method)
|
||||||
|
}
|
||||||
|
if customAlertProvider.Body != "Body=TRIGGERED%3A+service-name+-+alert-description&From=2&To=1" {
|
||||||
|
t.Errorf("expected body to be %s, got %s", "Body=TRIGGERED%3A+service-name+-+alert-description&From=2&To=1", customAlertProvider.Body)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+19
-3
@@ -4,6 +4,8 @@ import (
|
|||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/go-ping/ping"
|
"github.com/go-ping/ping"
|
||||||
@@ -16,17 +18,31 @@ var (
|
|||||||
// pingTimeout is the timeout for the Ping function
|
// pingTimeout is the timeout for the Ping function
|
||||||
// This is mainly exposed for testing purposes
|
// This is mainly exposed for testing purposes
|
||||||
pingTimeout = 5 * time.Second
|
pingTimeout = 5 * time.Second
|
||||||
|
|
||||||
|
// httpTimeout is the timeout for secureHTTPClient and insecureHTTPClient
|
||||||
|
httpTimeout = 10 * time.Second
|
||||||
)
|
)
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
// XXX: This is an undocumented feature. See https://github.com/TwinProduction/gatus/issues/104.
|
||||||
|
httpTimeoutInSecondsFromEnvironmentVariable := os.Getenv("HTTP_CLIENT_TIMEOUT_IN_SECONDS")
|
||||||
|
if len(httpTimeoutInSecondsFromEnvironmentVariable) > 0 {
|
||||||
|
if httpTimeoutInSeconds, err := strconv.Atoi(httpTimeoutInSecondsFromEnvironmentVariable); err == nil {
|
||||||
|
httpTimeout = time.Duration(httpTimeoutInSeconds) * time.Second
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// GetHTTPClient returns the shared HTTP client
|
// GetHTTPClient returns the shared HTTP client
|
||||||
func GetHTTPClient(insecure bool) *http.Client {
|
func GetHTTPClient(insecure bool) *http.Client {
|
||||||
if insecure {
|
if insecure {
|
||||||
if insecureHTTPClient == nil {
|
if insecureHTTPClient == nil {
|
||||||
insecureHTTPClient = &http.Client{
|
insecureHTTPClient = &http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: httpTimeout,
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
MaxIdleConns: 100,
|
MaxIdleConns: 100,
|
||||||
MaxIdleConnsPerHost: 20,
|
MaxIdleConnsPerHost: 20,
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
TLSClientConfig: &tls.Config{
|
TLSClientConfig: &tls.Config{
|
||||||
InsecureSkipVerify: true,
|
InsecureSkipVerify: true,
|
||||||
},
|
},
|
||||||
@@ -37,10 +53,11 @@ func GetHTTPClient(insecure bool) *http.Client {
|
|||||||
}
|
}
|
||||||
if secureHTTPClient == nil {
|
if secureHTTPClient == nil {
|
||||||
secureHTTPClient = &http.Client{
|
secureHTTPClient = &http.Client{
|
||||||
Timeout: 10 * time.Second,
|
Timeout: httpTimeout,
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
MaxIdleConns: 100,
|
MaxIdleConns: 100,
|
||||||
MaxIdleConnsPerHost: 20,
|
MaxIdleConnsPerHost: 20,
|
||||||
|
Proxy: http.ProxyFromEnvironment,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,7 +84,6 @@ func Ping(address string) (bool, time.Duration) {
|
|||||||
}
|
}
|
||||||
pinger.Count = 1
|
pinger.Count = 1
|
||||||
pinger.Timeout = pingTimeout
|
pinger.Timeout = pingTimeout
|
||||||
pinger.SetNetwork("ip4")
|
|
||||||
pinger.SetPrivileged(true)
|
pinger.SetPrivileged(true)
|
||||||
err = pinger.Run()
|
err = pinger.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
+16
@@ -36,3 +36,19 @@ services:
|
|||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
- "[BODY].deleted == false"
|
- "[BODY].deleted == false"
|
||||||
- "len([BODY].text) > 0"
|
- "len([BODY].text) > 0"
|
||||||
|
|
||||||
|
- name: example-dns-query
|
||||||
|
url: "8.8.8.8" # Address of the DNS server to use
|
||||||
|
interval: 5m
|
||||||
|
dns:
|
||||||
|
query-name: "example.com"
|
||||||
|
query-type: "A"
|
||||||
|
conditions:
|
||||||
|
- "[BODY] == 93.184.216.34"
|
||||||
|
- "[DNS_RCODE] == NOERROR"
|
||||||
|
|
||||||
|
- name: icmp-ping
|
||||||
|
url: "icmp://example.org"
|
||||||
|
interval: 1m
|
||||||
|
conditions:
|
||||||
|
- "[CONNECTED] == true"
|
||||||
+100
-94
@@ -5,8 +5,10 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/TwinProduction/gatus/alerting"
|
"github.com/TwinProduction/gatus/alerting"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/alerting/provider"
|
"github.com/TwinProduction/gatus/alerting/provider"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
"github.com/TwinProduction/gatus/k8s"
|
"github.com/TwinProduction/gatus/k8s"
|
||||||
@@ -39,13 +41,8 @@ var (
|
|||||||
// ErrConfigFileNotFound is an error returned when the configuration file could not be found
|
// ErrConfigFileNotFound is an error returned when the configuration file could not be found
|
||||||
ErrConfigFileNotFound = errors.New("configuration file not found")
|
ErrConfigFileNotFound = errors.New("configuration file not found")
|
||||||
|
|
||||||
// ErrConfigNotLoaded is an error returned when an attempt to Get() the configuration before loading it is made
|
|
||||||
ErrConfigNotLoaded = errors.New("configuration is nil")
|
|
||||||
|
|
||||||
// ErrInvalidSecurityConfig is an error returned when the security configuration is invalid
|
// ErrInvalidSecurityConfig is an error returned when the security configuration is invalid
|
||||||
ErrInvalidSecurityConfig = errors.New("invalid security configuration")
|
ErrInvalidSecurityConfig = errors.New("invalid security configuration")
|
||||||
|
|
||||||
config *Config
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config is the main configuration structure
|
// Config is the main configuration structure
|
||||||
@@ -56,6 +53,10 @@ type Config struct {
|
|||||||
// Metrics Whether to expose metrics at /metrics
|
// Metrics Whether to expose metrics at /metrics
|
||||||
Metrics bool `yaml:"metrics"`
|
Metrics bool `yaml:"metrics"`
|
||||||
|
|
||||||
|
// SkipInvalidConfigUpdate Whether to make the application ignore invalid configuration
|
||||||
|
// if the configuration file is updated while the application is running
|
||||||
|
SkipInvalidConfigUpdate bool `yaml:"skip-invalid-config-update"`
|
||||||
|
|
||||||
// DisableMonitoringLock Whether to disable the monitoring lock
|
// DisableMonitoringLock Whether to disable the monitoring lock
|
||||||
// The monitoring lock is what prevents multiple services from being processed at the same time.
|
// The monitoring lock is what prevents multiple services from being processed at the same time.
|
||||||
// Disabling this may lead to inaccurate response times
|
// Disabling this may lead to inaccurate response times
|
||||||
@@ -78,47 +79,57 @@ type Config struct {
|
|||||||
|
|
||||||
// Web is the configuration for the web listener
|
// Web is the configuration for the web listener
|
||||||
Web *WebConfig `yaml:"web"`
|
Web *WebConfig `yaml:"web"`
|
||||||
|
|
||||||
|
filePath string // path to the file from which config was loaded from
|
||||||
|
lastFileModTime time.Time // last modification time
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get returns the configuration, or panics if the configuration hasn't loaded yet
|
// HasLoadedConfigurationFileBeenModified returns whether the file that the
|
||||||
func Get() *Config {
|
// configuration has been loaded from has been modified since it was last read
|
||||||
if config == nil {
|
func (config Config) HasLoadedConfigurationFileBeenModified() bool {
|
||||||
panic(ErrConfigNotLoaded)
|
if fileInfo, err := os.Stat(config.filePath); err == nil {
|
||||||
|
if !fileInfo.ModTime().IsZero() {
|
||||||
|
return config.lastFileModTime.Unix() != fileInfo.ModTime().Unix()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return config
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set sets the configuration
|
// UpdateLastFileModTime refreshes Config.lastFileModTime
|
||||||
// Used only for testing
|
func (config *Config) UpdateLastFileModTime() {
|
||||||
func Set(cfg *Config) {
|
if fileInfo, err := os.Stat(config.filePath); err == nil {
|
||||||
config = cfg
|
if !fileInfo.ModTime().IsZero() {
|
||||||
|
config.lastFileModTime = fileInfo.ModTime()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load loads a custom configuration file
|
// Load loads a custom configuration file
|
||||||
// Note that the misconfiguration of some fields may lead to panics. This is on purpose.
|
// Note that the misconfiguration of some fields may lead to panics. This is on purpose.
|
||||||
func Load(configFile string) error {
|
func Load(configFile string) (*Config, error) {
|
||||||
log.Printf("[config][Load] Reading configuration from configFile=%s", configFile)
|
log.Printf("[config][Load] Reading configuration from configFile=%s", configFile)
|
||||||
cfg, err := readConfigurationFile(configFile)
|
cfg, err := readConfigurationFile(configFile)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if os.IsNotExist(err) {
|
if os.IsNotExist(err) {
|
||||||
return ErrConfigFileNotFound
|
return nil, ErrConfigFileNotFound
|
||||||
}
|
}
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
config = cfg
|
cfg.filePath = configFile
|
||||||
return nil
|
cfg.UpdateLastFileModTime()
|
||||||
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// LoadDefaultConfiguration loads the default configuration file
|
// LoadDefaultConfiguration loads the default configuration file
|
||||||
func LoadDefaultConfiguration() error {
|
func LoadDefaultConfiguration() (*Config, error) {
|
||||||
err := Load(DefaultConfigurationFilePath)
|
cfg, err := Load(DefaultConfigurationFilePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == ErrConfigFileNotFound {
|
if err == ErrConfigFileNotFound {
|
||||||
return Load(DefaultFallbackConfigurationFilePath)
|
return Load(DefaultFallbackConfigurationFilePath)
|
||||||
}
|
}
|
||||||
return err
|
return nil, err
|
||||||
}
|
}
|
||||||
return nil
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func readConfigurationFile(fileName string) (config *Config, err error) {
|
func readConfigurationFile(fileName string) (config *Config, err error) {
|
||||||
@@ -144,23 +155,33 @@ func parseAndValidateConfigBytes(yamlBytes []byte) (config *Config, err error) {
|
|||||||
} else {
|
} else {
|
||||||
// Note that the functions below may panic, and this is on purpose to prevent Gatus from starting with
|
// Note that the functions below may panic, and this is on purpose to prevent Gatus from starting with
|
||||||
// invalid configurations
|
// invalid configurations
|
||||||
validateAlertingConfig(config)
|
validateAlertingConfig(config.Alerting, config.Services, config.Debug)
|
||||||
validateSecurityConfig(config)
|
if err := validateSecurityConfig(config); err != nil {
|
||||||
validateServicesConfig(config)
|
return nil, err
|
||||||
validateKubernetesConfig(config)
|
}
|
||||||
validateWebConfig(config)
|
if err := validateServicesConfig(config); err != nil {
|
||||||
validateStorageConfig(config)
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := validateKubernetesConfig(config); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := validateWebConfig(config); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := validateStorageConfig(config); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateStorageConfig(config *Config) {
|
func validateStorageConfig(config *Config) error {
|
||||||
if config.Storage == nil {
|
if config.Storage == nil {
|
||||||
config.Storage = &storage.Config{}
|
config.Storage = &storage.Config{}
|
||||||
}
|
}
|
||||||
err := storage.Initialize(config.Storage)
|
err := storage.Initialize(config.Storage)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
// Remove all ServiceStatus that represent services which no longer exist in the configuration
|
// Remove all ServiceStatus that represent services which no longer exist in the configuration
|
||||||
var keys []string
|
var keys []string
|
||||||
@@ -171,44 +192,52 @@ func validateStorageConfig(config *Config) {
|
|||||||
if numberOfServiceStatusesDeleted > 0 {
|
if numberOfServiceStatusesDeleted > 0 {
|
||||||
log.Printf("[config][validateStorageConfig] Deleted %d service statuses because their matching services no longer existed", numberOfServiceStatusesDeleted)
|
log.Printf("[config][validateStorageConfig] Deleted %d service statuses because their matching services no longer existed", numberOfServiceStatusesDeleted)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateWebConfig(config *Config) {
|
func validateWebConfig(config *Config) error {
|
||||||
if config.Web == nil {
|
if config.Web == nil {
|
||||||
config.Web = &WebConfig{Address: DefaultAddress, Port: DefaultPort}
|
config.Web = &WebConfig{Address: DefaultAddress, Port: DefaultPort}
|
||||||
} else {
|
} else {
|
||||||
config.Web.validateAndSetDefaults()
|
return config.Web.validateAndSetDefaults()
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateKubernetesConfig(config *Config) {
|
// deprecated
|
||||||
|
// I don't like the current implementation.
|
||||||
|
func validateKubernetesConfig(config *Config) error {
|
||||||
if config.Kubernetes != nil && config.Kubernetes.AutoDiscover {
|
if config.Kubernetes != nil && config.Kubernetes.AutoDiscover {
|
||||||
if config.Kubernetes.ServiceTemplate == nil {
|
if config.Kubernetes.ServiceTemplate == nil {
|
||||||
panic("kubernetes.service-template cannot be nil")
|
return errors.New("kubernetes.service-template cannot be nil")
|
||||||
}
|
}
|
||||||
if config.Debug {
|
if config.Debug {
|
||||||
log.Println("[config][validateKubernetesConfig] Automatically discovering Kubernetes services...")
|
log.Println("[config][validateKubernetesConfig] Automatically discovering Kubernetes services...")
|
||||||
}
|
}
|
||||||
discoveredServices, err := k8s.DiscoverServices(config.Kubernetes)
|
discoveredServices, err := k8s.DiscoverServices(config.Kubernetes)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
config.Services = append(config.Services, discoveredServices...)
|
config.Services = append(config.Services, discoveredServices...)
|
||||||
log.Printf("[config][validateKubernetesConfig] Discovered %d Kubernetes services", len(discoveredServices))
|
log.Printf("[config][validateKubernetesConfig] Discovered %d Kubernetes services", len(discoveredServices))
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateServicesConfig(config *Config) {
|
func validateServicesConfig(config *Config) error {
|
||||||
for _, service := range config.Services {
|
for _, service := range config.Services {
|
||||||
if config.Debug {
|
if config.Debug {
|
||||||
log.Printf("[config][validateServicesConfig] Validating service '%s'", service.Name)
|
log.Printf("[config][validateServicesConfig] Validating service '%s'", service.Name)
|
||||||
}
|
}
|
||||||
service.ValidateAndSetDefaults()
|
if err := service.ValidateAndSetDefaults(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
log.Printf("[config][validateServicesConfig] Validated %d services", len(config.Services))
|
log.Printf("[config][validateServicesConfig] Validated %d services", len(config.Services))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateSecurityConfig(config *Config) {
|
func validateSecurityConfig(config *Config) error {
|
||||||
if config.Security != nil {
|
if config.Security != nil {
|
||||||
if config.Security.IsValid() {
|
if config.Security.IsValid() {
|
||||||
if config.Debug {
|
if config.Debug {
|
||||||
@@ -217,29 +246,49 @@ func validateSecurityConfig(config *Config) {
|
|||||||
} else {
|
} else {
|
||||||
// If there was an attempt to configure security, then it must mean that some confidential or private
|
// If there was an attempt to configure security, then it must mean that some confidential or private
|
||||||
// data are exposed. As a result, we'll force a panic because it's better to be safe than sorry.
|
// data are exposed. As a result, we'll force a panic because it's better to be safe than sorry.
|
||||||
panic(ErrInvalidSecurityConfig)
|
return ErrInvalidSecurityConfig
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func validateAlertingConfig(config *Config) {
|
// validateAlertingConfig validates the alerting configuration
|
||||||
if config.Alerting == nil {
|
// Note that the alerting configuration has to be validated before the service configuration, because the default alert
|
||||||
|
// returned by provider.AlertProvider.GetDefaultAlert() must be parsed before core.Service.ValidateAndSetDefaults()
|
||||||
|
// sets the default alert values when none are set.
|
||||||
|
func validateAlertingConfig(alertingConfig *alerting.Config, services []*core.Service, debug bool) {
|
||||||
|
if alertingConfig == nil {
|
||||||
log.Printf("[config][validateAlertingConfig] Alerting is not configured")
|
log.Printf("[config][validateAlertingConfig] Alerting is not configured")
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
alertTypes := []core.AlertType{
|
alertTypes := []alert.Type{
|
||||||
core.SlackAlert,
|
alert.TypeCustom,
|
||||||
core.MattermostAlert,
|
alert.TypeDiscord,
|
||||||
core.MessagebirdAlert,
|
alert.TypeMattermost,
|
||||||
core.TwilioAlert,
|
alert.TypeMessagebird,
|
||||||
core.PagerDutyAlert,
|
alert.TypePagerDuty,
|
||||||
core.CustomAlert,
|
alert.TypeSlack,
|
||||||
|
alert.TypeTelegram,
|
||||||
|
alert.TypeTwilio,
|
||||||
}
|
}
|
||||||
var validProviders, invalidProviders []core.AlertType
|
var validProviders, invalidProviders []alert.Type
|
||||||
for _, alertType := range alertTypes {
|
for _, alertType := range alertTypes {
|
||||||
alertProvider := GetAlertingProviderByAlertType(config, alertType)
|
alertProvider := alertingConfig.GetAlertingProviderByAlertType(alertType)
|
||||||
if alertProvider != nil {
|
if alertProvider != nil {
|
||||||
if alertProvider.IsValid() {
|
if alertProvider.IsValid() {
|
||||||
|
// Parse alerts with the provider's default alert
|
||||||
|
if alertProvider.GetDefaultAlert() != nil {
|
||||||
|
for _, service := range services {
|
||||||
|
for alertIndex, serviceAlert := range service.Alerts {
|
||||||
|
if alertType == serviceAlert.Type {
|
||||||
|
if debug {
|
||||||
|
log.Printf("[config][validateAlertingConfig] Parsing alert %d with provider's default alert for provider=%s in service=%s", alertIndex, alertType, service.Name)
|
||||||
|
}
|
||||||
|
provider.ParseWithDefaultAlert(alertProvider.GetDefaultAlert(), serviceAlert)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
validProviders = append(validProviders, alertType)
|
validProviders = append(validProviders, alertType)
|
||||||
} else {
|
} else {
|
||||||
log.Printf("[config][validateAlertingConfig] Ignoring provider=%s because configuration is invalid", alertType)
|
log.Printf("[config][validateAlertingConfig] Ignoring provider=%s because configuration is invalid", alertType)
|
||||||
@@ -251,46 +300,3 @@ func validateAlertingConfig(config *Config) {
|
|||||||
}
|
}
|
||||||
log.Printf("[config][validateAlertingConfig] configuredProviders=%s; ignoredProviders=%s", validProviders, invalidProviders)
|
log.Printf("[config][validateAlertingConfig] configuredProviders=%s; ignoredProviders=%s", validProviders, invalidProviders)
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAlertingProviderByAlertType returns an provider.AlertProvider by its corresponding core.AlertType
|
|
||||||
func GetAlertingProviderByAlertType(config *Config, alertType core.AlertType) provider.AlertProvider {
|
|
||||||
switch alertType {
|
|
||||||
case core.SlackAlert:
|
|
||||||
if config.Alerting.Slack == nil {
|
|
||||||
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return config.Alerting.Slack
|
|
||||||
case core.MattermostAlert:
|
|
||||||
if config.Alerting.Mattermost == nil {
|
|
||||||
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return config.Alerting.Mattermost
|
|
||||||
case core.MessagebirdAlert:
|
|
||||||
if config.Alerting.Messagebird == nil {
|
|
||||||
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return config.Alerting.Messagebird
|
|
||||||
case core.TwilioAlert:
|
|
||||||
if config.Alerting.Twilio == nil {
|
|
||||||
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return config.Alerting.Twilio
|
|
||||||
case core.PagerDutyAlert:
|
|
||||||
if config.Alerting.PagerDuty == nil {
|
|
||||||
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return config.Alerting.PagerDuty
|
|
||||||
case core.CustomAlert:
|
|
||||||
if config.Alerting.Custom == nil {
|
|
||||||
// Since we're returning an interface, we need to explicitly return nil, even if the provider itself is nil
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
return config.Alerting.Custom
|
|
||||||
}
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
+566
-48
@@ -6,36 +6,30 @@ import (
|
|||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/custom"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/discord"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/mattermost"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/messagebird"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/pagerduty"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/slack"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/telegram"
|
||||||
|
"github.com/TwinProduction/gatus/alerting/provider/twilio"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
"github.com/TwinProduction/gatus/k8stest"
|
"github.com/TwinProduction/gatus/k8stest"
|
||||||
v1 "k8s.io/api/core/v1"
|
v1 "k8s.io/api/core/v1"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestGetBeforeConfigIsLoaded(t *testing.T) {
|
|
||||||
defer func() { recover() }()
|
|
||||||
Get()
|
|
||||||
t.Fatal("Should've panicked because the configuration hasn't been loaded yet")
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestSet(t *testing.T) {
|
|
||||||
if config != nil {
|
|
||||||
t.Fatal("config should've been nil")
|
|
||||||
}
|
|
||||||
Set(&Config{})
|
|
||||||
if config == nil {
|
|
||||||
t.Fatal("config shouldn't have been nil")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestLoadFileThatDoesNotExist(t *testing.T) {
|
func TestLoadFileThatDoesNotExist(t *testing.T) {
|
||||||
err := Load("file-that-does-not-exist.yaml")
|
_, err := Load("file-that-does-not-exist.yaml")
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Should've returned an error, because the file specified doesn't exist")
|
t.Error("Should've returned an error, because the file specified doesn't exist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadDefaultConfigurationFile(t *testing.T) {
|
func TestLoadDefaultConfigurationFile(t *testing.T) {
|
||||||
err := LoadDefaultConfiguration()
|
_, err := LoadDefaultConfiguration()
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Error("Should've returned an error, because there's no configuration files at the default path nor the default fallback path")
|
t.Error("Should've returned an error, because there's no configuration files at the default path nor the default fallback path")
|
||||||
}
|
}
|
||||||
@@ -227,8 +221,7 @@ services:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndValidateConfigBytesWithInvalidPort(t *testing.T) {
|
func TestParseAndValidateConfigBytesWithInvalidPort(t *testing.T) {
|
||||||
defer func() { recover() }()
|
_, err := parseAndValidateConfigBytes([]byte(`
|
||||||
_, _ = parseAndValidateConfigBytes([]byte(`
|
|
||||||
web:
|
web:
|
||||||
port: 65536
|
port: 65536
|
||||||
address: 127.0.0.1
|
address: 127.0.0.1
|
||||||
@@ -238,7 +231,9 @@ services:
|
|||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
`))
|
`))
|
||||||
t.Fatal("Should've panicked because the configuration specifies an invalid port value")
|
if err == nil {
|
||||||
|
t.Fatal("Should've returned an error because the configuration specifies an invalid port value")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndValidateConfigBytesWithMetricsAndCustomUserAgentHeader(t *testing.T) {
|
func TestParseAndValidateConfigBytesWithMetricsAndCustomUserAgentHeader(t *testing.T) {
|
||||||
@@ -338,12 +333,25 @@ debug: true
|
|||||||
alerting:
|
alerting:
|
||||||
slack:
|
slack:
|
||||||
webhook-url: "http://example.com"
|
webhook-url: "http://example.com"
|
||||||
|
discord:
|
||||||
|
webhook-url: "http://example.org"
|
||||||
pagerduty:
|
pagerduty:
|
||||||
integration-key: "00000000000000000000000000000000"
|
integration-key: "00000000000000000000000000000000"
|
||||||
|
mattermost:
|
||||||
|
webhook-url: "http://example.com"
|
||||||
messagebird:
|
messagebird:
|
||||||
access-key: "1"
|
access-key: "1"
|
||||||
originator: "31619191918"
|
originator: "31619191918"
|
||||||
recipients: "31619191919"
|
recipients: "31619191919"
|
||||||
|
telegram:
|
||||||
|
token: 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
|
||||||
|
id: 0123456789
|
||||||
|
twilio:
|
||||||
|
sid: "1234"
|
||||||
|
token: "5678"
|
||||||
|
from: "+1-234-567-8901"
|
||||||
|
to: "+1-234-567-8901"
|
||||||
|
|
||||||
services:
|
services:
|
||||||
- name: twinnation
|
- name: twinnation
|
||||||
url: https://twinnation.org/health
|
url: https://twinnation.org/health
|
||||||
@@ -355,10 +363,196 @@ services:
|
|||||||
failure-threshold: 7
|
failure-threshold: 7
|
||||||
success-threshold: 5
|
success-threshold: 5
|
||||||
description: "Healthcheck failed 7 times in a row"
|
description: "Healthcheck failed 7 times in a row"
|
||||||
- type: messagebird
|
- type: mattermost
|
||||||
enabled: true
|
enabled: true
|
||||||
|
- type: messagebird
|
||||||
|
- type: discord
|
||||||
|
enabled: true
|
||||||
|
failure-threshold: 10
|
||||||
|
- type: telegram
|
||||||
|
enabled: true
|
||||||
|
- type: twilio
|
||||||
|
enabled: true
|
||||||
|
failure-threshold: 12
|
||||||
|
success-threshold: 15
|
||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
|
`))
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected no error, got", err.Error())
|
||||||
|
}
|
||||||
|
if config == nil {
|
||||||
|
t.Fatal("Config shouldn't have been nil")
|
||||||
|
}
|
||||||
|
// Alerting providers
|
||||||
|
if config.Alerting == nil {
|
||||||
|
t.Fatal("config.Alerting shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if config.Alerting.Slack == nil || !config.Alerting.Slack.IsValid() {
|
||||||
|
t.Fatal("Slack alerting config should've been valid")
|
||||||
|
}
|
||||||
|
// Services
|
||||||
|
if len(config.Services) != 1 {
|
||||||
|
t.Error("There should've been 1 service")
|
||||||
|
}
|
||||||
|
if config.Services[0].URL != "https://twinnation.org/health" {
|
||||||
|
t.Errorf("URL should have been %s", "https://twinnation.org/health")
|
||||||
|
}
|
||||||
|
if config.Services[0].Interval != 60*time.Second {
|
||||||
|
t.Errorf("Interval should have been %s, because it is the default value", 60*time.Second)
|
||||||
|
}
|
||||||
|
if len(config.Services[0].Alerts) != 7 {
|
||||||
|
t.Fatal("There should've been 7 alerts configured")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[0].Type != alert.TypeSlack {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeSlack, config.Services[0].Alerts[0].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[0].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[0].FailureThreshold != 3 {
|
||||||
|
t.Errorf("The default failure threshold of the alert should've been %d, but it was %d", 3, config.Services[0].Alerts[0].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[0].SuccessThreshold != 2 {
|
||||||
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[0].SuccessThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[1].Type != alert.TypePagerDuty {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypePagerDuty, config.Services[0].Alerts[1].Type)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[1].GetDescription() != "Healthcheck failed 7 times in a row" {
|
||||||
|
t.Errorf("The description of the alert should've been %s, but it was %s", "Healthcheck failed 7 times in a row", config.Services[0].Alerts[1].GetDescription())
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[1].FailureThreshold != 7 {
|
||||||
|
t.Errorf("The failure threshold of the alert should've been %d, but it was %d", 7, config.Services[0].Alerts[1].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[1].SuccessThreshold != 5 {
|
||||||
|
t.Errorf("The success threshold of the alert should've been %d, but it was %d", 5, config.Services[0].Alerts[1].SuccessThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[2].Type != alert.TypeMattermost {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeMattermost, config.Services[0].Alerts[2].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[2].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[2].FailureThreshold != 3 {
|
||||||
|
t.Errorf("The default failure threshold of the alert should've been %d, but it was %d", 3, config.Services[0].Alerts[2].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[2].SuccessThreshold != 2 {
|
||||||
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[2].SuccessThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[3].Type != alert.TypeMessagebird {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeMessagebird, config.Services[0].Alerts[3].Type)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[3].IsEnabled() {
|
||||||
|
t.Error("The alert should've been disabled")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[4].Type != alert.TypeDiscord {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeDiscord, config.Services[0].Alerts[4].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[4].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[4].FailureThreshold != 10 {
|
||||||
|
t.Errorf("The failure threshold of the alert should've been %d, but it was %d", 10, config.Services[0].Alerts[4].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[4].SuccessThreshold != 2 {
|
||||||
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[4].SuccessThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[5].Type != alert.TypeTelegram {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeTelegram, config.Services[0].Alerts[5].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[5].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[5].FailureThreshold != 3 {
|
||||||
|
t.Errorf("The default failure threshold of the alert should've been %d, but it was %d", 3, config.Services[0].Alerts[5].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[5].SuccessThreshold != 2 {
|
||||||
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[5].SuccessThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[6].Type != alert.TypeTwilio {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeTwilio, config.Services[0].Alerts[6].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[6].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[6].FailureThreshold != 12 {
|
||||||
|
t.Errorf("The default failure threshold of the alert should've been %d, but it was %d", 12, config.Services[0].Alerts[6].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[6].SuccessThreshold != 15 {
|
||||||
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 15, config.Services[0].Alerts[6].SuccessThreshold)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseAndValidateConfigBytesWithAlertingAndDefaultAlert(t *testing.T) {
|
||||||
|
config, err := parseAndValidateConfigBytes([]byte(`
|
||||||
|
debug: true
|
||||||
|
|
||||||
|
alerting:
|
||||||
|
slack:
|
||||||
|
webhook-url: "http://example.com"
|
||||||
|
default-alert:
|
||||||
|
enabled: true
|
||||||
|
discord:
|
||||||
|
webhook-url: "http://example.org"
|
||||||
|
default-alert:
|
||||||
|
enabled: true
|
||||||
|
failure-threshold: 10
|
||||||
|
success-threshold: 1
|
||||||
|
pagerduty:
|
||||||
|
integration-key: "00000000000000000000000000000000"
|
||||||
|
default-alert:
|
||||||
|
enabled: true
|
||||||
|
description: default description
|
||||||
|
failure-threshold: 7
|
||||||
|
success-threshold: 5
|
||||||
|
mattermost:
|
||||||
|
webhook-url: "http://example.com"
|
||||||
|
default-alert:
|
||||||
|
enabled: true
|
||||||
|
messagebird:
|
||||||
|
access-key: "1"
|
||||||
|
originator: "31619191918"
|
||||||
|
recipients: "31619191919"
|
||||||
|
default-alert:
|
||||||
|
enabled: false
|
||||||
|
send-on-resolved: true
|
||||||
|
telegram:
|
||||||
|
token: 123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11
|
||||||
|
id: 0123456789
|
||||||
|
default-alert:
|
||||||
|
enabled: true
|
||||||
|
twilio:
|
||||||
|
sid: "1234"
|
||||||
|
token: "5678"
|
||||||
|
from: "+1-234-567-8901"
|
||||||
|
to: "+1-234-567-8901"
|
||||||
|
default-alert:
|
||||||
|
enabled: true
|
||||||
|
failure-threshold: 12
|
||||||
|
success-threshold: 15
|
||||||
|
|
||||||
|
services:
|
||||||
|
- name: twinnation
|
||||||
|
url: https://twinnation.org/health
|
||||||
|
alerts:
|
||||||
|
- type: slack
|
||||||
|
- type: pagerduty
|
||||||
|
- type: mattermost
|
||||||
|
- type: messagebird
|
||||||
|
- type: discord
|
||||||
|
success-threshold: 2 # test service alert override
|
||||||
|
- type: telegram
|
||||||
|
- type: twilio
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
`))
|
`))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Error("expected no error, got", err.Error())
|
t.Error("expected no error, got", err.Error())
|
||||||
@@ -369,24 +563,43 @@ services:
|
|||||||
if config.Metrics {
|
if config.Metrics {
|
||||||
t.Error("Metrics should've been false by default")
|
t.Error("Metrics should've been false by default")
|
||||||
}
|
}
|
||||||
|
// Alerting providers
|
||||||
if config.Alerting == nil {
|
if config.Alerting == nil {
|
||||||
t.Fatal("config.Alerting shouldn't have been nil")
|
t.Fatal("config.Alerting shouldn't have been nil")
|
||||||
}
|
}
|
||||||
if config.Alerting.Slack == nil || !config.Alerting.Slack.IsValid() {
|
if config.Alerting.Slack == nil || !config.Alerting.Slack.IsValid() {
|
||||||
t.Fatal("Slack alerting config should've been valid")
|
t.Fatal("Slack alerting config should've been valid")
|
||||||
}
|
}
|
||||||
|
if config.Alerting.Slack.GetDefaultAlert() == nil {
|
||||||
|
t.Fatal("Slack.GetDefaultAlert() shouldn't have returned nil")
|
||||||
|
}
|
||||||
if config.Alerting.Slack.WebhookURL != "http://example.com" {
|
if config.Alerting.Slack.WebhookURL != "http://example.com" {
|
||||||
t.Errorf("Slack webhook should've been %s, but was %s", "http://example.com", config.Alerting.Slack.WebhookURL)
|
t.Errorf("Slack webhook should've been %s, but was %s", "http://example.com", config.Alerting.Slack.WebhookURL)
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.Alerting.PagerDuty == nil || !config.Alerting.PagerDuty.IsValid() {
|
if config.Alerting.PagerDuty == nil || !config.Alerting.PagerDuty.IsValid() {
|
||||||
t.Fatal("PagerDuty alerting config should've been valid")
|
t.Fatal("PagerDuty alerting config should've been valid")
|
||||||
}
|
}
|
||||||
if config.Alerting.Messagebird == nil || !config.Alerting.Messagebird.IsValid() {
|
if config.Alerting.PagerDuty.GetDefaultAlert() == nil {
|
||||||
t.Fatal("Messagebird alerting config should've been valid")
|
t.Fatal("PagerDuty.GetDefaultAlert() shouldn't have returned nil")
|
||||||
}
|
}
|
||||||
if config.Alerting.PagerDuty.IntegrationKey != "00000000000000000000000000000000" {
|
if config.Alerting.PagerDuty.IntegrationKey != "00000000000000000000000000000000" {
|
||||||
t.Errorf("PagerDuty integration key should've been %s, but was %s", "00000000000000000000000000000000", config.Alerting.PagerDuty.IntegrationKey)
|
t.Errorf("PagerDuty integration key should've been %s, but was %s", "00000000000000000000000000000000", config.Alerting.PagerDuty.IntegrationKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Alerting.Mattermost == nil || !config.Alerting.Mattermost.IsValid() {
|
||||||
|
t.Fatal("Mattermost alerting config should've been valid")
|
||||||
|
}
|
||||||
|
if config.Alerting.Mattermost.GetDefaultAlert() == nil {
|
||||||
|
t.Fatal("Mattermost.GetDefaultAlert() shouldn't have returned nil")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Alerting.Messagebird == nil || !config.Alerting.Messagebird.IsValid() {
|
||||||
|
t.Fatal("Messagebird alerting config should've been valid")
|
||||||
|
}
|
||||||
|
if config.Alerting.Messagebird.GetDefaultAlert() == nil {
|
||||||
|
t.Fatal("Messagebird.GetDefaultAlert() shouldn't have returned nil")
|
||||||
|
}
|
||||||
if config.Alerting.Messagebird.AccessKey != "1" {
|
if config.Alerting.Messagebird.AccessKey != "1" {
|
||||||
t.Errorf("Messagebird access key should've been %s, but was %s", "1", config.Alerting.Messagebird.AccessKey)
|
t.Errorf("Messagebird access key should've been %s, but was %s", "1", config.Alerting.Messagebird.AccessKey)
|
||||||
}
|
}
|
||||||
@@ -396,6 +609,40 @@ services:
|
|||||||
if config.Alerting.Messagebird.Recipients != "31619191919" {
|
if config.Alerting.Messagebird.Recipients != "31619191919" {
|
||||||
t.Errorf("Messagebird to recipients should've been %s, but was %s", "31619191919", config.Alerting.Messagebird.Recipients)
|
t.Errorf("Messagebird to recipients should've been %s, but was %s", "31619191919", config.Alerting.Messagebird.Recipients)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Alerting.Discord == nil || !config.Alerting.Discord.IsValid() {
|
||||||
|
t.Fatal("Discord alerting config should've been valid")
|
||||||
|
}
|
||||||
|
if config.Alerting.Discord.GetDefaultAlert() == nil {
|
||||||
|
t.Fatal("Discord.GetDefaultAlert() shouldn't have returned nil")
|
||||||
|
}
|
||||||
|
if config.Alerting.Discord.WebhookURL != "http://example.org" {
|
||||||
|
t.Errorf("Discord webhook should've been %s, but was %s", "http://example.org", config.Alerting.Discord.WebhookURL)
|
||||||
|
}
|
||||||
|
if config.Alerting.GetAlertingProviderByAlertType(alert.TypeDiscord) != config.Alerting.Discord {
|
||||||
|
t.Error("expected discord configuration")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Alerting.Telegram == nil || !config.Alerting.Telegram.IsValid() {
|
||||||
|
t.Fatal("Telegram alerting config should've been valid")
|
||||||
|
}
|
||||||
|
if config.Alerting.Telegram.GetDefaultAlert() == nil {
|
||||||
|
t.Fatal("Telegram.GetDefaultAlert() shouldn't have returned nil")
|
||||||
|
}
|
||||||
|
if config.Alerting.Telegram.Token != "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11" {
|
||||||
|
t.Errorf("Telegram token should've been %s, but was %s", "123456:ABC-DEF1234ghIkl-zyx57W2v1u123ew11", config.Alerting.Telegram.Token)
|
||||||
|
}
|
||||||
|
if config.Alerting.Telegram.ID != "0123456789" {
|
||||||
|
t.Errorf("Telegram ID should've been %s, but was %s", "012345689", config.Alerting.Telegram.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Alerting.Twilio == nil || !config.Alerting.Twilio.IsValid() {
|
||||||
|
t.Fatal("Twilio alerting config should've been valid")
|
||||||
|
}
|
||||||
|
if config.Alerting.Twilio.GetDefaultAlert() == nil {
|
||||||
|
t.Fatal("Twilio.GetDefaultAlert() shouldn't have returned nil")
|
||||||
|
}
|
||||||
|
// Services
|
||||||
if len(config.Services) != 1 {
|
if len(config.Services) != 1 {
|
||||||
t.Error("There should've been 1 service")
|
t.Error("There should've been 1 service")
|
||||||
}
|
}
|
||||||
@@ -405,13 +652,14 @@ services:
|
|||||||
if config.Services[0].Interval != 60*time.Second {
|
if config.Services[0].Interval != 60*time.Second {
|
||||||
t.Errorf("Interval should have been %s, because it is the default value", 60*time.Second)
|
t.Errorf("Interval should have been %s, because it is the default value", 60*time.Second)
|
||||||
}
|
}
|
||||||
if config.Services[0].Alerts == nil {
|
if len(config.Services[0].Alerts) != 7 {
|
||||||
t.Fatal("The service alerts shouldn't have been nil")
|
t.Fatal("There should've been 7 alerts configured")
|
||||||
}
|
}
|
||||||
if len(config.Services[0].Alerts) != 3 {
|
|
||||||
t.Fatal("There should've been 3 alert configured")
|
if config.Services[0].Alerts[0].Type != alert.TypeSlack {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeSlack, config.Services[0].Alerts[0].Type)
|
||||||
}
|
}
|
||||||
if !config.Services[0].Alerts[0].Enabled {
|
if !config.Services[0].Alerts[0].IsEnabled() {
|
||||||
t.Error("The alert should've been enabled")
|
t.Error("The alert should've been enabled")
|
||||||
}
|
}
|
||||||
if config.Services[0].Alerts[0].FailureThreshold != 3 {
|
if config.Services[0].Alerts[0].FailureThreshold != 3 {
|
||||||
@@ -420,23 +668,159 @@ services:
|
|||||||
if config.Services[0].Alerts[0].SuccessThreshold != 2 {
|
if config.Services[0].Alerts[0].SuccessThreshold != 2 {
|
||||||
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[0].SuccessThreshold)
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[0].SuccessThreshold)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[1].Type != alert.TypePagerDuty {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypePagerDuty, config.Services[0].Alerts[1].Type)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[1].GetDescription() != "default description" {
|
||||||
|
t.Errorf("The description of the alert should've been %s, but it was %s", "default description", config.Services[0].Alerts[1].GetDescription())
|
||||||
|
}
|
||||||
if config.Services[0].Alerts[1].FailureThreshold != 7 {
|
if config.Services[0].Alerts[1].FailureThreshold != 7 {
|
||||||
t.Errorf("The failure threshold of the alert should've been %d, but it was %d", 7, config.Services[0].Alerts[1].FailureThreshold)
|
t.Errorf("The failure threshold of the alert should've been %d, but it was %d", 7, config.Services[0].Alerts[1].FailureThreshold)
|
||||||
}
|
}
|
||||||
if config.Services[0].Alerts[1].SuccessThreshold != 5 {
|
if config.Services[0].Alerts[1].SuccessThreshold != 5 {
|
||||||
t.Errorf("The success threshold of the alert should've been %d, but it was %d", 5, config.Services[0].Alerts[1].SuccessThreshold)
|
t.Errorf("The success threshold of the alert should've been %d, but it was %d", 5, config.Services[0].Alerts[1].SuccessThreshold)
|
||||||
}
|
}
|
||||||
if config.Services[0].Alerts[0].Type != core.SlackAlert {
|
|
||||||
t.Errorf("The type of the alert should've been %s, but it was %s", core.SlackAlert, config.Services[0].Alerts[0].Type)
|
if config.Services[0].Alerts[2].Type != alert.TypeMattermost {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeMattermost, config.Services[0].Alerts[2].Type)
|
||||||
}
|
}
|
||||||
if config.Services[0].Alerts[1].Type != core.PagerDutyAlert {
|
if !config.Services[0].Alerts[2].IsEnabled() {
|
||||||
t.Errorf("The type of the alert should've been %s, but it was %s", core.PagerDutyAlert, config.Services[0].Alerts[1].Type)
|
t.Error("The alert should've been enabled")
|
||||||
}
|
}
|
||||||
if config.Services[0].Alerts[1].Description != "Healthcheck failed 7 times in a row" {
|
if config.Services[0].Alerts[2].FailureThreshold != 3 {
|
||||||
t.Errorf("The description of the alert should've been %s, but it was %s", "Healthcheck failed 7 times in a row", config.Services[0].Alerts[0].Description)
|
t.Errorf("The default failure threshold of the alert should've been %d, but it was %d", 3, config.Services[0].Alerts[2].FailureThreshold)
|
||||||
}
|
}
|
||||||
if config.Services[0].Alerts[2].Type != core.MessagebirdAlert {
|
if config.Services[0].Alerts[2].SuccessThreshold != 2 {
|
||||||
t.Errorf("The type of the alert should've been %s, but it was %s", core.MessagebirdAlert, config.Services[0].Alerts[1].Type)
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[2].SuccessThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[3].Type != alert.TypeMessagebird {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeMessagebird, config.Services[0].Alerts[3].Type)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[3].IsEnabled() {
|
||||||
|
t.Error("The alert should've been disabled")
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[3].IsSendingOnResolved() {
|
||||||
|
t.Error("The alert should be sending on resolve")
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[4].Type != alert.TypeDiscord {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeDiscord, config.Services[0].Alerts[4].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[4].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[4].FailureThreshold != 10 {
|
||||||
|
t.Errorf("The failure threshold of the alert should've been %d, but it was %d", 10, config.Services[0].Alerts[4].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[4].SuccessThreshold != 2 {
|
||||||
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[4].SuccessThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[5].Type != alert.TypeTelegram {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeTelegram, config.Services[0].Alerts[5].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[5].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[5].FailureThreshold != 3 {
|
||||||
|
t.Errorf("The default failure threshold of the alert should've been %d, but it was %d", 3, config.Services[0].Alerts[5].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[5].SuccessThreshold != 2 {
|
||||||
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 2, config.Services[0].Alerts[5].SuccessThreshold)
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Services[0].Alerts[6].Type != alert.TypeTwilio {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeTwilio, config.Services[0].Alerts[6].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[6].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[6].FailureThreshold != 12 {
|
||||||
|
t.Errorf("The default failure threshold of the alert should've been %d, but it was %d", 12, config.Services[0].Alerts[6].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[6].SuccessThreshold != 15 {
|
||||||
|
t.Errorf("The default success threshold of the alert should've been %d, but it was %d", 15, config.Services[0].Alerts[6].SuccessThreshold)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseAndValidateConfigBytesWithAlertingAndDefaultAlertAndMultipleAlertsOfSameTypeWithOverriddenParameters(t *testing.T) {
|
||||||
|
config, err := parseAndValidateConfigBytes([]byte(`
|
||||||
|
alerting:
|
||||||
|
slack:
|
||||||
|
webhook-url: "http://example.com"
|
||||||
|
default-alert:
|
||||||
|
enabled: true
|
||||||
|
description: "description"
|
||||||
|
|
||||||
|
services:
|
||||||
|
- name: twinnation
|
||||||
|
url: https://twinnation.org/health
|
||||||
|
alerts:
|
||||||
|
- type: slack
|
||||||
|
failure-threshold: 10
|
||||||
|
- type: slack
|
||||||
|
failure-threshold: 20
|
||||||
|
description: "wow"
|
||||||
|
- type: slack
|
||||||
|
enabled: false
|
||||||
|
failure-threshold: 30
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
`))
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected no error, got", err.Error())
|
||||||
|
}
|
||||||
|
if config == nil {
|
||||||
|
t.Fatal("Config shouldn't have been nil")
|
||||||
|
}
|
||||||
|
// Alerting providers
|
||||||
|
if config.Alerting == nil {
|
||||||
|
t.Fatal("config.Alerting shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if config.Alerting.Slack == nil || !config.Alerting.Slack.IsValid() {
|
||||||
|
t.Fatal("Slack alerting config should've been valid")
|
||||||
|
}
|
||||||
|
// Services
|
||||||
|
if len(config.Services) != 1 {
|
||||||
|
t.Error("There should've been 2 services")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[0].Type != alert.TypeSlack {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeSlack, config.Services[0].Alerts[0].Type)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[1].Type != alert.TypeSlack {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeSlack, config.Services[0].Alerts[1].Type)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[2].Type != alert.TypeSlack {
|
||||||
|
t.Errorf("The type of the alert should've been %s, but it was %s", alert.TypeSlack, config.Services[0].Alerts[2].Type)
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[0].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if !config.Services[0].Alerts[1].IsEnabled() {
|
||||||
|
t.Error("The alert should've been enabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[2].IsEnabled() {
|
||||||
|
t.Error("The alert should've been disabled")
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[0].GetDescription() != "description" {
|
||||||
|
t.Errorf("The description of the alert should've been %s, but it was %s", "description", config.Services[0].Alerts[0].GetDescription())
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[1].GetDescription() != "wow" {
|
||||||
|
t.Errorf("The description of the alert should've been %s, but it was %s", "description", config.Services[0].Alerts[1].GetDescription())
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[2].GetDescription() != "description" {
|
||||||
|
t.Errorf("The description of the alert should've been %s, but it was %s", "description", config.Services[0].Alerts[2].GetDescription())
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[0].FailureThreshold != 10 {
|
||||||
|
t.Errorf("The failure threshold of the alert should've been %d, but it was %d", 10, config.Services[0].Alerts[0].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[1].FailureThreshold != 20 {
|
||||||
|
t.Errorf("The failure threshold of the alert should've been %d, but it was %d", 20, config.Services[0].Alerts[1].FailureThreshold)
|
||||||
|
}
|
||||||
|
if config.Services[0].Alerts[2].FailureThreshold != 30 {
|
||||||
|
t.Errorf("The failure threshold of the alert should've been %d, but it was %d", 30, config.Services[0].Alerts[2].FailureThreshold)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -502,11 +886,106 @@ services:
|
|||||||
if !config.Alerting.Custom.IsValid() {
|
if !config.Alerting.Custom.IsValid() {
|
||||||
t.Fatal("Custom alerting config should've been valid")
|
t.Fatal("Custom alerting config should've been valid")
|
||||||
}
|
}
|
||||||
|
if config.Alerting.Custom.GetAlertStatePlaceholderValue(true) != "RESOLVED" {
|
||||||
|
t.Fatal("ALERT_TRIGGERED_OR_RESOLVED placeholder value for RESOLVED should've been 'RESOLVED', got", config.Alerting.Custom.GetAlertStatePlaceholderValue(true))
|
||||||
|
}
|
||||||
|
if config.Alerting.Custom.GetAlertStatePlaceholderValue(false) != "TRIGGERED" {
|
||||||
|
t.Fatal("ALERT_TRIGGERED_OR_RESOLVED placeholder value for TRIGGERED should've been 'TRIGGERED', got", config.Alerting.Custom.GetAlertStatePlaceholderValue(false))
|
||||||
|
}
|
||||||
if config.Alerting.Custom.Insecure {
|
if config.Alerting.Custom.Insecure {
|
||||||
t.Fatal("config.Alerting.Custom.Insecure shouldn't have been true")
|
t.Fatal("config.Alerting.Custom.Insecure shouldn't have been true")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestParseAndValidateConfigBytesWithCustomAlertingConfigAndCustomPlaceholderValues(t *testing.T) {
|
||||||
|
config, err := parseAndValidateConfigBytes([]byte(`
|
||||||
|
alerting:
|
||||||
|
custom:
|
||||||
|
placeholders:
|
||||||
|
ALERT_TRIGGERED_OR_RESOLVED:
|
||||||
|
TRIGGERED: "partial_outage"
|
||||||
|
RESOLVED: "operational"
|
||||||
|
url: "https://example.com"
|
||||||
|
insecure: true
|
||||||
|
body: "[ALERT_TRIGGERED_OR_RESOLVED]: [SERVICE_NAME] - [ALERT_DESCRIPTION]"
|
||||||
|
services:
|
||||||
|
- name: twinnation
|
||||||
|
url: https://twinnation.org/health
|
||||||
|
alerts:
|
||||||
|
- type: custom
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
`))
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected no error, got", err.Error())
|
||||||
|
}
|
||||||
|
if config == nil {
|
||||||
|
t.Fatal("Config shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if config.Alerting == nil {
|
||||||
|
t.Fatal("config.Alerting shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if config.Alerting.Custom == nil {
|
||||||
|
t.Fatal("PagerDuty alerting config shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if !config.Alerting.Custom.IsValid() {
|
||||||
|
t.Fatal("Custom alerting config should've been valid")
|
||||||
|
}
|
||||||
|
if config.Alerting.Custom.GetAlertStatePlaceholderValue(true) != "operational" {
|
||||||
|
t.Fatal("ALERT_TRIGGERED_OR_RESOLVED placeholder value for RESOLVED should've been 'operational'")
|
||||||
|
}
|
||||||
|
if config.Alerting.Custom.GetAlertStatePlaceholderValue(false) != "partial_outage" {
|
||||||
|
t.Fatal("ALERT_TRIGGERED_OR_RESOLVED placeholder value for TRIGGERED should've been 'partial_outage'")
|
||||||
|
}
|
||||||
|
if !config.Alerting.Custom.Insecure {
|
||||||
|
t.Fatal("config.Alerting.Custom.Insecure shouldn't have been true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestParseAndValidateConfigBytesWithCustomAlertingConfigAndOneCustomPlaceholderValue(t *testing.T) {
|
||||||
|
config, err := parseAndValidateConfigBytes([]byte(`
|
||||||
|
alerting:
|
||||||
|
custom:
|
||||||
|
placeholders:
|
||||||
|
ALERT_TRIGGERED_OR_RESOLVED:
|
||||||
|
TRIGGERED: "partial_outage"
|
||||||
|
url: "https://example.com"
|
||||||
|
insecure: true
|
||||||
|
body: "[ALERT_TRIGGERED_OR_RESOLVED]: [SERVICE_NAME] - [ALERT_DESCRIPTION]"
|
||||||
|
services:
|
||||||
|
- name: twinnation
|
||||||
|
url: https://twinnation.org/health
|
||||||
|
alerts:
|
||||||
|
- type: custom
|
||||||
|
conditions:
|
||||||
|
- "[STATUS] == 200"
|
||||||
|
`))
|
||||||
|
if err != nil {
|
||||||
|
t.Error("expected no error, got", err.Error())
|
||||||
|
}
|
||||||
|
if config == nil {
|
||||||
|
t.Fatal("Config shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if config.Alerting == nil {
|
||||||
|
t.Fatal("config.Alerting shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if config.Alerting.Custom == nil {
|
||||||
|
t.Fatal("PagerDuty alerting config shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if !config.Alerting.Custom.IsValid() {
|
||||||
|
t.Fatal("Custom alerting config should've been valid")
|
||||||
|
}
|
||||||
|
if config.Alerting.Custom.GetAlertStatePlaceholderValue(true) != "RESOLVED" {
|
||||||
|
t.Fatal("ALERT_TRIGGERED_OR_RESOLVED placeholder value for RESOLVED should've been 'RESOLVED'")
|
||||||
|
}
|
||||||
|
if config.Alerting.Custom.GetAlertStatePlaceholderValue(false) != "partial_outage" {
|
||||||
|
t.Fatal("ALERT_TRIGGERED_OR_RESOLVED placeholder value for TRIGGERED should've been 'partial_outage'")
|
||||||
|
}
|
||||||
|
if !config.Alerting.Custom.Insecure {
|
||||||
|
t.Fatal("config.Alerting.Custom.Insecure shouldn't have been true")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestParseAndValidateConfigBytesWithCustomAlertingConfigThatHasInsecureSetToTrue(t *testing.T) {
|
func TestParseAndValidateConfigBytesWithCustomAlertingConfigThatHasInsecureSetToTrue(t *testing.T) {
|
||||||
config, err := parseAndValidateConfigBytes([]byte(`
|
config, err := parseAndValidateConfigBytes([]byte(`
|
||||||
alerting:
|
alerting:
|
||||||
@@ -550,8 +1029,7 @@ services:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndValidateConfigBytesWithInvalidSecurityConfig(t *testing.T) {
|
func TestParseAndValidateConfigBytesWithInvalidSecurityConfig(t *testing.T) {
|
||||||
defer func() { recover() }()
|
_, err := parseAndValidateConfigBytes([]byte(`
|
||||||
_, _ = parseAndValidateConfigBytes([]byte(`
|
|
||||||
security:
|
security:
|
||||||
basic:
|
basic:
|
||||||
username: "admin"
|
username: "admin"
|
||||||
@@ -562,13 +1040,15 @@ services:
|
|||||||
conditions:
|
conditions:
|
||||||
- "[STATUS] == 200"
|
- "[STATUS] == 200"
|
||||||
`))
|
`))
|
||||||
t.Error("Function should've panicked")
|
if err == nil {
|
||||||
|
t.Error("Function should've returned an error")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndValidateConfigBytesWithValidSecurityConfig(t *testing.T) {
|
func TestParseAndValidateConfigBytesWithValidSecurityConfig(t *testing.T) {
|
||||||
const expectedUsername = "admin"
|
const expectedUsername = "admin"
|
||||||
const expectedPasswordHash = "6b97ed68d14eb3f1aa959ce5d49c7dc612e1eb1dafd73b1e705847483fd6a6c809f2ceb4e8df6ff9984c6298ff0285cace6614bf8daa9f0070101b6c89899e22"
|
const expectedPasswordHash = "6b97ed68d14eb3f1aa959ce5d49c7dc612e1eb1dafd73b1e705847483fd6a6c809f2ceb4e8df6ff9984c6298ff0285cace6614bf8daa9f0070101b6c89899e22"
|
||||||
config, err := parseAndValidateConfigBytes([]byte(fmt.Sprintf(`
|
config, err := parseAndValidateConfigBytes([]byte(fmt.Sprintf(`debug: true
|
||||||
security:
|
security:
|
||||||
basic:
|
basic:
|
||||||
username: "%s"
|
username: "%s"
|
||||||
@@ -683,8 +1163,7 @@ kubernetes:
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndValidateConfigBytesWithKubernetesAutoDiscoveryButNoServiceTemplate(t *testing.T) {
|
func TestParseAndValidateConfigBytesWithKubernetesAutoDiscoveryButNoServiceTemplate(t *testing.T) {
|
||||||
defer func() { recover() }()
|
_, err := parseAndValidateConfigBytes([]byte(`
|
||||||
_, _ = parseAndValidateConfigBytes([]byte(`
|
|
||||||
kubernetes:
|
kubernetes:
|
||||||
cluster-mode: "mock"
|
cluster-mode: "mock"
|
||||||
auto-discover: true
|
auto-discover: true
|
||||||
@@ -693,12 +1172,13 @@ kubernetes:
|
|||||||
hostname-suffix: ".default.svc.cluster.local"
|
hostname-suffix: ".default.svc.cluster.local"
|
||||||
target-path: "/health"
|
target-path: "/health"
|
||||||
`))
|
`))
|
||||||
t.Error("Function should've panicked because providing a service-template is mandatory")
|
if err == nil {
|
||||||
|
t.Error("Function should've returned an error because providing a service-template is mandatory")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseAndValidateConfigBytesWithKubernetesAutoDiscoveryUsingClusterModeIn(t *testing.T) {
|
func TestParseAndValidateConfigBytesWithKubernetesAutoDiscoveryUsingClusterModeIn(t *testing.T) {
|
||||||
defer func() { recover() }()
|
_, err := parseAndValidateConfigBytes([]byte(`
|
||||||
_, _ = parseAndValidateConfigBytes([]byte(`
|
|
||||||
kubernetes:
|
kubernetes:
|
||||||
cluster-mode: "in"
|
cluster-mode: "in"
|
||||||
auto-discover: true
|
auto-discover: true
|
||||||
@@ -711,6 +1191,44 @@ kubernetes:
|
|||||||
hostname-suffix: ".default.svc.cluster.local"
|
hostname-suffix: ".default.svc.cluster.local"
|
||||||
target-path: "/health"
|
target-path: "/health"
|
||||||
`))
|
`))
|
||||||
// TODO: find a way to test this?
|
if err == nil {
|
||||||
t.Error("Function should've panicked because testing with ClusterModeIn isn't supported")
|
t.Error("Function should've returned an error because testing with ClusterModeIn isn't supported")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGetAlertingProviderByAlertType(t *testing.T) {
|
||||||
|
alertingConfig := &alerting.Config{
|
||||||
|
Custom: &custom.AlertProvider{},
|
||||||
|
Discord: &discord.AlertProvider{},
|
||||||
|
Mattermost: &mattermost.AlertProvider{},
|
||||||
|
Messagebird: &messagebird.AlertProvider{},
|
||||||
|
PagerDuty: &pagerduty.AlertProvider{},
|
||||||
|
Slack: &slack.AlertProvider{},
|
||||||
|
Telegram: &telegram.AlertProvider{},
|
||||||
|
Twilio: &twilio.AlertProvider{},
|
||||||
|
}
|
||||||
|
if alertingConfig.GetAlertingProviderByAlertType(alert.TypeCustom) != alertingConfig.Custom {
|
||||||
|
t.Error("expected Custom configuration")
|
||||||
|
}
|
||||||
|
if alertingConfig.GetAlertingProviderByAlertType(alert.TypeDiscord) != alertingConfig.Discord {
|
||||||
|
t.Error("expected Discord configuration")
|
||||||
|
}
|
||||||
|
if alertingConfig.GetAlertingProviderByAlertType(alert.TypeMattermost) != alertingConfig.Mattermost {
|
||||||
|
t.Error("expected Mattermost configuration")
|
||||||
|
}
|
||||||
|
if alertingConfig.GetAlertingProviderByAlertType(alert.TypeMessagebird) != alertingConfig.Messagebird {
|
||||||
|
t.Error("expected Messagebird configuration")
|
||||||
|
}
|
||||||
|
if alertingConfig.GetAlertingProviderByAlertType(alert.TypePagerDuty) != alertingConfig.PagerDuty {
|
||||||
|
t.Error("expected PagerDuty configuration")
|
||||||
|
}
|
||||||
|
if alertingConfig.GetAlertingProviderByAlertType(alert.TypeSlack) != alertingConfig.Slack {
|
||||||
|
t.Error("expected Slack configuration")
|
||||||
|
}
|
||||||
|
if alertingConfig.GetAlertingProviderByAlertType(alert.TypeTelegram) != alertingConfig.Telegram {
|
||||||
|
t.Error("expected Telegram configuration")
|
||||||
|
}
|
||||||
|
if alertingConfig.GetAlertingProviderByAlertType(alert.TypeTwilio) != alertingConfig.Twilio {
|
||||||
|
t.Error("expected Twilio configuration")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+3
-2
@@ -16,7 +16,7 @@ type WebConfig struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// validateAndSetDefaults checks and sets the default values for fields that are not set
|
// validateAndSetDefaults checks and sets the default values for fields that are not set
|
||||||
func (web *WebConfig) validateAndSetDefaults() {
|
func (web *WebConfig) validateAndSetDefaults() error {
|
||||||
// Validate the Address
|
// Validate the Address
|
||||||
if len(web.Address) == 0 {
|
if len(web.Address) == 0 {
|
||||||
web.Address = DefaultAddress
|
web.Address = DefaultAddress
|
||||||
@@ -25,8 +25,9 @@ func (web *WebConfig) validateAndSetDefaults() {
|
|||||||
if web.Port == 0 {
|
if web.Port == 0 {
|
||||||
web.Port = DefaultPort
|
web.Port = DefaultPort
|
||||||
} else if web.Port < 0 || web.Port > math.MaxUint16 {
|
} else if web.Port < 0 || web.Port > math.MaxUint16 {
|
||||||
panic(fmt.Sprintf("invalid port: value should be between %d and %d", 0, math.MaxUint16))
|
return fmt.Errorf("invalid port: value should be between %d and %d", 0, math.MaxUint16)
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// SocketAddress returns the combination of the Address and the Port
|
// SocketAddress returns the combination of the Address and the Port
|
||||||
|
|||||||
+9
-4
@@ -7,7 +7,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
"github.com/TwinProduction/gatus/watchdog"
|
"github.com/TwinProduction/gatus/storage"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -25,18 +25,23 @@ func badgeHandler(writer http.ResponseWriter, request *http.Request) {
|
|||||||
}
|
}
|
||||||
identifier := variables["identifier"]
|
identifier := variables["identifier"]
|
||||||
key := strings.TrimSuffix(identifier, ".svg")
|
key := strings.TrimSuffix(identifier, ".svg")
|
||||||
uptime := watchdog.GetUptimeByKey(key)
|
serviceStatus := storage.Get().GetServiceStatusByKey(key)
|
||||||
if uptime == nil {
|
if serviceStatus == nil {
|
||||||
writer.WriteHeader(http.StatusNotFound)
|
writer.WriteHeader(http.StatusNotFound)
|
||||||
_, _ = writer.Write([]byte("Requested service not found"))
|
_, _ = writer.Write([]byte("Requested service not found"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
if serviceStatus.Uptime == nil {
|
||||||
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
|
_, _ = writer.Write([]byte("Failed to compute uptime"))
|
||||||
|
return
|
||||||
|
}
|
||||||
formattedDate := time.Now().Format(http.TimeFormat)
|
formattedDate := time.Now().Format(http.TimeFormat)
|
||||||
writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
writer.Header().Set("Cache-Control", "no-cache, no-store, must-revalidate")
|
||||||
writer.Header().Set("Date", formattedDate)
|
writer.Header().Set("Date", formattedDate)
|
||||||
writer.Header().Set("Expires", formattedDate)
|
writer.Header().Set("Expires", formattedDate)
|
||||||
writer.Header().Set("Content-Type", "image/svg+xml")
|
writer.Header().Set("Content-Type", "image/svg+xml")
|
||||||
_, _ = writer.Write(generateSVG(duration, uptime))
|
_, _ = writer.Write(generateSVG(duration, serviceStatus.Uptime))
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateSVG(duration string, uptime *core.Uptime) []byte {
|
func generateSVG(duration string, uptime *core.Uptime) []byte {
|
||||||
|
|||||||
+35
-40
@@ -3,6 +3,7 @@ package controller
|
|||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
@@ -13,8 +14,9 @@ import (
|
|||||||
|
|
||||||
"github.com/TwinProduction/gatus/config"
|
"github.com/TwinProduction/gatus/config"
|
||||||
"github.com/TwinProduction/gatus/security"
|
"github.com/TwinProduction/gatus/security"
|
||||||
"github.com/TwinProduction/gatus/watchdog"
|
"github.com/TwinProduction/gatus/storage"
|
||||||
"github.com/TwinProduction/gocache"
|
"github.com/TwinProduction/gocache"
|
||||||
|
"github.com/TwinProduction/health"
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
)
|
)
|
||||||
@@ -24,7 +26,7 @@ const (
|
|||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
cache = gocache.NewCache().WithMaxSize(100).WithEvictionPolicy(gocache.LeastRecentlyUsed)
|
cache = gocache.NewCache().WithMaxSize(100).WithEvictionPolicy(gocache.FirstInFirstOut)
|
||||||
|
|
||||||
// staticFolder is the path to the location of the static folder from the root path of the project
|
// staticFolder is the path to the location of the static folder from the root path of the project
|
||||||
// The only reason this is exposed is to allow running tests from a different path than the root path of the project
|
// The only reason this is exposed is to allow running tests from a different path than the root path of the project
|
||||||
@@ -42,36 +44,43 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Handle creates the router and starts the server
|
// Handle creates the router and starts the server
|
||||||
func Handle() {
|
func Handle(securityConfig *security.Config, webConfig *config.WebConfig, enableMetrics bool) {
|
||||||
cfg := config.Get()
|
var router http.Handler = CreateRouter(securityConfig, enableMetrics)
|
||||||
var router http.Handler = CreateRouter(cfg)
|
|
||||||
if os.Getenv("ENVIRONMENT") == "dev" {
|
if os.Getenv("ENVIRONMENT") == "dev" {
|
||||||
router = developmentCorsHandler(router)
|
router = developmentCorsHandler(router)
|
||||||
}
|
}
|
||||||
server = &http.Server{
|
server = &http.Server{
|
||||||
Addr: fmt.Sprintf("%s:%d", cfg.Web.Address, cfg.Web.Port),
|
Addr: fmt.Sprintf("%s:%d", webConfig.Address, webConfig.Port),
|
||||||
Handler: router,
|
Handler: router,
|
||||||
ReadTimeout: 15 * time.Second,
|
ReadTimeout: 15 * time.Second,
|
||||||
WriteTimeout: 15 * time.Second,
|
WriteTimeout: 15 * time.Second,
|
||||||
IdleTimeout: 15 * time.Second,
|
IdleTimeout: 15 * time.Second,
|
||||||
}
|
}
|
||||||
log.Println("[controller][Handle] Listening on " + cfg.Web.SocketAddress())
|
log.Println("[controller][Handle] Listening on " + webConfig.SocketAddress())
|
||||||
if os.Getenv("ROUTER_TEST") == "true" {
|
if os.Getenv("ROUTER_TEST") == "true" {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
log.Fatal(server.ListenAndServe())
|
log.Println("[controller][Handle]", server.ListenAndServe())
|
||||||
|
}
|
||||||
|
|
||||||
|
// Shutdown stops the server
|
||||||
|
func Shutdown() {
|
||||||
|
if server != nil {
|
||||||
|
_ = server.Shutdown(context.TODO())
|
||||||
|
server = nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// CreateRouter creates the router for the http server
|
// CreateRouter creates the router for the http server
|
||||||
func CreateRouter(cfg *config.Config) *mux.Router {
|
func CreateRouter(securityConfig *security.Config, enabledMetrics bool) *mux.Router {
|
||||||
router := mux.NewRouter()
|
router := mux.NewRouter()
|
||||||
if cfg.Metrics {
|
if enabledMetrics {
|
||||||
router.Handle("/metrics", promhttp.Handler()).Methods("GET")
|
router.Handle("/metrics", promhttp.Handler()).Methods("GET")
|
||||||
}
|
}
|
||||||
|
router.Handle("/health", health.Handler().WithJSON(true)).Methods("GET")
|
||||||
router.HandleFunc("/favicon.ico", favIconHandler).Methods("GET")
|
router.HandleFunc("/favicon.ico", favIconHandler).Methods("GET")
|
||||||
router.HandleFunc("/health", healthHandler).Methods("GET")
|
router.HandleFunc("/api/v1/statuses", secureIfNecessary(securityConfig, serviceStatusesHandler)).Methods("GET") // No GzipHandler for this one, because we cache the content
|
||||||
router.HandleFunc("/api/v1/statuses", secureIfNecessary(cfg, serviceStatusesHandler)).Methods("GET") // No GzipHandler for this one, because we cache the content
|
router.HandleFunc("/api/v1/statuses/{key}", secureIfNecessary(securityConfig, GzipHandlerFunc(serviceStatusHandler))).Methods("GET")
|
||||||
router.HandleFunc("/api/v1/statuses/{key}", secureIfNecessary(cfg, GzipHandlerFunc(serviceStatusHandler))).Methods("GET")
|
|
||||||
router.HandleFunc("/api/v1/badges/uptime/{duration}/{identifier}", badgeHandler).Methods("GET")
|
router.HandleFunc("/api/v1/badges/uptime/{duration}/{identifier}", badgeHandler).Methods("GET")
|
||||||
// SPA
|
// SPA
|
||||||
router.HandleFunc("/services/{service}", spaHandler).Methods("GET")
|
router.HandleFunc("/services/{service}", spaHandler).Methods("GET")
|
||||||
@@ -80,9 +89,9 @@ func CreateRouter(cfg *config.Config) *mux.Router {
|
|||||||
return router
|
return router
|
||||||
}
|
}
|
||||||
|
|
||||||
func secureIfNecessary(cfg *config.Config, handler http.HandlerFunc) http.HandlerFunc {
|
func secureIfNecessary(securityConfig *security.Config, handler http.HandlerFunc) http.HandlerFunc {
|
||||||
if cfg.Security != nil && cfg.Security.IsValid() {
|
if securityConfig != nil && securityConfig.IsValid() {
|
||||||
return security.Handler(handler, cfg.Security)
|
return security.Handler(handler, securityConfig)
|
||||||
}
|
}
|
||||||
return handler
|
return handler
|
||||||
}
|
}
|
||||||
@@ -91,21 +100,22 @@ func secureIfNecessary(cfg *config.Config, handler http.HandlerFunc) http.Handle
|
|||||||
// Due to the size of the response, this function leverages a cache.
|
// Due to the size of the response, this function leverages a cache.
|
||||||
// Must not be wrapped by GzipHandler
|
// Must not be wrapped by GzipHandler
|
||||||
func serviceStatusesHandler(writer http.ResponseWriter, r *http.Request) {
|
func serviceStatusesHandler(writer http.ResponseWriter, r *http.Request) {
|
||||||
|
page, pageSize := extractPageAndPageSizeFromRequest(r)
|
||||||
gzipped := strings.Contains(r.Header.Get("Accept-Encoding"), "gzip")
|
gzipped := strings.Contains(r.Header.Get("Accept-Encoding"), "gzip")
|
||||||
var exists bool
|
var exists bool
|
||||||
var value interface{}
|
var value interface{}
|
||||||
if gzipped {
|
if gzipped {
|
||||||
writer.Header().Set("Content-Encoding", "gzip")
|
writer.Header().Set("Content-Encoding", "gzip")
|
||||||
value, exists = cache.Get("service-status-gzipped")
|
value, exists = cache.Get(fmt.Sprintf("service-status-%d-%d-gzipped", page, pageSize))
|
||||||
} else {
|
} else {
|
||||||
value, exists = cache.Get("service-status")
|
value, exists = cache.Get(fmt.Sprintf("service-status-%d-%d", page, pageSize))
|
||||||
}
|
}
|
||||||
var data []byte
|
var data []byte
|
||||||
if !exists {
|
if !exists {
|
||||||
var err error
|
var err error
|
||||||
buffer := &bytes.Buffer{}
|
buffer := &bytes.Buffer{}
|
||||||
gzipWriter := gzip.NewWriter(buffer)
|
gzipWriter := gzip.NewWriter(buffer)
|
||||||
data, err = watchdog.GetServiceStatusesAsJSON()
|
data, err = json.Marshal(storage.Get().GetAllServiceStatusesWithResultPagination(page, pageSize))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[controller][serviceStatusesHandler] Unable to marshal object to JSON: %s", err.Error())
|
log.Printf("[controller][serviceStatusesHandler] Unable to marshal object to JSON: %s", err.Error())
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
@@ -115,8 +125,8 @@ func serviceStatusesHandler(writer http.ResponseWriter, r *http.Request) {
|
|||||||
_, _ = gzipWriter.Write(data)
|
_, _ = gzipWriter.Write(data)
|
||||||
_ = gzipWriter.Close()
|
_ = gzipWriter.Close()
|
||||||
gzippedData := buffer.Bytes()
|
gzippedData := buffer.Bytes()
|
||||||
cache.SetWithTTL("service-status", data, cacheTTL)
|
cache.SetWithTTL(fmt.Sprintf("service-status-%d-%d", page, pageSize), data, cacheTTL)
|
||||||
cache.SetWithTTL("service-status-gzipped", gzippedData, cacheTTL)
|
cache.SetWithTTL(fmt.Sprintf("service-status-%d-%d-gzipped", page, pageSize), gzippedData, cacheTTL)
|
||||||
if gzipped {
|
if gzipped {
|
||||||
data = gzippedData
|
data = gzippedData
|
||||||
}
|
}
|
||||||
@@ -130,8 +140,9 @@ func serviceStatusesHandler(writer http.ResponseWriter, r *http.Request) {
|
|||||||
|
|
||||||
// serviceStatusHandler retrieves a single ServiceStatus by group name and service name
|
// serviceStatusHandler retrieves a single ServiceStatus by group name and service name
|
||||||
func serviceStatusHandler(writer http.ResponseWriter, r *http.Request) {
|
func serviceStatusHandler(writer http.ResponseWriter, r *http.Request) {
|
||||||
|
page, pageSize := extractPageAndPageSizeFromRequest(r)
|
||||||
vars := mux.Vars(r)
|
vars := mux.Vars(r)
|
||||||
serviceStatus := watchdog.GetServiceStatusByKey(vars["key"])
|
serviceStatus := storage.Get().GetServiceStatusByKey(vars["key"])
|
||||||
if serviceStatus == nil {
|
if serviceStatus == nil {
|
||||||
log.Printf("[controller][serviceStatusHandler] Service with key=%s not found", vars["key"])
|
log.Printf("[controller][serviceStatusHandler] Service with key=%s not found", vars["key"])
|
||||||
writer.WriteHeader(http.StatusNotFound)
|
writer.WriteHeader(http.StatusNotFound)
|
||||||
@@ -139,7 +150,7 @@ func serviceStatusHandler(writer http.ResponseWriter, r *http.Request) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
data := map[string]interface{}{
|
data := map[string]interface{}{
|
||||||
"serviceStatus": serviceStatus,
|
"serviceStatus": serviceStatus.WithResultPagination(page, pageSize),
|
||||||
// The following fields, while present on core.ServiceStatus, are annotated to remain hidden so that we can
|
// The following fields, while present on core.ServiceStatus, are annotated to remain hidden so that we can
|
||||||
// expose only the necessary data on /api/v1/statuses.
|
// expose only the necessary data on /api/v1/statuses.
|
||||||
// Since the /api/v1/statuses/{key} endpoint does need this data, however, we explicitly expose it here
|
// Since the /api/v1/statuses/{key} endpoint does need this data, however, we explicitly expose it here
|
||||||
@@ -150,26 +161,10 @@ func serviceStatusHandler(writer http.ResponseWriter, r *http.Request) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("[controller][serviceStatusHandler] Unable to marshal object to JSON: %s", err.Error())
|
log.Printf("[controller][serviceStatusHandler] Unable to marshal object to JSON: %s", err.Error())
|
||||||
writer.WriteHeader(http.StatusInternalServerError)
|
writer.WriteHeader(http.StatusInternalServerError)
|
||||||
_, _ = writer.Write([]byte("Unable to marshal object to JSON"))
|
_, _ = writer.Write([]byte("unable to marshal object to JSON"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
writer.Header().Add("Content-Type", "application/json")
|
writer.Header().Add("Content-Type", "application/json")
|
||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
_, _ = writer.Write(output)
|
_, _ = writer.Write(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
func healthHandler(writer http.ResponseWriter, _ *http.Request) {
|
|
||||||
writer.Header().Add("Content-Type", "application/json")
|
|
||||||
writer.WriteHeader(http.StatusOK)
|
|
||||||
_, _ = writer.Write([]byte("{\"status\":\"UP\"}"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// favIconHandler handles requests for /favicon.ico
|
|
||||||
func favIconHandler(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
http.ServeFile(writer, request, staticFolder+"/favicon.ico")
|
|
||||||
}
|
|
||||||
|
|
||||||
// spaHandler handles requests for /favicon.ico
|
|
||||||
func spaHandler(writer http.ResponseWriter, request *http.Request) {
|
|
||||||
http.ServeFile(writer, request, staticFolder+"/index.html")
|
|
||||||
}
|
|
||||||
@@ -10,10 +10,85 @@ import (
|
|||||||
|
|
||||||
"github.com/TwinProduction/gatus/config"
|
"github.com/TwinProduction/gatus/config"
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
|
"github.com/TwinProduction/gatus/storage"
|
||||||
"github.com/TwinProduction/gatus/watchdog"
|
"github.com/TwinProduction/gatus/watchdog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
firstCondition = core.Condition("[STATUS] == 200")
|
||||||
|
secondCondition = core.Condition("[RESPONSE_TIME] < 500")
|
||||||
|
thirdCondition = core.Condition("[CERTIFICATE_EXPIRATION] < 72h")
|
||||||
|
|
||||||
|
timestamp = time.Now()
|
||||||
|
|
||||||
|
testService = core.Service{
|
||||||
|
Name: "name",
|
||||||
|
Group: "group",
|
||||||
|
URL: "https://example.org/what/ever",
|
||||||
|
Method: "GET",
|
||||||
|
Body: "body",
|
||||||
|
Interval: 30 * time.Second,
|
||||||
|
Conditions: []*core.Condition{&firstCondition, &secondCondition, &thirdCondition},
|
||||||
|
Alerts: nil,
|
||||||
|
Insecure: false,
|
||||||
|
NumberOfFailuresInARow: 0,
|
||||||
|
NumberOfSuccessesInARow: 0,
|
||||||
|
}
|
||||||
|
testSuccessfulResult = core.Result{
|
||||||
|
Hostname: "example.org",
|
||||||
|
IP: "127.0.0.1",
|
||||||
|
HTTPStatus: 200,
|
||||||
|
Errors: nil,
|
||||||
|
Connected: true,
|
||||||
|
Success: true,
|
||||||
|
Timestamp: timestamp,
|
||||||
|
Duration: 150 * time.Millisecond,
|
||||||
|
CertificateExpiration: 10 * time.Hour,
|
||||||
|
ConditionResults: []*core.ConditionResult{
|
||||||
|
{
|
||||||
|
Condition: "[STATUS] == 200",
|
||||||
|
Success: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Condition: "[RESPONSE_TIME] < 500",
|
||||||
|
Success: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Condition: "[CERTIFICATE_EXPIRATION] < 72h",
|
||||||
|
Success: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
testUnsuccessfulResult = core.Result{
|
||||||
|
Hostname: "example.org",
|
||||||
|
IP: "127.0.0.1",
|
||||||
|
HTTPStatus: 200,
|
||||||
|
Errors: []string{"error-1", "error-2"},
|
||||||
|
Connected: true,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: timestamp,
|
||||||
|
Duration: 750 * time.Millisecond,
|
||||||
|
CertificateExpiration: 10 * time.Hour,
|
||||||
|
ConditionResults: []*core.ConditionResult{
|
||||||
|
{
|
||||||
|
Condition: "[STATUS] == 200",
|
||||||
|
Success: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Condition: "[RESPONSE_TIME] < 500",
|
||||||
|
Success: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Condition: "[CERTIFICATE_EXPIRATION] < 72h",
|
||||||
|
Success: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
func TestCreateRouter(t *testing.T) {
|
func TestCreateRouter(t *testing.T) {
|
||||||
|
defer storage.Get().Clear()
|
||||||
|
defer cache.Clear()
|
||||||
staticFolder = "../web/static"
|
staticFolder = "../web/static"
|
||||||
cfg := &config.Config{
|
cfg := &config.Config{
|
||||||
Metrics: true,
|
Metrics: true,
|
||||||
@@ -30,7 +105,7 @@ func TestCreateRouter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
watchdog.UpdateServiceStatuses(cfg.Services[0], &core.Result{Success: true, Duration: time.Millisecond, Timestamp: time.Now()})
|
watchdog.UpdateServiceStatuses(cfg.Services[0], &core.Result{Success: true, Duration: time.Millisecond, Timestamp: time.Now()})
|
||||||
watchdog.UpdateServiceStatuses(cfg.Services[1], &core.Result{Success: false, Duration: time.Second, Timestamp: time.Now()})
|
watchdog.UpdateServiceStatuses(cfg.Services[1], &core.Result{Success: false, Duration: time.Second, Timestamp: time.Now()})
|
||||||
router := CreateRouter(cfg)
|
router := CreateRouter(cfg.Security, cfg.Metrics)
|
||||||
type Scenario struct {
|
type Scenario struct {
|
||||||
Name string
|
Name string
|
||||||
Path string
|
Path string
|
||||||
@@ -84,6 +159,11 @@ func TestCreateRouter(t *testing.T) {
|
|||||||
ExpectedCode: http.StatusOK,
|
ExpectedCode: http.StatusOK,
|
||||||
Gzip: true,
|
Gzip: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: "service-statuses-pagination",
|
||||||
|
Path: "/api/v1/statuses?page=1&pageSize=20",
|
||||||
|
ExpectedCode: http.StatusOK,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
Name: "service-status",
|
Name: "service-status",
|
||||||
Path: "/api/v1/statuses/core_frontend",
|
Path: "/api/v1/statuses/core_frontend",
|
||||||
@@ -137,6 +217,8 @@ func TestCreateRouter(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestHandle(t *testing.T) {
|
func TestHandle(t *testing.T) {
|
||||||
|
defer storage.Get().Clear()
|
||||||
|
defer cache.Clear()
|
||||||
cfg := &config.Config{
|
cfg := &config.Config{
|
||||||
Web: &config.WebConfig{
|
Web: &config.WebConfig{
|
||||||
Address: "0.0.0.0",
|
Address: "0.0.0.0",
|
||||||
@@ -153,10 +235,11 @@ func TestHandle(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
config.Set(cfg)
|
|
||||||
_ = os.Setenv("ROUTER_TEST", "true")
|
_ = os.Setenv("ROUTER_TEST", "true")
|
||||||
_ = os.Setenv("ENVIRONMENT", "dev")
|
_ = os.Setenv("ENVIRONMENT", "dev")
|
||||||
Handle()
|
defer os.Clearenv()
|
||||||
|
Handle(cfg.Security, cfg.Web, cfg.Metrics)
|
||||||
|
defer Shutdown()
|
||||||
request, _ := http.NewRequest("GET", "/health", nil)
|
request, _ := http.NewRequest("GET", "/health", nil)
|
||||||
responseRecorder := httptest.NewRecorder()
|
responseRecorder := httptest.NewRecorder()
|
||||||
server.Handler.ServeHTTP(responseRecorder, request)
|
server.Handler.ServeHTTP(responseRecorder, request)
|
||||||
@@ -167,3 +250,80 @@ func TestHandle(t *testing.T) {
|
|||||||
t.Fatal("server should've been set (but because we set ROUTER_TEST, it shouldn't have been started)")
|
t.Fatal("server should've been set (but because we set ROUTER_TEST, it shouldn't have been started)")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestShutdown(t *testing.T) {
|
||||||
|
// Pretend that we called controller.Handle(), which initializes the server variable
|
||||||
|
server = &http.Server{}
|
||||||
|
Shutdown()
|
||||||
|
if server != nil {
|
||||||
|
t.Error("server should've been shut down")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServiceStatusesHandler(t *testing.T) {
|
||||||
|
defer storage.Get().Clear()
|
||||||
|
defer cache.Clear()
|
||||||
|
staticFolder = "../web/static"
|
||||||
|
firstResult := &testSuccessfulResult
|
||||||
|
secondResult := &testUnsuccessfulResult
|
||||||
|
storage.Get().Insert(&testService, firstResult)
|
||||||
|
storage.Get().Insert(&testService, secondResult)
|
||||||
|
// Can't be bothered dealing with timezone issues on the worker that runs the automated tests
|
||||||
|
firstResult.Timestamp = time.Time{}
|
||||||
|
secondResult.Timestamp = time.Time{}
|
||||||
|
router := CreateRouter(nil, false)
|
||||||
|
|
||||||
|
type Scenario struct {
|
||||||
|
Name string
|
||||||
|
Path string
|
||||||
|
ExpectedCode int
|
||||||
|
ExpectedBody string
|
||||||
|
}
|
||||||
|
scenarios := []Scenario{
|
||||||
|
{
|
||||||
|
Name: "no-pagination",
|
||||||
|
Path: "/api/v1/statuses",
|
||||||
|
ExpectedCode: http.StatusOK,
|
||||||
|
ExpectedBody: `{"group_name":{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}]}}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "pagination-first-result",
|
||||||
|
Path: "/api/v1/statuses?page=1&pageSize=1",
|
||||||
|
ExpectedCode: http.StatusOK,
|
||||||
|
ExpectedBody: `{"group_name":{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}]}}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "pagination-second-result",
|
||||||
|
Path: "/api/v1/statuses?page=2&pageSize=1",
|
||||||
|
ExpectedCode: http.StatusOK,
|
||||||
|
ExpectedBody: `{"group_name":{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"}]}}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "pagination-no-results",
|
||||||
|
Path: "/api/v1/statuses?page=5&pageSize=20",
|
||||||
|
ExpectedCode: http.StatusOK,
|
||||||
|
ExpectedBody: `{"group_name":{"name":"name","group":"group","key":"group_name","results":[]}}`,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "invalid-pagination-should-fall-back-to-default",
|
||||||
|
Path: "/api/v1/statuses?page=INVALID&pageSize=INVALID",
|
||||||
|
ExpectedCode: http.StatusOK,
|
||||||
|
ExpectedBody: `{"group_name":{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}]}}`,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, scenario := range scenarios {
|
||||||
|
t.Run(scenario.Name, func(t *testing.T) {
|
||||||
|
request, _ := http.NewRequest("GET", scenario.Path, nil)
|
||||||
|
responseRecorder := httptest.NewRecorder()
|
||||||
|
router.ServeHTTP(responseRecorder, request)
|
||||||
|
if responseRecorder.Code != scenario.ExpectedCode {
|
||||||
|
t.Errorf("%s %s should have returned %d, but returned %d instead", request.Method, request.URL, scenario.ExpectedCode, responseRecorder.Code)
|
||||||
|
}
|
||||||
|
output := responseRecorder.Body.String()
|
||||||
|
if output != scenario.ExpectedBody {
|
||||||
|
t.Errorf("expected:\n %s\n\ngot:\n %s", scenario.ExpectedBody, output)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
// favIconHandler handles requests for /favicon.ico
|
||||||
|
func favIconHandler(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
http.ServeFile(writer, request, staticFolder+"/favicon.ico")
|
||||||
|
}
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
// spaHandler handles requests for /
|
||||||
|
func spaHandler(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
http.ServeFile(writer, request, staticFolder+"/index.html")
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// DefaultPage is the default page to use if none is specified or an invalid value is provided
|
||||||
|
DefaultPage = 1
|
||||||
|
|
||||||
|
// DefaultPageSize is the default page siZE to use if none is specified or an invalid value is provided
|
||||||
|
DefaultPageSize = 20
|
||||||
|
|
||||||
|
// MaximumPageSize is the maximum page size allowed
|
||||||
|
MaximumPageSize = 100
|
||||||
|
)
|
||||||
|
|
||||||
|
func extractPageAndPageSizeFromRequest(r *http.Request) (page int, pageSize int) {
|
||||||
|
var err error
|
||||||
|
if pageParameter := r.URL.Query().Get("page"); len(pageParameter) == 0 {
|
||||||
|
page = DefaultPage
|
||||||
|
} else {
|
||||||
|
page, err = strconv.Atoi(pageParameter)
|
||||||
|
if err != nil {
|
||||||
|
page = DefaultPage
|
||||||
|
}
|
||||||
|
if page < 1 {
|
||||||
|
page = DefaultPage
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if pageSizeParameter := r.URL.Query().Get("pageSize"); len(pageSizeParameter) == 0 {
|
||||||
|
pageSize = DefaultPageSize
|
||||||
|
} else {
|
||||||
|
pageSize, err = strconv.Atoi(pageSizeParameter)
|
||||||
|
if err != nil {
|
||||||
|
pageSize = DefaultPageSize
|
||||||
|
}
|
||||||
|
if pageSize > MaximumPageSize {
|
||||||
|
pageSize = MaximumPageSize
|
||||||
|
} else if pageSize < 1 {
|
||||||
|
pageSize = DefaultPageSize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
@@ -0,0 +1,67 @@
|
|||||||
|
package controller
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"net/http"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestExtractPageAndPageSizeFromRequest(t *testing.T) {
|
||||||
|
type Scenario struct {
|
||||||
|
Name string
|
||||||
|
Page string
|
||||||
|
PageSize string
|
||||||
|
ExpectedPage int
|
||||||
|
ExpectedPageSize int
|
||||||
|
}
|
||||||
|
scenarios := []Scenario{
|
||||||
|
{
|
||||||
|
Page: "1",
|
||||||
|
PageSize: "20",
|
||||||
|
ExpectedPage: 1,
|
||||||
|
ExpectedPageSize: 20,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Page: "2",
|
||||||
|
PageSize: "10",
|
||||||
|
ExpectedPage: 2,
|
||||||
|
ExpectedPageSize: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Page: "2",
|
||||||
|
PageSize: "10",
|
||||||
|
ExpectedPage: 2,
|
||||||
|
ExpectedPageSize: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Page: "1",
|
||||||
|
PageSize: "999999",
|
||||||
|
ExpectedPage: 1,
|
||||||
|
ExpectedPageSize: MaximumPageSize,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Page: "-1",
|
||||||
|
PageSize: "-1",
|
||||||
|
ExpectedPage: DefaultPage,
|
||||||
|
ExpectedPageSize: DefaultPageSize,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Page: "invalid",
|
||||||
|
PageSize: "invalid",
|
||||||
|
ExpectedPage: DefaultPage,
|
||||||
|
ExpectedPageSize: DefaultPageSize,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
for _, scenario := range scenarios {
|
||||||
|
t.Run("page-"+scenario.Page+"-pageSize-"+scenario.PageSize, func(t *testing.T) {
|
||||||
|
request, _ := http.NewRequest("GET", fmt.Sprintf("/api/v1/statuses?page=%s&pageSize=%s", scenario.Page, scenario.PageSize), nil)
|
||||||
|
actualPage, actualPageSize := extractPageAndPageSizeFromRequest(request)
|
||||||
|
if actualPage != scenario.ExpectedPage {
|
||||||
|
t.Errorf("expected %d, got %d", scenario.ExpectedPage, actualPage)
|
||||||
|
}
|
||||||
|
if actualPageSize != scenario.ExpectedPageSize {
|
||||||
|
t.Errorf("expected %d, got %d", scenario.ExpectedPageSize, actualPageSize)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
+56
-17
@@ -23,7 +23,7 @@ const (
|
|||||||
|
|
||||||
// DNSRCodePlaceholder is a place holder for DNS_RCODE
|
// DNSRCodePlaceholder is a place holder for DNS_RCODE
|
||||||
//
|
//
|
||||||
// Values that could be NOERROR, FORMERR, SERVFAIL, NXDOMAIN, NOTIMP and REFUSED
|
// Values that could replace the placeholder: NOERROR, FORMERR, SERVFAIL, NXDOMAIN, NOTIMP, REFUSED
|
||||||
DNSRCodePlaceholder = "[DNS_RCODE]"
|
DNSRCodePlaceholder = "[DNS_RCODE]"
|
||||||
|
|
||||||
// ResponseTimePlaceholder is a placeholder for the request response time, in milliseconds.
|
// ResponseTimePlaceholder is a placeholder for the request response time, in milliseconds.
|
||||||
@@ -51,14 +51,19 @@ const (
|
|||||||
// Usage: len([BODY].articles) == 10, len([BODY].name) > 5
|
// Usage: len([BODY].articles) == 10, len([BODY].name) > 5
|
||||||
LengthFunctionPrefix = "len("
|
LengthFunctionPrefix = "len("
|
||||||
|
|
||||||
|
// HasFunctionPrefix is the prefix for the has function
|
||||||
|
//
|
||||||
|
// Usage: has([BODY].errors) == true
|
||||||
|
HasFunctionPrefix = "has("
|
||||||
|
|
||||||
// PatternFunctionPrefix is the prefix for the pattern function
|
// PatternFunctionPrefix is the prefix for the pattern function
|
||||||
//
|
//
|
||||||
// Usage: pat(192.168.*.*)
|
// Usage: [IP] == pat(192.168.*.*)
|
||||||
PatternFunctionPrefix = "pat("
|
PatternFunctionPrefix = "pat("
|
||||||
|
|
||||||
// AnyFunctionPrefix is the prefix for the any function
|
// AnyFunctionPrefix is the prefix for the any function
|
||||||
//
|
//
|
||||||
// Usage: any(1.1.1.1, 1.0.0.1)
|
// Usage: [IP] == any(1.1.1.1, 1.0.0.1)
|
||||||
AnyFunctionPrefix = "any("
|
AnyFunctionPrefix = "any("
|
||||||
|
|
||||||
// FunctionSuffix is the suffix for all functions
|
// FunctionSuffix is the suffix for all functions
|
||||||
@@ -66,12 +71,20 @@ const (
|
|||||||
|
|
||||||
// InvalidConditionElementSuffix is the suffix that will be appended to an invalid condition
|
// InvalidConditionElementSuffix is the suffix that will be appended to an invalid condition
|
||||||
InvalidConditionElementSuffix = "(INVALID)"
|
InvalidConditionElementSuffix = "(INVALID)"
|
||||||
|
|
||||||
|
// maximumLengthBeforeTruncatingWhenComparedWithPattern is the maximum length an element being compared to a
|
||||||
|
// pattern can have.
|
||||||
|
//
|
||||||
|
// This is only used for aesthetic purposes; it does not influence whether the condition evaluation results in a
|
||||||
|
// success or a failure
|
||||||
|
maximumLengthBeforeTruncatingWhenComparedWithPattern = 25
|
||||||
)
|
)
|
||||||
|
|
||||||
// Condition is a condition that needs to be met in order for a Service to be considered healthy.
|
// Condition is a condition that needs to be met in order for a Service to be considered healthy.
|
||||||
type Condition string
|
type Condition string
|
||||||
|
|
||||||
// evaluate the Condition with the Result of the health check
|
// evaluate the Condition with the Result of the health check
|
||||||
|
// TODO: Add a mandatory space between each operators (e.g. " == " instead of "==") (BREAKING CHANGE)
|
||||||
func (c Condition) evaluate(result *Result) bool {
|
func (c Condition) evaluate(result *Result) bool {
|
||||||
condition := string(c)
|
condition := string(c)
|
||||||
success := false
|
success := false
|
||||||
@@ -123,6 +136,12 @@ func (c Condition) evaluate(result *Result) bool {
|
|||||||
return success
|
return success
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// hasBodyPlaceholder checks whether the condition has a BodyPlaceholder
|
||||||
|
// Used for determining whether the response body should be read or not
|
||||||
|
func (c Condition) hasBodyPlaceholder() bool {
|
||||||
|
return strings.Contains(string(c), BodyPlaceholder)
|
||||||
|
}
|
||||||
|
|
||||||
// isEqual compares two strings.
|
// isEqual compares two strings.
|
||||||
//
|
//
|
||||||
// Supports the pattern and the any functions.
|
// Supports the pattern and the any functions.
|
||||||
@@ -181,7 +200,7 @@ func isEqual(first, second string) bool {
|
|||||||
func sanitizeAndResolve(elements []string, result *Result) ([]string, []string) {
|
func sanitizeAndResolve(elements []string, result *Result) ([]string, []string) {
|
||||||
parameters := make([]string, len(elements))
|
parameters := make([]string, len(elements))
|
||||||
resolvedParameters := make([]string, len(elements))
|
resolvedParameters := make([]string, len(elements))
|
||||||
body := strings.TrimSpace(string(result.Body))
|
body := strings.TrimSpace(string(result.body))
|
||||||
for i, element := range elements {
|
for i, element := range elements {
|
||||||
element = strings.TrimSpace(element)
|
element = strings.TrimSpace(element)
|
||||||
parameters[i] = element
|
parameters[i] = element
|
||||||
@@ -203,26 +222,39 @@ func sanitizeAndResolve(elements []string, result *Result) ([]string, []string)
|
|||||||
default:
|
default:
|
||||||
// if contains the BodyPlaceholder, then evaluate json path
|
// if contains the BodyPlaceholder, then evaluate json path
|
||||||
if strings.Contains(element, BodyPlaceholder) {
|
if strings.Contains(element, BodyPlaceholder) {
|
||||||
wantLength := false
|
checkingForLength := false
|
||||||
|
checkingForExistence := false
|
||||||
if strings.HasPrefix(element, LengthFunctionPrefix) && strings.HasSuffix(element, FunctionSuffix) {
|
if strings.HasPrefix(element, LengthFunctionPrefix) && strings.HasSuffix(element, FunctionSuffix) {
|
||||||
wantLength = true
|
checkingForLength = true
|
||||||
element = strings.TrimSuffix(strings.TrimPrefix(element, LengthFunctionPrefix), FunctionSuffix)
|
element = strings.TrimSuffix(strings.TrimPrefix(element, LengthFunctionPrefix), FunctionSuffix)
|
||||||
}
|
}
|
||||||
resolvedElement, resolvedElementLength, err := jsonpath.Eval(strings.TrimPrefix(element, BodyPlaceholder+"."), result.Body)
|
if strings.HasPrefix(element, HasFunctionPrefix) && strings.HasSuffix(element, FunctionSuffix) {
|
||||||
if err != nil {
|
checkingForExistence = true
|
||||||
if err.Error() != "unexpected end of JSON input" {
|
element = strings.TrimSuffix(strings.TrimPrefix(element, HasFunctionPrefix), FunctionSuffix)
|
||||||
result.Errors = append(result.Errors, err.Error())
|
}
|
||||||
}
|
resolvedElement, resolvedElementLength, err := jsonpath.Eval(strings.TrimPrefix(strings.TrimPrefix(element, BodyPlaceholder), "."), result.body)
|
||||||
if wantLength {
|
if checkingForExistence {
|
||||||
element = LengthFunctionPrefix + element + FunctionSuffix + " " + InvalidConditionElementSuffix
|
if err != nil {
|
||||||
|
element = "false"
|
||||||
} else {
|
} else {
|
||||||
element = element + " " + InvalidConditionElementSuffix
|
element = "true"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if wantLength {
|
if err != nil {
|
||||||
element = strconv.Itoa(resolvedElementLength)
|
if err.Error() != "unexpected end of JSON input" {
|
||||||
|
result.Errors = append(result.Errors, err.Error())
|
||||||
|
}
|
||||||
|
if checkingForLength {
|
||||||
|
element = LengthFunctionPrefix + element + FunctionSuffix + " " + InvalidConditionElementSuffix
|
||||||
|
} else {
|
||||||
|
element = element + " " + InvalidConditionElementSuffix
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
element = resolvedElement
|
if checkingForLength {
|
||||||
|
element = strconv.Itoa(resolvedElementLength)
|
||||||
|
} else {
|
||||||
|
element = resolvedElement
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -258,6 +290,13 @@ func prettify(parameters []string, resolvedParameters []string, operator string)
|
|||||||
if strings.HasSuffix(resolvedParameters[0], InvalidConditionElementSuffix) || strings.HasSuffix(resolvedParameters[1], InvalidConditionElementSuffix) {
|
if strings.HasSuffix(resolvedParameters[0], InvalidConditionElementSuffix) || strings.HasSuffix(resolvedParameters[1], InvalidConditionElementSuffix) {
|
||||||
return resolvedParameters[0] + " " + operator + " " + resolvedParameters[1]
|
return resolvedParameters[0] + " " + operator + " " + resolvedParameters[1]
|
||||||
}
|
}
|
||||||
|
// If using the pattern function, truncate the parameter it's being compared to if said parameter is long enough
|
||||||
|
if strings.HasPrefix(parameters[0], PatternFunctionPrefix) && strings.HasSuffix(parameters[0], FunctionSuffix) && len(resolvedParameters[1]) > maximumLengthBeforeTruncatingWhenComparedWithPattern {
|
||||||
|
resolvedParameters[1] = fmt.Sprintf("%.25s...(truncated)", resolvedParameters[1])
|
||||||
|
}
|
||||||
|
if strings.HasPrefix(parameters[1], PatternFunctionPrefix) && strings.HasSuffix(parameters[1], FunctionSuffix) && len(resolvedParameters[0]) > maximumLengthBeforeTruncatingWhenComparedWithPattern {
|
||||||
|
resolvedParameters[0] = fmt.Sprintf("%.25s...(truncated)", resolvedParameters[0])
|
||||||
|
}
|
||||||
// First element is a placeholder
|
// First element is a placeholder
|
||||||
if parameters[0] != resolvedParameters[0] && parameters[1] == resolvedParameters[1] {
|
if parameters[0] != resolvedParameters[0] && parameters[1] == resolvedParameters[1] {
|
||||||
return parameters[0] + " (" + resolvedParameters[0] + ") " + operator + " " + parameters[1]
|
return parameters[0] + " (" + resolvedParameters[0] + ") " + operator + " " + parameters[1]
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import "testing"
|
|||||||
func BenchmarkCondition_evaluateWithBodyStringAny(b *testing.B) {
|
func BenchmarkCondition_evaluateWithBodyStringAny(b *testing.B) {
|
||||||
condition := Condition("[BODY].name == any(john.doe, jane.doe)")
|
condition := Condition("[BODY].name == any(john.doe, jane.doe)")
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
result := &Result{Body: []byte("{\"name\": \"john.doe\"}")}
|
result := &Result{body: []byte("{\"name\": \"john.doe\"}")}
|
||||||
condition.evaluate(result)
|
condition.evaluate(result)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -14,7 +14,7 @@ func BenchmarkCondition_evaluateWithBodyStringAny(b *testing.B) {
|
|||||||
func BenchmarkCondition_evaluateWithBodyStringAnyFailure(b *testing.B) {
|
func BenchmarkCondition_evaluateWithBodyStringAnyFailure(b *testing.B) {
|
||||||
condition := Condition("[BODY].name == any(john.doe, jane.doe)")
|
condition := Condition("[BODY].name == any(john.doe, jane.doe)")
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
result := &Result{Body: []byte("{\"name\": \"bob.doe\"}")}
|
result := &Result{body: []byte("{\"name\": \"bob.doe\"}")}
|
||||||
condition.evaluate(result)
|
condition.evaluate(result)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -23,7 +23,7 @@ func BenchmarkCondition_evaluateWithBodyStringAnyFailure(b *testing.B) {
|
|||||||
func BenchmarkCondition_evaluateWithBodyString(b *testing.B) {
|
func BenchmarkCondition_evaluateWithBodyString(b *testing.B) {
|
||||||
condition := Condition("[BODY].name == john.doe")
|
condition := Condition("[BODY].name == john.doe")
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
result := &Result{Body: []byte("{\"name\": \"john.doe\"}")}
|
result := &Result{body: []byte("{\"name\": \"john.doe\"}")}
|
||||||
condition.evaluate(result)
|
condition.evaluate(result)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -32,7 +32,7 @@ func BenchmarkCondition_evaluateWithBodyString(b *testing.B) {
|
|||||||
func BenchmarkCondition_evaluateWithBodyStringFailure(b *testing.B) {
|
func BenchmarkCondition_evaluateWithBodyStringFailure(b *testing.B) {
|
||||||
condition := Condition("[BODY].name == john.doe")
|
condition := Condition("[BODY].name == john.doe")
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
result := &Result{Body: []byte("{\"name\": \"bob.doe\"}")}
|
result := &Result{body: []byte("{\"name\": \"bob.doe\"}")}
|
||||||
condition.evaluate(result)
|
condition.evaluate(result)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -41,7 +41,7 @@ func BenchmarkCondition_evaluateWithBodyStringFailure(b *testing.B) {
|
|||||||
func BenchmarkCondition_evaluateWithBodyStringLen(b *testing.B) {
|
func BenchmarkCondition_evaluateWithBodyStringLen(b *testing.B) {
|
||||||
condition := Condition("len([BODY].name) == 8")
|
condition := Condition("len([BODY].name) == 8")
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
result := &Result{Body: []byte("{\"name\": \"john.doe\"}")}
|
result := &Result{body: []byte("{\"name\": \"john.doe\"}")}
|
||||||
condition.evaluate(result)
|
condition.evaluate(result)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
@@ -50,7 +50,7 @@ func BenchmarkCondition_evaluateWithBodyStringLen(b *testing.B) {
|
|||||||
func BenchmarkCondition_evaluateWithBodyStringLenFailure(b *testing.B) {
|
func BenchmarkCondition_evaluateWithBodyStringLenFailure(b *testing.B) {
|
||||||
condition := Condition("len([BODY].name) == 8")
|
condition := Condition("len([BODY].name) == 8")
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
result := &Result{Body: []byte("{\"name\": \"bob.doe\"}")}
|
result := &Result{body: []byte("{\"name\": \"bob.doe\"}")}
|
||||||
condition.evaluate(result)
|
condition.evaluate(result)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
|
|||||||
+453
-646
File diff suppressed because it is too large.
Load diff
+10
-9
@@ -29,16 +29,17 @@ type DNS struct {
|
|||||||
QueryName string `yaml:"query-name"`
|
QueryName string `yaml:"query-name"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNS) validateAndSetDefault() {
|
func (d *DNS) validateAndSetDefault() error {
|
||||||
if len(d.QueryName) == 0 {
|
if len(d.QueryName) == 0 {
|
||||||
panic(ErrDNSWithNoQueryName)
|
return ErrDNSWithNoQueryName
|
||||||
}
|
}
|
||||||
if !strings.HasSuffix(d.QueryName, ".") {
|
if !strings.HasSuffix(d.QueryName, ".") {
|
||||||
d.QueryName += "."
|
d.QueryName += "."
|
||||||
}
|
}
|
||||||
if _, ok := dns.StringToType[d.QueryType]; !ok {
|
if _, ok := dns.StringToType[d.QueryType]; !ok {
|
||||||
panic(ErrDNSWithInvalidQueryType)
|
return ErrDNSWithInvalidQueryType
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (d *DNS) query(url string, result *Result) {
|
func (d *DNS) query(url string, result *Result) {
|
||||||
@@ -60,26 +61,26 @@ func (d *DNS) query(url string, result *Result) {
|
|||||||
switch rr.Header().Rrtype {
|
switch rr.Header().Rrtype {
|
||||||
case dns.TypeA:
|
case dns.TypeA:
|
||||||
if a, ok := rr.(*dns.A); ok {
|
if a, ok := rr.(*dns.A); ok {
|
||||||
result.Body = []byte(a.A.String())
|
result.body = []byte(a.A.String())
|
||||||
}
|
}
|
||||||
case dns.TypeAAAA:
|
case dns.TypeAAAA:
|
||||||
if aaaa, ok := rr.(*dns.AAAA); ok {
|
if aaaa, ok := rr.(*dns.AAAA); ok {
|
||||||
result.Body = []byte(aaaa.AAAA.String())
|
result.body = []byte(aaaa.AAAA.String())
|
||||||
}
|
}
|
||||||
case dns.TypeCNAME:
|
case dns.TypeCNAME:
|
||||||
if cname, ok := rr.(*dns.CNAME); ok {
|
if cname, ok := rr.(*dns.CNAME); ok {
|
||||||
result.Body = []byte(cname.Target)
|
result.body = []byte(cname.Target)
|
||||||
}
|
}
|
||||||
case dns.TypeMX:
|
case dns.TypeMX:
|
||||||
if mx, ok := rr.(*dns.MX); ok {
|
if mx, ok := rr.(*dns.MX); ok {
|
||||||
result.Body = []byte(mx.Mx)
|
result.body = []byte(mx.Mx)
|
||||||
}
|
}
|
||||||
case dns.TypeNS:
|
case dns.TypeNS:
|
||||||
if ns, ok := rr.(*dns.NS); ok {
|
if ns, ok := rr.(*dns.NS); ok {
|
||||||
result.Body = []byte(ns.Ns)
|
result.body = []byte(ns.Ns)
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
result.Body = []byte("query type is not supported yet")
|
result.body = []byte("query type is not supported yet")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+12
-8
@@ -91,12 +91,12 @@ func TestIntegrationQuery(t *testing.T) {
|
|||||||
|
|
||||||
if test.inputDNS.QueryType == "NS" {
|
if test.inputDNS.QueryType == "NS" {
|
||||||
// Because there are often multiple nameservers backing a single domain, we'll only look at the suffix
|
// Because there are often multiple nameservers backing a single domain, we'll only look at the suffix
|
||||||
if !pattern.Match(test.expectedBody, string(result.Body)) {
|
if !pattern.Match(test.expectedBody, string(result.body)) {
|
||||||
t.Errorf("got %s, expected result %s,", string(result.Body), test.expectedBody)
|
t.Errorf("got %s, expected result %s,", string(result.body), test.expectedBody)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if string(result.Body) != test.expectedBody {
|
if string(result.body) != test.expectedBody {
|
||||||
t.Errorf("got %s, expected result %s,", string(result.Body), test.expectedBody)
|
t.Errorf("got %s, expected result %s,", string(result.body), test.expectedBody)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -109,8 +109,10 @@ func TestService_ValidateAndSetDefaultsWithNoDNSQueryName(t *testing.T) {
|
|||||||
QueryType: "A",
|
QueryType: "A",
|
||||||
QueryName: "",
|
QueryName: "",
|
||||||
}
|
}
|
||||||
dns.validateAndSetDefault()
|
err := dns.validateAndSetDefault()
|
||||||
t.Fatal("Should've panicked because service`s dns didn't have a query name, which is a mandatory field for dns")
|
if err == nil {
|
||||||
|
t.Fatal("Should've returned an error because service`s dns didn't have a query name, which is a mandatory field for dns")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestService_ValidateAndSetDefaultsWithInvalidDNSQueryType(t *testing.T) {
|
func TestService_ValidateAndSetDefaultsWithInvalidDNSQueryType(t *testing.T) {
|
||||||
@@ -119,6 +121,8 @@ func TestService_ValidateAndSetDefaultsWithInvalidDNSQueryType(t *testing.T) {
|
|||||||
QueryType: "B",
|
QueryType: "B",
|
||||||
QueryName: "example.com",
|
QueryName: "example.com",
|
||||||
}
|
}
|
||||||
dns.validateAndSetDefault()
|
err := dns.validateAndSetDefault()
|
||||||
t.Fatal("Should've panicked because service`s dns query type is invalid, it needs to be a valid query name like A, AAAA, CNAME...")
|
if err == nil {
|
||||||
|
t.Fatal("Should've returned an error because service`s dns query type is invalid, it needs to be a valid query name like A, AAAA, CNAME...")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+8
-4
@@ -12,10 +12,7 @@ type Result struct {
|
|||||||
// DNSRCode is the response code of a DNS query in a human readable format
|
// DNSRCode is the response code of a DNS query in a human readable format
|
||||||
DNSRCode string `json:"-"`
|
DNSRCode string `json:"-"`
|
||||||
|
|
||||||
// Body is the response body
|
// Hostname extracted from Service.URL
|
||||||
Body []byte `json:"-"`
|
|
||||||
|
|
||||||
// Hostname extracted from the Service URL
|
|
||||||
Hostname string `json:"hostname"`
|
Hostname string `json:"hostname"`
|
||||||
|
|
||||||
// IP resolved from the Service URL
|
// IP resolved from the Service URL
|
||||||
@@ -41,4 +38,11 @@ type Result struct {
|
|||||||
|
|
||||||
// CertificateExpiration is the duration before the certificate expires
|
// CertificateExpiration is the duration before the certificate expires
|
||||||
CertificateExpiration time.Duration `json:"-"`
|
CertificateExpiration time.Duration `json:"-"`
|
||||||
|
|
||||||
|
// body is the response body
|
||||||
|
//
|
||||||
|
// Note that this variable is only used during the evaluation of a service's health.
|
||||||
|
// This means that the call Service.EvaluateHealth both populates the body (if necessary)
|
||||||
|
// and sets it to nil after the evaluation has been completed.
|
||||||
|
body []byte
|
||||||
}
|
}
|
||||||
+41
-4
@@ -6,6 +6,14 @@ import (
|
|||||||
"github.com/TwinProduction/gatus/util"
|
"github.com/TwinProduction/gatus/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// MaximumNumberOfResults is the maximum number of results that ServiceStatus.Results can have
|
||||||
|
MaximumNumberOfResults = 100
|
||||||
|
|
||||||
|
// MaximumNumberOfEvents is the maximum number of events that ServiceStatus.Events can have
|
||||||
|
MaximumNumberOfEvents = 50
|
||||||
|
)
|
||||||
|
|
||||||
// ServiceStatus contains the evaluation Results of a Service
|
// ServiceStatus contains the evaluation Results of a Service
|
||||||
type ServiceStatus struct {
|
type ServiceStatus struct {
|
||||||
// Name of the service
|
// Name of the service
|
||||||
@@ -50,6 +58,29 @@ func NewServiceStatus(service *Service) *ServiceStatus {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WithResultPagination returns a shallow copy of the ServiceStatus with only the results
|
||||||
|
// within the range defined by the page and pageSize parameters
|
||||||
|
func (ss ServiceStatus) WithResultPagination(page, pageSize int) *ServiceStatus {
|
||||||
|
shallowCopy := ss
|
||||||
|
numberOfResults := len(shallowCopy.Results)
|
||||||
|
start := numberOfResults - (page * pageSize)
|
||||||
|
end := numberOfResults - ((page - 1) * pageSize)
|
||||||
|
if start > numberOfResults {
|
||||||
|
start = -1
|
||||||
|
} else if start < 0 {
|
||||||
|
start = 0
|
||||||
|
}
|
||||||
|
if end > numberOfResults {
|
||||||
|
end = numberOfResults
|
||||||
|
}
|
||||||
|
if start < 0 || end < 0 {
|
||||||
|
shallowCopy.Results = []*Result{}
|
||||||
|
} else {
|
||||||
|
shallowCopy.Results = shallowCopy.Results[start:end]
|
||||||
|
}
|
||||||
|
return &shallowCopy
|
||||||
|
}
|
||||||
|
|
||||||
// AddResult adds a Result to ServiceStatus.Results and makes sure that there are
|
// AddResult adds a Result to ServiceStatus.Results and makes sure that there are
|
||||||
// no more than 20 results in the Results slice
|
// no more than 20 results in the Results slice
|
||||||
func (ss *ServiceStatus) AddResult(result *Result) {
|
func (ss *ServiceStatus) AddResult(result *Result) {
|
||||||
@@ -64,14 +95,20 @@ func (ss *ServiceStatus) AddResult(result *Result) {
|
|||||||
event.Type = EventUnhealthy
|
event.Type = EventUnhealthy
|
||||||
}
|
}
|
||||||
ss.Events = append(ss.Events, event)
|
ss.Events = append(ss.Events, event)
|
||||||
if len(ss.Events) > 20 {
|
if len(ss.Events) > MaximumNumberOfEvents {
|
||||||
ss.Events = ss.Events[1:]
|
// Doing ss.Events[1:] would usually be sufficient, but in the case where for some reason, the slice has
|
||||||
|
// more than one extra element, we can get rid of all of them at once and thus returning the slice to a
|
||||||
|
// length of MaximumNumberOfEvents by using ss.Events[len(ss.Events)-MaximumNumberOfEvents:] instead
|
||||||
|
ss.Events = ss.Events[len(ss.Events)-MaximumNumberOfEvents:]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ss.Results = append(ss.Results, result)
|
ss.Results = append(ss.Results, result)
|
||||||
if len(ss.Results) > 20 {
|
if len(ss.Results) > MaximumNumberOfResults {
|
||||||
ss.Results = ss.Results[1:]
|
// Doing ss.Results[1:] would usually be sufficient, but in the case where for some reason, the slice has more
|
||||||
|
// than one extra element, we can get rid of all of them at once and thus returning the slice to a length of
|
||||||
|
// MaximumNumberOfResults by using ss.Results[len(ss.Results)-MaximumNumberOfResults:] instead
|
||||||
|
ss.Results = ss.Results[len(ss.Results)-MaximumNumberOfResults:]
|
||||||
}
|
}
|
||||||
ss.Uptime.ProcessResult(result)
|
ss.Uptime.ProcessResult(result)
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,92 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
firstCondition = Condition("[STATUS] == 200")
|
||||||
|
secondCondition = Condition("[RESPONSE_TIME] < 500")
|
||||||
|
thirdCondition = Condition("[CERTIFICATE_EXPIRATION] < 72h")
|
||||||
|
|
||||||
|
timestamp = time.Now()
|
||||||
|
|
||||||
|
testService = Service{
|
||||||
|
Name: "name",
|
||||||
|
Group: "group",
|
||||||
|
URL: "https://example.org/what/ever",
|
||||||
|
Method: "GET",
|
||||||
|
Body: "body",
|
||||||
|
Interval: 30 * time.Second,
|
||||||
|
Conditions: []*Condition{&firstCondition, &secondCondition, &thirdCondition},
|
||||||
|
Alerts: nil,
|
||||||
|
Insecure: false,
|
||||||
|
NumberOfFailuresInARow: 0,
|
||||||
|
NumberOfSuccessesInARow: 0,
|
||||||
|
}
|
||||||
|
testSuccessfulResult = Result{
|
||||||
|
Hostname: "example.org",
|
||||||
|
IP: "127.0.0.1",
|
||||||
|
HTTPStatus: 200,
|
||||||
|
body: []byte("body"),
|
||||||
|
Errors: nil,
|
||||||
|
Connected: true,
|
||||||
|
Success: true,
|
||||||
|
Timestamp: timestamp,
|
||||||
|
Duration: 150 * time.Millisecond,
|
||||||
|
CertificateExpiration: 10 * time.Hour,
|
||||||
|
ConditionResults: []*ConditionResult{
|
||||||
|
{
|
||||||
|
Condition: "[STATUS] == 200",
|
||||||
|
Success: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Condition: "[RESPONSE_TIME] < 500",
|
||||||
|
Success: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Condition: "[CERTIFICATE_EXPIRATION] < 72h",
|
||||||
|
Success: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
testUnsuccessfulResult = Result{
|
||||||
|
Hostname: "example.org",
|
||||||
|
IP: "127.0.0.1",
|
||||||
|
HTTPStatus: 200,
|
||||||
|
body: []byte("body"),
|
||||||
|
Errors: []string{"error-1", "error-2"},
|
||||||
|
Connected: true,
|
||||||
|
Success: false,
|
||||||
|
Timestamp: timestamp,
|
||||||
|
Duration: 750 * time.Millisecond,
|
||||||
|
CertificateExpiration: 10 * time.Hour,
|
||||||
|
ConditionResults: []*ConditionResult{
|
||||||
|
{
|
||||||
|
Condition: "[STATUS] == 200",
|
||||||
|
Success: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Condition: "[RESPONSE_TIME] < 500",
|
||||||
|
Success: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Condition: "[CERTIFICATE_EXPIRATION] < 72h",
|
||||||
|
Success: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkServiceStatus_WithResultPagination(b *testing.B) {
|
||||||
|
service := &testService
|
||||||
|
serviceStatus := NewServiceStatus(service)
|
||||||
|
for i := 0; i < MaximumNumberOfResults; i++ {
|
||||||
|
serviceStatus.AddResult(&testSuccessfulResult)
|
||||||
|
}
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
serviceStatus.WithResultPagination(1, 20)
|
||||||
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
}
|
||||||
@@ -22,10 +22,45 @@ func TestNewServiceStatus(t *testing.T) {
|
|||||||
func TestServiceStatus_AddResult(t *testing.T) {
|
func TestServiceStatus_AddResult(t *testing.T) {
|
||||||
service := &Service{Name: "name", Group: "group"}
|
service := &Service{Name: "name", Group: "group"}
|
||||||
serviceStatus := NewServiceStatus(service)
|
serviceStatus := NewServiceStatus(service)
|
||||||
for i := 0; i < 50; i++ {
|
for i := 0; i < MaximumNumberOfResults+10; i++ {
|
||||||
serviceStatus.AddResult(&Result{Timestamp: time.Now()})
|
serviceStatus.AddResult(&Result{Timestamp: time.Now()})
|
||||||
}
|
}
|
||||||
if len(serviceStatus.Results) != 20 {
|
if len(serviceStatus.Results) != MaximumNumberOfResults {
|
||||||
t.Errorf("expected serviceStatus.Results to not exceed a length of 20")
|
t.Errorf("expected serviceStatus.Results to not exceed a length of %d", MaximumNumberOfResults)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestServiceStatus_WithResultPagination(t *testing.T) {
|
||||||
|
service := &Service{Name: "name", Group: "group"}
|
||||||
|
serviceStatus := NewServiceStatus(service)
|
||||||
|
for i := 0; i < 25; i++ {
|
||||||
|
serviceStatus.AddResult(&Result{Timestamp: time.Now()})
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(1, 1).Results) != 1 {
|
||||||
|
t.Errorf("expected to have 1 result")
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(5, 0).Results) != 0 {
|
||||||
|
t.Errorf("expected to have 0 results")
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(-1, 20).Results) != 0 {
|
||||||
|
t.Errorf("expected to have 0 result, because the page was invalid")
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(1, -1).Results) != 0 {
|
||||||
|
t.Errorf("expected to have 0 result, because the page size was invalid")
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(1, 10).Results) != 10 {
|
||||||
|
t.Errorf("expected to have 10 results, because given a page size of 10, page 1 should have 10 elements")
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(2, 10).Results) != 10 {
|
||||||
|
t.Errorf("expected to have 10 results, because given a page size of 10, page 2 should have 10 elements")
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(3, 10).Results) != 5 {
|
||||||
|
t.Errorf("expected to have 5 results, because given a page size of 10, page 3 should have 5 elements")
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(4, 10).Results) != 0 {
|
||||||
|
t.Errorf("expected to have 0 results, because given a page size of 10, page 4 should have 0 elements")
|
||||||
|
}
|
||||||
|
if len(serviceStatus.WithResultPagination(1, 50).Results) != 25 {
|
||||||
|
t.Errorf("expected to have 25 results, because there's only 25 results")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
+38
-21
@@ -11,6 +11,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
"github.com/TwinProduction/gatus/client"
|
"github.com/TwinProduction/gatus/client"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -72,7 +73,7 @@ type Service struct {
|
|||||||
Conditions []*Condition `yaml:"conditions"`
|
Conditions []*Condition `yaml:"conditions"`
|
||||||
|
|
||||||
// Alerts is the alerting configuration for the service in case of failure
|
// Alerts is the alerting configuration for the service in case of failure
|
||||||
Alerts []*Alert `yaml:"alerts"`
|
Alerts []*alert.Alert `yaml:"alerts"`
|
||||||
|
|
||||||
// Insecure is whether to skip verifying the server's certificate chain and host name
|
// Insecure is whether to skip verifying the server's certificate chain and host name
|
||||||
Insecure bool `yaml:"insecure,omitempty"`
|
Insecure bool `yaml:"insecure,omitempty"`
|
||||||
@@ -80,12 +81,12 @@ type Service struct {
|
|||||||
// NumberOfFailuresInARow is the number of unsuccessful evaluations in a row
|
// NumberOfFailuresInARow is the number of unsuccessful evaluations in a row
|
||||||
NumberOfFailuresInARow int
|
NumberOfFailuresInARow int
|
||||||
|
|
||||||
// NumberOfFailuresInARow is the number of successful evaluations in a row
|
// NumberOfSuccessesInARow is the number of successful evaluations in a row
|
||||||
NumberOfSuccessesInARow int
|
NumberOfSuccessesInARow int
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateAndSetDefaults validates the service's configuration and sets the default value of fields that have one
|
// ValidateAndSetDefaults validates the service's configuration and sets the default value of fields that have one
|
||||||
func (service *Service) ValidateAndSetDefaults() {
|
func (service *Service) ValidateAndSetDefaults() error {
|
||||||
// Set default values
|
// Set default values
|
||||||
if service.Interval == 0 {
|
if service.Interval == 0 {
|
||||||
service.Interval = 1 * time.Minute
|
service.Interval = 1 * time.Minute
|
||||||
@@ -105,32 +106,32 @@ func (service *Service) ValidateAndSetDefaults() {
|
|||||||
if _, contentTypeHeaderExists := service.Headers[ContentTypeHeader]; !contentTypeHeaderExists && service.GraphQL {
|
if _, contentTypeHeaderExists := service.Headers[ContentTypeHeader]; !contentTypeHeaderExists && service.GraphQL {
|
||||||
service.Headers[ContentTypeHeader] = "application/json"
|
service.Headers[ContentTypeHeader] = "application/json"
|
||||||
}
|
}
|
||||||
for _, alert := range service.Alerts {
|
for _, serviceAlert := range service.Alerts {
|
||||||
if alert.FailureThreshold <= 0 {
|
if serviceAlert.FailureThreshold <= 0 {
|
||||||
alert.FailureThreshold = 3
|
serviceAlert.FailureThreshold = 3
|
||||||
}
|
}
|
||||||
if alert.SuccessThreshold <= 0 {
|
if serviceAlert.SuccessThreshold <= 0 {
|
||||||
alert.SuccessThreshold = 2
|
serviceAlert.SuccessThreshold = 2
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if len(service.Name) == 0 {
|
if len(service.Name) == 0 {
|
||||||
panic(ErrServiceWithNoName)
|
return ErrServiceWithNoName
|
||||||
}
|
}
|
||||||
if len(service.URL) == 0 {
|
if len(service.URL) == 0 {
|
||||||
panic(ErrServiceWithNoURL)
|
return ErrServiceWithNoURL
|
||||||
}
|
}
|
||||||
if len(service.Conditions) == 0 {
|
if len(service.Conditions) == 0 {
|
||||||
panic(ErrServiceWithNoCondition)
|
return ErrServiceWithNoCondition
|
||||||
}
|
}
|
||||||
if service.DNS != nil {
|
if service.DNS != nil {
|
||||||
service.DNS.validateAndSetDefault()
|
return service.DNS.validateAndSetDefault()
|
||||||
return
|
|
||||||
}
|
}
|
||||||
// Make sure that the request can be created
|
// Make sure that the request can be created
|
||||||
_, err := http.NewRequest(service.Method, service.URL, bytes.NewBuffer([]byte(service.Body)))
|
_, err := http.NewRequest(service.Method, service.URL, bytes.NewBuffer([]byte(service.Body)))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
return err
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// EvaluateHealth sends a request to the service's URL and evaluates the conditions of the service.
|
// EvaluateHealth sends a request to the service's URL and evaluates the conditions of the service.
|
||||||
@@ -149,17 +150,19 @@ func (service *Service) EvaluateHealth() *Result {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
result.Timestamp = time.Now()
|
result.Timestamp = time.Now()
|
||||||
|
// No need to keep the body after the service has been evaluated
|
||||||
|
result.body = nil
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAlertsTriggered returns a slice of alerts that have been triggered
|
// GetAlertsTriggered returns a slice of alerts that have been triggered
|
||||||
func (service *Service) GetAlertsTriggered() []Alert {
|
func (service *Service) GetAlertsTriggered() []alert.Alert {
|
||||||
var alerts []Alert
|
var alerts []alert.Alert
|
||||||
if service.NumberOfFailuresInARow == 0 {
|
if service.NumberOfFailuresInARow == 0 {
|
||||||
return alerts
|
return alerts
|
||||||
}
|
}
|
||||||
for _, alert := range service.Alerts {
|
for _, alert := range service.Alerts {
|
||||||
if alert.Enabled && alert.FailureThreshold == service.NumberOfFailuresInARow {
|
if alert.IsEnabled() && alert.FailureThreshold == service.NumberOfFailuresInARow {
|
||||||
alerts = append(alerts, *alert)
|
alerts = append(alerts, *alert)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@@ -213,15 +216,19 @@ func (service *Service) call(result *Result) {
|
|||||||
result.Errors = append(result.Errors, err.Error())
|
result.Errors = append(result.Errors, err.Error())
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
defer response.Body.Close()
|
||||||
if response.TLS != nil && len(response.TLS.PeerCertificates) > 0 {
|
if response.TLS != nil && len(response.TLS.PeerCertificates) > 0 {
|
||||||
certificate := response.TLS.PeerCertificates[0]
|
certificate := response.TLS.PeerCertificates[0]
|
||||||
result.CertificateExpiration = certificate.NotAfter.Sub(time.Now())
|
result.CertificateExpiration = time.Until(certificate.NotAfter)
|
||||||
}
|
}
|
||||||
result.HTTPStatus = response.StatusCode
|
result.HTTPStatus = response.StatusCode
|
||||||
result.Connected = response.StatusCode > 0
|
result.Connected = response.StatusCode > 0
|
||||||
result.Body, err = ioutil.ReadAll(response.Body)
|
// Only read the body if there's a condition that uses the BodyPlaceholder
|
||||||
if err != nil {
|
if service.needsToReadBody() {
|
||||||
result.Errors = append(result.Errors, err.Error())
|
result.body, err = ioutil.ReadAll(response.Body)
|
||||||
|
if err != nil {
|
||||||
|
result.Errors = append(result.Errors, err.Error())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -246,3 +253,13 @@ func (service *Service) buildHTTPRequest() *http.Request {
|
|||||||
}
|
}
|
||||||
return request
|
return request
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// needsToReadBody checks if there's any conditions that requires the response body to be read
|
||||||
|
func (service *Service) needsToReadBody() bool {
|
||||||
|
for _, condition := range service.Conditions {
|
||||||
|
if condition.hasBodyPlaceholder() {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
+61
-24
@@ -5,15 +5,17 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/gatus/alerting/alert"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestService_ValidateAndSetDefaults(t *testing.T) {
|
func TestService_ValidateAndSetDefaults(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "twinnation-health",
|
||||||
URL: "https://twinnation.org/health",
|
URL: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
Alerts: []*Alert{{Type: PagerDutyAlert}},
|
Alerts: []*alert.Alert{{Type: alert.TypePagerDuty}},
|
||||||
}
|
}
|
||||||
service.ValidateAndSetDefaults()
|
service.ValidateAndSetDefaults()
|
||||||
if service.Method != "GET" {
|
if service.Method != "GET" {
|
||||||
@@ -28,7 +30,7 @@ func TestService_ValidateAndSetDefaults(t *testing.T) {
|
|||||||
if len(service.Alerts) != 1 {
|
if len(service.Alerts) != 1 {
|
||||||
t.Error("Service should've had 1 alert")
|
t.Error("Service should've had 1 alert")
|
||||||
}
|
}
|
||||||
if service.Alerts[0].Enabled {
|
if service.Alerts[0].IsEnabled() {
|
||||||
t.Error("Service alert should've defaulted to disabled")
|
t.Error("Service alert should've defaulted to disabled")
|
||||||
}
|
}
|
||||||
if service.Alerts[0].SuccessThreshold != 2 {
|
if service.Alerts[0].SuccessThreshold != 2 {
|
||||||
@@ -47,8 +49,10 @@ func TestService_ValidateAndSetDefaultsWithNoName(t *testing.T) {
|
|||||||
URL: "http://example.com",
|
URL: "http://example.com",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
}
|
}
|
||||||
service.ValidateAndSetDefaults()
|
err := service.ValidateAndSetDefaults()
|
||||||
t.Fatal("Should've panicked because service didn't have a name, which is a mandatory field")
|
if err == nil {
|
||||||
|
t.Fatal("Should've returned an error because service didn't have a name, which is a mandatory field")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestService_ValidateAndSetDefaultsWithNoUrl(t *testing.T) {
|
func TestService_ValidateAndSetDefaultsWithNoUrl(t *testing.T) {
|
||||||
@@ -59,8 +63,10 @@ func TestService_ValidateAndSetDefaultsWithNoUrl(t *testing.T) {
|
|||||||
URL: "",
|
URL: "",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
}
|
}
|
||||||
service.ValidateAndSetDefaults()
|
err := service.ValidateAndSetDefaults()
|
||||||
t.Fatal("Should've panicked because service didn't have an url, which is a mandatory field")
|
if err == nil {
|
||||||
|
t.Fatal("Should've returned an error because service didn't have an url, which is a mandatory field")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestService_ValidateAndSetDefaultsWithNoConditions(t *testing.T) {
|
func TestService_ValidateAndSetDefaultsWithNoConditions(t *testing.T) {
|
||||||
@@ -70,8 +76,10 @@ func TestService_ValidateAndSetDefaultsWithNoConditions(t *testing.T) {
|
|||||||
URL: "http://example.com",
|
URL: "http://example.com",
|
||||||
Conditions: nil,
|
Conditions: nil,
|
||||||
}
|
}
|
||||||
service.ValidateAndSetDefaults()
|
err := service.ValidateAndSetDefaults()
|
||||||
t.Fatal("Should've panicked because service didn't have at least 1 condition")
|
if err == nil {
|
||||||
|
t.Fatal("Should've returned an error because service didn't have at least 1 condition")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestService_ValidateAndSetDefaultsWithDNS(t *testing.T) {
|
func TestService_ValidateAndSetDefaultsWithDNS(t *testing.T) {
|
||||||
@@ -85,7 +93,10 @@ func TestService_ValidateAndSetDefaultsWithDNS(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Conditions: []*Condition{&conditionSuccess},
|
Conditions: []*Condition{&conditionSuccess},
|
||||||
}
|
}
|
||||||
service.ValidateAndSetDefaults()
|
err := service.ValidateAndSetDefaults()
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
if service.DNS.QueryName != "example.com." {
|
if service.DNS.QueryName != "example.com." {
|
||||||
t.Error("Service.dns.query-name should be formatted with . suffix")
|
t.Error("Service.dns.query-name should be formatted with . suffix")
|
||||||
}
|
}
|
||||||
@@ -93,11 +104,12 @@ func TestService_ValidateAndSetDefaultsWithDNS(t *testing.T) {
|
|||||||
|
|
||||||
func TestService_GetAlertsTriggered(t *testing.T) {
|
func TestService_GetAlertsTriggered(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
|
enabled := true
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "twinnation-health",
|
||||||
URL: "https://twinnation.org/health",
|
URL: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
Alerts: []*Alert{{Type: PagerDutyAlert, Enabled: true}},
|
Alerts: []*alert.Alert{{Type: alert.TypePagerDuty, Enabled: &enabled}},
|
||||||
}
|
}
|
||||||
service.ValidateAndSetDefaults()
|
service.ValidateAndSetDefaults()
|
||||||
if service.NumberOfFailuresInARow != 0 {
|
if service.NumberOfFailuresInARow != 0 {
|
||||||
@@ -118,7 +130,7 @@ func TestService_GetAlertsTriggered(t *testing.T) {
|
|||||||
func TestService_buildHTTPRequest(t *testing.T) {
|
func TestService_buildHTTPRequest(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "twinnation-health",
|
||||||
URL: "https://twinnation.org/health",
|
URL: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
}
|
}
|
||||||
@@ -138,7 +150,7 @@ func TestService_buildHTTPRequest(t *testing.T) {
|
|||||||
func TestService_buildHTTPRequestWithCustomUserAgent(t *testing.T) {
|
func TestService_buildHTTPRequestWithCustomUserAgent(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "twinnation-health",
|
||||||
URL: "https://twinnation.org/health",
|
URL: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
Headers: map[string]string{
|
Headers: map[string]string{
|
||||||
@@ -161,7 +173,7 @@ func TestService_buildHTTPRequestWithCustomUserAgent(t *testing.T) {
|
|||||||
func TestService_buildHTTPRequestWithHostHeader(t *testing.T) {
|
func TestService_buildHTTPRequestWithHostHeader(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "twinnation-health",
|
||||||
URL: "https://twinnation.org/health",
|
URL: "https://twinnation.org/health",
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
@@ -182,13 +194,13 @@ func TestService_buildHTTPRequestWithHostHeader(t *testing.T) {
|
|||||||
func TestService_buildHTTPRequestWithGraphQLEnabled(t *testing.T) {
|
func TestService_buildHTTPRequestWithGraphQLEnabled(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "twinnation-graphql",
|
||||||
URL: "https://twinnation.org/graphql",
|
URL: "https://twinnation.org/graphql",
|
||||||
Method: "POST",
|
Method: "POST",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
GraphQL: true,
|
GraphQL: true,
|
||||||
Body: `{
|
Body: `{
|
||||||
user(gender: "female") {
|
users(gender: "female") {
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
gender
|
gender
|
||||||
@@ -206,16 +218,17 @@ func TestService_buildHTTPRequestWithGraphQLEnabled(t *testing.T) {
|
|||||||
}
|
}
|
||||||
body, _ := ioutil.ReadAll(request.Body)
|
body, _ := ioutil.ReadAll(request.Body)
|
||||||
if !strings.HasPrefix(string(body), "{\"query\":") {
|
if !strings.HasPrefix(string(body), "{\"query\":") {
|
||||||
t.Error("request.Body should've started with '{\"query\":', but it didn't:", string(body))
|
t.Error("request.body should've started with '{\"query\":', but it didn't:", string(body))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestIntegrationEvaluateHealth(t *testing.T) {
|
func TestIntegrationEvaluateHealth(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 200")
|
condition := Condition("[STATUS] == 200")
|
||||||
|
bodyCondition := Condition("[BODY].status == UP")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "twinnation-health",
|
||||||
URL: "https://twinnation.org/health",
|
URL: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition, &bodyCondition},
|
||||||
}
|
}
|
||||||
result := service.EvaluateHealth()
|
result := service.EvaluateHealth()
|
||||||
if !result.ConditionResults[0].Success {
|
if !result.ConditionResults[0].Success {
|
||||||
@@ -232,7 +245,7 @@ func TestIntegrationEvaluateHealth(t *testing.T) {
|
|||||||
func TestIntegrationEvaluateHealthWithFailure(t *testing.T) {
|
func TestIntegrationEvaluateHealthWithFailure(t *testing.T) {
|
||||||
condition := Condition("[STATUS] == 500")
|
condition := Condition("[STATUS] == 500")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "twinnation-health",
|
||||||
URL: "https://twinnation.org/health",
|
URL: "https://twinnation.org/health",
|
||||||
Conditions: []*Condition{&condition},
|
Conditions: []*Condition{&condition},
|
||||||
}
|
}
|
||||||
@@ -252,7 +265,7 @@ func TestIntegrationEvaluateHealthForDNS(t *testing.T) {
|
|||||||
conditionSuccess := Condition("[DNS_RCODE] == NOERROR")
|
conditionSuccess := Condition("[DNS_RCODE] == NOERROR")
|
||||||
conditionBody := Condition("[BODY] == 93.184.216.34")
|
conditionBody := Condition("[BODY] == 93.184.216.34")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "TwiNNatioN",
|
Name: "example",
|
||||||
URL: "8.8.8.8",
|
URL: "8.8.8.8",
|
||||||
DNS: &DNS{
|
DNS: &DNS{
|
||||||
QueryType: "A",
|
QueryType: "A",
|
||||||
@@ -275,7 +288,7 @@ func TestIntegrationEvaluateHealthForDNS(t *testing.T) {
|
|||||||
func TestIntegrationEvaluateHealthForICMP(t *testing.T) {
|
func TestIntegrationEvaluateHealthForICMP(t *testing.T) {
|
||||||
conditionSuccess := Condition("[CONNECTED] == true")
|
conditionSuccess := Condition("[CONNECTED] == true")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "ICMP test",
|
Name: "icmp-test",
|
||||||
URL: "icmp://127.0.0.1",
|
URL: "icmp://127.0.0.1",
|
||||||
Conditions: []*Condition{&conditionSuccess},
|
Conditions: []*Condition{&conditionSuccess},
|
||||||
}
|
}
|
||||||
@@ -294,7 +307,7 @@ func TestIntegrationEvaluateHealthForICMP(t *testing.T) {
|
|||||||
func TestService_getIP(t *testing.T) {
|
func TestService_getIP(t *testing.T) {
|
||||||
conditionSuccess := Condition("[CONNECTED] == true")
|
conditionSuccess := Condition("[CONNECTED] == true")
|
||||||
service := Service{
|
service := Service{
|
||||||
Name: "Invalid URL test",
|
Name: "invalid-url-test",
|
||||||
URL: "",
|
URL: "",
|
||||||
Conditions: []*Condition{&conditionSuccess},
|
Conditions: []*Condition{&conditionSuccess},
|
||||||
}
|
}
|
||||||
@@ -304,3 +317,27 @@ func TestService_getIP(t *testing.T) {
|
|||||||
t.Error("service.getIP(result) should've thrown an error because the URL is invalid, thus cannot be parsed")
|
t.Error("service.getIP(result) should've thrown an error because the URL is invalid, thus cannot be parsed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestService_NeedsToReadBody(t *testing.T) {
|
||||||
|
statusCondition := Condition("[STATUS] == 200")
|
||||||
|
bodyCondition := Condition("[BODY].status == UP")
|
||||||
|
bodyConditionWithLength := Condition("len([BODY].tags) > 0")
|
||||||
|
if (&Service{Conditions: []*Condition{&statusCondition}}).needsToReadBody() {
|
||||||
|
t.Error("expected false, got true")
|
||||||
|
}
|
||||||
|
if !(&Service{Conditions: []*Condition{&bodyCondition}}).needsToReadBody() {
|
||||||
|
t.Error("expected true, got false")
|
||||||
|
}
|
||||||
|
if !(&Service{Conditions: []*Condition{&bodyConditionWithLength}}).needsToReadBody() {
|
||||||
|
t.Error("expected true, got false")
|
||||||
|
}
|
||||||
|
if !(&Service{Conditions: []*Condition{&statusCondition, &bodyCondition}}).needsToReadBody() {
|
||||||
|
t.Error("expected true, got false")
|
||||||
|
}
|
||||||
|
if !(&Service{Conditions: []*Condition{&bodyCondition, &statusCondition}}).needsToReadBody() {
|
||||||
|
t.Error("expected true, got false")
|
||||||
|
}
|
||||||
|
if !(&Service{Conditions: []*Condition{&bodyConditionWithLength, &statusCondition}}).needsToReadBody() {
|
||||||
|
t.Error("expected true, got false")
|
||||||
|
}
|
||||||
|
}
|
||||||
+76
-43
@@ -6,66 +6,75 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
// RFC3339WithoutMinutesAndSeconds is the format defined by RFC3339 (see time.RFC3339) but with the minutes
|
|
||||||
// and seconds hardcoded to 0.
|
|
||||||
RFC3339WithoutMinutesAndSeconds = "2006-01-02T15:00:00Z07:00"
|
|
||||||
|
|
||||||
numberOfHoursInTenDays = 10 * 24
|
numberOfHoursInTenDays = 10 * 24
|
||||||
sevenDays = 7 * 24 * time.Hour
|
sevenDays = 7 * 24 * time.Hour
|
||||||
)
|
)
|
||||||
|
|
||||||
// Uptime is the struct that contains the relevant data for calculating the uptime as well as the uptime itself
|
// Uptime is the struct that contains the relevant data for calculating the uptime as well as the uptime itself
|
||||||
|
// and some other statistics
|
||||||
type Uptime struct {
|
type Uptime struct {
|
||||||
// LastSevenDays is the uptime percentage over the past 7 days
|
LastSevenDays float64 `json:"7d"` // Uptime percentage over the past 7 days
|
||||||
LastSevenDays float64 `json:"7d"`
|
LastTwentyFourHours float64 `json:"24h"` // Uptime percentage over the past 24 hours
|
||||||
|
LastHour float64 `json:"1h"` // Uptime percentage over the past hour
|
||||||
|
|
||||||
// LastTwentyFourHours is the uptime percentage over the past 24 hours
|
// SuccessfulExecutionsPerHour is a map containing the number of successes (value)
|
||||||
LastTwentyFourHours float64 `json:"24h"`
|
// for every hourly unix timestamps (key)
|
||||||
|
// Deprecated
|
||||||
|
SuccessfulExecutionsPerHour map[int64]uint64 `json:"-"`
|
||||||
|
|
||||||
// LastHour is the uptime percentage over the past hour
|
// TotalExecutionsPerHour is a map containing the total number of checks (value)
|
||||||
LastHour float64 `json:"1h"`
|
// for every hourly unix timestamps (key)
|
||||||
|
// Deprecated
|
||||||
|
TotalExecutionsPerHour map[int64]uint64 `json:"-"`
|
||||||
|
|
||||||
// SuccessCountPerHour is a map containing the number of successes per hour, per timestamp following the
|
// HourlyStatistics is a map containing metrics collected (value) for every hourly unix timestamps (key)
|
||||||
// custom RFC3339WithoutMinutesAndSeconds format
|
HourlyStatistics map[int64]*HourlyUptimeStatistics `json:"-"`
|
||||||
SuccessCountPerHour map[string]uint64 `json:"-"`
|
}
|
||||||
|
|
||||||
// TotalCountPerHour is a map containing the total number of checks per hour, per timestamp following the
|
// HourlyUptimeStatistics is a struct containing all metrics collected over the course of an hour
|
||||||
// custom RFC3339WithoutMinutesAndSeconds format
|
type HourlyUptimeStatistics struct {
|
||||||
TotalCountPerHour map[string]uint64 `json:"-"`
|
TotalExecutions uint64 // Total number of checks
|
||||||
|
SuccessfulExecutions uint64 // Number of successful executions
|
||||||
|
TotalExecutionsResponseTime uint64 // Total response time for all executions
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewUptime creates a new Uptime
|
// NewUptime creates a new Uptime
|
||||||
func NewUptime() *Uptime {
|
func NewUptime() *Uptime {
|
||||||
return &Uptime{
|
return &Uptime{
|
||||||
SuccessCountPerHour: make(map[string]uint64),
|
HourlyStatistics: make(map[int64]*HourlyUptimeStatistics),
|
||||||
TotalCountPerHour: make(map[string]uint64),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// ProcessResult processes the result by extracting the relevant from the result and recalculating the uptime
|
// ProcessResult processes the result by extracting the relevant from the result and recalculating the uptime
|
||||||
// if necessary
|
// if necessary
|
||||||
func (uptime *Uptime) ProcessResult(result *Result) {
|
func (uptime *Uptime) ProcessResult(result *Result) {
|
||||||
timestampDateWithHour := result.Timestamp.Format(RFC3339WithoutMinutesAndSeconds)
|
// XXX: Remove this on v3.0.0
|
||||||
if result.Success {
|
if len(uptime.SuccessfulExecutionsPerHour) != 0 || len(uptime.TotalExecutionsPerHour) != 0 {
|
||||||
uptime.SuccessCountPerHour[timestampDateWithHour]++
|
uptime.migrateToHourlyStatistics()
|
||||||
}
|
}
|
||||||
uptime.TotalCountPerHour[timestampDateWithHour]++
|
if uptime.HourlyStatistics == nil {
|
||||||
|
uptime.HourlyStatistics = make(map[int64]*HourlyUptimeStatistics)
|
||||||
|
}
|
||||||
|
unixTimestampFlooredAtHour := result.Timestamp.Unix() - (result.Timestamp.Unix() % 3600)
|
||||||
|
hourlyStats, _ := uptime.HourlyStatistics[unixTimestampFlooredAtHour]
|
||||||
|
if hourlyStats == nil {
|
||||||
|
hourlyStats = &HourlyUptimeStatistics{}
|
||||||
|
uptime.HourlyStatistics[unixTimestampFlooredAtHour] = hourlyStats
|
||||||
|
}
|
||||||
|
if result.Success {
|
||||||
|
hourlyStats.SuccessfulExecutions++
|
||||||
|
}
|
||||||
|
hourlyStats.TotalExecutions++
|
||||||
|
hourlyStats.TotalExecutionsResponseTime += uint64(result.Duration.Milliseconds())
|
||||||
// Clean up only when we're starting to have too many useless keys
|
// Clean up only when we're starting to have too many useless keys
|
||||||
// Note that this is only triggered when there are more entries than there should be after
|
// Note that this is only triggered when there are more entries than there should be after
|
||||||
// 10 days, despite the fact that we are deleting everything that's older than 7 days.
|
// 10 days, despite the fact that we are deleting everything that's older than 7 days.
|
||||||
// This is to prevent re-iterating on every `ProcessResult` as soon as the uptime has been logged for 7 days.
|
// This is to prevent re-iterating on every `ProcessResult` as soon as the uptime has been logged for 7 days.
|
||||||
if len(uptime.TotalCountPerHour) > numberOfHoursInTenDays {
|
if len(uptime.HourlyStatistics) > numberOfHoursInTenDays {
|
||||||
sevenDaysAgo := time.Now().Add(-(sevenDays + time.Hour))
|
sevenDaysAgo := time.Now().Add(-(sevenDays + time.Hour)).Unix()
|
||||||
for k := range uptime.TotalCountPerHour {
|
for hourlyUnixTimestamp := range uptime.HourlyStatistics {
|
||||||
dateWithHour, err := time.Parse(time.RFC3339, k)
|
if sevenDaysAgo > hourlyUnixTimestamp {
|
||||||
if err != nil {
|
delete(uptime.HourlyStatistics, hourlyUnixTimestamp)
|
||||||
// This shouldn't happen, but we'll log it in case it does happen
|
|
||||||
log.Println("[uptime][ProcessResult] Failed to parse programmatically generated timestamp:", err.Error())
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
if sevenDaysAgo.Unix() > dateWithHour.Unix() {
|
|
||||||
delete(uptime.TotalCountPerHour, k)
|
|
||||||
delete(uptime.SuccessCountPerHour, k)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -92,18 +101,21 @@ func (uptime *Uptime) recalculate() {
|
|||||||
// The oldest uptime bracket starts 7 days ago, so we'll start from there
|
// The oldest uptime bracket starts 7 days ago, so we'll start from there
|
||||||
timestamp := now.Add(-sevenDays)
|
timestamp := now.Add(-sevenDays)
|
||||||
for now.Sub(timestamp) >= 0 {
|
for now.Sub(timestamp) >= 0 {
|
||||||
timestampDateWithHour := timestamp.Format(RFC3339WithoutMinutesAndSeconds)
|
hourlyUnixTimestamp := timestamp.Unix() - (timestamp.Unix() % 3600)
|
||||||
successCountForTimestamp := uptime.SuccessCountPerHour[timestampDateWithHour]
|
hourlyStats := uptime.HourlyStatistics[hourlyUnixTimestamp]
|
||||||
totalCountForTimestamp := uptime.TotalCountPerHour[timestampDateWithHour]
|
if hourlyStats == nil || hourlyStats.TotalExecutions == 0 {
|
||||||
uptimeBrackets["7d_success"] += successCountForTimestamp
|
timestamp = timestamp.Add(time.Hour)
|
||||||
uptimeBrackets["7d_total"] += totalCountForTimestamp
|
continue
|
||||||
|
}
|
||||||
|
uptimeBrackets["7d_success"] += hourlyStats.SuccessfulExecutions
|
||||||
|
uptimeBrackets["7d_total"] += hourlyStats.TotalExecutions
|
||||||
if now.Sub(timestamp) <= 24*time.Hour {
|
if now.Sub(timestamp) <= 24*time.Hour {
|
||||||
uptimeBrackets["24h_success"] += successCountForTimestamp
|
uptimeBrackets["24h_success"] += hourlyStats.SuccessfulExecutions
|
||||||
uptimeBrackets["24h_total"] += totalCountForTimestamp
|
uptimeBrackets["24h_total"] += hourlyStats.TotalExecutions
|
||||||
}
|
}
|
||||||
if now.Sub(timestamp) <= time.Hour {
|
if now.Sub(timestamp) <= time.Hour {
|
||||||
uptimeBrackets["1h_success"] += successCountForTimestamp
|
uptimeBrackets["1h_success"] += hourlyStats.SuccessfulExecutions
|
||||||
uptimeBrackets["1h_total"] += totalCountForTimestamp
|
uptimeBrackets["1h_total"] += hourlyStats.TotalExecutions
|
||||||
}
|
}
|
||||||
timestamp = timestamp.Add(time.Hour)
|
timestamp = timestamp.Add(time.Hour)
|
||||||
}
|
}
|
||||||
@@ -117,3 +129,24 @@ func (uptime *Uptime) recalculate() {
|
|||||||
uptime.LastHour = float64(uptimeBrackets["1h_success"]) / float64(uptimeBrackets["1h_total"])
|
uptime.LastHour = float64(uptimeBrackets["1h_success"]) / float64(uptimeBrackets["1h_total"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// XXX: Remove this on v3.0.0
|
||||||
|
// Deprecated
|
||||||
|
func (uptime *Uptime) migrateToHourlyStatistics() {
|
||||||
|
log.Println("[migrateToHourlyStatistics] Got", len(uptime.SuccessfulExecutionsPerHour), "entries for successful executions and", len(uptime.TotalExecutionsPerHour), "entries for total executions")
|
||||||
|
uptime.HourlyStatistics = make(map[int64]*HourlyUptimeStatistics)
|
||||||
|
for hourlyUnixTimestamp, totalExecutions := range uptime.TotalExecutionsPerHour {
|
||||||
|
if totalExecutions == 0 {
|
||||||
|
log.Println("[migrateToHourlyStatistics] Skipping entry at", hourlyUnixTimestamp, "because total number of executions is 0")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
uptime.HourlyStatistics[hourlyUnixTimestamp] = &HourlyUptimeStatistics{
|
||||||
|
TotalExecutions: totalExecutions,
|
||||||
|
SuccessfulExecutions: uptime.SuccessfulExecutionsPerHour[hourlyUnixTimestamp],
|
||||||
|
TotalExecutionsResponseTime: 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.Println("[migrateToHourlyStatistics] Migrated", len(uptime.HourlyStatistics), "entries")
|
||||||
|
uptime.SuccessfulExecutionsPerHour = nil
|
||||||
|
uptime.TotalExecutionsPerHour = nil
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
package core
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func BenchmarkUptime_ProcessResult(b *testing.B) {
|
||||||
|
uptime := NewUptime()
|
||||||
|
now := time.Now()
|
||||||
|
now = time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location())
|
||||||
|
// Start 12000 days ago
|
||||||
|
timestamp := now.Add(-12000 * 24 * time.Hour)
|
||||||
|
for n := 0; n < b.N; n++ {
|
||||||
|
uptime.ProcessResult(&Result{
|
||||||
|
Duration: 18 * time.Millisecond,
|
||||||
|
Success: n%15 == 0,
|
||||||
|
Timestamp: timestamp,
|
||||||
|
})
|
||||||
|
// Simulate service with an interval of 3 minutes
|
||||||
|
timestamp = timestamp.Add(3 * time.Minute)
|
||||||
|
}
|
||||||
|
b.ReportAllocs()
|
||||||
|
}
|
||||||
+38
-21
@@ -12,33 +12,39 @@ func TestUptime_ProcessResult(t *testing.T) {
|
|||||||
|
|
||||||
checkUptimes(t, serviceStatus, 0.00, 0.00, 0.00)
|
checkUptimes(t, serviceStatus, 0.00, 0.00, 0.00)
|
||||||
|
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-7 * 24 * time.Hour), Success: true})
|
now := time.Now()
|
||||||
|
now = time.Date(now.Year(), now.Month(), now.Day(), now.Hour(), 0, 0, 0, now.Location())
|
||||||
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-7 * 24 * time.Hour), Success: true})
|
||||||
checkUptimes(t, serviceStatus, 1.00, 0.00, 0.00)
|
checkUptimes(t, serviceStatus, 1.00, 0.00, 0.00)
|
||||||
|
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-6 * 24 * time.Hour), Success: false})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-6 * 24 * time.Hour), Success: false})
|
||||||
checkUptimes(t, serviceStatus, 0.50, 0.00, 0.00)
|
checkUptimes(t, serviceStatus, 0.50, 0.00, 0.00)
|
||||||
|
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-8 * 24 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-8 * 24 * time.Hour), Success: true})
|
||||||
checkUptimes(t, serviceStatus, 0.50, 0.00, 0.00)
|
checkUptimes(t, serviceStatus, 0.50, 0.00, 0.00)
|
||||||
|
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-24 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-24 * time.Hour), Success: true})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-12 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-12 * time.Hour), Success: true})
|
||||||
checkUptimes(t, serviceStatus, 0.75, 1.00, 0.00)
|
checkUptimes(t, serviceStatus, 0.75, 1.00, 0.00)
|
||||||
|
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-1 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-1 * time.Hour), Success: true, Duration: 10 * time.Millisecond})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-30 * time.Minute), Success: false})
|
checkHourlyStatistics(t, uptime.HourlyStatistics[now.Unix()-now.Unix()%3600-3600], 10, 1, 1)
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-15 * time.Minute), Success: false})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-30 * time.Minute), Success: false, Duration: 500 * time.Millisecond})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-10 * time.Minute), Success: false})
|
checkHourlyStatistics(t, uptime.HourlyStatistics[now.Unix()-now.Unix()%3600-3600], 510, 2, 1)
|
||||||
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-15 * time.Minute), Success: false, Duration: 25 * time.Millisecond})
|
||||||
|
checkHourlyStatistics(t, uptime.HourlyStatistics[now.Unix()-now.Unix()%3600-3600], 535, 3, 1)
|
||||||
|
|
||||||
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-10 * time.Minute), Success: false})
|
||||||
checkUptimes(t, serviceStatus, 0.50, 0.50, 0.25)
|
checkUptimes(t, serviceStatus, 0.50, 0.50, 0.25)
|
||||||
|
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-120 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-120 * time.Hour), Success: true})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-119 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-119 * time.Hour), Success: true})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-118 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-118 * time.Hour), Success: true})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-117 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-117 * time.Hour), Success: true})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-10 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-10 * time.Hour), Success: true})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-8 * time.Hour), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-8 * time.Hour), Success: true})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-30 * time.Minute), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-30 * time.Minute), Success: true})
|
||||||
uptime.ProcessResult(&Result{Timestamp: time.Now().Add(-25 * time.Minute), Success: true})
|
uptime.ProcessResult(&Result{Timestamp: now.Add(-25 * time.Minute), Success: true})
|
||||||
checkUptimes(t, serviceStatus, 0.75, 0.70, 0.50)
|
checkUptimes(t, serviceStatus, 0.75, 0.70, 0.50)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -51,17 +57,16 @@ func TestServiceStatus_AddResultUptimeIsCleaningUpAfterItself(t *testing.T) {
|
|||||||
timestamp := now.Add(-12 * 24 * time.Hour)
|
timestamp := now.Add(-12 * 24 * time.Hour)
|
||||||
for timestamp.Unix() <= now.Unix() {
|
for timestamp.Unix() <= now.Unix() {
|
||||||
serviceStatus.AddResult(&Result{Timestamp: timestamp, Success: true})
|
serviceStatus.AddResult(&Result{Timestamp: timestamp, Success: true})
|
||||||
if len(serviceStatus.Uptime.SuccessCountPerHour) > numberOfHoursInTenDays {
|
if len(serviceStatus.Uptime.HourlyStatistics) > numberOfHoursInTenDays {
|
||||||
t.Errorf("At no point in time should there be more than %d entries in serviceStatus.SuccessCountPerHour", numberOfHoursInTenDays)
|
t.Errorf("At no point in time should there be more than %d entries in serviceStatus.SuccessfulExecutionsPerHour, but there are %d", numberOfHoursInTenDays, len(serviceStatus.Uptime.HourlyStatistics))
|
||||||
}
|
}
|
||||||
//fmt.Printf("timestamp=%s; uptimeDuringLastHour=%f; timeAgo=%s\n", timestamp.Format(time.RFC3339), serviceStatus.UptimeDuringLastHour, time.Since(timestamp))
|
|
||||||
if now.Sub(timestamp) > time.Hour && serviceStatus.Uptime.LastHour != 0 {
|
if now.Sub(timestamp) > time.Hour && serviceStatus.Uptime.LastHour != 0 {
|
||||||
t.Error("most recent timestamp > 1h ago, expected serviceStatus.Uptime.LastHour to be 0, got", serviceStatus.Uptime.LastHour)
|
t.Error("most recent timestamp > 1h ago, expected serviceStatus.Uptime.LastHour to be 0, got", serviceStatus.Uptime.LastHour)
|
||||||
}
|
}
|
||||||
if now.Sub(timestamp) < time.Hour && serviceStatus.Uptime.LastHour == 0 {
|
if now.Sub(timestamp) < time.Hour && serviceStatus.Uptime.LastHour == 0 {
|
||||||
t.Error("most recent timestamp < 1h ago, expected serviceStatus.Uptime.LastHour to NOT be 0, got", serviceStatus.Uptime.LastHour)
|
t.Error("most recent timestamp < 1h ago, expected serviceStatus.Uptime.LastHour to NOT be 0, got", serviceStatus.Uptime.LastHour)
|
||||||
}
|
}
|
||||||
// Simulate service with an interval of 1 minute
|
// Simulate service with an interval of 3 minutes
|
||||||
timestamp = timestamp.Add(3 * time.Minute)
|
timestamp = timestamp.Add(3 * time.Minute)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,3 +82,15 @@ func checkUptimes(t *testing.T, status *ServiceStatus, expectedUptimeDuringLastS
|
|||||||
t.Errorf("expected status.Uptime.LastHour to be %f, got %f", expectedUptimeDuringLastHour, status.Uptime.LastHour)
|
t.Errorf("expected status.Uptime.LastHour to be %f, got %f", expectedUptimeDuringLastHour, status.Uptime.LastHour)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func checkHourlyStatistics(t *testing.T, hourlyUptimeStatistics *HourlyUptimeStatistics, expectedTotalExecutionsResponseTime uint64, expectedTotalExecutions uint64, expectedSuccessfulExecutions uint64) {
|
||||||
|
if hourlyUptimeStatistics.TotalExecutionsResponseTime != expectedTotalExecutionsResponseTime {
|
||||||
|
t.Error("TotalExecutionsResponseTime should've been", expectedTotalExecutionsResponseTime, "got", hourlyUptimeStatistics.TotalExecutionsResponseTime)
|
||||||
|
}
|
||||||
|
if hourlyUptimeStatistics.TotalExecutions != expectedTotalExecutions {
|
||||||
|
t.Error("TotalExecutions should've been", expectedTotalExecutions, "got", hourlyUptimeStatistics.TotalExecutions)
|
||||||
|
}
|
||||||
|
if hourlyUptimeStatistics.SuccessfulExecutions != expectedSuccessfulExecutions {
|
||||||
|
t.Error("SuccessfulExecutions should've been", expectedSuccessfulExecutions, "got", hourlyUptimeStatistics.SuccessfulExecutions)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -81,11 +81,11 @@ spec:
|
|||||||
protocol: TCP
|
protocol: TCP
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 200m
|
cpu: 250m
|
||||||
memory: 50M
|
memory: 100M
|
||||||
requests:
|
requests:
|
||||||
cpu: 50m
|
cpu: 50m
|
||||||
memory: 20M
|
memory: 30M
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- mountPath: /config
|
- mountPath: /config
|
||||||
name: gatus-config
|
name: gatus-config
|
||||||
|
|||||||
@@ -59,11 +59,11 @@ spec:
|
|||||||
protocol: TCP
|
protocol: TCP
|
||||||
resources:
|
resources:
|
||||||
limits:
|
limits:
|
||||||
cpu: 200m
|
cpu: 250m
|
||||||
memory: 50M
|
memory: 100M
|
||||||
requests:
|
requests:
|
||||||
cpu: 50m
|
cpu: 50m
|
||||||
memory: 20M
|
memory: 30M
|
||||||
volumeMounts:
|
volumeMounts:
|
||||||
- mountPath: /config
|
- mountPath: /config
|
||||||
name: gatus-config
|
name: gatus-config
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
module github.com/TwinProduction/gatus
|
module github.com/TwinProduction/gatus
|
||||||
|
|
||||||
go 1.15
|
go 1.16
|
||||||
|
|
||||||
require (
|
require (
|
||||||
cloud.google.com/go v0.74.0 // indirect
|
cloud.google.com/go v0.74.0 // indirect
|
||||||
github.com/TwinProduction/gocache v1.2.0
|
github.com/TwinProduction/gocache v1.2.1
|
||||||
|
github.com/TwinProduction/health v1.0.0
|
||||||
github.com/go-ping/ping v0.0.0-20201115131931-3300c582a663
|
github.com/go-ping/ping v0.0.0-20201115131931-3300c582a663
|
||||||
github.com/google/gofuzz v1.2.0 // indirect
|
github.com/google/gofuzz v1.2.0 // indirect
|
||||||
github.com/gorilla/mux v1.8.0
|
github.com/gorilla/mux v1.8.0
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
cloud.google.com/go v0.34.0 h1:eOI3/cP2VTU6uZLDYAoic+eyzzB9YyGmJ7eIjl8rOPg=
|
|
||||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||||
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
cloud.google.com/go v0.38.0/go.mod h1:990N+gfupTy94rShfmMCWGDn0LpTmnzTp2qbd1dvSRU=
|
||||||
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
|
cloud.google.com/go v0.44.1/go.mod h1:iSa0KzasP4Uvy3f1mN/7PiObzGgflwredwwASm/v6AU=
|
||||||
@@ -50,8 +49,10 @@ github.com/PuerkitoBio/purell v1.0.0/go.mod h1:c11w/QuzBsJSee3cPx9rAFu61PvFxuPbt
|
|||||||
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
|
||||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||||
github.com/TwinProduction/gocache v1.2.0 h1:iZBUuri5VydxYhNkWEOZm/JzX/X2b3OZzfLrPaRWKjk=
|
github.com/TwinProduction/gocache v1.2.1 h1:NAdMwO9SQEZFmX69YWx6fzhwb6fHakkLri0451c+V1w=
|
||||||
github.com/TwinProduction/gocache v1.2.0/go.mod h1:+qH57V/K4oAcX9C7CvgJTwUX4lzfIUXQC/6XaRSOS1Y=
|
github.com/TwinProduction/gocache v1.2.1/go.mod h1:6zkBoLjrFLkIISwkZTgLy67qliCGSon1xpORM4Ri5HM=
|
||||||
|
github.com/TwinProduction/health v1.0.0 h1:TVyYTAORQQZ8LaptX8jCHZRCGCAO6e+oJx19BUIzQYY=
|
||||||
|
github.com/TwinProduction/health v1.0.0/go.mod h1:ys4mYKUeEfYrWmkm60xLtPjTuLIEDQNBZaTZvenLG1c=
|
||||||
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
github.com/VividCortex/gohistogram v1.0.0/go.mod h1:Pf5mBqqDxYaXu3hDrrU+w6nw50o/4+TcAqDqk/vUH7g=
|
||||||
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
github.com/afex/hystrix-go v0.0.0-20180502004556-fa1af6a1f4f5/go.mod h1:SkGFH1ia65gfNATL8TAiHDNxPzPdmEL5uirI2Uyuz6c=
|
||||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||||
@@ -73,8 +74,6 @@ github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+Ce
|
|||||||
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
|
||||||
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
|
||||||
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
|
||||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
|
||||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
|
||||||
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
github.com/casbin/casbin/v2 v2.1.2/go.mod h1:YcPU1XXisHhLzuxH9coDNf2FbKpjGlbCg3n9yuLkIJQ=
|
||||||
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
github.com/cenkalti/backoff v2.2.1+incompatible/go.mod h1:90ReRw6GdpyfrHakVjL/QHaoyV4aDUVVkXQJJJ3NXXM=
|
||||||
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
|
||||||
@@ -142,7 +141,6 @@ github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/me
|
|||||||
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
github.com/gogo/googleapis v1.1.0/go.mod h1:gf4bu3Q80BeJ6H1S1vYPm8/ELATdvryBaNFGgqEef3s=
|
||||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||||
github.com/gogo/protobuf v1.2.1 h1:/s5zKNz0uPFCZ5hddgPdo2TK2TVrUNMn0OOX8/aZMTE=
|
|
||||||
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
github.com/gogo/protobuf v1.2.1/go.mod h1:hp+jE20tsWTFYpLwKvXlhS1hjn+gTNwPg2I6zVXpSg4=
|
||||||
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
github.com/gogo/protobuf v1.3.1 h1:DqDEcV5aeaTmdFBePNpYsp3FlcVH/2ISVVM9Qf8PSls=
|
||||||
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o=
|
||||||
@@ -161,7 +159,6 @@ github.com/golang/mock v1.4.4/go.mod h1:l3mdAwkq5BuhzHwde/uurv3sEJeZMXNpwsxVWU71
|
|||||||
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v0.0.0-20161109072736-4bd1920723d7/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.3.1/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
|
|
||||||
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||||
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||||
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
github.com/golang/protobuf v1.3.4/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
|
||||||
@@ -172,7 +169,6 @@ github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrU
|
|||||||
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w=
|
||||||
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0=
|
||||||
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8=
|
||||||
github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0=
|
|
||||||
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM=
|
||||||
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI=
|
||||||
@@ -184,13 +180,11 @@ github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMyw
|
|||||||
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
|
||||||
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.4.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w=
|
|
||||||
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.1/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
github.com/google/go-cmp v0.5.4 h1:L8R9j+yAqZuZjsqh/z+F1NCffTKKLShY6zXTItVIZ8M=
|
||||||
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
|
||||||
github.com/google/gofuzz v1.0.0 h1:A8PeW59pxE9IoFRqBp37U+mSNaQoZ46F1f0f863XSXw=
|
|
||||||
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
github.com/google/gofuzz v1.1.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
|
||||||
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
|
||||||
@@ -220,7 +214,6 @@ github.com/gophercloud/gophercloud v0.1.0/go.mod h1:vxM41WHh5uqHVBMZHzuwNOHh8XEo
|
|||||||
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
github.com/gopherjs/gopherjs v0.0.0-20181017120253-0766667cb4d1/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
|
||||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||||
github.com/gorilla/mux v1.7.3 h1:gnP5JzjVOuiZD07fKKToCAOjS0yOpj/qPETTXCCS6hw=
|
|
||||||
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||||
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
|
||||||
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
|
||||||
@@ -362,21 +355,18 @@ github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXP
|
|||||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||||
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
|
||||||
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
|
github.com/prometheus/client_golang v1.3.0/go.mod h1:hJaj2vgQTGQmVCsAACORcieXFeDPbaTKGT+JTgUa3og=
|
||||||
github.com/prometheus/client_golang v1.7.1 h1:NTGy1Ja9pByO+xAeH/qiWnLrKtr3hJPNjaVUwnjpdpA=
|
|
||||||
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
github.com/prometheus/client_golang v1.7.1/go.mod h1:PY5Wy2awLA44sXw4AOSfFBetzPP4j5+D6mVACh+pe2M=
|
||||||
github.com/prometheus/client_golang v1.9.0 h1:Rrch9mh17XcxvEu9D9DEpb4isxjGBtcevQjKvxPRQIU=
|
github.com/prometheus/client_golang v1.9.0 h1:Rrch9mh17XcxvEu9D9DEpb4isxjGBtcevQjKvxPRQIU=
|
||||||
github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU=
|
github.com/prometheus/client_golang v1.9.0/go.mod h1:FqZLKOZnGdFAhOK4nqGHa7D66IdsO+O441Eve7ptJDU=
|
||||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||||
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190129233127-fd36f4220a90/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4 h1:gQz4mCbXsO+nc9n1hCxHcGA3Zx3Eo+UHZoInFGUIXNM=
|
|
||||||
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.1.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
|
github.com/prometheus/client_model v0.2.0 h1:uq5h0d+GuxiXLJLNABMgp2qUWDPiLvgCzz2dUR+/W/M=
|
||||||
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
github.com/prometheus/client_model v0.2.0/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
|
||||||
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||||
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
github.com/prometheus/common v0.4.1/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||||
github.com/prometheus/common v0.7.0 h1:L+1lyG48J1zAQXA3RBX/nG/B3gjlHq0zTt2tlbJLyCY=
|
|
||||||
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
|
github.com/prometheus/common v0.7.0/go.mod h1:DjGbpBbp5NYNiECxcL/VnbXCCaQpKd3tt26CguLLsqA=
|
||||||
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
github.com/prometheus/common v0.10.0/go.mod h1:Tlit/dnDKsSWFlCLTWaA1cyBgKHSMdTB80sz/V91rCo=
|
||||||
github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM=
|
github.com/prometheus/common v0.15.0 h1:4fgOnadei3EZvgRwxJ7RMpG1k1pOZth5Pc13tyspaKM=
|
||||||
@@ -385,7 +375,6 @@ github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R
|
|||||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||||
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
github.com/prometheus/procfs v0.0.2/go.mod h1:TjEm7ze935MbeOT/UhFTIMYKhuLP4wbCsTZCD3I8kEA=
|
||||||
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
github.com/prometheus/procfs v0.0.8/go.mod h1:7Qr8sr6344vo1JqZ6HhLceV9o3AJ1Ff+GxbHq6oeK9A=
|
||||||
github.com/prometheus/procfs v0.1.3 h1:F0+tqvhOksq22sc6iCHF5WGlWjdwj92p0udFh1VFBS8=
|
|
||||||
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
github.com/prometheus/procfs v0.1.3/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||||
github.com/prometheus/procfs v0.2.0 h1:wH4vA7pcjKuZzjF7lM8awk4fnuJO6idemZXoKnULUx4=
|
github.com/prometheus/procfs v0.2.0 h1:wH4vA7pcjKuZzjF7lM8awk4fnuJO6idemZXoKnULUx4=
|
||||||
github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
github.com/prometheus/procfs v0.2.0/go.mod h1:lV6e/gmhEcM9IjHGsFOCxxuZ+z1YqCvr4OA4YeYWdaU=
|
||||||
@@ -407,7 +396,6 @@ github.com/sony/gobreaker v0.4.1/go.mod h1:ZKptC7FHNvhBz7dN2LGjPVBz2sZJmc0/PkyDJ
|
|||||||
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
github.com/spf13/afero v1.2.2/go.mod h1:9ZxEEn6pIJ8Rxe320qSDBk6AsU0r9pR7Q4OcevTdifk=
|
||||||
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
github.com/spf13/cobra v0.0.3/go.mod h1:1l0Ry5zgKvJasoi3XT1TypsSe7PqH0Sj9dhYf7v3XqQ=
|
||||||
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
github.com/spf13/pflag v0.0.0-20170130214245-9ff6c6923cff/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
github.com/spf13/pflag v1.0.1 h1:aCvUg6QPl3ibpQUxyLkrEkCHtPqYJL4x9AuhqVqFis4=
|
|
||||||
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
github.com/spf13/pflag v1.0.1/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
|
||||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||||
@@ -418,7 +406,6 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+
|
|||||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||||
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
|
|
||||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||||
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
github.com/stretchr/testify v1.5.1 h1:nOGnQDM7FYENwehXlg/kFVnos3rEvtKTjRvOWSzb6H4=
|
||||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||||
@@ -432,6 +419,8 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
|
|||||||
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
|
||||||
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
go.etcd.io/bbolt v1.3.3/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
|
||||||
|
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
|
||||||
|
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||||
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
go.etcd.io/etcd v0.0.0-20191023171146-3cf2f69b5738/go.mod h1:dnLIgRNXwCJa5e+c6mIZCrds/GIG4ncV9HhK5PX7jPg=
|
||||||
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
go.opencensus.io v0.20.1/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||||
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
go.opencensus.io v0.20.2/go.mod h1:6WKK9ahsWS3RSO+PY9ZHZUfv2irvY6gN279GOPZjmmk=
|
||||||
@@ -457,7 +446,6 @@ golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8U
|
|||||||
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||||
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9 h1:psW17arqaxU48Z5kZ0CQnkZWQJsqcURM6tKiBApRjXI=
|
|
||||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY=
|
||||||
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I=
|
||||||
@@ -479,7 +467,6 @@ golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTk
|
|||||||
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190909230951-414d861bb4ac/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de h1:5hukYrvBGR8/eNkX5mdUezrA6JiaEZDtJb9Ei+1LlBs=
|
|
||||||
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
golang.org/x/lint v0.0.0-20190930215403-16217165b5de/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
|
||||||
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
golang.org/x/lint v0.0.0-20191125180803-fdd1cda4f05f/go.mod h1:5qLYkcX4OjUUV8bRuDixDT3tpyyb+LUpUlRWLxfhWrs=
|
||||||
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
golang.org/x/lint v0.0.0-20200130185559-910be7a94367/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
|
||||||
@@ -529,7 +516,6 @@ golang.org/x/net v0.0.0-20200506145744-7e3656a0809f/go.mod h1:qpuaurCH72eLCgpAm/
|
|||||||
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200513185701-a91f0712d120/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
golang.org/x/net v0.0.0-20200520182314-0ba52f642ac2/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A=
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344 h1:vGXIOMxbNfDTk/aXCmfdLgkrSV+Z2tcbze+pEc3v5W4=
|
|
||||||
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200625001655-4c5254603344/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200707034311-ab3426394381/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||||
@@ -540,7 +526,6 @@ golang.org/x/net v0.0.0-20201209123823-ac852fbbde11/go.mod h1:m0MpNAwzfU5UDzcl9v
|
|||||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
|
golang.org/x/net v0.0.0-20201224014010-6772e930b67b h1:iFwSg7t5GZmB/Q5TjiEAsdoLDrdJRC1RiF2WhuV29Qw=
|
||||||
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
golang.org/x/net v0.0.0-20201224014010-6772e930b67b/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
|
||||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421 h1:Wo7BWFiOk0QRFMLYMqJGFMd9CgUAcGx7V+qEg/h5IBI=
|
|
||||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
golang.org/x/oauth2 v0.0.0-20191202225959-858c2ad4c8b6/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||||
@@ -554,7 +539,6 @@ golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJ
|
|||||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e h1:vcxGaoTs7kV8m5Np9uUNQin4BrLOthgV7252N8V+FwY=
|
|
||||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20200317015054-43a5402ce75a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
@@ -608,7 +592,6 @@ golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200803210538-64077c9b5642/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200905004654-be1d3432aa8f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f h1:+Nyd8tzPX9R7BWHguqsrbFdRx3WQ/1ib8I44HXV5yTA=
|
|
||||||
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201201145000-ef89a241ccb3/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
@@ -616,7 +599,6 @@ golang.org/x/sys v0.0.0-20201214210602-f9fddec55a1e/go.mod h1:h1NjWce9XRLGQEsW7w
|
|||||||
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 h1:vRgIt+nup/B/BwIS0g2oC0haq0iqbV3ZA+u6+0TlNCo=
|
golang.org/x/sys v0.0.0-20201223074533-0d417f636930 h1:vRgIt+nup/B/BwIS0g2oC0haq0iqbV3ZA+u6+0TlNCo=
|
||||||
golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20201223074533-0d417f636930/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1 h1:v+OssWQX+hTHEmOBgwxdZxK4zHq3yOs8F9J7mk0PY8E=
|
|
||||||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
|
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf h1:MZ2shdL+ZM/XzY3ZGOnh4Nlpnxz5GSOhOmtHo3iPU6M=
|
||||||
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
golang.org/x/term v0.0.0-20201210144234-2321bbc49cbf/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
|
||||||
@@ -624,7 +606,6 @@ golang.org/x/text v0.0.0-20160726164857-2910a502d2bf/go.mod h1:NqM8EUOU14njkJ3fq
|
|||||||
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
|
||||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||||
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
|
golang.org/x/text v0.3.4 h1:0YWbFKbhXG/wIiuHDSKpS0Iy7FSA+u45VtBMfQcFTTc=
|
||||||
@@ -632,7 +613,6 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
|||||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0 h1:/5xXl8Y5W96D+TtHSlonuFqGHIWVuyCkGJLwGh9JJFs=
|
|
||||||
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
|
||||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||||
@@ -666,7 +646,6 @@ golang.org/x/tools v0.0.0-20191130070609-6e064ea0cf2d/go.mod h1:b+2E5dAYhXwXZwtn
|
|||||||
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20191216052735-49a3e744a425/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20191216173652-a0e659d51361/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20191227053925-7b8e75db28f4/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114 h1:DnSr2mCsxyCE6ZgIkmcWUQY2R5cH/6wL7eIxEmQOMSE=
|
|
||||||
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200103221440-774c71fcf114/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200117161641-43d50277825c/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
golang.org/x/tools v0.0.0-20200122220014-bf1340f18c4a/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
|
||||||
@@ -692,7 +671,6 @@ golang.org/x/tools v0.0.0-20201201161351-ac6f37ff4c2a/go.mod h1:emZCQorbCU4vsT4f
|
|||||||
golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
golang.org/x/tools v0.0.0-20201208233053-a543418bbed2/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
|
||||||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
|
|
||||||
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
|
||||||
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
|
||||||
@@ -717,7 +695,6 @@ google.golang.org/api v0.35.0/go.mod h1:/XrVsuzM0rZmrsbjJutiuftIzeuTQcEeaYcSk/mQ
|
|||||||
google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE=
|
google.golang.org/api v0.36.0/go.mod h1:+z5ficQTmoYpPn8LCUNVpK5I7hwkpjbcgqA7I34qYtE=
|
||||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
google.golang.org/appengine v1.4.0 h1:/wp5JvzpHIxhs/dumFmF7BXTf3Z+dd4uXta4kVyO508=
|
|
||||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
google.golang.org/appengine v1.5.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||||
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
google.golang.org/appengine v1.6.1/go.mod h1:i06prIuMbXzDqacNJfV5OdTW448YApPu5ww/cMBSeb0=
|
||||||
@@ -785,14 +762,12 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
|
|||||||
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
|
||||||
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
|
||||||
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.22.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.23.0 h1:4MY060fB1DLGMB/7MBTLnwQUY6+F09GEiz6SsrNqyzM=
|
|
||||||
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
|
||||||
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
google.golang.org/protobuf v1.24.0/go.mod h1:r/3tXBNzIEhYS9I1OUVjXDlt8tc493IdKGjtUeSXeh4=
|
||||||
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c=
|
||||||
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c=
|
||||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
|
|
||||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 h1:YR8cESwS4TdDjEe65xsg0ogRM/Nc3DYOhEAlW+xobZo=
|
||||||
@@ -808,12 +783,10 @@ gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWD
|
|||||||
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI=
|
||||||
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
gopkg.in/yaml.v2 v2.0.0-20170812160011-eb3733d160e7/go.mod h1:JAlM8MvJe8wmxCU4Bli9HhUf9+ttbYbLASfIpnQbh74=
|
||||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
|
||||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.3.0 h1:clyUAQHOM3G0M3f5vQj7LuJrETvjVot3Z5el9nffUtU=
|
|
||||||
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||||
@@ -845,7 +818,6 @@ rsc.io/sampler v1.3.0/go.mod h1:T1hPZKmBbMNahiBKFy5HrXp6adAjACjK9JXDnKaTXpA=
|
|||||||
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
|
sigs.k8s.io/structured-merge-diff/v3 v3.0.0-20200116222232-67a7b8c61874/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
|
||||||
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 h1:dOmIZBMfhcHS09XZkMyUgkq5trg3/jRyJYFZUiaOp8E=
|
sigs.k8s.io/structured-merge-diff/v3 v3.0.0 h1:dOmIZBMfhcHS09XZkMyUgkq5trg3/jRyJYFZUiaOp8E=
|
||||||
sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
|
sigs.k8s.io/structured-merge-diff/v3 v3.0.0/go.mod h1:PlARxl6Hbt/+BC80dRLi1qAmnMqwqDg62YvvVkZjemw=
|
||||||
sigs.k8s.io/yaml v1.1.0 h1:4A07+ZFc2wgJwo8YNlQpr1rVlgUDlxXHhPJciaPY5gs=
|
|
||||||
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
sigs.k8s.io/yaml v1.1.0/go.mod h1:UJmg0vDUVViEyp3mgSv9WPwZCDxu4rQW1olrI1uml+o=
|
||||||
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
sigs.k8s.io/yaml v1.2.0 h1:kr/MCeFWJWTwyaHoR9c8EjH9OumOmoF9YGiZd7lFm/Q=
|
||||||
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
sigs.k8s.io/yaml v1.2.0/go.mod h1:yfXDCHCao9+ENCvLSE62v9VSji2MKu5jeNfTrofGhJc=
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ func extractValue(currentKey string, value interface{}) interface{} {
|
|||||||
tmp := strings.SplitN(currentKey, "[", 3)
|
tmp := strings.SplitN(currentKey, "[", 3)
|
||||||
arrayIndex, err := strconv.Atoi(strings.Replace(tmp[1], "]", "", 1))
|
arrayIndex, err := strconv.Atoi(strings.Replace(tmp[1], "]", "", 1))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return value
|
return nil
|
||||||
}
|
}
|
||||||
currentKey := tmp[0]
|
currentKey := tmp[0]
|
||||||
// if currentKey contains only an index (i.e. [0] or 0)
|
// if currentKey contains only an index (i.e. [0] or 0)
|
||||||
|
|||||||
@@ -20,6 +20,24 @@ func TestEval(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEvalWithInvalidData(t *testing.T) {
|
||||||
|
path := "simple"
|
||||||
|
data := `invalid data`
|
||||||
|
_, _, err := Eval(path, []byte(data))
|
||||||
|
if err == nil {
|
||||||
|
t.Error("expected an error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestEvalWithInvalidPath(t *testing.T) {
|
||||||
|
path := "errors"
|
||||||
|
data := `{}`
|
||||||
|
_, _, err := Eval(path, []byte(data))
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected error, but got", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEvalWithLongSimpleWalk(t *testing.T) {
|
func TestEvalWithLongSimpleWalk(t *testing.T) {
|
||||||
path := "long.simple.walk"
|
path := "long.simple.walk"
|
||||||
data := `{"long": {"simple": {"walk": "value"}}}`
|
data := `{"long": {"simple": {"walk": "value"}}}`
|
||||||
@@ -66,6 +84,16 @@ func TestEvalWithArrayOfValues(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEvalWithArrayOfValuesAndInvalidIndex(t *testing.T) {
|
||||||
|
path := "ids[wat]"
|
||||||
|
data := `{"ids": [1, 2]}`
|
||||||
|
|
||||||
|
_, _, err := Eval(path, []byte(data))
|
||||||
|
if err == nil {
|
||||||
|
t.Error("Expected an error")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEvalWithRootArrayOfValues(t *testing.T) {
|
func TestEvalWithRootArrayOfValues(t *testing.T) {
|
||||||
path := "[1]"
|
path := "[1]"
|
||||||
data := `[1, 2]`
|
data := `[1, 2]`
|
||||||
|
|||||||
+4
-4
@@ -16,13 +16,13 @@ import (
|
|||||||
"k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
)
|
)
|
||||||
|
|
||||||
// KubernetesClientApi is a minimal interface for interacting with Kubernetes
|
// KubernetesClientAPI is a minimal interface for interacting with Kubernetes
|
||||||
// Created mostly to make mocking the Kubernetes client easier
|
// Created mostly to make mocking the Kubernetes client easier
|
||||||
type KubernetesClientApi interface {
|
type KubernetesClientAPI interface {
|
||||||
GetServices(namespace string) ([]v1.Service, error)
|
GetServices(namespace string) ([]v1.Service, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
// KubernetesClient is a working implementation of KubernetesClientApi
|
// KubernetesClient is a working implementation of KubernetesClientAPI
|
||||||
type KubernetesClient struct {
|
type KubernetesClient struct {
|
||||||
client *kubernetes.Clientset
|
client *kubernetes.Clientset
|
||||||
}
|
}
|
||||||
@@ -44,7 +44,7 @@ func NewKubernetesClient(client *kubernetes.Clientset) *KubernetesClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewClient creates a Kubernetes client for the given ClusterMode
|
// NewClient creates a Kubernetes client for the given ClusterMode
|
||||||
func NewClient(clusterMode ClusterMode) (KubernetesClientApi, error) {
|
func NewClient(clusterMode ClusterMode) (KubernetesClientAPI, error) {
|
||||||
var kubeConfig *rest.Config
|
var kubeConfig *rest.Config
|
||||||
var err error
|
var err error
|
||||||
switch clusterMode {
|
switch clusterMode {
|
||||||
|
|||||||
+1
-1
@@ -5,6 +5,6 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// GetKubernetesServices return a list of Services from the given namespace
|
// GetKubernetesServices return a list of Services from the given namespace
|
||||||
func GetKubernetesServices(client KubernetesClientApi, namespace string) ([]v1.Service, error) {
|
func GetKubernetesServices(client KubernetesClientAPI, namespace string) ([]v1.Service, error) {
|
||||||
return client.GetServices(namespace)
|
return client.GetServices(namespace)
|
||||||
}
|
}
|
||||||
@@ -1,29 +1,88 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"log"
|
||||||
"os"
|
"os"
|
||||||
|
"os/signal"
|
||||||
|
"syscall"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/TwinProduction/gatus/config"
|
"github.com/TwinProduction/gatus/config"
|
||||||
"github.com/TwinProduction/gatus/controller"
|
"github.com/TwinProduction/gatus/controller"
|
||||||
|
"github.com/TwinProduction/gatus/storage"
|
||||||
"github.com/TwinProduction/gatus/watchdog"
|
"github.com/TwinProduction/gatus/watchdog"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
cfg := loadConfiguration()
|
cfg, err := loadConfiguration()
|
||||||
go watchdog.Monitor(cfg)
|
|
||||||
controller.Handle()
|
|
||||||
}
|
|
||||||
|
|
||||||
func loadConfiguration() *config.Config {
|
|
||||||
var err error
|
|
||||||
customConfigFile := os.Getenv("GATUS_CONFIG_FILE")
|
|
||||||
if len(customConfigFile) > 0 {
|
|
||||||
err = config.Load(customConfigFile)
|
|
||||||
} else {
|
|
||||||
err = config.LoadDefaultConfiguration()
|
|
||||||
}
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
return config.Get()
|
start(cfg)
|
||||||
|
// Wait for termination signal
|
||||||
|
signalChannel := make(chan os.Signal, 1)
|
||||||
|
done := make(chan bool, 1)
|
||||||
|
signal.Notify(signalChannel, os.Interrupt, syscall.SIGTERM)
|
||||||
|
go func() {
|
||||||
|
<-signalChannel
|
||||||
|
log.Println("Received termination signal, attempting to gracefully shut down")
|
||||||
|
stop()
|
||||||
|
save()
|
||||||
|
done <- true
|
||||||
|
}()
|
||||||
|
<-done
|
||||||
|
log.Println("Shutting down")
|
||||||
|
}
|
||||||
|
|
||||||
|
func stop() {
|
||||||
|
watchdog.Shutdown()
|
||||||
|
controller.Shutdown()
|
||||||
|
}
|
||||||
|
|
||||||
|
func save() {
|
||||||
|
err := storage.Get().Save()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Failed to save storage provider:", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func start(cfg *config.Config) {
|
||||||
|
go controller.Handle(cfg.Security, cfg.Web, cfg.Metrics)
|
||||||
|
watchdog.Monitor(cfg)
|
||||||
|
go listenToConfigurationFileChanges(cfg)
|
||||||
|
}
|
||||||
|
|
||||||
|
func loadConfiguration() (cfg *config.Config, err error) {
|
||||||
|
customConfigFile := os.Getenv("GATUS_CONFIG_FILE")
|
||||||
|
if len(customConfigFile) > 0 {
|
||||||
|
cfg, err = config.Load(customConfigFile)
|
||||||
|
} else {
|
||||||
|
cfg, err = config.LoadDefaultConfiguration()
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
func listenToConfigurationFileChanges(cfg *config.Config) {
|
||||||
|
for {
|
||||||
|
time.Sleep(30 * time.Second)
|
||||||
|
if cfg.HasLoadedConfigurationFileBeenModified() {
|
||||||
|
log.Println("[main][listenToConfigurationFileChanges] Configuration file has been modified")
|
||||||
|
save()
|
||||||
|
updatedConfig, err := loadConfiguration()
|
||||||
|
if err != nil {
|
||||||
|
if cfg.SkipInvalidConfigUpdate {
|
||||||
|
log.Println("[main][listenToConfigurationFileChanges] Failed to load new configuration:", err.Error())
|
||||||
|
log.Println("[main][listenToConfigurationFileChanges] The configuration file was updated, but it is not valid. The old configuration will continue being used.")
|
||||||
|
// Update the last file modification time to avoid trying to process the same invalid configuration again
|
||||||
|
cfg.UpdateLastFileModTime()
|
||||||
|
continue
|
||||||
|
} else {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
stop()
|
||||||
|
start(updatedConfig)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
+11
-14
@@ -5,7 +5,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"sync"
|
"sync"
|
||||||
|
|
||||||
"github.com/TwinProduction/gatus/config"
|
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
@@ -19,18 +18,16 @@ var (
|
|||||||
// PublishMetricsForService publishes metrics for the given service and its result.
|
// PublishMetricsForService publishes metrics for the given service and its result.
|
||||||
// These metrics will be exposed at /metrics if the metrics are enabled
|
// These metrics will be exposed at /metrics if the metrics are enabled
|
||||||
func PublishMetricsForService(service *core.Service, result *core.Result) {
|
func PublishMetricsForService(service *core.Service, result *core.Result) {
|
||||||
if config.Get().Metrics {
|
rwLock.Lock()
|
||||||
rwLock.Lock()
|
gauge, exists := gauges[fmt.Sprintf("%s_%s", service.Name, service.URL)]
|
||||||
gauge, exists := gauges[fmt.Sprintf("%s_%s", service.Name, service.URL)]
|
if !exists {
|
||||||
if !exists {
|
gauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
||||||
gauge = promauto.NewGaugeVec(prometheus.GaugeOpts{
|
Subsystem: "gatus",
|
||||||
Subsystem: "gatus",
|
Name: "tasks",
|
||||||
Name: "tasks",
|
ConstLabels: prometheus.Labels{"service": service.Name, "url": service.URL},
|
||||||
ConstLabels: prometheus.Labels{"service": service.Name, "url": service.URL},
|
}, []string{"status", "success"})
|
||||||
}, []string{"status", "success"})
|
gauges[fmt.Sprintf("%s_%s", service.Name, service.URL)] = gauge
|
||||||
gauges[fmt.Sprintf("%s_%s", service.Name, service.URL)] = gauge
|
|
||||||
}
|
|
||||||
rwLock.Unlock()
|
|
||||||
gauge.WithLabelValues(strconv.Itoa(result.HTTPStatus), strconv.FormatBool(result.Success)).Inc()
|
|
||||||
}
|
}
|
||||||
|
rwLock.Unlock()
|
||||||
|
gauge.WithLabelValues(strconv.Itoa(result.HTTPStatus), strconv.FormatBool(result.Success)).Inc()
|
||||||
}
|
}
|
||||||
+1
-1
@@ -5,7 +5,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Handler takes care of security for a given handler with the given security configuratioon
|
// Handler takes care of security for a given handler with the given security configuration
|
||||||
func Handler(handler http.HandlerFunc, security *Config) http.HandlerFunc {
|
func Handler(handler http.HandlerFunc, security *Config) http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
usernameEntered, passwordEntered, ok := r.BasicAuth()
|
usernameEntered, passwordEntered, ok := r.BasicAuth()
|
||||||
|
|||||||
+2
-1
@@ -2,6 +2,7 @@ package storage
|
|||||||
|
|
||||||
// Config is the configuration for alerting providers
|
// Config is the configuration for alerting providers
|
||||||
type Config struct {
|
type Config struct {
|
||||||
// File is the path of the file to use when using file.Store
|
// File is the path of the file to use for persistence
|
||||||
|
// If blank, persistence is disabled.
|
||||||
File string `yaml:"file"`
|
File string `yaml:"file"`
|
||||||
}
|
}
|
||||||
+28
-2
@@ -1,6 +1,7 @@
|
|||||||
package storage
|
package storage
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -15,6 +16,9 @@ var (
|
|||||||
// Because store.Store is an interface, a nil check wouldn't be sufficient, so instead of doing reflection
|
// Because store.Store is an interface, a nil check wouldn't be sufficient, so instead of doing reflection
|
||||||
// every single time Get is called, we'll just lazily keep track of its existence through this variable
|
// every single time Get is called, we'll just lazily keep track of its existence through this variable
|
||||||
initialized bool
|
initialized bool
|
||||||
|
|
||||||
|
ctx context.Context
|
||||||
|
cancelFunc context.CancelFunc
|
||||||
)
|
)
|
||||||
|
|
||||||
// Get retrieves the storage provider
|
// Get retrieves the storage provider
|
||||||
@@ -33,16 +37,38 @@ func Get() store.Store {
|
|||||||
func Initialize(cfg *Config) error {
|
func Initialize(cfg *Config) error {
|
||||||
initialized = true
|
initialized = true
|
||||||
var err error
|
var err error
|
||||||
|
if cancelFunc != nil {
|
||||||
|
// Stop the active autoSave task
|
||||||
|
cancelFunc()
|
||||||
|
}
|
||||||
if cfg == nil || len(cfg.File) == 0 {
|
if cfg == nil || len(cfg.File) == 0 {
|
||||||
log.Println("[storage][Initialize] Creating storage provider")
|
log.Println("[storage][Initialize] Creating storage provider")
|
||||||
provider, err = memory.NewStore("")
|
provider, _ = memory.NewStore("")
|
||||||
} else {
|
} else {
|
||||||
|
ctx, cancelFunc = context.WithCancel(context.Background())
|
||||||
log.Printf("[storage][Initialize] Creating storage provider with file=%s", cfg.File)
|
log.Printf("[storage][Initialize] Creating storage provider with file=%s", cfg.File)
|
||||||
provider, err = memory.NewStore(cfg.File)
|
provider, err = memory.NewStore(cfg.File)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
go provider.(*memory.Store).AutoSave(7 * time.Minute)
|
go autoSave(7*time.Minute, ctx)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// autoSave automatically calls the SaveFunc function of the provider at every interval
|
||||||
|
func autoSave(interval time.Duration, ctx context.Context) {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
log.Printf("[storage][autoSave] Stopping active job")
|
||||||
|
return
|
||||||
|
case <-time.After(interval):
|
||||||
|
log.Printf("[storage][autoSave] Saving")
|
||||||
|
err := provider.Save()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("[storage][autoSave] Save failed:", err.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
package storage
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestInitialize(t *testing.T) {
|
||||||
|
file := t.TempDir() + "/test.db"
|
||||||
|
err := Initialize(&Config{File: file})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("shouldn't have returned an error")
|
||||||
|
}
|
||||||
|
if cancelFunc == nil {
|
||||||
|
t.Error("cancelFunc shouldn't have been nil")
|
||||||
|
}
|
||||||
|
if ctx == nil {
|
||||||
|
t.Error("ctx shouldn't have been nil")
|
||||||
|
}
|
||||||
|
// Try to initialize it again
|
||||||
|
err = Initialize(&Config{File: file})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("shouldn't have returned an error")
|
||||||
|
}
|
||||||
|
cancelFunc()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAutoSave(t *testing.T) {
|
||||||
|
file := t.TempDir() + "/test.db"
|
||||||
|
if err := Initialize(&Config{File: file}); err != nil {
|
||||||
|
t.Fatal("shouldn't have returned an error")
|
||||||
|
}
|
||||||
|
go autoSave(3*time.Millisecond, ctx)
|
||||||
|
time.Sleep(15 * time.Millisecond)
|
||||||
|
cancelFunc()
|
||||||
|
time.Sleep(5 * time.Millisecond)
|
||||||
|
}
|
||||||
@@ -2,9 +2,6 @@ package memory
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/gob"
|
"encoding/gob"
|
||||||
"encoding/json"
|
|
||||||
"log"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/TwinProduction/gatus/core"
|
"github.com/TwinProduction/gatus/core"
|
||||||
"github.com/TwinProduction/gatus/util"
|
"github.com/TwinProduction/gatus/util"
|
||||||
@@ -39,9 +36,15 @@ func NewStore(file string) (*Store, error) {
|
|||||||
return store, nil
|
return store, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetAllAsJSON returns the JSON encoding of all monitored core.ServiceStatus
|
// GetAllServiceStatusesWithResultPagination returns all monitored core.ServiceStatus
|
||||||
func (s *Store) GetAllAsJSON() ([]byte, error) {
|
// with a subset of core.Result defined by the page and pageSize parameters
|
||||||
return json.Marshal(s.cache.GetAll())
|
func (s *Store) GetAllServiceStatusesWithResultPagination(page, pageSize int) map[string]*core.ServiceStatus {
|
||||||
|
serviceStatuses := s.cache.GetAll()
|
||||||
|
pagedServiceStatuses := make(map[string]*core.ServiceStatus, len(serviceStatuses))
|
||||||
|
for k, v := range serviceStatuses {
|
||||||
|
pagedServiceStatuses[k] = v.(*core.ServiceStatus).WithResultPagination(page, pageSize)
|
||||||
|
}
|
||||||
|
return pagedServiceStatuses
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetServiceStatus returns the service status for a given service name in the given group
|
// GetServiceStatus returns the service status for a given service name in the given group
|
||||||
@@ -94,17 +97,8 @@ func (s *Store) Clear() {
|
|||||||
|
|
||||||
// Save persists the cache to the store file
|
// Save persists the cache to the store file
|
||||||
func (s *Store) Save() error {
|
func (s *Store) Save() error {
|
||||||
return s.cache.SaveToFile(s.file)
|
if len(s.file) > 0 {
|
||||||
}
|
return s.cache.SaveToFile(s.file)
|
||||||
|
|
||||||
// AutoSave automatically calls the Save function at every interval
|
|
||||||
func (s *Store) AutoSave(interval time.Duration) {
|
|
||||||
for {
|
|
||||||
time.Sleep(interval)
|
|
||||||
log.Printf("[memory][AutoSave] Persisting data to file")
|
|
||||||
err := s.Save()
|
|
||||||
if err != nil {
|
|
||||||
log.Printf("[memory][AutoSave] failed to save to file=%s: %s", s.file, err.Error())
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
@@ -33,7 +33,6 @@ var (
|
|||||||
Hostname: "example.org",
|
Hostname: "example.org",
|
||||||
IP: "127.0.0.1",
|
IP: "127.0.0.1",
|
||||||
HTTPStatus: 200,
|
HTTPStatus: 200,
|
||||||
Body: []byte("body"),
|
|
||||||
Errors: nil,
|
Errors: nil,
|
||||||
Connected: true,
|
Connected: true,
|
||||||
Success: true,
|
Success: true,
|
||||||
@@ -59,7 +58,6 @@ var (
|
|||||||
Hostname: "example.org",
|
Hostname: "example.org",
|
||||||
IP: "127.0.0.1",
|
IP: "127.0.0.1",
|
||||||
HTTPStatus: 200,
|
HTTPStatus: 200,
|
||||||
Body: []byte("body"),
|
|
||||||
Errors: []string{"error-1", "error-2"},
|
Errors: []string{"error-1", "error-2"},
|
||||||
Connected: true,
|
Connected: true,
|
||||||
Success: false,
|
Success: false,
|
||||||
@@ -107,9 +105,6 @@ func TestStore_Insert(t *testing.T) {
|
|||||||
if r.DNSRCode != expectedResult.DNSRCode {
|
if r.DNSRCode != expectedResult.DNSRCode {
|
||||||
t.Errorf("Result at index %d should've had a DNSRCode of %s, but was actually %s", i, expectedResult.DNSRCode, r.DNSRCode)
|
t.Errorf("Result at index %d should've had a DNSRCode of %s, but was actually %s", i, expectedResult.DNSRCode, r.DNSRCode)
|
||||||
}
|
}
|
||||||
if len(r.Body) != len(expectedResult.Body) {
|
|
||||||
t.Errorf("Result at index %d should've had a body of length %d, but was actually %d", i, len(expectedResult.Body), len(r.Body))
|
|
||||||
}
|
|
||||||
if r.Hostname != expectedResult.Hostname {
|
if r.Hostname != expectedResult.Hostname {
|
||||||
t.Errorf("Result at index %d should've had a Hostname of %s, but was actually %s", i, expectedResult.Hostname, r.Hostname)
|
t.Errorf("Result at index %d should've had a Hostname of %s, but was actually %s", i, expectedResult.Hostname, r.Hostname)
|
||||||
}
|
}
|
||||||
@@ -204,7 +199,7 @@ func TestStore_GetServiceStatusByKey(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestStore_GetAllAsJSON(t *testing.T) {
|
func TestStore_GetAllServiceStatusesWithResultPagination(t *testing.T) {
|
||||||
store, _ := NewStore("")
|
store, _ := NewStore("")
|
||||||
firstResult := &testSuccessfulResult
|
firstResult := &testSuccessfulResult
|
||||||
secondResult := &testUnsuccessfulResult
|
secondResult := &testUnsuccessfulResult
|
||||||
@@ -213,13 +208,19 @@ func TestStore_GetAllAsJSON(t *testing.T) {
|
|||||||
// Can't be bothered dealing with timezone issues on the worker that runs the automated tests
|
// Can't be bothered dealing with timezone issues on the worker that runs the automated tests
|
||||||
firstResult.Timestamp = time.Time{}
|
firstResult.Timestamp = time.Time{}
|
||||||
secondResult.Timestamp = time.Time{}
|
secondResult.Timestamp = time.Time{}
|
||||||
output, err := store.GetAllAsJSON()
|
serviceStatuses := store.GetAllServiceStatusesWithResultPagination(1, 20)
|
||||||
if err != nil {
|
if len(serviceStatuses) != 1 {
|
||||||
t.Fatal("shouldn't have returned an error, got", err.Error())
|
t.Fatal("expected 1 service status")
|
||||||
}
|
}
|
||||||
expectedOutput := `{"group_name":{"name":"name","group":"group","key":"group_name","results":[{"status":200,"hostname":"example.org","duration":150000000,"errors":null,"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":true},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":true}],"success":true,"timestamp":"0001-01-01T00:00:00Z"},{"status":200,"hostname":"example.org","duration":750000000,"errors":["error-1","error-2"],"conditionResults":[{"condition":"[STATUS] == 200","success":true},{"condition":"[RESPONSE_TIME] \u003c 500","success":false},{"condition":"[CERTIFICATE_EXPIRATION] \u003c 72h","success":false}],"success":false,"timestamp":"0001-01-01T00:00:00Z"}]}}`
|
actual, exists := serviceStatuses[util.ConvertGroupAndServiceToKey(testService.Group, testService.Name)]
|
||||||
if string(output) != expectedOutput {
|
if !exists {
|
||||||
t.Errorf("expected:\n %s\n\ngot:\n %s", expectedOutput, string(output))
|
t.Fatal("expected service status to exist")
|
||||||
|
}
|
||||||
|
if len(actual.Results) != 2 {
|
||||||
|
t.Error("expected 2 results, got", len(actual.Results))
|
||||||
|
}
|
||||||
|
if len(actual.Events) != 2 {
|
||||||
|
t.Error("expected 2 events, got", len(actual.Events))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -250,3 +251,22 @@ func TestStore_DeleteAllServiceStatusesNotInKeys(t *testing.T) {
|
|||||||
t.Error("firstService should still exist")
|
t.Error("firstService should still exist")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestStore_Save(t *testing.T) {
|
||||||
|
files := []string{
|
||||||
|
"",
|
||||||
|
t.TempDir() + "/test.db",
|
||||||
|
}
|
||||||
|
for _, file := range files {
|
||||||
|
t.Run(file, func(t *testing.T) {
|
||||||
|
store, err := NewStore(file)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("expected no error, got", err.Error())
|
||||||
|
}
|
||||||
|
err = store.Save()
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal("expected no error, got", err.Error())
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,8 +7,9 @@ import (
|
|||||||
|
|
||||||
// Store is the interface that each stores should implement
|
// Store is the interface that each stores should implement
|
||||||
type Store interface {
|
type Store interface {
|
||||||
// GetAllAsJSON returns the JSON encoding of all monitored core.ServiceStatus
|
// GetAllServiceStatusesWithResultPagination returns the JSON encoding of all monitored core.ServiceStatus
|
||||||
GetAllAsJSON() ([]byte, error)
|
// with a subset of core.Result defined by the page and pageSize parameters
|
||||||
|
GetAllServiceStatusesWithResultPagination(page, pageSize int) map[string]*core.ServiceStatus
|
||||||
|
|
||||||
// GetServiceStatus returns the service status for a given service name in the given group
|
// GetServiceStatus returns the service status for a given service name in the given group
|
||||||
GetServiceStatus(groupName, serviceName string) *core.ServiceStatus
|
GetServiceStatus(groupName, serviceName string) *core.ServiceStatus
|
||||||
@@ -26,6 +27,9 @@ type Store interface {
|
|||||||
|
|
||||||
// Clear deletes everything from the store
|
// Clear deletes everything from the store
|
||||||
Clear()
|
Clear()
|
||||||
|
|
||||||
|
// Save persists the data if and where it needs to be persisted
|
||||||
|
Save() error
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ var (
|
|||||||
Hostname: "example.org",
|
Hostname: "example.org",
|
||||||
IP: "127.0.0.1",
|
IP: "127.0.0.1",
|
||||||
HTTPStatus: 200,
|
HTTPStatus: 200,
|
||||||
Body: []byte("body"),
|
|
||||||
Errors: nil,
|
Errors: nil,
|
||||||
Connected: true,
|
Connected: true,
|
||||||
Success: true,
|
Success: true,
|
||||||
@@ -58,7 +57,6 @@ var (
|
|||||||
Hostname: "example.org",
|
Hostname: "example.org",
|
||||||
IP: "127.0.0.1",
|
IP: "127.0.0.1",
|
||||||
HTTPStatus: 200,
|
HTTPStatus: 200,
|
||||||
Body: []byte("body"),
|
|
||||||
Errors: []string{"error-1", "error-2"},
|
Errors: []string{"error-1", "error-2"},
|
||||||
Connected: true,
|
Connected: true,
|
||||||
Success: false,
|
Success: false,
|
||||||
@@ -102,7 +100,7 @@ func BenchmarkStore_GetAllAsJSON(b *testing.B) {
|
|||||||
scenario.Store.Insert(&testService, &testUnsuccessfulResult)
|
scenario.Store.Insert(&testService, &testUnsuccessfulResult)
|
||||||
b.Run(scenario.Name, func(b *testing.B) {
|
b.Run(scenario.Name, func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
scenario.Store.GetAllAsJSON()
|
scenario.Store.GetAllServiceStatusesWithResultPagination(1, 20)
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
})
|
})
|
||||||
@@ -127,8 +125,11 @@ func BenchmarkStore_Insert(b *testing.B) {
|
|||||||
for _, scenario := range scenarios {
|
for _, scenario := range scenarios {
|
||||||
b.Run(scenario.Name, func(b *testing.B) {
|
b.Run(scenario.Name, func(b *testing.B) {
|
||||||
for n := 0; n < b.N; n++ {
|
for n := 0; n < b.N; n++ {
|
||||||
scenario.Store.Insert(&testService, &testSuccessfulResult)
|
if n%100 == 0 {
|
||||||
scenario.Store.Insert(&testService, &testUnsuccessfulResult)
|
scenario.Store.Insert(&testService, &testSuccessfulResult)
|
||||||
|
} else {
|
||||||
|
scenario.Store.Insert(&testService, &testUnsuccessfulResult)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
b.ReportAllocs()
|
b.ReportAllocs()
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -3,9 +3,9 @@ module github.com/TwinProduction/gocache
|
|||||||
go 1.15
|
go 1.15
|
||||||
|
|
||||||
require (
|
require (
|
||||||
github.com/boltdb/bolt v1.3.1
|
|
||||||
github.com/go-redis/redis v6.15.9+incompatible
|
github.com/go-redis/redis v6.15.9+incompatible
|
||||||
github.com/onsi/ginkgo v1.14.1 // indirect
|
github.com/onsi/ginkgo v1.14.1 // indirect
|
||||||
github.com/onsi/gomega v1.10.2 // indirect
|
github.com/onsi/gomega v1.10.2 // indirect
|
||||||
github.com/tidwall/redcon v1.3.2
|
github.com/tidwall/redcon v1.3.2
|
||||||
|
go.etcd.io/bbolt v1.3.5
|
||||||
)
|
)
|
||||||
+3
-2
@@ -1,5 +1,3 @@
|
|||||||
github.com/boltdb/bolt v1.3.1 h1:JQmyP4ZBrce+ZQu0dY660FMfatumYDLun9hBCUVIkF4=
|
|
||||||
github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps=
|
|
||||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||||
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4=
|
||||||
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ=
|
||||||
@@ -30,6 +28,8 @@ github.com/onsi/gomega v1.10.2 h1:aY/nuoWlKJud2J6U0E3NWsjlg+0GtwXxgEqthRdzlcs=
|
|||||||
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
github.com/onsi/gomega v1.10.2/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
|
||||||
github.com/tidwall/redcon v1.3.2 h1:8INx/Nm3VSUbDUT16TH1rMgYQsbXNqy9xcX70edHXbo=
|
github.com/tidwall/redcon v1.3.2 h1:8INx/Nm3VSUbDUT16TH1rMgYQsbXNqy9xcX70edHXbo=
|
||||||
github.com/tidwall/redcon v1.3.2/go.mod h1:bdYBm4rlcWpst2XMwKVzWDF9CoUxEbUmM7CQrKeOZas=
|
github.com/tidwall/redcon v1.3.2/go.mod h1:bdYBm4rlcWpst2XMwKVzWDF9CoUxEbUmM7CQrKeOZas=
|
||||||
|
go.etcd.io/bbolt v1.3.5 h1:XAzx9gjCb0Rxj7EoqcClPD1d5ZBxZJk0jbuoPHenBt0=
|
||||||
|
go.etcd.io/bbolt v1.3.5/go.mod h1:G5EMThwa9y8QZGBClrRx5EY+Yw9kAhnjy3bSjsnlVTQ=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||||
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dDLfdtbT/IVn4keq83P0=
|
golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7 h1:AeiKBIuRw3UomYXSbLy0Mc2dDLfdtbT/IVn4keq83P0=
|
||||||
@@ -40,6 +40,7 @@ golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5h
|
|||||||
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299 h1:DYfZAGf2WMFjMxbgTjaC+2HC7NkNAQs+6Q8b9WEB/F4=
|
||||||
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||||
|
|||||||
+1
-1
@@ -8,7 +8,7 @@ import (
|
|||||||
"sort"
|
"sort"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
bolt "go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SaveToFile stores the content of the cache to a file so that it can be read using
|
// SaveToFile stores the content of the cache to a file so that it can be read using
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
* text=lf
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
.idea
|
||||||
|
*.iml
|
||||||
+72
@@ -0,0 +1,72 @@
|
|||||||
|
# health
|
||||||
|
|
||||||
|

|
||||||
|
[](https://goreportcard.com/report/github.com/TwinProduction/health)
|
||||||
|
[](https://codecov.io/gh/TwinProduction/health)
|
||||||
|
[](https://github.com/TwinProduction/health)
|
||||||
|
[](https://pkg.go.dev/github.com/TwinProduction/health)
|
||||||
|
|
||||||
|
Health is a library used for creating a very simple health endpoint.
|
||||||
|
|
||||||
|
While implementing a health endpoint is very simple, I've grown tired of implementing
|
||||||
|
it over and over again.
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
```
|
||||||
|
go get -u github.com/TwinProduction/health
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
To retrieve the handler, you must use `health.Handler()` and are expected to pass it to the router like so:
|
||||||
|
```go
|
||||||
|
router := http.NewServeMux()
|
||||||
|
router.Handle("/health", health.Handler())
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: ":8080",
|
||||||
|
Handler: router,
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
By default, the handler will return `UP` when the status is down, and `DOWN` when the status is down.
|
||||||
|
If you prefer using JSON, however, you may initialize the health handler like so:
|
||||||
|
```go
|
||||||
|
router.Handle("/health", health.Handler().WithJSON(true))
|
||||||
|
```
|
||||||
|
The above will cause the response body to become `{"status":"UP"}` and `{"status":"DOWN"}` for both status respectively.
|
||||||
|
|
||||||
|
To change the health of the application, you can use `health.SetStatus(<status>)` where `<status>` is one `health.Up`
|
||||||
|
or `health.Down`:
|
||||||
|
|
||||||
|
```go
|
||||||
|
health.SetStatus(health.Up)
|
||||||
|
health.SetStatus(health.Down)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Complete example
|
||||||
|
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/TwinProduction/health"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
router := http.NewServeMux()
|
||||||
|
router.Handle("/health", health.Handler())
|
||||||
|
server := &http.Server{
|
||||||
|
Addr: "0.0.0.0:8080",
|
||||||
|
Handler: router,
|
||||||
|
ReadTimeout: 15 * time.Second,
|
||||||
|
WriteTimeout: 15 * time.Second,
|
||||||
|
IdleTimeout: 15 * time.Second,
|
||||||
|
}
|
||||||
|
server.ListenAndServe()
|
||||||
|
}
|
||||||
|
```
|
||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
module github.com/TwinProduction/health
|
||||||
|
|
||||||
|
go 1.15
|
||||||
+51
@@ -0,0 +1,51 @@
|
|||||||
|
package health
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
var (
|
||||||
|
handler = &healthHandler{
|
||||||
|
useJSON: false,
|
||||||
|
status: Up,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
type healthHandler struct {
|
||||||
|
useJSON bool
|
||||||
|
status Status
|
||||||
|
}
|
||||||
|
|
||||||
|
// WithJSON configures whether the handler should output a response in JSON or in raw text
|
||||||
|
//
|
||||||
|
// Defaults to false
|
||||||
|
func (h *healthHandler) WithJSON(v bool) *healthHandler {
|
||||||
|
h.useJSON = v
|
||||||
|
return h
|
||||||
|
}
|
||||||
|
|
||||||
|
func (h healthHandler) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
||||||
|
var status int
|
||||||
|
var body []byte
|
||||||
|
if h.status == Up {
|
||||||
|
status = http.StatusOK
|
||||||
|
} else {
|
||||||
|
status = http.StatusInternalServerError
|
||||||
|
}
|
||||||
|
if h.useJSON {
|
||||||
|
writer.Header().Set("Content-Type", "application/json")
|
||||||
|
body = []byte(`{"status":"` + h.status + `"}`)
|
||||||
|
} else {
|
||||||
|
body = []byte(h.status)
|
||||||
|
}
|
||||||
|
writer.WriteHeader(status)
|
||||||
|
_, _ = writer.Write(body)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handler retrieves the health handler
|
||||||
|
func Handler() *healthHandler {
|
||||||
|
return handler
|
||||||
|
}
|
||||||
|
|
||||||
|
// SetStatus sets the status to be reflected by the health handler
|
||||||
|
func SetStatus(status Status) {
|
||||||
|
handler.status = status
|
||||||
|
}
|
||||||
+8
@@ -0,0 +1,8 @@
|
|||||||
|
package health
|
||||||
|
|
||||||
|
type Status string
|
||||||
|
|
||||||
|
var (
|
||||||
|
Down Status = "DOWN"
|
||||||
|
Up Status = "UP"
|
||||||
|
)
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
BRANCH=`git rev-parse --abbrev-ref HEAD`
|
|
||||||
COMMIT=`git rev-parse --short HEAD`
|
|
||||||
GOLDFLAGS="-X main.branch $(BRANCH) -X main.commit $(COMMIT)"
|
|
||||||
|
|
||||||
default: build
|
|
||||||
|
|
||||||
race:
|
|
||||||
@go test -v -race -test.run="TestSimulate_(100op|1000op)"
|
|
||||||
|
|
||||||
# go get github.com/kisielk/errcheck
|
|
||||||
errcheck:
|
|
||||||
@errcheck -ignorepkg=bytes -ignore=os:Remove github.com/boltdb/bolt
|
|
||||||
|
|
||||||
test:
|
|
||||||
@go test -v -cover .
|
|
||||||
@go test -v ./cmd/bolt
|
|
||||||
|
|
||||||
.PHONY: fmt test
|
|
||||||
-18
@@ -1,18 +0,0 @@
|
|||||||
version: "{build}"
|
|
||||||
|
|
||||||
os: Windows Server 2012 R2
|
|
||||||
|
|
||||||
clone_folder: c:\gopath\src\github.com\boltdb\bolt
|
|
||||||
|
|
||||||
environment:
|
|
||||||
GOPATH: c:\gopath
|
|
||||||
|
|
||||||
install:
|
|
||||||
- echo %PATH%
|
|
||||||
- echo %GOPATH%
|
|
||||||
- go version
|
|
||||||
- go env
|
|
||||||
- go get -v -t ./...
|
|
||||||
|
|
||||||
build_script:
|
|
||||||
- go test -v ./...
|
|
||||||
-28
@@ -1,28 +0,0 @@
|
|||||||
package bolt
|
|
||||||
|
|
||||||
import "unsafe"
|
|
||||||
|
|
||||||
// maxMapSize represents the largest mmap size supported by Bolt.
|
|
||||||
const maxMapSize = 0x7FFFFFFF // 2GB
|
|
||||||
|
|
||||||
// maxAllocSize is the size used when creating array pointers.
|
|
||||||
const maxAllocSize = 0xFFFFFFF
|
|
||||||
|
|
||||||
// Are unaligned load/stores broken on this arch?
|
|
||||||
var brokenUnaligned bool
|
|
||||||
|
|
||||||
func init() {
|
|
||||||
// Simple check to see whether this arch handles unaligned load/stores
|
|
||||||
// correctly.
|
|
||||||
|
|
||||||
// ARM9 and older devices require load/stores to be from/to aligned
|
|
||||||
// addresses. If not, the lower 2 bits are cleared and that address is
|
|
||||||
// read in a jumbled up order.
|
|
||||||
|
|
||||||
// See http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.faqs/ka15414.html
|
|
||||||
|
|
||||||
raw := [6]byte{0xfe, 0xef, 0x11, 0x22, 0x22, 0x11}
|
|
||||||
val := *(*uint32)(unsafe.Pointer(uintptr(unsafe.Pointer(&raw)) + 2))
|
|
||||||
|
|
||||||
brokenUnaligned = val != 0x11222211
|
|
||||||
}
|
|
||||||
-252
@@ -1,252 +0,0 @@
|
|||||||
package bolt
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"sort"
|
|
||||||
"unsafe"
|
|
||||||
)
|
|
||||||
|
|
||||||
// freelist represents a list of all pages that are available for allocation.
|
|
||||||
// It also tracks pages that have been freed but are still in use by open transactions.
|
|
||||||
type freelist struct {
|
|
||||||
ids []pgid // all free and available free page ids.
|
|
||||||
pending map[txid][]pgid // mapping of soon-to-be free page ids by tx.
|
|
||||||
cache map[pgid]bool // fast lookup of all free and pending page ids.
|
|
||||||
}
|
|
||||||
|
|
||||||
// newFreelist returns an empty, initialized freelist.
|
|
||||||
func newFreelist() *freelist {
|
|
||||||
return &freelist{
|
|
||||||
pending: make(map[txid][]pgid),
|
|
||||||
cache: make(map[pgid]bool),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// size returns the size of the page after serialization.
|
|
||||||
func (f *freelist) size() int {
|
|
||||||
n := f.count()
|
|
||||||
if n >= 0xFFFF {
|
|
||||||
// The first element will be used to store the count. See freelist.write.
|
|
||||||
n++
|
|
||||||
}
|
|
||||||
return pageHeaderSize + (int(unsafe.Sizeof(pgid(0))) * n)
|
|
||||||
}
|
|
||||||
|
|
||||||
// count returns count of pages on the freelist
|
|
||||||
func (f *freelist) count() int {
|
|
||||||
return f.free_count() + f.pending_count()
|
|
||||||
}
|
|
||||||
|
|
||||||
// free_count returns count of free pages
|
|
||||||
func (f *freelist) free_count() int {
|
|
||||||
return len(f.ids)
|
|
||||||
}
|
|
||||||
|
|
||||||
// pending_count returns count of pending pages
|
|
||||||
func (f *freelist) pending_count() int {
|
|
||||||
var count int
|
|
||||||
for _, list := range f.pending {
|
|
||||||
count += len(list)
|
|
||||||
}
|
|
||||||
return count
|
|
||||||
}
|
|
||||||
|
|
||||||
// copyall copies into dst a list of all free ids and all pending ids in one sorted list.
|
|
||||||
// f.count returns the minimum length required for dst.
|
|
||||||
func (f *freelist) copyall(dst []pgid) {
|
|
||||||
m := make(pgids, 0, f.pending_count())
|
|
||||||
for _, list := range f.pending {
|
|
||||||
m = append(m, list...)
|
|
||||||
}
|
|
||||||
sort.Sort(m)
|
|
||||||
mergepgids(dst, f.ids, m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// allocate returns the starting page id of a contiguous list of pages of a given size.
|
|
||||||
// If a contiguous block cannot be found then 0 is returned.
|
|
||||||
func (f *freelist) allocate(n int) pgid {
|
|
||||||
if len(f.ids) == 0 {
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
var initial, previd pgid
|
|
||||||
for i, id := range f.ids {
|
|
||||||
if id <= 1 {
|
|
||||||
panic(fmt.Sprintf("invalid page allocation: %d", id))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Reset initial page if this is not contiguous.
|
|
||||||
if previd == 0 || id-previd != 1 {
|
|
||||||
initial = id
|
|
||||||
}
|
|
||||||
|
|
||||||
// If we found a contiguous block then remove it and return it.
|
|
||||||
if (id-initial)+1 == pgid(n) {
|
|
||||||
// If we're allocating off the beginning then take the fast path
|
|
||||||
// and just adjust the existing slice. This will use extra memory
|
|
||||||
// temporarily but the append() in free() will realloc the slice
|
|
||||||
// as is necessary.
|
|
||||||
if (i + 1) == n {
|
|
||||||
f.ids = f.ids[i+1:]
|
|
||||||
} else {
|
|
||||||
copy(f.ids[i-n+1:], f.ids[i+1:])
|
|
||||||
f.ids = f.ids[:len(f.ids)-n]
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove from the free cache.
|
|
||||||
for i := pgid(0); i < pgid(n); i++ {
|
|
||||||
delete(f.cache, initial+i)
|
|
||||||
}
|
|
||||||
|
|
||||||
return initial
|
|
||||||
}
|
|
||||||
|
|
||||||
previd = id
|
|
||||||
}
|
|
||||||
return 0
|
|
||||||
}
|
|
||||||
|
|
||||||
// free releases a page and its overflow for a given transaction id.
|
|
||||||
// If the page is already free then a panic will occur.
|
|
||||||
func (f *freelist) free(txid txid, p *page) {
|
|
||||||
if p.id <= 1 {
|
|
||||||
panic(fmt.Sprintf("cannot free page 0 or 1: %d", p.id))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Free page and all its overflow pages.
|
|
||||||
var ids = f.pending[txid]
|
|
||||||
for id := p.id; id <= p.id+pgid(p.overflow); id++ {
|
|
||||||
// Verify that page is not already free.
|
|
||||||
if f.cache[id] {
|
|
||||||
panic(fmt.Sprintf("page %d already freed", id))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add to the freelist and cache.
|
|
||||||
ids = append(ids, id)
|
|
||||||
f.cache[id] = true
|
|
||||||
}
|
|
||||||
f.pending[txid] = ids
|
|
||||||
}
|
|
||||||
|
|
||||||
// release moves all page ids for a transaction id (or older) to the freelist.
|
|
||||||
func (f *freelist) release(txid txid) {
|
|
||||||
m := make(pgids, 0)
|
|
||||||
for tid, ids := range f.pending {
|
|
||||||
if tid <= txid {
|
|
||||||
// Move transaction's pending pages to the available freelist.
|
|
||||||
// Don't remove from the cache since the page is still free.
|
|
||||||
m = append(m, ids...)
|
|
||||||
delete(f.pending, tid)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
sort.Sort(m)
|
|
||||||
f.ids = pgids(f.ids).merge(m)
|
|
||||||
}
|
|
||||||
|
|
||||||
// rollback removes the pages from a given pending tx.
|
|
||||||
func (f *freelist) rollback(txid txid) {
|
|
||||||
// Remove page ids from cache.
|
|
||||||
for _, id := range f.pending[txid] {
|
|
||||||
delete(f.cache, id)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Remove pages from pending list.
|
|
||||||
delete(f.pending, txid)
|
|
||||||
}
|
|
||||||
|
|
||||||
// freed returns whether a given page is in the free list.
|
|
||||||
func (f *freelist) freed(pgid pgid) bool {
|
|
||||||
return f.cache[pgid]
|
|
||||||
}
|
|
||||||
|
|
||||||
// read initializes the freelist from a freelist page.
|
|
||||||
func (f *freelist) read(p *page) {
|
|
||||||
// If the page.count is at the max uint16 value (64k) then it's considered
|
|
||||||
// an overflow and the size of the freelist is stored as the first element.
|
|
||||||
idx, count := 0, int(p.count)
|
|
||||||
if count == 0xFFFF {
|
|
||||||
idx = 1
|
|
||||||
count = int(((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[0])
|
|
||||||
}
|
|
||||||
|
|
||||||
// Copy the list of page ids from the freelist.
|
|
||||||
if count == 0 {
|
|
||||||
f.ids = nil
|
|
||||||
} else {
|
|
||||||
ids := ((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[idx:count]
|
|
||||||
f.ids = make([]pgid, len(ids))
|
|
||||||
copy(f.ids, ids)
|
|
||||||
|
|
||||||
// Make sure they're sorted.
|
|
||||||
sort.Sort(pgids(f.ids))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Rebuild the page cache.
|
|
||||||
f.reindex()
|
|
||||||
}
|
|
||||||
|
|
||||||
// write writes the page ids onto a freelist page. All free and pending ids are
|
|
||||||
// saved to disk since in the event of a program crash, all pending ids will
|
|
||||||
// become free.
|
|
||||||
func (f *freelist) write(p *page) error {
|
|
||||||
// Combine the old free pgids and pgids waiting on an open transaction.
|
|
||||||
|
|
||||||
// Update the header flag.
|
|
||||||
p.flags |= freelistPageFlag
|
|
||||||
|
|
||||||
// The page.count can only hold up to 64k elements so if we overflow that
|
|
||||||
// number then we handle it by putting the size in the first element.
|
|
||||||
lenids := f.count()
|
|
||||||
if lenids == 0 {
|
|
||||||
p.count = uint16(lenids)
|
|
||||||
} else if lenids < 0xFFFF {
|
|
||||||
p.count = uint16(lenids)
|
|
||||||
f.copyall(((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[:])
|
|
||||||
} else {
|
|
||||||
p.count = 0xFFFF
|
|
||||||
((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[0] = pgid(lenids)
|
|
||||||
f.copyall(((*[maxAllocSize]pgid)(unsafe.Pointer(&p.ptr)))[1:])
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// reload reads the freelist from a page and filters out pending items.
|
|
||||||
func (f *freelist) reload(p *page) {
|
|
||||||
f.read(p)
|
|
||||||
|
|
||||||
// Build a cache of only pending pages.
|
|
||||||
pcache := make(map[pgid]bool)
|
|
||||||
for _, pendingIDs := range f.pending {
|
|
||||||
for _, pendingID := range pendingIDs {
|
|
||||||
pcache[pendingID] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check each page in the freelist and build a new available freelist
|
|
||||||
// with any pages not in the pending lists.
|
|
||||||
var a []pgid
|
|
||||||
for _, id := range f.ids {
|
|
||||||
if !pcache[id] {
|
|
||||||
a = append(a, id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
f.ids = a
|
|
||||||
|
|
||||||
// Once the available list is rebuilt then rebuild the free cache so that
|
|
||||||
// it includes the available and pending free pages.
|
|
||||||
f.reindex()
|
|
||||||
}
|
|
||||||
|
|
||||||
// reindex rebuilds the free cache based on available and pending free lists.
|
|
||||||
func (f *freelist) reindex() {
|
|
||||||
f.cache = make(map[pgid]bool, len(f.ids))
|
|
||||||
for _, id := range f.ids {
|
|
||||||
f.cache[id] = true
|
|
||||||
}
|
|
||||||
for _, pendingIDs := range f.pending {
|
|
||||||
for _, pendingID := range pendingIDs {
|
|
||||||
f.cache[pendingID] = true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+1
@@ -2,3 +2,4 @@
|
|||||||
*.test
|
*.test
|
||||||
*.swp
|
*.swp
|
||||||
/bin/
|
/bin/
|
||||||
|
cover.out
|
||||||
+17
@@ -0,0 +1,17 @@
|
|||||||
|
language: go
|
||||||
|
go_import_path: go.etcd.io/bbolt
|
||||||
|
|
||||||
|
sudo: false
|
||||||
|
|
||||||
|
go:
|
||||||
|
- 1.12
|
||||||
|
|
||||||
|
before_install:
|
||||||
|
- go get -v honnef.co/go/tools/...
|
||||||
|
- go get -v github.com/kisielk/errcheck
|
||||||
|
|
||||||
|
script:
|
||||||
|
- make fmt
|
||||||
|
- make test
|
||||||
|
- make race
|
||||||
|
# - make errcheck
|
||||||
File renamed without changes.
+38
@@ -0,0 +1,38 @@
|
|||||||
|
BRANCH=`git rev-parse --abbrev-ref HEAD`
|
||||||
|
COMMIT=`git rev-parse --short HEAD`
|
||||||
|
GOLDFLAGS="-X main.branch $(BRANCH) -X main.commit $(COMMIT)"
|
||||||
|
|
||||||
|
default: build
|
||||||
|
|
||||||
|
race:
|
||||||
|
@TEST_FREELIST_TYPE=hashmap go test -v -race -test.run="TestSimulate_(100op|1000op)"
|
||||||
|
@echo "array freelist test"
|
||||||
|
@TEST_FREELIST_TYPE=array go test -v -race -test.run="TestSimulate_(100op|1000op)"
|
||||||
|
|
||||||
|
fmt:
|
||||||
|
!(gofmt -l -s -d $(shell find . -name \*.go) | grep '[a-z]')
|
||||||
|
|
||||||
|
# go get honnef.co/go/tools/simple
|
||||||
|
gosimple:
|
||||||
|
gosimple ./...
|
||||||
|
|
||||||
|
# go get honnef.co/go/tools/unused
|
||||||
|
unused:
|
||||||
|
unused ./...
|
||||||
|
|
||||||
|
# go get github.com/kisielk/errcheck
|
||||||
|
errcheck:
|
||||||
|
@errcheck -ignorepkg=bytes -ignore=os:Remove go.etcd.io/bbolt
|
||||||
|
|
||||||
|
test:
|
||||||
|
TEST_FREELIST_TYPE=hashmap go test -timeout 20m -v -coverprofile cover.out -covermode atomic
|
||||||
|
# Note: gets "program not an importable package" in out of path builds
|
||||||
|
TEST_FREELIST_TYPE=hashmap go test -v ./cmd/bbolt
|
||||||
|
|
||||||
|
@echo "array freelist test"
|
||||||
|
|
||||||
|
@TEST_FREELIST_TYPE=array go test -timeout 20m -v -coverprofile cover.out -covermode atomic
|
||||||
|
# Note: gets "program not an importable package" in out of path builds
|
||||||
|
@TEST_FREELIST_TYPE=array go test -v ./cmd/bbolt
|
||||||
|
|
||||||
|
.PHONY: race fmt errcheck test gosimple unused
|
||||||
+123
-82
@@ -1,5 +1,18 @@
|
|||||||
Bolt [](https://coveralls.io/r/boltdb/bolt?branch=master) [](https://godoc.org/github.com/boltdb/bolt) 
|
bbolt
|
||||||
====
|
=====
|
||||||
|
|
||||||
|
[](https://goreportcard.com/report/github.com/etcd-io/bbolt)
|
||||||
|
[](https://codecov.io/gh/etcd-io/bbolt)
|
||||||
|
[](https://travis-ci.com/etcd-io/bbolt)
|
||||||
|
[](https://godoc.org/github.com/etcd-io/bbolt)
|
||||||
|
[](https://github.com/etcd-io/bbolt/releases)
|
||||||
|
[](https://github.com/etcd-io/bbolt/blob/master/LICENSE)
|
||||||
|
|
||||||
|
bbolt is a fork of [Ben Johnson's][gh_ben] [Bolt][bolt] key/value
|
||||||
|
store. The purpose of this fork is to provide the Go community with an active
|
||||||
|
maintenance and development target for Bolt; the goal is improved reliability
|
||||||
|
and stability. bbolt includes bug fixes, performance enhancements, and features
|
||||||
|
not found in Bolt while preserving backwards compatibility with the Bolt API.
|
||||||
|
|
||||||
Bolt is a pure Go key/value store inspired by [Howard Chu's][hyc_symas]
|
Bolt is a pure Go key/value store inspired by [Howard Chu's][hyc_symas]
|
||||||
[LMDB project][lmdb]. The goal of the project is to provide a simple,
|
[LMDB project][lmdb]. The goal of the project is to provide a simple,
|
||||||
@@ -10,6 +23,8 @@ Since Bolt is meant to be used as such a low-level piece of functionality,
|
|||||||
simplicity is key. The API will be small and only focus on getting values
|
simplicity is key. The API will be small and only focus on getting values
|
||||||
and setting values. That's it.
|
and setting values. That's it.
|
||||||
|
|
||||||
|
[gh_ben]: https://github.com/benbjohnson
|
||||||
|
[bolt]: https://github.com/boltdb/bolt
|
||||||
[hyc_symas]: https://twitter.com/hyc_symas
|
[hyc_symas]: https://twitter.com/hyc_symas
|
||||||
[lmdb]: http://symas.com/mdb/
|
[lmdb]: http://symas.com/mdb/
|
||||||
|
|
||||||
@@ -21,36 +36,42 @@ consistency and thread safety. Bolt is currently used in high-load production
|
|||||||
environments serving databases as large as 1TB. Many companies such as
|
environments serving databases as large as 1TB. Many companies such as
|
||||||
Shopify and Heroku use Bolt-backed services every day.
|
Shopify and Heroku use Bolt-backed services every day.
|
||||||
|
|
||||||
|
## Project versioning
|
||||||
|
|
||||||
|
bbolt uses [semantic versioning](http://semver.org).
|
||||||
|
API should not change between patch and minor releases.
|
||||||
|
New minor versions may add additional features to the API.
|
||||||
|
|
||||||
## Table of Contents
|
## Table of Contents
|
||||||
|
|
||||||
- [Getting Started](#getting-started)
|
- [Getting Started](#getting-started)
|
||||||
- [Installing](#installing)
|
- [Installing](#installing)
|
||||||
- [Opening a database](#opening-a-database)
|
- [Opening a database](#opening-a-database)
|
||||||
- [Transactions](#transactions)
|
- [Transactions](#transactions)
|
||||||
- [Read-write transactions](#read-write-transactions)
|
- [Read-write transactions](#read-write-transactions)
|
||||||
- [Read-only transactions](#read-only-transactions)
|
- [Read-only transactions](#read-only-transactions)
|
||||||
- [Batch read-write transactions](#batch-read-write-transactions)
|
- [Batch read-write transactions](#batch-read-write-transactions)
|
||||||
- [Managing transactions manually](#managing-transactions-manually)
|
- [Managing transactions manually](#managing-transactions-manually)
|
||||||
- [Using buckets](#using-buckets)
|
- [Using buckets](#using-buckets)
|
||||||
- [Using key/value pairs](#using-keyvalue-pairs)
|
- [Using key/value pairs](#using-keyvalue-pairs)
|
||||||
- [Autoincrementing integer for the bucket](#autoincrementing-integer-for-the-bucket)
|
- [Autoincrementing integer for the bucket](#autoincrementing-integer-for-the-bucket)
|
||||||
- [Iterating over keys](#iterating-over-keys)
|
- [Iterating over keys](#iterating-over-keys)
|
||||||
- [Prefix scans](#prefix-scans)
|
- [Prefix scans](#prefix-scans)
|
||||||
- [Range scans](#range-scans)
|
- [Range scans](#range-scans)
|
||||||
- [ForEach()](#foreach)
|
- [ForEach()](#foreach)
|
||||||
- [Nested buckets](#nested-buckets)
|
- [Nested buckets](#nested-buckets)
|
||||||
- [Database backups](#database-backups)
|
- [Database backups](#database-backups)
|
||||||
- [Statistics](#statistics)
|
- [Statistics](#statistics)
|
||||||
- [Read-Only Mode](#read-only-mode)
|
- [Read-Only Mode](#read-only-mode)
|
||||||
- [Mobile Use (iOS/Android)](#mobile-use-iosandroid)
|
- [Mobile Use (iOS/Android)](#mobile-use-iosandroid)
|
||||||
- [Resources](#resources)
|
- [Resources](#resources)
|
||||||
- [Comparison with other databases](#comparison-with-other-databases)
|
- [Comparison with other databases](#comparison-with-other-databases)
|
||||||
- [Postgres, MySQL, & other relational databases](#postgres-mysql--other-relational-databases)
|
- [Postgres, MySQL, & other relational databases](#postgres-mysql--other-relational-databases)
|
||||||
- [LevelDB, RocksDB](#leveldb-rocksdb)
|
- [LevelDB, RocksDB](#leveldb-rocksdb)
|
||||||
- [LMDB](#lmdb)
|
- [LMDB](#lmdb)
|
||||||
- [Caveats & Limitations](#caveats--limitations)
|
- [Caveats & Limitations](#caveats--limitations)
|
||||||
- [Reading the Source](#reading-the-source)
|
- [Reading the Source](#reading-the-source)
|
||||||
- [Other Projects Using Bolt](#other-projects-using-bolt)
|
- [Other Projects Using Bolt](#other-projects-using-bolt)
|
||||||
|
|
||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
@@ -59,13 +80,28 @@ Shopify and Heroku use Bolt-backed services every day.
|
|||||||
To start using Bolt, install Go and run `go get`:
|
To start using Bolt, install Go and run `go get`:
|
||||||
|
|
||||||
```sh
|
```sh
|
||||||
$ go get github.com/boltdb/bolt/...
|
$ go get go.etcd.io/bbolt/...
|
||||||
```
|
```
|
||||||
|
|
||||||
This will retrieve the library and install the `bolt` command line utility into
|
This will retrieve the library and install the `bolt` command line utility into
|
||||||
your `$GOBIN` path.
|
your `$GOBIN` path.
|
||||||
|
|
||||||
|
|
||||||
|
### Importing bbolt
|
||||||
|
|
||||||
|
To use bbolt as an embedded key-value store, import as:
|
||||||
|
|
||||||
|
```go
|
||||||
|
import bolt "go.etcd.io/bbolt"
|
||||||
|
|
||||||
|
db, err := bolt.Open(path, 0666, nil)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer db.Close()
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
### Opening a database
|
### Opening a database
|
||||||
|
|
||||||
The top-level object in Bolt is a `DB`. It is represented as a single file on
|
The top-level object in Bolt is a `DB`. It is represented as a single file on
|
||||||
@@ -79,7 +115,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
"github.com/boltdb/bolt"
|
bolt "go.etcd.io/bbolt"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@@ -116,11 +152,12 @@ are not thread safe. To work with data in multiple goroutines you must start
|
|||||||
a transaction for each one or use locking to ensure only one goroutine accesses
|
a transaction for each one or use locking to ensure only one goroutine accesses
|
||||||
a transaction at a time. Creating transaction from the `DB` is thread safe.
|
a transaction at a time. Creating transaction from the `DB` is thread safe.
|
||||||
|
|
||||||
Read-only transactions and read-write transactions should not depend on one
|
Transactions should not depend on one another and generally shouldn't be opened
|
||||||
another and generally shouldn't be opened simultaneously in the same goroutine.
|
simultaneously in the same goroutine. This can cause a deadlock as the read-write
|
||||||
This can cause a deadlock as the read-write transaction needs to periodically
|
transaction needs to periodically re-map the data file but it cannot do so while
|
||||||
re-map the data file but it cannot do so while a read-only transaction is open.
|
any read-only transaction is open. Even a nested read-only transaction can cause
|
||||||
|
a deadlock, as the child transaction can block the parent transaction from releasing
|
||||||
|
its resources.
|
||||||
|
|
||||||
#### Read-write transactions
|
#### Read-write transactions
|
||||||
|
|
||||||
@@ -239,7 +276,7 @@ should be writable.
|
|||||||
### Using buckets
|
### Using buckets
|
||||||
|
|
||||||
Buckets are collections of key/value pairs within the database. All keys in a
|
Buckets are collections of key/value pairs within the database. All keys in a
|
||||||
bucket must be unique. You can create a bucket using the `DB.CreateBucket()`
|
bucket must be unique. You can create a bucket using the `Tx.CreateBucket()`
|
||||||
function:
|
function:
|
||||||
|
|
||||||
```go
|
```go
|
||||||
@@ -522,7 +559,7 @@ this from a read-only transaction, it will perform a hot backup and not block
|
|||||||
your other database reads and writes.
|
your other database reads and writes.
|
||||||
|
|
||||||
By default, it will use a regular file handle which will utilize the operating
|
By default, it will use a regular file handle which will utilize the operating
|
||||||
system's page cache. See the [`Tx`](https://godoc.org/github.com/boltdb/bolt#Tx)
|
system's page cache. See the [`Tx`](https://godoc.org/go.etcd.io/bbolt#Tx)
|
||||||
documentation for information about optimizing for larger-than-RAM datasets.
|
documentation for information about optimizing for larger-than-RAM datasets.
|
||||||
|
|
||||||
One common use case is to backup over HTTP so you can use tools like `cURL` to
|
One common use case is to backup over HTTP so you can use tools like `cURL` to
|
||||||
@@ -811,7 +848,7 @@ Here are a few things to note when evaluating and using Bolt:
|
|||||||
|
|
||||||
## Reading the Source
|
## Reading the Source
|
||||||
|
|
||||||
Bolt is a relatively small code base (<3KLOC) for an embedded, serializable,
|
Bolt is a relatively small code base (<5KLOC) for an embedded, serializable,
|
||||||
transactional key/value database so it can be a good starting point for people
|
transactional key/value database so it can be a good starting point for people
|
||||||
interested in how databases work.
|
interested in how databases work.
|
||||||
|
|
||||||
@@ -863,54 +900,58 @@ them via pull request.
|
|||||||
|
|
||||||
Below is a list of public, open source projects that use Bolt:
|
Below is a list of public, open source projects that use Bolt:
|
||||||
|
|
||||||
* [BoltDbWeb](https://github.com/evnix/boltdbweb) - A web based GUI for BoltDB files.
|
* [Algernon](https://github.com/xyproto/algernon) - A HTTP/2 web server with built-in support for Lua. Uses BoltDB as the default database backend.
|
||||||
* [Operation Go: A Routine Mission](http://gocode.io) - An online programming game for Golang using Bolt for user accounts and a leaderboard.
|
|
||||||
* [Bazil](https://bazil.org/) - A file system that lets your data reside where it is most convenient for it to reside.
|
* [Bazil](https://bazil.org/) - A file system that lets your data reside where it is most convenient for it to reside.
|
||||||
* [DVID](https://github.com/janelia-flyem/dvid) - Added Bolt as optional storage engine and testing it against Basho-tuned leveldb.
|
* [bolter](https://github.com/hasit/bolter) - Command-line app for viewing BoltDB file in your terminal.
|
||||||
* [Skybox Analytics](https://github.com/skybox/skybox) - A standalone funnel analysis tool for web analytics.
|
* [boltcli](https://github.com/spacewander/boltcli) - the redis-cli for boltdb with Lua script support.
|
||||||
* [Scuttlebutt](https://github.com/benbjohnson/scuttlebutt) - Uses Bolt to store and process all Twitter mentions of GitHub projects.
|
* [BoltHold](https://github.com/timshannon/bolthold) - An embeddable NoSQL store for Go types built on BoltDB
|
||||||
* [Wiki](https://github.com/peterhellberg/wiki) - A tiny wiki using Goji, BoltDB and Blackfriday.
|
|
||||||
* [ChainStore](https://github.com/pressly/chainstore) - Simple key-value interface to a variety of storage engines organized as a chain of operations.
|
|
||||||
* [MetricBase](https://github.com/msiebuhr/MetricBase) - Single-binary version of Graphite.
|
|
||||||
* [Gitchain](https://github.com/gitchain/gitchain) - Decentralized, peer-to-peer Git repositories aka "Git meets Bitcoin".
|
|
||||||
* [event-shuttle](https://github.com/sclasen/event-shuttle) - A Unix system service to collect and reliably deliver messages to Kafka.
|
|
||||||
* [ipxed](https://github.com/kelseyhightower/ipxed) - Web interface and api for ipxed.
|
|
||||||
* [BoltStore](https://github.com/yosssi/boltstore) - Session store using Bolt.
|
* [BoltStore](https://github.com/yosssi/boltstore) - Session store using Bolt.
|
||||||
* [photosite/session](https://godoc.org/bitbucket.org/kardianos/photosite/session) - Sessions for a photo viewing site.
|
* [Boltdb Boilerplate](https://github.com/bobintornado/boltdb-boilerplate) - Boilerplate wrapper around bolt aiming to make simple calls one-liners.
|
||||||
* [LedisDB](https://github.com/siddontang/ledisdb) - A high performance NoSQL, using Bolt as optional storage.
|
* [BoltDbWeb](https://github.com/evnix/boltdbweb) - A web based GUI for BoltDB files.
|
||||||
* [ipLocator](https://github.com/AndreasBriese/ipLocator) - A fast ip-geo-location-server using bolt with bloom filters.
|
|
||||||
* [cayley](https://github.com/google/cayley) - Cayley is an open-source graph database using Bolt as optional backend.
|
|
||||||
* [bleve](http://www.blevesearch.com/) - A pure Go search engine similar to ElasticSearch that uses Bolt as the default storage backend.
|
* [bleve](http://www.blevesearch.com/) - A pure Go search engine similar to ElasticSearch that uses Bolt as the default storage backend.
|
||||||
* [tentacool](https://github.com/optiflows/tentacool) - REST api server to manage system stuff (IP, DNS, Gateway...) on a linux server.
|
* [btcwallet](https://github.com/btcsuite/btcwallet) - A bitcoin wallet.
|
||||||
* [Seaweed File System](https://github.com/chrislusf/seaweedfs) - Highly scalable distributed key~file system with O(1) disk read.
|
|
||||||
* [InfluxDB](https://influxdata.com) - Scalable datastore for metrics, events, and real-time analytics.
|
|
||||||
* [Freehold](http://tshannon.bitbucket.org/freehold/) - An open, secure, and lightweight platform for your files and data.
|
|
||||||
* [Prometheus Annotation Server](https://github.com/oliver006/prom_annotation_server) - Annotation server for PromDash & Prometheus service monitoring system.
|
|
||||||
* [Consul](https://github.com/hashicorp/consul) - Consul is service discovery and configuration made easy. Distributed, highly available, and datacenter-aware.
|
|
||||||
* [Kala](https://github.com/ajvb/kala) - Kala is a modern job scheduler optimized to run on a single node. It is persistent, JSON over HTTP API, ISO 8601 duration notation, and dependent jobs.
|
|
||||||
* [drive](https://github.com/odeke-em/drive) - drive is an unofficial Google Drive command line client for \*NIX operating systems.
|
|
||||||
* [stow](https://github.com/djherbis/stow) - a persistence manager for objects
|
|
||||||
backed by boltdb.
|
|
||||||
* [buckets](https://github.com/joyrexus/buckets) - a bolt wrapper streamlining
|
* [buckets](https://github.com/joyrexus/buckets) - a bolt wrapper streamlining
|
||||||
simple tx and key scans.
|
simple tx and key scans.
|
||||||
* [mbuckets](https://github.com/abhigupta912/mbuckets) - A Bolt wrapper that allows easy operations on multi level (nested) buckets.
|
* [cayley](https://github.com/google/cayley) - Cayley is an open-source graph database using Bolt as optional backend.
|
||||||
* [Request Baskets](https://github.com/darklynx/request-baskets) - A web service to collect arbitrary HTTP requests and inspect them via REST API or simple web UI, similar to [RequestBin](http://requestb.in/) service
|
* [ChainStore](https://github.com/pressly/chainstore) - Simple key-value interface to a variety of storage engines organized as a chain of operations.
|
||||||
* [Go Report Card](https://goreportcard.com/) - Go code quality report cards as a (free and open source) service.
|
* [Consul](https://github.com/hashicorp/consul) - Consul is service discovery and configuration made easy. Distributed, highly available, and datacenter-aware.
|
||||||
* [Boltdb Boilerplate](https://github.com/bobintornado/boltdb-boilerplate) - Boilerplate wrapper around bolt aiming to make simple calls one-liners.
|
* [DVID](https://github.com/janelia-flyem/dvid) - Added Bolt as optional storage engine and testing it against Basho-tuned leveldb.
|
||||||
* [lru](https://github.com/crowdriff/lru) - Easy to use Bolt-backed Least-Recently-Used (LRU) read-through cache with chainable remote stores.
|
|
||||||
* [Storm](https://github.com/asdine/storm) - Simple and powerful ORM for BoltDB.
|
|
||||||
* [GoWebApp](https://github.com/josephspurrier/gowebapp) - A basic MVC web application in Go using BoltDB.
|
|
||||||
* [SimpleBolt](https://github.com/xyproto/simplebolt) - A simple way to use BoltDB. Deals mainly with strings.
|
|
||||||
* [Algernon](https://github.com/xyproto/algernon) - A HTTP/2 web server with built-in support for Lua. Uses BoltDB as the default database backend.
|
|
||||||
* [MuLiFS](https://github.com/dankomiocevic/mulifs) - Music Library Filesystem creates a filesystem to organise your music files.
|
|
||||||
* [GoShort](https://github.com/pankajkhairnar/goShort) - GoShort is a URL shortener written in Golang and BoltDB for persistent key/value storage and for routing it's using high performent HTTPRouter.
|
|
||||||
* [torrent](https://github.com/anacrolix/torrent) - Full-featured BitTorrent client package and utilities in Go. BoltDB is a storage backend in development.
|
|
||||||
* [gopherpit](https://github.com/gopherpit/gopherpit) - A web service to manage Go remote import paths with custom domains
|
|
||||||
* [bolter](https://github.com/hasit/bolter) - Command-line app for viewing BoltDB file in your terminal.
|
|
||||||
* [btcwallet](https://github.com/btcsuite/btcwallet) - A bitcoin wallet.
|
|
||||||
* [dcrwallet](https://github.com/decred/dcrwallet) - A wallet for the Decred cryptocurrency.
|
* [dcrwallet](https://github.com/decred/dcrwallet) - A wallet for the Decred cryptocurrency.
|
||||||
|
* [drive](https://github.com/odeke-em/drive) - drive is an unofficial Google Drive command line client for \*NIX operating systems.
|
||||||
|
* [event-shuttle](https://github.com/sclasen/event-shuttle) - A Unix system service to collect and reliably deliver messages to Kafka.
|
||||||
|
* [Freehold](http://tshannon.bitbucket.org/freehold/) - An open, secure, and lightweight platform for your files and data.
|
||||||
|
* [Go Report Card](https://goreportcard.com/) - Go code quality report cards as a (free and open source) service.
|
||||||
|
* [GoWebApp](https://github.com/josephspurrier/gowebapp) - A basic MVC web application in Go using BoltDB.
|
||||||
|
* [GoShort](https://github.com/pankajkhairnar/goShort) - GoShort is a URL shortener written in Golang and BoltDB for persistent key/value storage and for routing it's using high performent HTTPRouter.
|
||||||
|
* [gopherpit](https://github.com/gopherpit/gopherpit) - A web service to manage Go remote import paths with custom domains
|
||||||
|
* [gokv](https://github.com/philippgille/gokv) - Simple key-value store abstraction and implementations for Go (Redis, Consul, etcd, bbolt, BadgerDB, LevelDB, Memcached, DynamoDB, S3, PostgreSQL, MongoDB, CockroachDB and many more)
|
||||||
|
* [Gitchain](https://github.com/gitchain/gitchain) - Decentralized, peer-to-peer Git repositories aka "Git meets Bitcoin".
|
||||||
|
* [InfluxDB](https://influxdata.com) - Scalable datastore for metrics, events, and real-time analytics.
|
||||||
|
* [ipLocator](https://github.com/AndreasBriese/ipLocator) - A fast ip-geo-location-server using bolt with bloom filters.
|
||||||
|
* [ipxed](https://github.com/kelseyhightower/ipxed) - Web interface and api for ipxed.
|
||||||
* [Ironsmith](https://github.com/timshannon/ironsmith) - A simple, script-driven continuous integration (build - > test -> release) tool, with no external dependencies
|
* [Ironsmith](https://github.com/timshannon/ironsmith) - A simple, script-driven continuous integration (build - > test -> release) tool, with no external dependencies
|
||||||
* [BoltHold](https://github.com/timshannon/bolthold) - An embeddable NoSQL store for Go types built on BoltDB
|
* [Kala](https://github.com/ajvb/kala) - Kala is a modern job scheduler optimized to run on a single node. It is persistent, JSON over HTTP API, ISO 8601 duration notation, and dependent jobs.
|
||||||
* [Ponzu CMS](https://ponzu-cms.org) - Headless CMS + automatic JSON API with auto-HTTPS, HTTP/2 Server Push, and flexible server framework.
|
* [Key Value Access Langusge (KVAL)](https://github.com/kval-access-language) - A proposed grammar for key-value datastores offering a bbolt binding.
|
||||||
|
* [LedisDB](https://github.com/siddontang/ledisdb) - A high performance NoSQL, using Bolt as optional storage.
|
||||||
|
* [lru](https://github.com/crowdriff/lru) - Easy to use Bolt-backed Least-Recently-Used (LRU) read-through cache with chainable remote stores.
|
||||||
|
* [mbuckets](https://github.com/abhigupta912/mbuckets) - A Bolt wrapper that allows easy operations on multi level (nested) buckets.
|
||||||
|
* [MetricBase](https://github.com/msiebuhr/MetricBase) - Single-binary version of Graphite.
|
||||||
|
* [MuLiFS](https://github.com/dankomiocevic/mulifs) - Music Library Filesystem creates a filesystem to organise your music files.
|
||||||
|
* [NATS](https://github.com/nats-io/nats-streaming-server) - NATS Streaming uses bbolt for message and metadata storage.
|
||||||
|
* [Operation Go: A Routine Mission](http://gocode.io) - An online programming game for Golang using Bolt for user accounts and a leaderboard.
|
||||||
|
* [photosite/session](https://godoc.org/bitbucket.org/kardianos/photosite/session) - Sessions for a photo viewing site.
|
||||||
|
* [Prometheus Annotation Server](https://github.com/oliver006/prom_annotation_server) - Annotation server for PromDash & Prometheus service monitoring system.
|
||||||
|
* [reef-pi](https://github.com/reef-pi/reef-pi) - reef-pi is an award winning, modular, DIY reef tank controller using easy to learn electronics based on a Raspberry Pi.
|
||||||
|
* [Request Baskets](https://github.com/darklynx/request-baskets) - A web service to collect arbitrary HTTP requests and inspect them via REST API or simple web UI, similar to [RequestBin](http://requestb.in/) service
|
||||||
|
* [Seaweed File System](https://github.com/chrislusf/seaweedfs) - Highly scalable distributed key~file system with O(1) disk read.
|
||||||
|
* [stow](https://github.com/djherbis/stow) - a persistence manager for objects
|
||||||
|
backed by boltdb.
|
||||||
|
* [Storm](https://github.com/asdine/storm) - Simple and powerful ORM for BoltDB.
|
||||||
|
* [SimpleBolt](https://github.com/xyproto/simplebolt) - A simple way to use BoltDB. Deals mainly with strings.
|
||||||
|
* [Skybox Analytics](https://github.com/skybox/skybox) - A standalone funnel analysis tool for web analytics.
|
||||||
|
* [Scuttlebutt](https://github.com/benbjohnson/scuttlebutt) - Uses Bolt to store and process all Twitter mentions of GitHub projects.
|
||||||
|
* [tentacool](https://github.com/optiflows/tentacool) - REST api server to manage system stuff (IP, DNS, Gateway...) on a linux server.
|
||||||
|
* [torrent](https://github.com/anacrolix/torrent) - Full-featured BitTorrent client package and utilities in Go. BoltDB is a storage backend in development.
|
||||||
|
* [Wiki](https://github.com/peterhellberg/wiki) - A tiny wiki using Goji, BoltDB and Blackfriday.
|
||||||
|
|
||||||
If you are using Bolt in a project please send a pull request to add it to the list.
|
If you are using Bolt in a project please send a pull request to add it to the list.
|
||||||
+1
-4
@@ -1,10 +1,7 @@
|
|||||||
package bolt
|
package bbolt
|
||||||
|
|
||||||
// maxMapSize represents the largest mmap size supported by Bolt.
|
// maxMapSize represents the largest mmap size supported by Bolt.
|
||||||
const maxMapSize = 0x7FFFFFFF // 2GB
|
const maxMapSize = 0x7FFFFFFF // 2GB
|
||||||
|
|
||||||
// maxAllocSize is the size used when creating array pointers.
|
// maxAllocSize is the size used when creating array pointers.
|
||||||
const maxAllocSize = 0xFFFFFFF
|
const maxAllocSize = 0xFFFFFFF
|
||||||
|
|
||||||
// Are unaligned load/stores broken on this arch?
|
|
||||||
var brokenUnaligned = false
|
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package bbolt
|
||||||
|
|
||||||
|
// maxMapSize represents the largest mmap size supported by Bolt.
|
||||||
|
const maxMapSize = 0xFFFFFFFFFFFF // 256TB
|
||||||
|
|
||||||
|
// maxAllocSize is the size used when creating array pointers.
|
||||||
|
const maxAllocSize = 0x7FFFFFFF
|
||||||
+7
@@ -0,0 +1,7 @@
|
|||||||
|
package bbolt
|
||||||
|
|
||||||
|
// maxMapSize represents the largest mmap size supported by Bolt.
|
||||||
|
const maxMapSize = 0x7FFFFFFF // 2GB
|
||||||
|
|
||||||
|
// maxAllocSize is the size used when creating array pointers.
|
||||||
|
const maxAllocSize = 0xFFFFFFF
|
||||||
Generated
Vendored
+1
-4
@@ -1,12 +1,9 @@
|
|||||||
// +build arm64
|
// +build arm64
|
||||||
|
|
||||||
package bolt
|
package bbolt
|
||||||
|
|
||||||
// maxMapSize represents the largest mmap size supported by Bolt.
|
// maxMapSize represents the largest mmap size supported by Bolt.
|
||||||
const maxMapSize = 0xFFFFFFFFFFFF // 256TB
|
const maxMapSize = 0xFFFFFFFFFFFF // 256TB
|
||||||
|
|
||||||
// maxAllocSize is the size used when creating array pointers.
|
// maxAllocSize is the size used when creating array pointers.
|
||||||
const maxAllocSize = 0x7FFFFFFF
|
const maxAllocSize = 0x7FFFFFFF
|
||||||
|
|
||||||
// Are unaligned load/stores broken on this arch?
|
|
||||||
var brokenUnaligned = false
|
|
||||||
Generated
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package bolt
|
package bbolt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// +build mips64 mips64le
|
||||||
|
|
||||||
|
package bbolt
|
||||||
|
|
||||||
|
// maxMapSize represents the largest mmap size supported by Bolt.
|
||||||
|
const maxMapSize = 0x8000000000 // 512GB
|
||||||
|
|
||||||
|
// maxAllocSize is the size used when creating array pointers.
|
||||||
|
const maxAllocSize = 0x7FFFFFFF
|
||||||
+9
@@ -0,0 +1,9 @@
|
|||||||
|
// +build mips mipsle
|
||||||
|
|
||||||
|
package bbolt
|
||||||
|
|
||||||
|
// maxMapSize represents the largest mmap size supported by Bolt.
|
||||||
|
const maxMapSize = 0x40000000 // 1GB
|
||||||
|
|
||||||
|
// maxAllocSize is the size used when creating array pointers.
|
||||||
|
const maxAllocSize = 0xFFFFFFF
|
||||||
Generated
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
|||||||
package bolt
|
package bbolt
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"syscall"
|
"syscall"
|
||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
// +build ppc
|
// +build ppc
|
||||||
|
|
||||||
package bolt
|
package bbolt
|
||||||
|
|
||||||
// maxMapSize represents the largest mmap size supported by Bolt.
|
// maxMapSize represents the largest mmap size supported by Bolt.
|
||||||
const maxMapSize = 0x7FFFFFFF // 2GB
|
const maxMapSize = 0x7FFFFFFF // 2GB
|
||||||
Loaded 100 of 146 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user