2017-11-07 03:00:15 +00:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
cRPC "git.loafle.net/commons_go/rpc"
|
2017-11-17 10:44:09 +00:00
|
|
|
oodamdm "git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
|
2017-11-07 03:00:15 +00:00
|
|
|
"git.loafle.net/overflow/overflow_discovery/client"
|
|
|
|
"git.loafle.net/overflow/overflow_discovery/rpc"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
registry := cRPC.NewRegistry()
|
|
|
|
registry.RegisterService(new(rpc.DiscoveryService), "")
|
|
|
|
|
|
|
|
c := client.New("/tmp/discovery.sock", registry)
|
|
|
|
if err := c.Connect(); nil != err {
|
|
|
|
fmt.Printf("%v", err)
|
|
|
|
}
|
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
dz := newDiscoveryZone(true)
|
|
|
|
if err := c.Notify("DiscoveryService.DiscoverZone", dz); nil != err {
|
2017-11-07 03:00:15 +00:00
|
|
|
fmt.Printf("%v\n", err)
|
|
|
|
}
|
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
}
|
2017-11-07 03:00:15 +00:00
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
func newDiscoveryZone(includeDHost bool) *oodamdm.DiscoveryZone {
|
|
|
|
dz := &oodamdm.DiscoveryZone{
|
|
|
|
ExcludePatterns: []string{},
|
2017-11-07 03:00:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
if includeDHost {
|
|
|
|
dz.DiscoveryHost = newDiscoveryHost(true, nil)
|
|
|
|
}
|
2017-11-07 03:00:15 +00:00
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
return dz
|
2017-11-07 03:00:15 +00:00
|
|
|
}
|
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
func newDiscoveryHost(includeDPort bool, zone *oodamdm.Zone) *oodamdm.DiscoveryHost {
|
|
|
|
dh := &oodamdm.DiscoveryHost{
|
|
|
|
Zone: zone,
|
|
|
|
FirstScanRange: "192.168.1.1",
|
|
|
|
LastScanRange: "192.168.1.254",
|
|
|
|
ExcludeHosts: []string{},
|
|
|
|
}
|
2017-11-07 03:00:15 +00:00
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
if includeDPort {
|
|
|
|
dh.DiscoveryPort = newDiscoveryPort(true, nil)
|
|
|
|
}
|
2017-11-07 03:00:15 +00:00
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
return dh
|
|
|
|
}
|
2017-11-07 03:00:15 +00:00
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
func newDiscoveryPort(includeDService bool, host *oodamdm.Host) *oodamdm.DiscoveryPort {
|
|
|
|
dp := &oodamdm.DiscoveryPort{
|
|
|
|
Host: host,
|
|
|
|
FirstScanRange: 1,
|
|
|
|
LastScanRange: 1024,
|
|
|
|
ExcludePorts: []int{},
|
|
|
|
}
|
2017-11-07 03:00:15 +00:00
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
if includeDService {
|
|
|
|
dp.DiscoveryService = newDiscoveryService(nil)
|
|
|
|
}
|
2017-11-07 03:00:15 +00:00
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
return dp
|
|
|
|
}
|
2017-11-07 03:00:15 +00:00
|
|
|
|
2017-11-17 10:44:09 +00:00
|
|
|
func newDiscoveryService(port *oodamdm.Port) *oodamdm.DiscoveryService {
|
|
|
|
ds := &oodamdm.DiscoveryService{
|
|
|
|
Port: port,
|
|
|
|
IncludeServices: []string{},
|
|
|
|
}
|
|
|
|
return ds
|
|
|
|
}
|