From 900a5c42dda481286e2f148abde81e40002286cf Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 14 Dec 2017 15:17:58 +0900 Subject: [PATCH] ing --- client/client.go | 15 ------- client/client_handler.go | 7 --- client/client_handlers.go | 19 -------- client/socket_builders.go | 17 -------- client/socket_builders_unix.go | 13 ------ client/socket_builders_windows.go | 23 ---------- client/socket_handlers.go | 28 ------------ crawler/crawler.go | 18 ++++---- crawler/impl/impl.go | 72 +++++++++++++++++++++++++++++++ service/ConfigService.go | 35 ++++++++++++--- service/ContainerService.go | 13 ------ service/DataService.go | 11 +++++ service/StateService.go | 8 ++++ service/service.go | 4 +- 14 files changed, 131 insertions(+), 152 deletions(-) delete mode 100644 client/client.go delete mode 100644 client/client_handler.go delete mode 100644 client/client_handlers.go delete mode 100644 client/socket_builders.go delete mode 100644 client/socket_builders_unix.go delete mode 100644 client/socket_builders_windows.go delete mode 100644 client/socket_handlers.go create mode 100644 crawler/impl/impl.go delete mode 100644 service/ContainerService.go create mode 100644 service/DataService.go create mode 100644 service/StateService.go diff --git a/client/client.go b/client/client.go deleted file mode 100644 index c598817..0000000 --- a/client/client.go +++ /dev/null @@ -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 -} diff --git a/client/client_handler.go b/client/client_handler.go deleted file mode 100644 index 7e0ce21..0000000 --- a/client/client_handler.go +++ /dev/null @@ -1,7 +0,0 @@ -package client - -import "git.loafle.net/commons_go/rpc/client" - -type ClientHandler interface { - client.ClientHandler -} diff --git a/client/client_handlers.go b/client/client_handlers.go deleted file mode 100644 index 769379d..0000000 --- a/client/client_handlers.go +++ /dev/null @@ -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 -} diff --git a/client/socket_builders.go b/client/socket_builders.go deleted file mode 100644 index d6292e8..0000000 --- a/client/socket_builders.go +++ /dev/null @@ -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() -} diff --git a/client/socket_builders_unix.go b/client/socket_builders_unix.go deleted file mode 100644 index 0923953..0000000 --- a/client/socket_builders_unix.go +++ /dev/null @@ -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 -} diff --git a/client/socket_builders_windows.go b/client/socket_builders_windows.go deleted file mode 100644 index c8c8dd5..0000000 --- a/client/socket_builders_windows.go +++ /dev/null @@ -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) -} diff --git a/client/socket_handlers.go b/client/socket_handlers.go deleted file mode 100644 index c287ace..0000000 --- a/client/socket_handlers.go +++ /dev/null @@ -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{} -} diff --git a/crawler/crawler.go b/crawler/crawler.go index 4f5bd96..4036e60 100644 --- a/crawler/crawler.go +++ b/crawler/crawler.go @@ -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) { diff --git a/crawler/impl/impl.go b/crawler/impl/impl.go new file mode 100644 index 0000000..4058525 --- /dev/null +++ b/crawler/impl/impl.go @@ -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 +} diff --git a/service/ConfigService.go b/service/ConfigService.go index 58c2c51..fbdff3a 100644 --- a/service/ConfigService.go +++ b/service/ConfigService.go @@ -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 } diff --git a/service/ContainerService.go b/service/ContainerService.go deleted file mode 100644 index 47b07c2..0000000 --- a/service/ContainerService.go +++ /dev/null @@ -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() { - -} diff --git a/service/DataService.go b/service/DataService.go new file mode 100644 index 0000000..b0b7d3c --- /dev/null +++ b/service/DataService.go @@ -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) +} diff --git a/service/StateService.go b/service/StateService.go new file mode 100644 index 0000000..79f2220 --- /dev/null +++ b/service/StateService.go @@ -0,0 +1,8 @@ +package service + +type StateService struct { +} + +func (s *StateService) State() (bool, error) { + return true, nil +} diff --git a/service/service.go b/service/service.go index e402667..c2bba53 100644 --- a/service/service.go +++ b/service/service.go @@ -5,5 +5,7 @@ import ( ) func RegisterRPC(rpcRegistry crr.RPCRegistry) { - rpcRegistry.RegisterService(&ContainerService{}, "") + rpcRegistry.RegisterService(&ConfigService{}, "") + rpcRegistry.RegisterService(&DataService{}, "") + rpcRegistry.RegisterService(&StateService{}, "") }