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"
|
||||
"github.com/wercker/journalhook"
|
||||
"gopkg.in/yaml.v2"
|
||||
"net"
|
||||
"os"
|
||||
"os/exec"
|
||||
"os/signal"
|
||||
@@ -30,6 +31,7 @@ type Conf struct {
|
||||
UploadInterface string `yaml:"upload_interface"`
|
||||
ThrottlePingThreshold int64 `yaml:"throttle_ping_threshold"`
|
||||
TryRestoringAfter int `yaml:"try_restoring_after"`
|
||||
PingInterface string `yaml:"ping_interface"`
|
||||
}
|
||||
|
||||
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.Count = count
|
||||
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()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
|
Reference in New Issue
Block a user