added bind to interface
This commit is contained in:
17
main.go
17
main.go
@@ -7,6 +7,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/wercker/journalhook"
|
"github.com/wercker/journalhook"
|
||||||
"gopkg.in/yaml.v2"
|
"gopkg.in/yaml.v2"
|
||||||
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
@@ -30,6 +31,7 @@ type Conf struct {
|
|||||||
UploadInterface string `yaml:"upload_interface"`
|
UploadInterface string `yaml:"upload_interface"`
|
||||||
ThrottlePingThreshold int64 `yaml:"throttle_ping_threshold"`
|
ThrottlePingThreshold int64 `yaml:"throttle_ping_threshold"`
|
||||||
TryRestoringAfter int `yaml:"try_restoring_after"`
|
TryRestoringAfter int `yaml:"try_restoring_after"`
|
||||||
|
PingInterface string `yaml:"ping_interface"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -81,6 +83,21 @@ func doPing(host string, count int, interval time.Duration) (*ping.Statistics, e
|
|||||||
pinger.Timeout = time.Second * time.Duration(count) * 2
|
pinger.Timeout = time.Second * time.Duration(count) * 2
|
||||||
pinger.Count = count
|
pinger.Count = count
|
||||||
pinger.Interval = interval
|
pinger.Interval = interval
|
||||||
|
|
||||||
|
// get interface
|
||||||
|
nif, err := net.InterfaceByName(conf.PingInterface)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
addr, err := nif.Addrs()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
if len(addr) == 0 {
|
||||||
|
return nil, fmt.Errorf("interface %s has no addressed assigned", conf.PingInterface)
|
||||||
|
}
|
||||||
|
pinger.Source = addr[0].(*net.IPNet).IP.String()
|
||||||
|
|
||||||
err = pinger.Run()
|
err = pinger.Run()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
Reference in New Issue
Block a user