Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9072d97bb8 | ||
|
|
cdd8a69669 | ||
|
|
3c14a02770 | ||
|
|
328ea83c25 |
+2
-2
@@ -4,7 +4,7 @@ name: test
|
||||
|
||||
steps:
|
||||
- name: test
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
environment:
|
||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
||||
commands:
|
||||
@@ -30,7 +30,7 @@ trigger:
|
||||
|
||||
steps:
|
||||
- name: build all binaries
|
||||
image: golang:1.15
|
||||
image: golang:1.17
|
||||
environment:
|
||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
||||
commands:
|
||||
|
||||
@@ -10,12 +10,15 @@ repos:
|
||||
- id: trailing-whitespace
|
||||
- id: end-of-file-fixer
|
||||
- id: check-merge-conflict
|
||||
- repo: https://github.com/golangci/golangci-lint
|
||||
rev: v1.42.1
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
- repo: git://github.com/dnephin/pre-commit-golang
|
||||
rev: v0.4.0
|
||||
hooks:
|
||||
- id: go-fmt
|
||||
- id: go-imports
|
||||
- id: golangci-lint
|
||||
- repo: https://github.com/hadolint/hadolint
|
||||
rev: v2.4.0
|
||||
hooks:
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
ARG REPO=library
|
||||
FROM golang:1.12-alpine AS builder
|
||||
|
||||
RUN apk add --no-cache git=~2
|
||||
FROM golang:1.17 AS builder
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app
|
||||
|
||||
@@ -36,6 +36,8 @@ func sendAlerts(config *Config, monitor *Monitor, alertNotice *AlertNotice) erro
|
||||
"Received alert, but no alert mechanisms exist. MonitorName=%s IsUp=%t",
|
||||
alertNotice.MonitorName, alertNotice.IsUp,
|
||||
)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
for _, alertName := range alertNames {
|
||||
@@ -66,10 +68,10 @@ func sendAlerts(config *Config, monitor *Monitor, alertNotice *AlertNotice) erro
|
||||
}
|
||||
|
||||
func checkMonitors(config *Config) error {
|
||||
// TODO: Run this in goroutines and capture exceptions
|
||||
for _, monitor := range config.Monitors {
|
||||
if monitor.ShouldCheck() {
|
||||
success, alertNotice := monitor.Check()
|
||||
|
||||
hasAlert := alertNotice != nil
|
||||
|
||||
// Track status metrics
|
||||
@@ -77,7 +79,11 @@ func checkMonitors(config *Config) error {
|
||||
Metrics.CountCheck(monitor.Name, success, monitor.LastCheckMilliseconds(), hasAlert)
|
||||
|
||||
if alertNotice != nil {
|
||||
return sendAlerts(config, monitor, alertNotice)
|
||||
err := sendAlerts(config, monitor, alertNotice)
|
||||
// If there was an error in sending an alert, exit early and bubble it up
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -92,7 +98,7 @@ func main() {
|
||||
flag.BoolVar(&slog.DebugLevel, "debug", false, "Enables debug logs (default: false)")
|
||||
flag.BoolVar(&ExportMetrics, "metrics", false, "Enables prometheus metrics exporting (default: false)")
|
||||
flag.BoolVar(&PyCompat, "py-compat", false, "Enables support for legacy Python Minitor config. Will eventually be removed. (default: false)")
|
||||
flag.IntVar(&MetricsPort, "metrics-port", 8080, "The port that Prometheus metrics should be exported on, if enabled. (default: 8080)")
|
||||
flag.IntVar(&MetricsPort, "metrics-port", MetricsPort, "The port that Prometheus metrics should be exported on, if enabled. (default: 8080)")
|
||||
flag.Parse()
|
||||
|
||||
// Print version if flag is provided
|
||||
@@ -116,9 +122,7 @@ func main() {
|
||||
// Start main loop
|
||||
for {
|
||||
err = checkMonitors(&config)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
slog.OnErrPanicf(err, "Error checking monitors")
|
||||
|
||||
time.Sleep(config.CheckInterval.Value())
|
||||
}
|
||||
|
||||
+9
-9
@@ -16,7 +16,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
{
|
||||
Name: "Success",
|
||||
Command: CommandOrShell{Command: []string{"true"}},
|
||||
},
|
||||
@@ -28,7 +28,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
{
|
||||
Name: "Failure",
|
||||
Command: CommandOrShell{Command: []string{"false"}},
|
||||
AlertAfter: 1,
|
||||
@@ -41,7 +41,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
{
|
||||
Name: "Success",
|
||||
Command: CommandOrShell{Command: []string{"ls"}},
|
||||
alertCount: 1,
|
||||
@@ -54,7 +54,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
{
|
||||
Name: "Failure",
|
||||
Command: CommandOrShell{Command: []string{"false"}},
|
||||
AlertDown: []string{"unknown"},
|
||||
@@ -68,7 +68,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
{
|
||||
Name: "Success",
|
||||
Command: CommandOrShell{Command: []string{"true"}},
|
||||
AlertUp: []string{"unknown"},
|
||||
@@ -82,7 +82,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
{
|
||||
Name: "Failure",
|
||||
Command: CommandOrShell{Command: []string{"false"}},
|
||||
AlertDown: []string{"good"},
|
||||
@@ -90,7 +90,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Alerts: map[string]*Alert{
|
||||
"good": &Alert{
|
||||
"good": {
|
||||
Command: CommandOrShell{Command: []string{"true"}},
|
||||
},
|
||||
},
|
||||
@@ -101,7 +101,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
{
|
||||
config: Config{
|
||||
Monitors: []*Monitor{
|
||||
&Monitor{
|
||||
{
|
||||
Name: "Failure",
|
||||
Command: CommandOrShell{Command: []string{"false"}},
|
||||
AlertDown: []string{"bad"},
|
||||
@@ -109,7 +109,7 @@ func TestCheckMonitors(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Alerts: map[string]*Alert{
|
||||
"bad": &Alert{
|
||||
"bad": {
|
||||
Name: "bad",
|
||||
Command: CommandOrShell{Command: []string{"false"}},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user