aboutsummaryrefslogtreecommitdiff
path: root/cmd/main/main.go
diff options
context:
space:
mode:
Diffstat (limited to 'cmd/main/main.go')
-rw-r--r--cmd/main/main.go45
1 files changed, 5 insertions, 40 deletions
diff --git a/cmd/main/main.go b/cmd/main/main.go
index aa37a7f..c81a329 100644
--- a/cmd/main/main.go
+++ b/cmd/main/main.go
@@ -1,12 +1,10 @@
package main
import (
- "bytes"
"flag"
"fmt"
"gopkg.in/yaml.v3"
"os"
- "time"
"riedstra.dev/go/checkup"
)
@@ -19,6 +17,7 @@ type Config struct {
CheckCerts map[string]*string `yaml:"CheckCerts"`
ExpectedStatusCode int `yaml:"ExpectedStatusCode"`
StatusChecks map[string]*int `yaml:"StatusChecks"`
+ Workers int `yaml:"Workers"`
}
func ReadConfig(fn string) (*Config, error) {
@@ -56,44 +55,6 @@ func notify(conf *Config, b []byte) {
}
}
-func checkCerts(conf *Config) {
- msg := &bytes.Buffer{}
- for host, port := range conf.CheckCerts {
- if port == nil {
- port = &conf.DefaultCertPort
- }
-
- conn, err := checkup.CertExpiresSoon(
- host,
- *port,
- time.Duration(conf.CertWindow)*time.Hour*24)
- if err != nil {
- fmt.Fprintf(msg, "%s:%s --> %s\n", host, *port, err)
- continue
- }
- conn.Close()
- }
-
- notify(conf, msg.Bytes())
-}
-
-func checkStatus(conf *Config) {
- msg := &bytes.Buffer{}
-
- for url, code := range conf.StatusChecks {
- if code == nil {
- code = &conf.ExpectedStatusCode
- }
- err := checkup.HttpStatusOK(url, *code)
- if err != nil {
- fmt.Fprintf(msg, "Checking: %s, %v\n",
- url, err)
- }
- }
-
- notify(conf, msg.Bytes())
-}
-
func main() {
fl := flag.NewFlagSet("checkup", flag.ExitOnError)
@@ -107,6 +68,10 @@ func main() {
os.Exit(1)
}
+ if conf.Workers == 0 {
+ conf.Workers = 1
+ }
+
checkCerts(conf)
checkStatus(conf)