aha
This commit is contained in:
parent
959daf2d22
commit
04d3c2a2e4
19
conf.yaml
19
conf.yaml
|
@ -4,6 +4,11 @@ IDE:
|
||||||
hosts:
|
hosts:
|
||||||
- 172.17.4.30
|
- 172.17.4.30
|
||||||
- 172.17.4.31
|
- 172.17.4.31
|
||||||
|
check:
|
||||||
|
type: http
|
||||||
|
port: 80
|
||||||
|
uri: /
|
||||||
|
method: HEAD
|
||||||
|
|
||||||
PLOOPI:
|
PLOOPI:
|
||||||
tables:
|
tables:
|
||||||
|
@ -11,3 +16,17 @@ PLOOPI:
|
||||||
hosts:
|
hosts:
|
||||||
- 172.17.4.40
|
- 172.17.4.40
|
||||||
- 172.17.4.20
|
- 172.17.4.20
|
||||||
|
check:
|
||||||
|
type: tcp
|
||||||
|
port: 80
|
||||||
|
|
||||||
|
SMTP:
|
||||||
|
tables:
|
||||||
|
- smtp
|
||||||
|
hosts:
|
||||||
|
- 172.17.4.40
|
||||||
|
- 172.17.4.20
|
||||||
|
check:
|
||||||
|
type: smtp
|
||||||
|
port: 25
|
||||||
|
|
||||||
|
|
71
main.go
71
main.go
|
@ -8,39 +8,52 @@ import "log"
|
||||||
import "gopkg.in/yaml.v3"
|
import "gopkg.in/yaml.v3"
|
||||||
import "time"
|
import "time"
|
||||||
|
|
||||||
|
type Check struct {
|
||||||
|
Type string `yaml:"type"`
|
||||||
|
Port int `yaml:"port"`
|
||||||
|
Uri string `yaml:"uri"`
|
||||||
|
Method string `yaml:"method"`
|
||||||
|
}
|
||||||
type Group struct {
|
type Group struct {
|
||||||
Name string `yaml:"group"`
|
Name string `yaml:"group"`
|
||||||
Tables []string `yaml:"tables"`
|
Tables []string `yaml:"tables"`
|
||||||
Hosts []string `yaml:"hosts"`
|
Hosts []string `yaml:"hosts"`
|
||||||
|
Check Check `yaml:"check"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("starting")
|
log.Println("Starting")
|
||||||
|
|
||||||
var conf map[string]Group
|
var conf map[string]Group
|
||||||
yamlFile, err := ioutil.ReadFile("conf.yaml")
|
yamlFile, err := ioutil.ReadFile("conf.yaml")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Printf("Configuration open error #%v ", err)
|
log.Printf("Configuration open error #%v ", err)
|
||||||
}
|
}
|
||||||
err = yaml.Unmarshal(yamlFile, &conf)
|
err = yaml.Unmarshal(yamlFile, &conf)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Configuration read error #%v", err)
|
log.Fatalf("Configuration read error #%v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
for name, group := range conf {
|
for name, group := range conf {
|
||||||
fmt.Println("Checking group", name )
|
|
||||||
for _, host := range group.Hosts {
|
log.Println("Checking group", name, group)
|
||||||
client := &http.Client{
|
go checkGroup(group)
|
||||||
Timeout: time.Second * 5,
|
}
|
||||||
}
|
}
|
||||||
resp, err := client.Head(fmt.Sprintf("http://%s", host))
|
|
||||||
if err != nil {
|
func checkGroup(group Group) {
|
||||||
fmt.Println(host, "Failed")
|
for _, host := range group.Hosts {
|
||||||
} else {
|
client := &http.Client{
|
||||||
_, _ = io.ReadAll(resp.Body)
|
Timeout: time.Second * 5,
|
||||||
resp.Body.Close()
|
}
|
||||||
fmt.Println(host, "Status", resp.StatusCode)
|
resp, err := client.Head(fmt.Sprintf("http://%s", host))
|
||||||
}
|
if err != nil {
|
||||||
}
|
log.Println(host, "Failed")
|
||||||
}
|
} else {
|
||||||
|
_, _ = io.ReadAll(resp.Body)
|
||||||
|
resp.Body.Close()
|
||||||
|
log.Println(host, "Status", resp.StatusCode)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue