fix handling of ping response
Update the code handling sending the ping command to the fail2ban server to correctly handle the response. The response is of type `Tupple`, not `[]string`.
This commit is contained in:
parent
86f8fd2c07
commit
556c09c2f4
@ -1,9 +1,11 @@
|
||||
package socket
|
||||
|
||||
import (
|
||||
"github.com/kisielk/og-rek"
|
||||
"log"
|
||||
"net"
|
||||
|
||||
"github.com/kisielk/og-rek"
|
||||
"github.com/nlpodyssey/gopickle/types"
|
||||
)
|
||||
|
||||
type Fail2BanSocket struct {
|
||||
@ -18,9 +20,7 @@ func MustConnectToSocket(path string) *Fail2BanSocket {
|
||||
}
|
||||
return &Fail2BanSocket{
|
||||
socket: c,
|
||||
encoder: ogórek.NewEncoderWithConfig(c, &ogórek.EncoderConfig{
|
||||
Protocol: 5,
|
||||
}),
|
||||
encoder: ogórek.NewEncoder(c),
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,9 +30,13 @@ func (s *Fail2BanSocket) Ping() bool {
|
||||
log.Printf("server ping failed: %v", err)
|
||||
return false
|
||||
}
|
||||
if v, ok := response.([]string); ok && v[1] == "pong" {
|
||||
return true
|
||||
|
||||
if t, ok := response.(*types.Tuple); ok {
|
||||
if (*t)[1] == "pong" {
|
||||
return true
|
||||
}
|
||||
log.Printf("unexpected response data: %s", t)
|
||||
}
|
||||
log.Printf("unexpected response from server: %v", response)
|
||||
log.Printf("unexpected response format - cannot parse: %v", response)
|
||||
return false
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user