ing
This commit is contained in:
parent
4d83529943
commit
900a5c42dd
|
@ -1,15 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
crcrs "git.loafle.net/commons_go/rpc/client/rwc/socket"
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
)
|
||||
|
||||
func New(clientHandler ClientHandler, socketBuilder csc.SocketBuilder) crc.Client {
|
||||
cRWCHandler := crcrs.New(socketBuilder)
|
||||
|
||||
c := crc.New(clientHandler, cRWCHandler)
|
||||
|
||||
return c
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
package client
|
||||
|
||||
import "git.loafle.net/commons_go/rpc/client"
|
||||
|
||||
type ClientHandler interface {
|
||||
client.ClientHandler
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
crc "git.loafle.net/commons_go/rpc/client"
|
||||
"git.loafle.net/commons_go/rpc/protocol/json"
|
||||
crr "git.loafle.net/commons_go/rpc/registry"
|
||||
)
|
||||
|
||||
func NewClientHandler(rpcInvoker crr.RPCInvoker) ClientHandler {
|
||||
ch := &ClientHandlers{}
|
||||
ch.RPCInvoker = rpcInvoker
|
||||
ch.Codec = json.NewClientCodec()
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
type ClientHandlers struct {
|
||||
crc.ClientHandlers
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
)
|
||||
|
||||
func NewSocketBuilder(address string) csc.SocketBuilder {
|
||||
return newSocketBuilder(address)
|
||||
}
|
||||
|
||||
type SocketBuilders struct {
|
||||
csc.SocketBuilders
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) SocketHandler() csc.SocketHandler {
|
||||
return NewSocketHandler()
|
||||
}
|
|
@ -1,13 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
)
|
||||
|
||||
func newSocketBuilder(address string) csc.SocketBuilder {
|
||||
sb := &SocketBuilders{}
|
||||
sb.Network = "unix"
|
||||
sb.Address = address
|
||||
|
||||
return sb
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"net"
|
||||
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
"gopkg.in/natefinch/npipe.v2"
|
||||
)
|
||||
|
||||
func newSocketBuilder(address string) csc.SocketBuilder {
|
||||
sb := &SocketBuilders{}
|
||||
sb.Network = "pipe"
|
||||
sb.Address = address
|
||||
|
||||
return sb
|
||||
}
|
||||
|
||||
func (sb *SocketBuilders) Dial(network, address string) (net.Conn, error) {
|
||||
if 0 == sb.HandshakeTimeout {
|
||||
return npipe.Dial(`\\.\pipe\` + address)
|
||||
}
|
||||
return npipe.DialTimeout(`\\.\pipe\`+address, sb.HandshakeTimeout)
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package client
|
||||
|
||||
import (
|
||||
"log"
|
||||
"net"
|
||||
|
||||
csc "git.loafle.net/commons_go/server/client"
|
||||
)
|
||||
|
||||
type SocketHandlers struct {
|
||||
csc.SocketHandlers
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnConnect(socketContext csc.SocketContext, conn net.Conn) {
|
||||
log.Printf("OnConnect res: %v \n", conn)
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) OnDisconnect(soc csc.Socket) {
|
||||
log.Printf("OnDisconnect \n")
|
||||
}
|
||||
|
||||
func (sh *SocketHandlers) Validate() {
|
||||
sh.SocketHandlers.Validate()
|
||||
}
|
||||
|
||||
func NewSocketHandler() csc.SocketHandler {
|
||||
return &SocketHandlers{}
|
||||
}
|
|
@ -5,9 +5,9 @@ import (
|
|||
)
|
||||
|
||||
type Crawler interface {
|
||||
Init(config *configM.Config) (bool, error)
|
||||
Add(config *configM.Config) (bool, error)
|
||||
Remove(id string) (bool, error)
|
||||
Init(config *configM.Config) error
|
||||
Add(config *configM.Config) error
|
||||
Remove(id string) error
|
||||
Get(id string) (map[string]string, error)
|
||||
|
||||
Name() string
|
||||
|
@ -44,19 +44,19 @@ func (c *Crawlers) PutConfig(id string, config *configM.Config) {
|
|||
c.configs[id] = config
|
||||
}
|
||||
|
||||
func (c *Crawlers) Init(config *configM.Config) (bool, error) {
|
||||
func (c *Crawlers) Init(config *configM.Config) error {
|
||||
c.PutConfig(config.ID.String(), config)
|
||||
return true, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Crawlers) Add(config *configM.Config) (bool, error) {
|
||||
func (c *Crawlers) Add(config *configM.Config) error {
|
||||
c.PutConfig(config.ID.String(), config)
|
||||
return true, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Crawlers) Remove(id string) (bool, error) {
|
||||
func (c *Crawlers) Remove(id string) error {
|
||||
c.RemoveConfig(id)
|
||||
return true, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (c *Crawlers) Get(id string) (map[string]string, error) {
|
||||
|
|
72
crawler/impl/impl.go
Normal file
72
crawler/impl/impl.go
Normal file
|
@ -0,0 +1,72 @@
|
|||
package impl
|
||||
|
||||
import (
|
||||
"git.loafle.net/overflow/overflow_probe_container_network/crawler"
|
||||
activedirectoryH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/activedirectory"
|
||||
cassandraH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/cassandra"
|
||||
dnsH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/dns"
|
||||
ftpH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/ftp"
|
||||
httpH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/http"
|
||||
imapH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/imap"
|
||||
ldapH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/ldap"
|
||||
mongodbH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/mongodb"
|
||||
mysqlH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/mysql"
|
||||
netbiosH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/netbios"
|
||||
oracleH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/oracle"
|
||||
popH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/pop"
|
||||
postgresqlH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/postgresql"
|
||||
redisH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/redis"
|
||||
rmiH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/rmi"
|
||||
smbH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/smb"
|
||||
smtpH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/smtp"
|
||||
snmpV2H "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/snmp/v2"
|
||||
snmpV3H "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/snmp/v3"
|
||||
sqlserverH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/sqlserver"
|
||||
sshH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/ssh"
|
||||
telnetH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/telnet"
|
||||
wmiH "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/health/wmi"
|
||||
"git.loafle.net/overflow/overflow_probe_container_network/crawler/impl/ssh"
|
||||
)
|
||||
|
||||
var crawlers map[string]crawler.Crawler
|
||||
|
||||
func init() {
|
||||
crawlers = make(map[string]crawler.Crawler, 0)
|
||||
|
||||
addCrawler(activedirectoryH.NewCrawler())
|
||||
addCrawler(cassandraH.NewCrawler())
|
||||
addCrawler(dnsH.NewCrawler())
|
||||
addCrawler(ftpH.NewCrawler())
|
||||
addCrawler(httpH.NewCrawler())
|
||||
addCrawler(imapH.NewCrawler())
|
||||
addCrawler(ldapH.NewCrawler())
|
||||
addCrawler(mongodbH.NewCrawler())
|
||||
addCrawler(mysqlH.NewCrawler())
|
||||
addCrawler(netbiosH.NewCrawler())
|
||||
addCrawler(oracleH.NewCrawler())
|
||||
addCrawler(popH.NewCrawler())
|
||||
addCrawler(postgresqlH.NewCrawler())
|
||||
addCrawler(redisH.NewCrawler())
|
||||
addCrawler(rmiH.NewCrawler())
|
||||
addCrawler(smbH.NewCrawler())
|
||||
addCrawler(smtpH.NewCrawler())
|
||||
addCrawler(snmpV2H.NewCrawler())
|
||||
addCrawler(snmpV3H.NewCrawler())
|
||||
addCrawler(sqlserverH.NewCrawler())
|
||||
addCrawler(sshH.NewCrawler())
|
||||
addCrawler(telnetH.NewCrawler())
|
||||
addCrawler(wmiH.NewCrawler())
|
||||
addCrawler(ssh.NewCrawler())
|
||||
}
|
||||
|
||||
func addCrawler(c crawler.Crawler) {
|
||||
crawlers[c.Name()] = c
|
||||
}
|
||||
|
||||
func GetCrawler(name string) crawler.Crawler {
|
||||
c, ok := crawlers[name]
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return c
|
||||
}
|
|
@ -2,25 +2,46 @@ package service
|
|||
|
||||
import (
|
||||
configM "git.loafle.net/overflow/overflow_commons_go/modules/config/model"
|
||||
"git.loafle.net/overflow/overflow_probe_container_network/crawler/impl"
|
||||
)
|
||||
|
||||
type ConfigService struct {
|
||||
}
|
||||
|
||||
func (cs *ConfigService) Add() {
|
||||
|
||||
func (s *ConfigService) Add(crawlerName string, config *configM.Config) error {
|
||||
c := impl.GetCrawler(crawlerName)
|
||||
return c.Add(config)
|
||||
}
|
||||
|
||||
func (cs *ConfigService) Remove() {
|
||||
|
||||
func (s *ConfigService) Remove(crawlerName string, id string) error {
|
||||
c := impl.GetCrawler(crawlerName)
|
||||
return c.Remove(id)
|
||||
}
|
||||
|
||||
func (cs *ConfigService) Init(configs []map[string]configM.Config) bool {
|
||||
func (s *ConfigService) Init(configs []map[string]*configM.Config) error {
|
||||
var err error
|
||||
sensorIDs := make([]map[string]*configM.Config, 0)
|
||||
ok := true
|
||||
Loop:
|
||||
for _, item := range configs {
|
||||
for k, v := range item {
|
||||
|
||||
c := impl.GetCrawler(k)
|
||||
if err = c.Init(v); nil != err {
|
||||
ok = false
|
||||
break Loop
|
||||
}
|
||||
sensorIDs = append(sensorIDs, item)
|
||||
}
|
||||
}
|
||||
|
||||
return true
|
||||
if !ok {
|
||||
for _, item := range sensorIDs {
|
||||
for k, v := range item {
|
||||
s.Remove(k, v.ID.String())
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
package service
|
||||
|
||||
type ContainerService struct {
|
||||
}
|
||||
|
||||
func (cs *ContainerService) Get(crawlerName string, sensorID string) (interface{}, error) {
|
||||
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (cs *ContainerService) State() {
|
||||
|
||||
}
|
11
service/DataService.go
Normal file
11
service/DataService.go
Normal file
|
@ -0,0 +1,11 @@
|
|||
package service
|
||||
|
||||
import "git.loafle.net/overflow/overflow_probe_container_network/crawler/impl"
|
||||
|
||||
type DataService struct {
|
||||
}
|
||||
|
||||
func (s *DataService) Get(crawlerName string, sensorID string) (interface{}, error) {
|
||||
c := impl.GetCrawler(crawlerName)
|
||||
return c.Get(sensorID)
|
||||
}
|
8
service/StateService.go
Normal file
8
service/StateService.go
Normal file
|
@ -0,0 +1,8 @@
|
|||
package service
|
||||
|
||||
type StateService struct {
|
||||
}
|
||||
|
||||
func (s *StateService) State() (bool, error) {
|
||||
return true, nil
|
||||
}
|
|
@ -5,5 +5,7 @@ import (
|
|||
)
|
||||
|
||||
func RegisterRPC(rpcRegistry crr.RPCRegistry) {
|
||||
rpcRegistry.RegisterService(&ContainerService{}, "")
|
||||
rpcRegistry.RegisterService(&ConfigService{}, "")
|
||||
rpcRegistry.RegisterService(&DataService{}, "")
|
||||
rpcRegistry.RegisterService(&StateService{}, "")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user