This commit is contained in:
crusader 2018-09-13 20:05:03 +09:00
parent ec0e83e38b
commit 4868d241cc

View File

@ -36,6 +36,9 @@ type DiscoverySession interface {
DiscoverService() *omd.DiscoverService DiscoverService() *omd.DiscoverService
TargetHosts() []net.IP TargetHosts() []net.IP
IsTargetHost(host *omd.Host) bool
IsTargetPort(port *omd.Port) bool
IsTargetService(service *omd.Service) bool
SetDiscoveryDelegator(chan<- interface{}) SetDiscoveryDelegator(chan<- interface{})
@ -232,6 +235,52 @@ func (ds *ofDiscoverySession) TargetHosts() []net.IP {
return ds.targetHosts return ds.targetHosts
} }
func (ds *ofDiscoverySession) IsTargetHost(host *omd.Host) bool {
for _, targetHost := range ds.targetHosts {
if targetHost.String() == host.Address {
return true
}
}
return false
}
func (ds *ofDiscoverySession) IsTargetPort(port *omd.Port) bool {
if nil == ds.discoverPort {
return false
}
portNumber, err := ouej.NumberToInt(port.PortNumber)
if nil != err {
return false
}
if !ds.IsTargetHost(port.Host) {
return false
}
if nil != ds.discoverPort.ExcludePorts {
for _, exPortNumber := range ds.discoverPort.ExcludePorts {
if portNumber == exPortNumber {
return false
}
}
}
if portNumber < ds.discoverPort.FirstScanRange || portNumber > ds.discoverPort.LastScanRange {
return false
}
return true
}
func (ds *ofDiscoverySession) IsTargetService(service *omd.Service) bool {
if nil == ds.discoverService {
return false
}
return true
}
func (ds *ofDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host { func (ds *ofDiscoverySession) AddHost(discoveredBy string, host *omd.Host, meta map[string]string) *omd.Host {
ds.discoveredMtx.Lock() ds.discoveredMtx.Lock()
defer ds.discoveredMtx.Unlock() defer ds.discoveredMtx.Unlock()
@ -468,6 +517,23 @@ func (ds *ofDiscoverySession) StopChan() <-chan struct{} {
} }
func (ds *ofDiscoverySession) delegate(data interface{}) { func (ds *ofDiscoverySession) delegate(data interface{}) {
switch v := data.(type) {
case *omd.Host:
if !ds.IsTargetHost(v) {
return
}
case *omd.Port:
if !ds.IsTargetPort(v) {
return
}
case *omd.Service:
if !ds.IsTargetService(v) {
return
}
default:
return
}
if nil != ds.discoveryDelegator { if nil != ds.discoveryDelegator {
ds.discoveryDelegator <- data ds.discoveryDelegator <- data
} }