ipc_client/main.go

78 lines
1.5 KiB
Go
Raw Normal View History

2017-11-07 03:00:15 +00:00
package main
import (
"fmt"
2017-11-29 05:47:10 +00:00
"time"
2017-11-07 03:00:15 +00:00
cRPC "git.loafle.net/commons_go/rpc"
2017-11-29 05:47:10 +00:00
"git.loafle.net/overflow/ipc_client/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"
)
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)
2017-11-29 05:47:10 +00:00
if err := c.Send("DiscoveryService.DiscoverZone", dz); nil != err {
2017-11-07 03:00:15 +00:00
fmt.Printf("%v\n", err)
}
2017-11-29 05:47:10 +00:00
time.Sleep(1 * time.Minute)
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 {
2017-11-29 05:47:10 +00:00
dz.DiscoveryHost = newDiscoveryHost(true)
2017-11-17 10:44:09 +00:00
}
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-29 05:47:10 +00:00
func newDiscoveryHost(includeDPort bool) *oodamdm.DiscoveryHost {
2017-11-17 10:44:09 +00:00
dh := &oodamdm.DiscoveryHost{
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 {
2017-11-29 05:47:10 +00:00
dh.DiscoveryPort = newDiscoveryPort(true)
2017-11-17 10:44:09 +00:00
}
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-29 05:47:10 +00:00
func newDiscoveryPort(includeDService bool) *oodamdm.DiscoveryPort {
2017-11-17 10:44:09 +00:00
dp := &oodamdm.DiscoveryPort{
FirstScanRange: 1,
LastScanRange: 1024,
ExcludePorts: []int{},
2017-11-29 05:47:10 +00:00
IncludeTCP: true,
IncludeUDP: true,
2017-11-17 10:44:09 +00:00
}
2017-11-07 03:00:15 +00:00
2017-11-17 10:44:09 +00:00
if includeDService {
2017-11-29 05:47:10 +00:00
dp.DiscoveryService = newDiscoveryService()
2017-11-17 10:44:09 +00:00
}
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-29 05:47:10 +00:00
func newDiscoveryService() *oodamdm.DiscoveryService {
2017-11-17 10:44:09 +00:00
ds := &oodamdm.DiscoveryService{
IncludeServices: []string{},
}
return ds
}