mirror of
https://github.com/TwiN/gatus.git
synced 2024-11-21 15:33:17 +01:00
Add support for environment variables in configuration file
This commit is contained in:
parent
753435dc37
commit
c90ca8fa85
@ -13,4 +13,4 @@ COPY --from=builder /app/static static/
|
||||
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/ca-certificates.crt
|
||||
ENV PORT=8080
|
||||
EXPOSE ${PORT}
|
||||
ENTRYPOINT ["/gatus"]
|
||||
ENTRYPOINT ["/gatus"]
|
@ -17,13 +17,15 @@ services:
|
||||
url: https://twinnation.org/actuator/health
|
||||
interval: 15s # Duration to wait between every status check (opt. default: 10s)
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
- name: github
|
||||
url: https://api.github.com/healthz
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
```
|
||||
|
||||
Note that you can also add environment variables in the your configuration file (i.e. `$DOMAIN`, `${DOMAIN}`)
|
||||
|
||||
|
||||
## Docker
|
||||
|
||||
|
@ -4,8 +4,8 @@ services:
|
||||
url: https://twinnation.org/actuator/health
|
||||
interval: 15s
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
- name: github
|
||||
url: https://api.github.com/healthz
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
@ -64,6 +64,9 @@ func readConfigurationFile(fileName string) (config *Config, err error) {
|
||||
}
|
||||
|
||||
func parseAndValidateConfigBytes(yamlBytes []byte) (config *Config, err error) {
|
||||
// Expand environment variables
|
||||
yamlBytes = []byte(os.ExpandEnv(string(yamlBytes)))
|
||||
// Parse configuration file
|
||||
err = yaml.Unmarshal(yamlBytes, &config)
|
||||
// Check if the configuration file at least has services.
|
||||
if config == nil || len(config.Services) == 0 {
|
||||
|
@ -13,12 +13,12 @@ services:
|
||||
url: https://twinnation.org/actuator/health
|
||||
interval: 15s
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
- name: github
|
||||
url: https://api.github.com/healthz
|
||||
conditions:
|
||||
- "$STATUS != 400"
|
||||
- "$STATUS != 500"
|
||||
- "[STATUS] != 400"
|
||||
- "[STATUS] != 500"
|
||||
`))
|
||||
if err != nil {
|
||||
t.Error("No error should've been returned")
|
||||
@ -53,7 +53,7 @@ services:
|
||||
- name: twinnation
|
||||
url: https://twinnation.org/actuator/health
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
`))
|
||||
if err != nil {
|
||||
t.Error("No error should've been returned")
|
||||
@ -76,7 +76,7 @@ services:
|
||||
- name: twinnation
|
||||
url: https://twinnation.org/actuator/health
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
`))
|
||||
if err != nil {
|
||||
t.Error("No error should've been returned")
|
||||
|
@ -140,9 +140,9 @@ func sanitizeAndResolve(list []string, result *Result) []string {
|
||||
for _, element := range list {
|
||||
element = strings.TrimSpace(element)
|
||||
switch strings.ToUpper(element) {
|
||||
case "$STATUS":
|
||||
case "[STATUS]":
|
||||
element = strconv.Itoa(result.HttpStatus)
|
||||
case "$IP":
|
||||
case "[IP]":
|
||||
element = result.Ip
|
||||
default:
|
||||
}
|
||||
|
@ -5,7 +5,7 @@ import (
|
||||
)
|
||||
|
||||
func TestEvaluateWithIp(t *testing.T) {
|
||||
condition := Condition("$IP == 127.0.0.1")
|
||||
condition := Condition("[IP] == 127.0.0.1")
|
||||
result := &Result{Ip: "127.0.0.1"}
|
||||
condition.Evaluate(result)
|
||||
if !result.ConditionResults[0].Success {
|
||||
@ -14,7 +14,7 @@ func TestEvaluateWithIp(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEvaluateWithStatus(t *testing.T) {
|
||||
condition := Condition("$STATUS == 201")
|
||||
condition := Condition("[STATUS] == 201")
|
||||
result := &Result{HttpStatus: 201}
|
||||
condition.Evaluate(result)
|
||||
if !result.ConditionResults[0].Success {
|
||||
@ -23,7 +23,7 @@ func TestEvaluateWithStatus(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestEvaluateWithFailure(t *testing.T) {
|
||||
condition := Condition("$STATUS == 200")
|
||||
condition := Condition("[STATUS] == 200")
|
||||
result := &Result{HttpStatus: 500}
|
||||
condition.Evaluate(result)
|
||||
if result.ConditionResults[0].Success {
|
||||
@ -32,7 +32,7 @@ func TestEvaluateWithFailure(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIntegrationEvaluateConditions(t *testing.T) {
|
||||
condition := Condition("$STATUS == 200")
|
||||
condition := Condition("[STATUS] == 200")
|
||||
service := Service{
|
||||
Name: "GitHub",
|
||||
Url: "https://api.github.com/healthz",
|
||||
@ -48,7 +48,7 @@ func TestIntegrationEvaluateConditions(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestIntegrationEvaluateConditionsWithFailure(t *testing.T) {
|
||||
condition := Condition("$STATUS == 500")
|
||||
condition := Condition("[STATUS] == 500")
|
||||
service := Service{
|
||||
Name: "GitHub",
|
||||
Url: "https://api.github.com/healthz",
|
||||
|
@ -4,12 +4,12 @@ services:
|
||||
url: https://twinnation.org/actuator/health
|
||||
interval: 10s
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
- name: GitHub
|
||||
url: https://api.github.com/healthz
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
- name: Example
|
||||
url: https://example.com/
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
@ -3,4 +3,4 @@ services:
|
||||
url: http://example.org
|
||||
interval: 30s
|
||||
conditions:
|
||||
- "$STATUS == 200"
|
||||
- "[STATUS] == 200"
|
||||
|
Loading…
Reference in New Issue
Block a user