47 lines
1013 B
Go
47 lines
1013 B
Go
package main
|
|
|
|
import "fmt"
|
|
import "net/http"
|
|
import "io"
|
|
import "io/ioutil"
|
|
import "log"
|
|
import "gopkg.in/yaml.v3"
|
|
import "time"
|
|
|
|
type Group struct {
|
|
Name string `yaml:"group"`
|
|
Tables []string `yaml:"tables"`
|
|
Hosts []string `yaml:"hosts"`
|
|
}
|
|
func main() {
|
|
fmt.Println("starting")
|
|
|
|
var conf map[string]Group
|
|
yamlFile, err := ioutil.ReadFile("conf.yaml")
|
|
if err != nil {
|
|
log.Printf("Configuration open error #%v ", err)
|
|
}
|
|
err = yaml.Unmarshal(yamlFile, &conf)
|
|
if err != nil {
|
|
log.Fatalf("Configuration read error #%v", err)
|
|
}
|
|
|
|
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)
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|