Write status checker

Signed-off-by: adrien <adrien@iglou.eu>
This commit is contained in:
adrien 2019-11-19 18:29:30 +01:00
parent 2d5d3552de
commit 4e89c0c2c3
4 changed files with 72 additions and 0 deletions

0
bin/.keep Normal file
View File

53
cmd/xavier-srv/main.go Normal file
View File

@ -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
}

View File

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

View File

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