diff --git a/Dockerfile b/Dockerfile index 900dfe79..ac7e1dce 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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"] \ No newline at end of file diff --git a/README.md b/README.md index 2ff4aeb6..4b4db5a1 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/config.yaml b/config.yaml index c86d1bd7..8d9e7efc 100644 --- a/config.yaml +++ b/config.yaml @@ -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" \ No newline at end of file + - "[STATUS] == 200" \ No newline at end of file diff --git a/config/config.go b/config/config.go index cb0a533c..7a2b5202 100644 --- a/config/config.go +++ b/config/config.go @@ -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 { diff --git a/config/config_test.go b/config/config_test.go index 2210aa23..c8f5cc25 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -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") diff --git a/core/types.go b/core/types.go index c471127d..f5726981 100644 --- a/core/types.go +++ b/core/types.go @@ -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: } diff --git a/core/types_test.go b/core/types_test.go index 7ba711a3..9ad1f61b 100644 --- a/core/types_test.go +++ b/core/types_test.go @@ -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", diff --git a/example/docker-compose-grafana-prometheus/config.yaml b/example/docker-compose-grafana-prometheus/config.yaml index 9006721c..4f43281b 100644 --- a/example/docker-compose-grafana-prometheus/config.yaml +++ b/example/docker-compose-grafana-prometheus/config.yaml @@ -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" \ No newline at end of file + - "[STATUS] == 200" \ No newline at end of file diff --git a/example/minimal/config.yaml b/example/minimal/config.yaml index d5eacd80..431be6aa 100644 --- a/example/minimal/config.yaml +++ b/example/minimal/config.yaml @@ -3,4 +3,4 @@ services: url: http://example.org interval: 30s conditions: - - "$STATUS == 200" + - "[STATUS] == 200"