feat: publish standalone worker
Separate worker packaging and service lifecycle from the control plane.
Этот коммит содержится в:
79
checks/cssl/cssl.go
Обычный файл
79
checks/cssl/cssl.go
Обычный файл
@@ -0,0 +1,79 @@
|
||||
// Package cssl provides functionality.
|
||||
package cssl
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/pkg/errors"
|
||||
|
||||
"rsgit.ru/rsmon/rsmon/app/models"
|
||||
)
|
||||
|
||||
var client *http.Client
|
||||
|
||||
func init() {
|
||||
client = &http.Client{
|
||||
Timeout: time.Second * 60,
|
||||
CheckRedirect: func(_ *http.Request, _ []*http.Request) error {
|
||||
return http.ErrUseLastResponse
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
// Perform provides functionality.
|
||||
func Perform(c *models.Check) *Result {
|
||||
result := &Result{}
|
||||
result.State = "OK"
|
||||
|
||||
var ur string
|
||||
if c.URL != nil && *c.URL != "" {
|
||||
ur = *c.URL
|
||||
|
||||
u, err := url.Parse(ur)
|
||||
if err != nil {
|
||||
result.State = "FAIL"
|
||||
result.Error = errors.Wrap(err, "bad url")
|
||||
return result
|
||||
}
|
||||
u.Scheme = "https"
|
||||
ur = u.String()
|
||||
} else {
|
||||
ur = "https://" + c.Monitor.Host
|
||||
}
|
||||
log.Println("URL:", ur)
|
||||
reqest, err := http.NewRequest("GET", ur, http.NoBody)
|
||||
if err != nil {
|
||||
result.State = "FAIL"
|
||||
result.Error = err
|
||||
return result
|
||||
}
|
||||
|
||||
reqest.Header.Set("Cache-Control", "max-age=0")
|
||||
reqest.Header.Set("Connection", "close")
|
||||
resp, err := client.Do(reqest)
|
||||
if err != nil {
|
||||
result.State = "ERR"
|
||||
result.Error = errors.Wrap(err, "https request error")
|
||||
return result
|
||||
}
|
||||
defer resp.Body.Close() //nolint:errcheck
|
||||
|
||||
if resp.TLS == nil {
|
||||
result.State = "ERR"
|
||||
result.Error = errors.New("bad SSL cert CN")
|
||||
} else {
|
||||
cert := resp.TLS.VerifiedChains[0][0]
|
||||
result.Expires = &cert.NotAfter
|
||||
exp := time.Until(*result.Expires).Hours() / 24
|
||||
|
||||
if exp < 2 {
|
||||
result.State = "WARN"
|
||||
result.Warnings = append(result.Warnings, "Certificate expires soon")
|
||||
}
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
10
checks/cssl/result.go
Обычный файл
10
checks/cssl/result.go
Обычный файл
@@ -0,0 +1,10 @@
|
||||
package cssl
|
||||
|
||||
import (
|
||||
"rsgit.ru/rsmon/rsmon/internal/checkresult"
|
||||
)
|
||||
|
||||
// Result is a result of a check
|
||||
type Result struct {
|
||||
checkresult.CheckResult
|
||||
}
|
||||
Ссылка в новой задаче
Block a user