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: tables:
- ide - ide
hosts: hosts:
- 172.17.4.30
- 172.17.4.31
PLOOPI:
tables:
- ploopi
hosts:
- 172.17.4.40
- 172.17.4.20 - 172.17.4.20
- 172.17.4.21

23
main.go
View File

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