77 lines
1.6 KiB
Go
77 lines
1.6 KiB
Go
package main
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
cRPC "git.loafle.net/commons_go/rpc"
|
|
oodamdm "git.loafle.net/overflow/overflow_discovery/api/module/discovery/model"
|
|
"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)
|
|
}
|
|
|
|
dz := newDiscoveryZone(true)
|
|
if err := c.Notify("DiscoveryService.DiscoverZone", dz); nil != err {
|
|
fmt.Printf("%v\n", err)
|
|
}
|
|
|
|
}
|
|
|
|
func newDiscoveryZone(includeDHost bool) *oodamdm.DiscoveryZone {
|
|
dz := &oodamdm.DiscoveryZone{
|
|
ExcludePatterns: []string{},
|
|
}
|
|
|
|
if includeDHost {
|
|
dz.DiscoveryHost = newDiscoveryHost(true, nil)
|
|
}
|
|
|
|
return dz
|
|
}
|
|
|
|
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{},
|
|
}
|
|
|
|
if includeDPort {
|
|
dh.DiscoveryPort = newDiscoveryPort(true, nil)
|
|
}
|
|
|
|
return dh
|
|
}
|
|
|
|
func newDiscoveryPort(includeDService bool, host *oodamdm.Host) *oodamdm.DiscoveryPort {
|
|
dp := &oodamdm.DiscoveryPort{
|
|
Host: host,
|
|
FirstScanRange: 1,
|
|
LastScanRange: 1024,
|
|
ExcludePorts: []int{},
|
|
}
|
|
|
|
if includeDService {
|
|
dp.DiscoveryService = newDiscoveryService(nil)
|
|
}
|
|
|
|
return dp
|
|
}
|
|
|
|
func newDiscoveryService(port *oodamdm.Port) *oodamdm.DiscoveryService {
|
|
ds := &oodamdm.DiscoveryService{
|
|
Port: port,
|
|
IncludeServices: []string{},
|
|
}
|
|
return ds
|
|
}
|