This commit is contained in:
crusader 2018-05-11 11:44:47 +09:00
parent e107b6b207
commit d178262d08
10 changed files with 57 additions and 38 deletions

View File

@ -25,7 +25,6 @@ type DiscoveryData struct {
Type DiscoveryDataType Type DiscoveryDataType
Result interface{} Result interface{}
Error error Error error
Time util.Timestamp
} }
func (dd *DiscoveryData) Release() { func (dd *DiscoveryData) Release() {
@ -276,7 +275,6 @@ func retainDiscoveryData(discoveryDataType DiscoveryDataType, t util.Timestamp,
} }
discoveryData.Type = discoveryDataType discoveryData.Type = discoveryDataType
discoveryData.Time = t
discoveryData.Result = result discoveryData.Result = result
discoveryData.Error = err discoveryData.Error = err
@ -287,7 +285,6 @@ func releaseDiscoveryData(discoveryData *DiscoveryData) {
discoveryData.Type = DiscoveryDataTypeNone discoveryData.Type = DiscoveryDataTypeNone
discoveryData.Result = nil discoveryData.Result = nil
discoveryData.Error = nil discoveryData.Error = nil
discoveryData.Time = util.Timestamp{}
discoveryDataPool.Put(discoveryData) discoveryDataPool.Put(discoveryData)
} }

View File

@ -8,6 +8,7 @@ import (
logging "git.loafle.net/commons/logging-go" logging "git.loafle.net/commons/logging-go"
occc "git.loafle.net/overflow/commons-go/core/constants" occc "git.loafle.net/overflow/commons-go/core/constants"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
"git.loafle.net/overflow/container_discovery/internal/discoverer" "git.loafle.net/overflow/container_discovery/internal/discoverer"
) )
@ -44,6 +45,7 @@ var (
Host: h, Host: h,
PortType: occc.PortTypeTCP, PortType: occc.PortTypeTCP,
PortNumber: json.Number(strconv.Itoa(80)), PortNumber: json.Number(strconv.Itoa(80)),
DiscoveredDate: occu.NowPtr(),
} }
ds = &ocmd.DiscoverService{ ds = &ocmd.DiscoverService{
IncludeServices: []string{ IncludeServices: []string{

View File

@ -8,11 +8,11 @@ import (
"git.loafle.net/commons/logging-go" "git.loafle.net/commons/logging-go"
"git.loafle.net/commons/util-go/net/cidr" "git.loafle.net/commons/util-go/net/cidr"
"github.com/google/gopacket" occu "git.loafle.net/overflow/commons-go/core/util"
"github.com/google/gopacket/layers"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
"git.loafle.net/overflow/container_discovery/internal/pcap" "git.loafle.net/overflow/container_discovery/internal/pcap"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
) )
func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoverHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) { func ScanHost(zone *ocmd.Zone, dh *ocmd.DiscoverHost, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
@ -145,10 +145,12 @@ func handlePacketARP(zone *ocmd.Zone, hostRanges []net.IP, hosts map[string]*ocm
return nil return nil
} }
h := &ocmd.Host{} h := &ocmd.Host{
h.IPV4 = ip.String() IPV4: ip.String(),
h.Mac = net.HardwareAddr(packet.SourceHwAddress).String() Mac: net.HardwareAddr(packet.SourceHwAddress).String(),
h.Zone = zone Zone: zone,
DiscoveredDate: occu.NowPtr(),
}
hosts[ip.String()] = h hosts[ip.String()] = h

View File

@ -11,6 +11,7 @@ import (
"git.loafle.net/commons/logging-go" "git.loafle.net/commons/logging-go"
occc "git.loafle.net/overflow/commons-go/core/constants" occc "git.loafle.net/overflow/commons-go/core/constants"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
"git.loafle.net/overflow/container_discovery/internal/pcap" "git.loafle.net/overflow/container_discovery/internal/pcap"
@ -142,6 +143,7 @@ func handlePacketTCP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd
p := &ocmd.Port{ p := &ocmd.Port{
PortType: occc.PortTypeTCP, PortType: occc.PortTypeTCP,
PortNumber: json.Number(strconv.Itoa(port)), PortNumber: json.Number(strconv.Itoa(port)),
DiscoveredDate: occu.NowPtr(),
} }
p.Host = host p.Host = host

View File

@ -11,6 +11,7 @@ import (
"git.loafle.net/commons/logging-go" "git.loafle.net/commons/logging-go"
occc "git.loafle.net/overflow/commons-go/core/constants" occc "git.loafle.net/overflow/commons-go/core/constants"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
"git.loafle.net/overflow/container_discovery/internal/pcap" "git.loafle.net/overflow/container_discovery/internal/pcap"
@ -159,6 +160,7 @@ func handlePacketUDP(host *ocmd.Host, dp *ocmd.DiscoverPort, ports map[int]*ocmd
PortType: occc.PortTypeUDP, PortType: occc.PortTypeUDP,
PortNumber: json.Number(strconv.Itoa(port)), PortNumber: json.Number(strconv.Itoa(port)),
UDPLayer: udpLayer, UDPLayer: udpLayer,
DiscoveredDate: occu.NowPtr(),
} }
p.Host = host p.Host = host
ports[port] = p ports[port] = p

View File

@ -5,6 +5,7 @@ import (
cuej "git.loafle.net/commons/util-go/encoding/json" cuej "git.loafle.net/commons/util-go/encoding/json"
occc "git.loafle.net/overflow/commons-go/core/constants" occc "git.loafle.net/overflow/commons-go/core/constants"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
"github.com/google/gopacket/layers" "github.com/google/gopacket/layers"
) )
@ -24,8 +25,9 @@ func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan inte
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber) sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
s := &ocmd.Service{ s := &ocmd.Service{
ServiceName: sName, ServiceName: sName,
DiscoveredDate: occu.NowPtr(),
Port: port,
} }
s.Port = port
resultChan <- s resultChan <- s
} }
} }
@ -36,8 +38,9 @@ func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan inte
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber) sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
s := &ocmd.Service{ s := &ocmd.Service{
ServiceName: sName, ServiceName: sName,
DiscoveredDate: occu.NowPtr(),
Port: port,
} }
s.Port = port
resultChan <- s resultChan <- s
} }
} }

View File

@ -9,6 +9,7 @@ import (
csm "git.loafle.net/commons/service_matcher-go" csm "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"
occc "git.loafle.net/overflow/commons-go/core/constants" occc "git.loafle.net/overflow/commons-go/core/constants"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
"git.loafle.net/overflow/container_discovery/internal/matcher" "git.loafle.net/overflow/container_discovery/internal/matcher"
) )
@ -104,6 +105,7 @@ LOOP:
s = &ocmd.Service{ s = &ocmd.Service{
ServiceName: m.Name(), ServiceName: m.Name(),
CryptoType: occc.ToCryptoType(sc.CryptoType()), CryptoType: occc.ToCryptoType(sc.CryptoType()),
DiscoveredDate: occu.NowPtr(),
} }
break LOOP break LOOP
} }
@ -155,6 +157,7 @@ LOOP:
s = &ocmd.Service{ s = &ocmd.Service{
ServiceName: m.Name(), ServiceName: m.Name(),
CryptoType: occc.ToCryptoType(sc.CryptoType()), CryptoType: occc.ToCryptoType(sc.CryptoType()),
DiscoveredDate: occu.NowPtr(),
} }
break LOOP break LOOP
} }
@ -212,6 +215,7 @@ LOOP:
s = &ocmd.Service{ s = &ocmd.Service{
ServiceName: m.Name(), ServiceName: m.Name(),
CryptoType: occc.ToCryptoType(sc.CryptoType()), CryptoType: occc.ToCryptoType(sc.CryptoType()),
DiscoveredDate: occu.NowPtr(),
} }
break break
} }
@ -225,6 +229,7 @@ LOOP:
s = &ocmd.Service{ s = &ocmd.Service{
ServiceName: m.Name(), ServiceName: m.Name(),
CryptoType: occc.ToCryptoType(sc.CryptoType()), CryptoType: occc.ToCryptoType(sc.CryptoType()),
DiscoveredDate: occu.NowPtr(),
} }
break break
} }

View File

@ -5,6 +5,7 @@ import (
csm "git.loafle.net/commons/service_matcher-go" csm "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"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
"git.loafle.net/overflow/container_discovery/internal/matcher" "git.loafle.net/overflow/container_discovery/internal/matcher"
) )
@ -26,8 +27,10 @@ func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan i
if m.Match(mi, 0, p) { if m.Match(mi, 0, p) {
s := &ocmd.Service{ s := &ocmd.Service{
ServiceName: m.Name(), ServiceName: m.Name(),
Port: port,
DiscoveredDate: occu.NowPtr(),
} }
s.Port = port
resultChan <- s resultChan <- s
return true return true
} }

View File

@ -5,6 +5,7 @@ import (
"regexp" "regexp"
"strings" "strings"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
) )
@ -57,6 +58,7 @@ func scanZone(dz *ocmd.DiscoverZone, resultChan chan interface{}, errChan chan e
Iface: i.Name, Iface: i.Name,
Mac: i.HardwareAddr.String(), Mac: i.HardwareAddr.String(),
IPV4: strings.Split(addr.String(), "/")[0], IPV4: strings.Split(addr.String(), "/")[0],
DiscoveredDate: occu.NowPtr(),
} }
resultChan <- z resultChan <- z

View File

@ -9,6 +9,7 @@ import (
cda "git.loafle.net/commons/di-go/annotation" cda "git.loafle.net/commons/di-go/annotation"
cdr "git.loafle.net/commons/di-go/registry" cdr "git.loafle.net/commons/di-go/registry"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery" ocmd "git.loafle.net/overflow/commons-go/model/discovery"
ocscd "git.loafle.net/overflow/commons-go/service/container/discovery" ocscd "git.loafle.net/overflow/commons-go/service/container/discovery"
ocs "git.loafle.net/overflow/container-go/service" ocs "git.loafle.net/overflow/container-go/service"
@ -131,10 +132,10 @@ func (s *DiscoveryService) handleDiscovery(requesterID string, discoveryFunc fun
switch data.Type { switch data.Type {
case discoverer.DiscoveryDataTypeStart: case discoverer.DiscoveryDataTypeStart:
logging.Logger().Debugf("DiscoveryService.DiscoveryStart") logging.Logger().Debugf("DiscoveryService.DiscoveryStart")
s.ProbeService.Send("DiscoveryService.DiscoveryStart", requesterID, data.Time) s.ProbeService.Send("DiscoveryService.DiscoveryStart", requesterID, occu.Now())
case discoverer.DiscoveryDataTypeStop: case discoverer.DiscoveryDataTypeStop:
logging.Logger().Debugf("DiscoveryService.DiscoveryStop") logging.Logger().Debugf("DiscoveryService.DiscoveryStop")
s.ProbeService.Send("DiscoveryService.DiscoveryStop", requesterID, data.Time) s.ProbeService.Send("DiscoveryService.DiscoveryStop", requesterID, occu.Now())
data.Release() data.Release()
return nil return nil
case discoverer.DiscoveryDataTypeError: case discoverer.DiscoveryDataTypeError: