probe/ping/service/service.go
crusader 419c5cb6ac ing
2018-09-18 01:25:56 +09:00

29 lines
790 B
Go

package service
import (
omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta"
ounp "git.loafle.net/overflow/util-go/net/ping"
"git.loafle.net/overflow_scanner/probe/ping/service/connection"
"git.loafle.net/overflow_scanner/probe/ping/service/matcher"
)
func Ping(service *omd.Service, pingOption ounp.Option) (ounp.Result, error) {
if isDiscoveredByMatcher(service) {
return matcher.Ping(service, pingOption)
}
return connection.Ping(service, pingOption)
}
func isDiscoveredByMatcher(service *omd.Service) bool {
for _, discoveredBy := range service.DiscoveredBy {
switch omm.ToMetaDiscovererTypeEnum(discoveredBy) {
case omm.MetaDiscovererTypeEnumUDPMatcher, omm.MetaDiscovererTypeEnumTCPMatcher:
return true
}
}
return false
}