probe/ping/service/service.go

29 lines
790 B
Go
Raw Normal View History

2018-09-17 14:18:49 +00:00
package service
import (
omd "git.loafle.net/overflow/model/discovery"
2018-09-17 16:25:56 +00:00
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"
2018-09-17 14:18:49 +00:00
)
2018-09-17 16:25:56 +00:00
func Ping(service *omd.Service, pingOption ounp.Option) (ounp.Result, error) {
if isDiscoveredByMatcher(service) {
return matcher.Ping(service, pingOption)
}
2018-09-17 14:18:49 +00:00
2018-09-17 16:25:56 +00:00
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
2018-09-17 14:18:49 +00:00
}