ing
This commit is contained in:
parent
5089fc2478
commit
a7480afdd5
|
@ -4,6 +4,8 @@ import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"net"
|
"net"
|
||||||
|
"os"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
cnsm "git.loafle.net/commons/service_matcher-go"
|
cnsm "git.loafle.net/commons/service_matcher-go"
|
||||||
cuej "git.loafle.net/commons/util-go/encoding/json"
|
cuej "git.loafle.net/commons/util-go/encoding/json"
|
||||||
|
@ -73,6 +75,21 @@ func (s *SocketHealthCrawler) GetConnection(config *ocmsc.SensorConfig) (net.Con
|
||||||
return conn, nil
|
return conn, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ToSocketErrorEnum(err error) SocketErrorEnum {
|
||||||
|
n, ok := err.(*net.OpError).Err.(*os.SyscallError).Err.(syscall.Errno)
|
||||||
|
if !ok {
|
||||||
|
return SocketErrorEnumUNKNOWN
|
||||||
|
}
|
||||||
|
switch n {
|
||||||
|
case syscall.EHOSTUNREACH:
|
||||||
|
return SocketErrorEnumHOSTUNREACH
|
||||||
|
case syscall.ECONNREFUSED:
|
||||||
|
return SocketErrorEnumCONNREFUSED
|
||||||
|
default:
|
||||||
|
return SocketErrorEnumUNKNOWN
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Duplication Method
|
// Duplication Method
|
||||||
func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig) (map[string]string, error) {
|
func (s *SocketHealthCrawler) CheckHealth(config *ocmsc.SensorConfig) (map[string]string, error) {
|
||||||
result := make(map[string]string, 0)
|
result := make(map[string]string, 0)
|
||||||
|
|
55
crawler/health/socket_error.go
Normal file
55
crawler/health/socket_error.go
Normal file
|
@ -0,0 +1,55 @@
|
||||||
|
package health
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
)
|
||||||
|
|
||||||
|
type SocketErrorEnum int
|
||||||
|
|
||||||
|
const (
|
||||||
|
SocketErrorEnumUNKNOWN SocketErrorEnum = iota + 1
|
||||||
|
SocketErrorEnumHOSTUNREACH
|
||||||
|
SocketErrorEnumCONNREFUSED
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
socketErrorEnumID = map[SocketErrorEnum]string{
|
||||||
|
SocketErrorEnumUNKNOWN: "UNKNOWN",
|
||||||
|
SocketErrorEnumHOSTUNREACH: "HOSTUNREACH",
|
||||||
|
SocketErrorEnumCONNREFUSED: "CONNREFUSED",
|
||||||
|
}
|
||||||
|
|
||||||
|
socketErrorEnumKey = map[string]SocketErrorEnum{
|
||||||
|
"UNKNOWN": SocketErrorEnumUNKNOWN,
|
||||||
|
"HOSTUNREACH": SocketErrorEnumHOSTUNREACH,
|
||||||
|
"CONNREFUSED": SocketErrorEnumCONNREFUSED,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
func (e SocketErrorEnum) String() string {
|
||||||
|
return socketErrorEnumID[e]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e SocketErrorEnum) MarshalJSON() ([]byte, error) {
|
||||||
|
value, ok := socketErrorEnumID[e]
|
||||||
|
if !ok {
|
||||||
|
return nil, fmt.Errorf("Invalid EnumType[%s] value", e)
|
||||||
|
}
|
||||||
|
return json.Marshal(value)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (e SocketErrorEnum) UnmarshalJSON(b []byte) error {
|
||||||
|
var s string
|
||||||
|
err := json.Unmarshal(b, &s)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
value, ok := socketErrorEnumKey[s]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("Invalid EnumType[%s] value", s)
|
||||||
|
}
|
||||||
|
e = value
|
||||||
|
return nil
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user