-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheck_site_availability.go
49 lines (42 loc) · 1.39 KB
/
check_site_availability.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package varanus
import (
"context"
"github.com/rickb777/date/period"
log "github.com/sirupsen/logrus"
"russt.io/varanus/connectivity_check"
"russt.io/varanus/mail"
)
type PubSubMessage struct {
CheckAttributes connectivity_check.Attributes `json:"attributes"`
}
func CheckSiteAvailability(_ context.Context, message PubSubMessage) error {
expirationAlertPeriod := period.New(0, 0, 7, 0, 0, 0)
parsedAttrs, err := connectivity_check.ValidateAttributes(message.CheckAttributes)
if err != nil {
log.Errorf("Error parsing request attributes!")
panic("Error parsing request attributes. Error: " + err.Error())
}
log.Infof("Validating DNS record for %v", parsedAttrs.UrlString)
err = connectivity_check.CheckDns(parsedAttrs)
if err != nil {
mail.SendAlertEmail(parsedAttrs, err)
return err
}
log.Infof("Checking connectivity to %v", parsedAttrs.UrlString)
err = connectivity_check.CheckConnectivity(parsedAttrs)
if err != nil {
mail.SendAlertEmail(parsedAttrs, err)
log.Infof("Unable to connect to site: %v", parsedAttrs.UrlString)
return err
}
if parsedAttrs.SSL == true {
log.Infof("Checking SSL connection to %v", parsedAttrs.UrlString)
err = connectivity_check.CheckTLSConnection(parsedAttrs, expirationAlertPeriod)
if err != nil {
mail.SendAlertEmail(parsedAttrs, err)
return err
}
}
log.Infof("Successfully connected to '%v'", parsedAttrs.UrlString)
return nil
}