Set timeout and re-dial on any failures.

This commit is contained in:
Bill Thiede 2017-10-10 10:08:00 -07:00
parent a61e9c7e1c
commit 5171c33d3c

View File

@ -151,16 +151,23 @@ func main() {
Auth: ams,
// TODO(wathiede); use FixedHostKey?
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}
c, err := ssh.Dial("tcp", *host, config)
if err != nil {
glog.Exitf("Error dialing %q: %v", *host, err)
Timeout: 5 * time.Second,
}
go func() {
for {
var c *ssh.Client
if c == nil {
var err error
c, err = ssh.Dial("tcp", *host, config)
if err != nil {
glog.Errorf("Error dialing %q: %v", *host, err)
}
}
if err := updateMetrics(c); err != nil {
glog.Errorf("Failed to update metrics: %v", err)
c.Close()
c = nil
}
time.Sleep(*refreshInterval)
}