added command for pfctl and flag for lauching hostchecker
This commit is contained in:
parent
351e6fe67c
commit
acba43fdae
|
@ -12,6 +12,8 @@ import "os/signal"
|
||||||
import "os"
|
import "os"
|
||||||
import "errors"
|
import "errors"
|
||||||
import "net"
|
import "net"
|
||||||
|
import "os/exec"
|
||||||
|
import "flag"
|
||||||
|
|
||||||
type Check struct {
|
type Check struct {
|
||||||
Type string `yaml:"type"`
|
Type string `yaml:"type"`
|
||||||
|
@ -34,10 +36,13 @@ type Group struct {
|
||||||
func main() {
|
func main() {
|
||||||
log.Println("Starting")
|
log.Println("Starting")
|
||||||
|
|
||||||
|
confFileName := flag.String("f", "/usr/local/etc/hostchecker.yaml", "YAML configuration file")
|
||||||
|
flag.Parse()
|
||||||
|
|
||||||
var waitGroup sync.WaitGroup
|
var waitGroup sync.WaitGroup
|
||||||
|
|
||||||
var conf map[string]Group
|
var conf map[string]Group
|
||||||
yamlFile, err := ioutil.ReadFile("conf.yaml")
|
yamlFile, err := ioutil.ReadFile(*confFileName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Configuration open error #%v ", err)
|
log.Fatalf("Configuration open error #%v ", err)
|
||||||
}
|
}
|
||||||
|
@ -92,11 +97,7 @@ func checkGroup(name string, group Group, waitGroup *sync.WaitGroup, stopChannel
|
||||||
break
|
break
|
||||||
case status := <-channel:
|
case status := <-channel:
|
||||||
log.Println("Status for ", host, "is", status, "in group", name)
|
log.Println("Status for ", host, "is", status, "in group", name)
|
||||||
if status == 0 {
|
updateTables( host, status, group.Tables )
|
||||||
addHostToTables( host, group.Tables )
|
|
||||||
} else {
|
|
||||||
removeHostFromTables( host, group.Tables)
|
|
||||||
}
|
|
||||||
default:
|
default:
|
||||||
time.Sleep(100 * time.Millisecond)
|
time.Sleep(100 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
@ -105,10 +106,20 @@ func checkGroup(name string, group Group, waitGroup *sync.WaitGroup, stopChannel
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func addHostToTables( host string, tables []string ) {
|
func updateTables( host string, status int, tables []string ) {
|
||||||
}
|
for _, table := range tables {
|
||||||
func removeHostFromTables( host string, tables []string ) {
|
op := "add"
|
||||||
|
if status != 0 {
|
||||||
|
op = "del"
|
||||||
|
}
|
||||||
|
cmd := exec.Command("pfctl", "-t", table, "-T", op, host)
|
||||||
|
err := cmd.Run()
|
||||||
|
if err != nil {
|
||||||
|
log.Println("Unable to run command #", cmd)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func checkHost(status chan<- int, group string, host string, check Check, waitGroup *sync.WaitGroup, stopChannel chan bool) {
|
func checkHost(status chan<- int, group string, host string, check Check, waitGroup *sync.WaitGroup, stopChannel chan bool) {
|
||||||
|
|
||||||
var lastCheck time.Time
|
var lastCheck time.Time
|
||||||
|
|
Loading…
Reference in New Issue