ben c'est pas fini mais c'est déjà pas mal

This commit is contained in:
laurentu 2023-08-11 16:03:51 +02:00
parent f707380387
commit 205ea46163
2 changed files with 24 additions and 8 deletions

View File

@ -2,5 +2,12 @@ IDE:
tables:
- ide
hosts:
- 172.17.4.30
- 172.17.4.31
PLOOPI:
tables:
- ploopi
hosts:
- 172.17.4.40
- 172.17.4.20
- 172.17.4.21

23
main.go
View File

@ -6,6 +6,7 @@ import "io"
import "io/ioutil"
import "log"
import "gopkg.in/yaml.v3"
import "time"
type Group struct {
Name string `yaml:"group"`
@ -25,13 +26,21 @@ func main() {
log.Fatalf("Configuration read error #%v", err)
}
resp, err := http.Head("http://example.com")
if err != nil {
fmt.Println("Failed")
} else {
_, _ = io.ReadAll(resp.Body)
resp.Body.Close()
fmt.Println("status", resp.StatusCode)
for name, group := range conf {
fmt.Println("Checking group", name )
for _, host := range group.Hosts {
client := &http.Client{
Timeout: time.Second * 5,
}
resp, err := client.Head(fmt.Sprintf("http://%s", host))
if err != nil {
fmt.Println(host, "Failed")
} else {
_, _ = io.ReadAll(resp.Body)
resp.Body.Close()
fmt.Println(host, "Status", resp.StatusCode)
}
}
}
}