Compare commits
11 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5f6c924089 | ||
|
|
e614fb35b5 | ||
|
|
3323a562c9 | ||
|
|
c40841ef61 | ||
|
|
59ce31c35f | ||
|
|
39359ffb1e | ||
|
|
7d92458a7a | ||
|
|
723cf7d127 | ||
|
|
fd8e81cb1a | ||
|
|
0e291719c9 | ||
|
|
884fbaceac |
+86
-39
@@ -1,53 +1,100 @@
|
||||
---
|
||||
kind: pipeline
|
||||
type: kubernetes
|
||||
name: default
|
||||
name: test
|
||||
|
||||
node_selector:
|
||||
zone: dev
|
||||
steps:
|
||||
- name: test
|
||||
image: golang:1.26
|
||||
environment:
|
||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
||||
commands:
|
||||
- make test
|
||||
|
||||
- name: check
|
||||
image: iamthefij/drone-pre-commit:personal
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: publish
|
||||
|
||||
depends_on:
|
||||
- test
|
||||
|
||||
trigger:
|
||||
event:
|
||||
- push
|
||||
- tag
|
||||
|
||||
workspace:
|
||||
path: /drone/src
|
||||
refs:
|
||||
- refs/heads/master
|
||||
- refs/tags/v*
|
||||
|
||||
steps:
|
||||
- name: pull image to dockerhub
|
||||
image: docker.io/owncloudci/drone-docker-buildx:4
|
||||
privileged: true
|
||||
settings:
|
||||
cache-from: [ "safebox/minitor" ]
|
||||
repo: safebox/minitor
|
||||
tags: latest
|
||||
username:
|
||||
from_secret: dockerhub-username
|
||||
password:
|
||||
from_secret: dockerhub-password
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
when:
|
||||
event:
|
||||
- tag
|
||||
- name: build all binaries
|
||||
image: golang:1.26
|
||||
environment:
|
||||
VERSION: ${DRONE_TAG:-${DRONE_COMMIT}}
|
||||
commands:
|
||||
- make all
|
||||
|
||||
- name: build multiarch from dev
|
||||
image: docker.io/owncloudci/drone-docker-buildx:4
|
||||
privileged: true
|
||||
- name: compress binaries for release
|
||||
image: ubuntu
|
||||
commands:
|
||||
- find ./dist -type f -executable -execdir tar -czvf {}.tar.gz {} \;
|
||||
when:
|
||||
event: tag
|
||||
|
||||
- name: upload gitea release
|
||||
image: plugins/gitea-release
|
||||
settings:
|
||||
cache-from: [ "registry.dev.format.hu/minitor" ]
|
||||
registry: registry.dev.format.hu
|
||||
repo: registry.dev.format.hu/minitor
|
||||
tags: latest
|
||||
dockerfile: Dockerfile
|
||||
username:
|
||||
from_secret: dev-hu-registry-username
|
||||
password:
|
||||
from_secret: dev-hu-registry-password
|
||||
title: ${DRONE_TAG}
|
||||
files: dist/*.tar.gz
|
||||
checksum:
|
||||
- md5
|
||||
- sha1
|
||||
- sha256
|
||||
- sha512
|
||||
base_url:
|
||||
from_secret: gitea_base_url
|
||||
api_key:
|
||||
from_secret: gitea_token
|
||||
when:
|
||||
event: tag
|
||||
|
||||
- name: Build and publish docker images
|
||||
image: thegeeklab/drone-docker-buildx
|
||||
settings:
|
||||
repo: iamthefij/minitor-go
|
||||
auto_tag: true
|
||||
platforms:
|
||||
- linux/amd64
|
||||
- linux/arm64
|
||||
when:
|
||||
event:
|
||||
- push
|
||||
- linux/arm
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
|
||||
---
|
||||
kind: pipeline
|
||||
name: notify
|
||||
|
||||
depends_on:
|
||||
- test
|
||||
- publish
|
||||
|
||||
trigger:
|
||||
status:
|
||||
- failure
|
||||
|
||||
steps:
|
||||
|
||||
- name: notify
|
||||
image: drillster/drone-email
|
||||
settings:
|
||||
host:
|
||||
from_secret: SMTP_HOST # pragma: whitelist secret
|
||||
username:
|
||||
from_secret: SMTP_USER # pragma: whitelist secret
|
||||
password:
|
||||
from_secret: SMTP_PASS # pragma: whitelist secret
|
||||
from: drone@iamthefij.com
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
name: ci
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- main
|
||||
tags:
|
||||
- "v*"
|
||||
pull_request:
|
||||
branches:
|
||||
- main
|
||||
|
||||
jobs:
|
||||
tests:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v6
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
|
||||
- name: Run tests
|
||||
run: make test
|
||||
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v6
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v6
|
||||
|
||||
- name: Run pre-commit
|
||||
uses: https://git.iamthefij.com/iamthefij/pre-commit-action@v3.1.0
|
||||
|
||||
release:
|
||||
runs-on: ubuntu-latest
|
||||
needs: test
|
||||
if: "${{ github.event_name != 'pull_request' }}"
|
||||
steps:
|
||||
- uses: actions/checkout@v6
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v6
|
||||
with:
|
||||
go-version-file: go.mod
|
||||
|
||||
- name: Build binaries
|
||||
env:
|
||||
VERSION: "${{ github.REF_NAME }}"
|
||||
run: make all
|
||||
|
||||
# Package binaries and create release if this is a tagged build
|
||||
- name: Compress binaries
|
||||
if: "${{ github.ref_type == 'tag' }}"
|
||||
run: find ./dist -type f -executable -execdir tar -czvf {}.tar.gz {} \;
|
||||
|
||||
- name: Upload release
|
||||
uses: https://gitea.com/actions/gitea-release-action@v1
|
||||
if: "${{ github.ref_type == 'tag' }}"
|
||||
with:
|
||||
files: |-
|
||||
dist/*.tar.gz
|
||||
md5sum: true
|
||||
sha256sum: true
|
||||
|
||||
- name: Docker meta
|
||||
id: meta
|
||||
uses: docker/metadata-action@v5
|
||||
with:
|
||||
# list of Docker images to use as base name for tags
|
||||
images: |
|
||||
${{ github.REPOSITORY }}
|
||||
# generate Docker tags based on the following events/attributes
|
||||
tags: |
|
||||
type=ref,event=branch
|
||||
type=ref,event=pr
|
||||
type=semver,pattern={{version}}
|
||||
type=semver,pattern={{major}}.{{minor}}
|
||||
type=semver,pattern={{major}}
|
||||
|
||||
- name: Login to Docker Hub
|
||||
uses: docker/login-action@v3
|
||||
if: "${{ github.event_name != 'pull_request' }}"
|
||||
with:
|
||||
username: ${{ secrets.DOCKER_USERNAME }}
|
||||
password: ${{ secrets.DOCKER_PASSWORD }}
|
||||
|
||||
- name: Set up QEMU
|
||||
uses: docker/setup-qemu-action@v3
|
||||
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v3
|
||||
|
||||
- name: Build and push
|
||||
uses: docker/build-push-action@v6
|
||||
with:
|
||||
# Use path context so we can access pre-compiled binaries
|
||||
context: .
|
||||
push: ${{ github.event_name != 'pull_request' }}
|
||||
platforms: |
|
||||
linux/amd64
|
||||
linux/arm64
|
||||
linux/arm/v7
|
||||
tags: ${{ steps.meta.outputs.tags }}
|
||||
labels: ${{ steps.meta.outputs.labels }}
|
||||
+9
-27
@@ -1,52 +1,34 @@
|
||||
version: "2"
|
||||
linters:
|
||||
enable:
|
||||
- errcheck
|
||||
- errname
|
||||
- errorlint
|
||||
- exhaustive
|
||||
- goprintffuncname
|
||||
- gosec
|
||||
- govet
|
||||
- ineffassign
|
||||
- misspell
|
||||
- mnd
|
||||
- tagliatelle
|
||||
- modernize
|
||||
- staticcheck
|
||||
- tagalign
|
||||
- testpackage
|
||||
- thelper
|
||||
- tparallel
|
||||
- unconvert
|
||||
- unused
|
||||
- wrapcheck
|
||||
- wsl
|
||||
disable:
|
||||
- gochecknoglobals
|
||||
settings:
|
||||
gosec:
|
||||
excludes:
|
||||
- G204
|
||||
tagliatelle:
|
||||
case:
|
||||
rules:
|
||||
json: snake
|
||||
yaml: snake
|
||||
- wsl_v5
|
||||
exclusions:
|
||||
generated: lax
|
||||
presets:
|
||||
- comments
|
||||
- common-false-positives
|
||||
- legacy
|
||||
- std-error-handling
|
||||
rules:
|
||||
- linters:
|
||||
- gosec
|
||||
path: _test\.go
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
formatters:
|
||||
enable:
|
||||
- gofumpt
|
||||
- goimports
|
||||
exclusions:
|
||||
generated: lax
|
||||
paths:
|
||||
- third_party$
|
||||
- builtin$
|
||||
- examples$
|
||||
|
||||
@@ -11,7 +11,7 @@ repos:
|
||||
- id: end-of-file-fixer
|
||||
- id: check-merge-conflict
|
||||
- repo: https://github.com/golangci/golangci-lint
|
||||
rev: v2.7.2
|
||||
rev: v2.10.1
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
- repo: https://github.com/hadolint/hadolint
|
||||
|
||||
+6
-111
@@ -1,117 +1,8 @@
|
||||
FROM golang:1.25 AS gomail-builder
|
||||
ARG TARGETARCH=amd64
|
||||
ARG TARGETOS=linux
|
||||
WORKDIR /gomail
|
||||
RUN { \
|
||||
echo 'package main'; \
|
||||
echo ''; \
|
||||
echo 'import ('; \
|
||||
echo ' "fmt"'; \
|
||||
echo ' "io"'; \
|
||||
echo ' "net/mail"'; \
|
||||
echo ' "net/smtp"'; \
|
||||
echo ' "os"'; \
|
||||
echo ' "strings"'; \
|
||||
echo ')'; \
|
||||
echo ''; \
|
||||
echo 'func main() {'; \
|
||||
echo ' readHeaders := strings.Contains(strings.Join(os.Args[1:], " "), "-t")'; \
|
||||
echo ' recipients := []string{}'; \
|
||||
echo ' for _, arg := range os.Args[1:] {'; \
|
||||
echo ' if !strings.HasPrefix(arg, "-") {'; \
|
||||
echo ' recipients = append(recipients, arg)'; \
|
||||
echo ' }'; \
|
||||
echo ' }'; \
|
||||
echo ''; \
|
||||
echo ' body, err := io.ReadAll(os.Stdin)'; \
|
||||
echo ' if err != nil {'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, err)'; \
|
||||
echo ' os.Exit(1)'; \
|
||||
echo ' }'; \
|
||||
echo ''; \
|
||||
echo ' if readHeaders {'; \
|
||||
echo ' msg, parseErr := mail.ReadMessage(strings.NewReader(string(body)))'; \
|
||||
echo ' if parseErr != nil {'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, parseErr)'; \
|
||||
echo ' os.Exit(1)'; \
|
||||
echo ' }'; \
|
||||
echo ' for _, hdr := range []string{"To", "Cc", "Bcc"} {'; \
|
||||
echo ' if val := msg.Header.Get(hdr); val != "" {'; \
|
||||
echo ' addrs, addrErr := mail.ParseAddressList(val)'; \
|
||||
echo ' if addrErr != nil {'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, addrErr)'; \
|
||||
echo ' os.Exit(1)'; \
|
||||
echo ' }'; \
|
||||
echo ' for _, addr := range addrs {'; \
|
||||
echo ' recipients = append(recipients, addr.Address)'; \
|
||||
echo ' }'; \
|
||||
echo ' }'; \
|
||||
echo ' }'; \
|
||||
echo ' }'; \
|
||||
echo ''; \
|
||||
echo ' if len(recipients) == 0 {'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, "usage: sendmail [-t] recipient...")'; \
|
||||
echo ' os.Exit(1)'; \
|
||||
echo ' }'; \
|
||||
echo ''; \
|
||||
echo ' relay := os.Getenv("SMTP_RELAY")'; \
|
||||
echo ' if relay == "" {'; \
|
||||
echo ' relay = "172.17.0.2"'; \
|
||||
echo ' }'; \
|
||||
echo ''; \
|
||||
echo ' port := os.Getenv("SMTP_PORT")'; \
|
||||
echo ' if port == "" {'; \
|
||||
echo ' port = "25"'; \
|
||||
echo ' }'; \
|
||||
echo ''; \
|
||||
echo ' sender := os.Getenv("EMAIL_FROM")'; \
|
||||
echo ' if sender == "" {'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, "[sendmail] EMAIL_FROM is not set, skipping")'; \
|
||||
echo ' os.Exit(0)'; \
|
||||
echo ' }'; \
|
||||
echo ''; \
|
||||
echo ' debug := os.Getenv("DEBUG") != ""'; \
|
||||
echo ' if debug {'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, fmt.Sprintf("[sendmail] relay=%s port=%s sender=%s recipients=%v", relay, port, sender, recipients))'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, "[sendmail] body:")'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, string(body))'; \
|
||||
echo ' }'; \
|
||||
echo ''; \
|
||||
echo ' if err = smtp.SendMail(relay+":"+port, nil, sender, recipients, body); err != nil {'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, err)'; \
|
||||
echo ' os.Exit(1)'; \
|
||||
echo ' }'; \
|
||||
echo ' if debug {'; \
|
||||
echo ' fmt.Fprintln(os.Stderr, "[sendmail] sent successfully")'; \
|
||||
echo ' }'; \
|
||||
echo '}'; \
|
||||
} > main.go
|
||||
RUN go mod init gomail && \
|
||||
CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -o /usr/local/bin/sendmail .
|
||||
|
||||
|
||||
FROM golang:1.25 AS builder
|
||||
WORKDIR /app
|
||||
COPY ./go.mod ./go.sum /app/
|
||||
RUN go mod download
|
||||
COPY ./*.go /app/
|
||||
RUN rm -f /app/gomail.go
|
||||
|
||||
ARG TARGETARCH=amd64
|
||||
ARG TARGETOS=linux
|
||||
ARG VERSION=dev
|
||||
RUN CGO_ENABLED=0 GOOS=${TARGETOS} GOARCH=${TARGETARCH} go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o minitor .
|
||||
|
||||
FROM alpine:3.23
|
||||
|
||||
RUN mkdir /app
|
||||
WORKDIR /app/
|
||||
|
||||
# Copy minitor in
|
||||
COPY --from=builder /app/minitor .
|
||||
|
||||
# Copy sendmail (gomail) in
|
||||
COPY --from=gomail-builder /usr/local/bin/sendmail /usr/local/bin/sendmail
|
||||
|
||||
# Add common checking tools
|
||||
# hadolint ignore=DL3018
|
||||
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata
|
||||
@@ -121,9 +12,13 @@ RUN addgroup -S minitor && adduser -S minitor -G minitor
|
||||
|
||||
# Copy scripts
|
||||
COPY ./scripts /app/scripts
|
||||
COPY default_config.hcl /app/config.hcl
|
||||
RUN chmod -R 755 /app/scripts
|
||||
|
||||
# Copy minitor in
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
COPY ./dist/minitor-${TARGETOS}-${TARGETARCH} ./minitor
|
||||
|
||||
# Drop to non-root user
|
||||
USER minitor
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
FROM golang:1.26 AS builder
|
||||
|
||||
WORKDIR /app
|
||||
|
||||
COPY ./go.mod ./go.sum /app/
|
||||
RUN go mod download
|
||||
|
||||
COPY ./*.go /app/
|
||||
|
||||
ARG TARGETOS
|
||||
ARG TARGETARCH
|
||||
ARG VERSION=dev
|
||||
ENV CGO_ENABLED=0 GOOS=$TARGETOS GOARCH=${TARGETARCH}
|
||||
RUN go build -ldflags "-X main.version=${VERSION}" -a -installsuffix nocgo -o minitor .
|
||||
|
||||
FROM alpine:3.23
|
||||
RUN mkdir /app
|
||||
WORKDIR /app/
|
||||
|
||||
# Copy minitor in
|
||||
COPY --from=builder /app/minitor .
|
||||
|
||||
# Add common checking tools
|
||||
# hadolint ignore=DL3018
|
||||
RUN apk --no-cache add bash=~5 curl=~8 jq=~1 bind-tools=~9 tzdata
|
||||
|
||||
# Add minitor user for running as non-root
|
||||
RUN addgroup -S minitor && adduser -S minitor -G minitor
|
||||
|
||||
# Copy scripts
|
||||
COPY ./scripts /app/scripts
|
||||
RUN chmod -R 755 /app/scripts
|
||||
|
||||
# Drop to non-root user
|
||||
USER minitor
|
||||
|
||||
ENTRYPOINT [ "./minitor" ]
|
||||
|
||||
# vim: set filetype=dockerfile:
|
||||
@@ -8,7 +8,7 @@ import (
|
||||
"text/template"
|
||||
"time"
|
||||
|
||||
"git.iamthefij.com/iamthefij/slog"
|
||||
"git.iamthefij.com/iamthefij/slog/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -22,7 +22,6 @@ func TestAlertValidate(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -77,7 +76,6 @@ func TestAlertSend(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -123,7 +121,6 @@ func TestAlertBuildTemplate(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -5,7 +5,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"git.iamthefij.com/iamthefij/slog"
|
||||
"git.iamthefij.com/iamthefij/slog/v2"
|
||||
"github.com/hashicorp/hcl/v2/hclsimple"
|
||||
)
|
||||
|
||||
|
||||
+2
-4
@@ -24,7 +24,6 @@ func TestLoadConfig(t *testing.T) {
|
||||
{"./test/valid-config.hcl", nil, "Valid config file"},
|
||||
}
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -51,7 +50,7 @@ func TestDefaultConfig(t *testing.T) {
|
||||
m.Config{
|
||||
CheckInterval: 1 * time.Second,
|
||||
DefaultAlertAfter: 2,
|
||||
DefaultAlertEvery: Ptr(0),
|
||||
DefaultAlertEvery: new(0),
|
||||
DefaultAlertDown: []string{"log_command"},
|
||||
},
|
||||
"override defaults",
|
||||
@@ -61,7 +60,7 @@ func TestDefaultConfig(t *testing.T) {
|
||||
m.Config{
|
||||
CheckInterval: 30 * time.Second,
|
||||
DefaultAlertAfter: 1,
|
||||
DefaultAlertEvery: Ptr(-1),
|
||||
DefaultAlertEvery: new(-1),
|
||||
DefaultAlertDown: []string{},
|
||||
},
|
||||
"default defaults",
|
||||
@@ -69,7 +68,6 @@ func TestDefaultConfig(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -1,29 +0,0 @@
|
||||
check_interval = "1s"
|
||||
|
||||
monitor "mdstat_raid" {
|
||||
command = [
|
||||
"sh",
|
||||
"-c",
|
||||
"grep -q '\\[U_\\|_U\\]' /host_proc/mdstat && exit 1 || exit 0"
|
||||
]
|
||||
check_interval = "30s"
|
||||
alert_after = 1
|
||||
alert_every = 0
|
||||
|
||||
alert_down = ["email_alert"]
|
||||
alert_up = ["email_recovery"]
|
||||
}
|
||||
alert "email_alert" {
|
||||
command = [
|
||||
"sh",
|
||||
"-c",
|
||||
"EMAIL=$EMAIL_RECIPIENT; printf 'Subject: RAID ALERT\nTo: %s\n\nRAID degraded\n' \"$EMAIL\" | /usr/local/bin/sendmail -t || true"
|
||||
]
|
||||
}
|
||||
alert "email_recovery" {
|
||||
command = [
|
||||
"sh",
|
||||
"-c",
|
||||
"EMAIL=$EMAIL_RECIPIENT; printf 'Subject: RAID ALERT\nTo: %s\n\nRAID clean\n' \"$EMAIL\" | /usr/local/bin/sendmail -t || true"
|
||||
]
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
module git.iamthefij.com/iamthefij/minitor-go/v2
|
||||
|
||||
go 1.25.0
|
||||
go 1.26.0
|
||||
|
||||
require (
|
||||
git.iamthefij.com/iamthefij/slog v1.3.0
|
||||
git.iamthefij.com/iamthefij/slog/v2 v2.0.1
|
||||
github.com/hashicorp/hcl/v2 v2.11.1
|
||||
github.com/prometheus/client_golang v1.23.2
|
||||
)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
git.iamthefij.com/iamthefij/slog v1.3.0 h1:4Hu5PQvDrW5e3FrTS3q2iIXW0iPvhNY/9qJsqDR3K3I=
|
||||
git.iamthefij.com/iamthefij/slog v1.3.0/go.mod h1:1RUj4hcCompZkAxXCRfUX786tb3cM/Zpkn97dGfUfbg=
|
||||
git.iamthefij.com/iamthefij/slog/v2 v2.0.1 h1:eXf3ga0aMTkm0l6EMYOQpg34S+dQw7cN8o+W1Cg/0C0=
|
||||
git.iamthefij.com/iamthefij/slog/v2 v2.0.1/go.mod h1:VFjX1e1tfHADyQr2wJBAz0JUQT+K/5FBjzSHgUKOuu8=
|
||||
github.com/agext/levenshtein v1.2.1 h1:QmvMAjj2aEICytGiWzmxoE0x2KZvE0fvmqMOfy2tjT8=
|
||||
github.com/agext/levenshtein v1.2.1/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558=
|
||||
github.com/apparentlymart/go-dump v0.0.0-20180507223929-23540a00eaa3/go.mod h1:oL81AME2rN47vu18xqj1S1jPIPuN7afo62yKTNn3XMM=
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"git.iamthefij.com/iamthefij/slog"
|
||||
"git.iamthefij.com/iamthefij/slog/v2"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -6,10 +6,6 @@ import (
|
||||
m "git.iamthefij.com/iamthefij/minitor-go/v2"
|
||||
)
|
||||
|
||||
func Ptr[T any](v T) *T {
|
||||
return &v
|
||||
}
|
||||
|
||||
// TestCheckConfig tests the checkConfig function
|
||||
// It also tests results for potentially invalid configuration. For example, no alerts
|
||||
func TestCheckMonitors(t *testing.T) {
|
||||
@@ -91,7 +87,6 @@ func TestCheckMonitors(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -171,7 +166,6 @@ func TestFirstRunAlerts(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ import (
|
||||
"os/exec"
|
||||
"time"
|
||||
|
||||
"git.iamthefij.com/iamthefij/slog"
|
||||
"git.iamthefij.com/iamthefij/slog/v2"
|
||||
)
|
||||
|
||||
// Monitor represents a particular periodic check of a command
|
||||
|
||||
+3
-8
@@ -25,7 +25,6 @@ func TestMonitorValidate(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -103,7 +102,6 @@ func TestMonitorGetAlertNames(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -175,7 +173,6 @@ func TestMonitorFailureAlertAfter(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -204,15 +201,14 @@ func TestMonitorFailureAlertEvery(t *testing.T) {
|
||||
}{
|
||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1}, []bool{true}, "No AlertEvery set"}, // Defaults to true because AlertAfter and AlertEvery default to nil
|
||||
// Alert first time only, after 1
|
||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: Ptr(0)}, []bool{true, false, false}, "Alert first time only after 1"},
|
||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: new(0)}, []bool{true, false, false}, "Alert first time only after 1"},
|
||||
// Alert every time, after 1
|
||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: Ptr(1)}, []bool{true, true, true}, "Alert every time after 1"},
|
||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: new(1)}, []bool{true, true, true}, "Alert every time after 1"},
|
||||
// Alert every other time, after 1
|
||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: Ptr(2)}, []bool{true, false, true, false}, "Alert every other time after 1"},
|
||||
{m.Monitor{ShellCommand: "false", AlertAfter: 1, AlertEvery: new(2)}, []bool{true, false, true, false}, "Alert every other time after 1"},
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -301,7 +297,6 @@ func TestMonitorCheck(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(c.name, func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
@@ -24,7 +24,6 @@ func TestUtilEqualSliceString(t *testing.T) {
|
||||
}
|
||||
|
||||
for _, c := range cases {
|
||||
c := c
|
||||
|
||||
t.Run(fmt.Sprintf("%v %v", c.a, c.b), func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
Reference in New Issue
Block a user