Write status checker

Signed-off-by: adrien <adrien@iglou.eu>
pull/3/head
adrien 3 years ago
parent 2d5d3552de
commit 4e89c0c2c3
  1. 0
      bin/.keep
  2. 53
      cmd/xavier-srv/main.go
  3. 14
      examples/etc/xavier-srv/check.json
  4. 5
      examples/etc/xavier-srv/check.toml

@ -0,0 +1,53 @@
package main
import (
"fmt"
"errors"
"strconv"
"net/http"
)
func main() {
fmt.Println(cerebro("https://test.iglou.eu", 200))
fmt.Println(cerebro("https://iglou.eu", 200))
fmt.Println(cerebro("https://iglou.eu", 301))
fmt.Println(cerebro("https://git.iglou.eu", 200))
fmt.Println(cerebro("https://media.iglou.eu", 200))
fmt.Println(cerebro("https://51.15.11.133", 200))
}
func httpStatus(url string, need int) (bool, error) {
client := &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}}
resp, err := client.Head(url)
if err == nil {
statusCode := (need == resp.StatusCode)
if statusCode {
return true, nil
} else {
return false, errors.New("Head " + url + ": Response " + strconv.Itoa(resp.StatusCode) + ": Expected status code " + strconv.Itoa(need))
}
}
return false, err
}
func cerebro(url string, need int) (bool) {
xPsyAgatha, err := httpStatus(url, need)
xPsyArthur, _ := httpStatus(url, need)
xPsyDash , _ := httpStatus(url, need)
if (xPsyAgatha && xPsyArthur) ||
(xPsyAgatha && xPsyDash) ||
(xPsyArthur && xPsyDash) {
return true
}
fmt.Println(err)
return false
}

@ -0,0 +1,14 @@
{
"groupe1": {
"try": {
"appName": [301, "https://iglou.eu"]
},
"err": {}
},
"groupe2": {
"try": {
"appName": [200, "https://iglou.eu"]
},
"err": {}
}
}

@ -0,0 +1,5 @@
[app.groupe]
enable = true
ssl_check = true
error = []
server.name = []
Loading…
Cancel
Save