Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
37db4b2db0 | ||
|
|
41a1dbeceb | ||
|
|
c02d64d674 | ||
|
|
46f4561bea | ||
|
|
a1e0e9698b |
+2
-2
@@ -4,7 +4,7 @@ name: test
|
||||
|
||||
steps:
|
||||
- name: test
|
||||
image: golang:1.17
|
||||
image: golang:1.20
|
||||
environment:
|
||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
||||
commands:
|
||||
@@ -30,7 +30,7 @@ trigger:
|
||||
|
||||
steps:
|
||||
- name: build all binaries
|
||||
image: golang:1.17
|
||||
image: golang:1.20
|
||||
environment:
|
||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
||||
commands:
|
||||
|
||||
+2
-2
@@ -1,11 +1,11 @@
|
||||
ARG REPO=library
|
||||
FROM ${REPO}/alpine:3.12
|
||||
FROM ${REPO}/alpine:3.18
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app/
|
||||
|
||||
# Add common checking tools
|
||||
RUN apk --no-cache add bash=~5.0 curl=~7.79 jq=~1.6
|
||||
RUN apk --no-cache add bash=~5 curl=~8 jq=~1.6 bind-tools~=9
|
||||
|
||||
# Add minitor user for running as non-root
|
||||
RUN addgroup -S minitor && adduser -S minitor -G minitor
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
ARG REPO=library
|
||||
FROM golang:1.17 AS builder
|
||||
FROM golang:1.20 AS builder
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
@@ -14,7 +14,7 @@ ARG VERSION=dev
|
||||
ENV CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH}
|
||||
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o minitor .
|
||||
|
||||
FROM ${REPO}/alpine:3.12
|
||||
FROM ${REPO}/alpine:3.18
|
||||
RUN mkdir /app
|
||||
WORKDIR /app/
|
||||
|
||||
@@ -22,7 +22,7 @@ WORKDIR /app/
|
||||
COPY --from=builder /app/minitor .
|
||||
|
||||
# Add common checking tools
|
||||
RUN apk --no-cache add bash=~5.0 curl=~7.79 jq=~1.6
|
||||
RUN apk --no-cache add bash=~5 curl=~8 jq=~1.6 bind-tools~=9
|
||||
|
||||
# Add minitor user for running as non-root
|
||||
RUN addgroup -S minitor && adduser -S minitor -G minitor
|
||||
|
||||
@@ -94,10 +94,28 @@ Also, when alerts are executed, they will be passed through Go's format function
|
||||
|`{{.AlertCount}}`|Number of times this monitor has alerted|
|
||||
|`{{.FailureCount}}`|The total number of sequential failed checks for this monitor|
|
||||
|`{{.LastCheckOutput}}`|The last returned value from the check command to either stderr or stdout|
|
||||
|`{{.LastSuccess}}`|The ISO datetime of the last successful check|
|
||||
|`{{.LastSuccess}}`|The datetime of the last successful check as a go Time struct|
|
||||
|`{{.MonitorName}}`|The name of the monitor that failed and triggered the alert|
|
||||
|`{{.IsUp}}`|Indicates if the monitor that is alerting is up or not. Can be used in a conditional message template|
|
||||
|
||||
To provide flexible formatting, the following non-standard functions are available in templates:
|
||||
|
||||
|func|description|
|
||||
|---|---|
|
||||
|`ANSIC <Time>`|Formats provided time in ANSIC format|
|
||||
|`UnixDate <Time>`|Formats provided time in UnixDate format|
|
||||
|`RubyDate <Time>`|Formats provided time in RubyDate format|
|
||||
|`RFC822Z <Time>`|Formats provided time in RFC822Z format|
|
||||
|`RFC850 <Time>`|Formats provided time in RFC850 format|
|
||||
|`RFC1123 <Time>`|Formats provided time in RFC1123 format|
|
||||
|`RFC1123Z <Time>`|Formats provided time in RFC1123Z format|
|
||||
|`RFC3339 <Time>`|Formats provided time in RFC3339 format|
|
||||
|`RFC3339Nano <Time>`|Formats provided time in RFC3339Nano format|
|
||||
|`FormatTime <Time> <string template>`|Formats provided time according to provided template|
|
||||
|`InTZ <Time> <string timezone name>`|Converts provided time to parsed timezone from the provided name|
|
||||
|
||||
For more information, check out the [Go documentation for the time module](https://pkg.go.dev/time@go1.20.7#pkg-constants).
|
||||
|
||||
### Metrics
|
||||
|
||||
Minitor supports exporting metrics for [Prometheus](https://prometheus.io/). Prometheus is an open source tool for reading and querying metrics from different sources. Combined with another tool, [Grafana](https://grafana.com/), it allows building of charts and dashboards. You could also opt to just use Minitor to log check results, and instead do your alerting with Grafana.
|
||||
|
||||
@@ -57,6 +57,37 @@ func (alert *Alert) BuildTemplates() error {
|
||||
|
||||
slog.Debugf("Building template for alert %s", alert.Name)
|
||||
|
||||
// Time format func factory
|
||||
tff := func(formatString string) func(time.Time) string {
|
||||
return func(t time.Time) string {
|
||||
return t.Format(formatString)
|
||||
}
|
||||
}
|
||||
|
||||
// Create some functions for formatting datetimes in popular formats
|
||||
timeFormatFuncs := template.FuncMap{
|
||||
"ANSIC": tff(time.ANSIC),
|
||||
"UnixDate": tff(time.UnixDate),
|
||||
"RubyDate": tff(time.RubyDate),
|
||||
"RFC822Z": tff(time.RFC822Z),
|
||||
"RFC850": tff(time.RFC850),
|
||||
"RFC1123": tff(time.RFC1123),
|
||||
"RFC1123Z": tff(time.RFC1123Z),
|
||||
"RFC3339": tff(time.RFC3339),
|
||||
"RFC3339Nano": tff(time.RFC3339Nano),
|
||||
"FormatTime": func(t time.Time, timeFormat string) string {
|
||||
return t.Format(timeFormat)
|
||||
},
|
||||
"InTZ": func(t time.Time, tzName string) (time.Time, error) {
|
||||
tz, err := time.LoadLocation(tzName)
|
||||
if err != nil {
|
||||
return t, fmt.Errorf("failed to convert time to specified tz: %w", err)
|
||||
}
|
||||
|
||||
return t.In(tz), nil
|
||||
},
|
||||
}
|
||||
|
||||
switch {
|
||||
case alert.commandTemplate == nil && alert.Command.Command != nil:
|
||||
alert.commandTemplate = []*template.Template{}
|
||||
@@ -66,7 +97,7 @@ func (alert *Alert) BuildTemplates() error {
|
||||
}
|
||||
|
||||
alert.commandTemplate = append(alert.commandTemplate, template.Must(
|
||||
template.New(alert.Name+fmt.Sprint(i)).Parse(cmdPart),
|
||||
template.New(alert.Name+fmt.Sprint(i)).Funcs(timeFormatFuncs).Parse(cmdPart),
|
||||
))
|
||||
}
|
||||
case alert.commandShellTemplate == nil && alert.Command.ShellCommand != "":
|
||||
@@ -77,7 +108,7 @@ func (alert *Alert) BuildTemplates() error {
|
||||
}
|
||||
|
||||
alert.commandShellTemplate = template.Must(
|
||||
template.New(alert.Name).Parse(shellCmd),
|
||||
template.New(alert.Name).Funcs(timeFormatFuncs).Parse(shellCmd),
|
||||
)
|
||||
default:
|
||||
return fmt.Errorf("No template provided for alert %s: %w", alert.Name, errNoTemplate)
|
||||
@@ -137,7 +168,7 @@ func (alert Alert) Send(notice AlertNotice) (outputStr string, err error) {
|
||||
|
||||
if err != nil {
|
||||
err = fmt.Errorf(
|
||||
"Alert '%s' failed to send. Returned %v: %w",
|
||||
"Alert %s failed to send. Returned %w: %w",
|
||||
alert.Name,
|
||||
err,
|
||||
ErrAlertFailed,
|
||||
|
||||
Reference in New Issue
Block a user