Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
8071b4bab0
173
dh.json
Normal file
173
dh.json
Normal file
@ -0,0 +1,173 @@
|
|||||||
|
{"hosts": [{
|
||||||
|
"firstScanRange": 1,
|
||||||
|
"lastScanRange": 10000,
|
||||||
|
"name": "",
|
||||||
|
"ip": 3232235818,
|
||||||
|
"mac": 91754662925,
|
||||||
|
"os":"Windows",
|
||||||
|
"ports": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "SSH",
|
||||||
|
"target":true
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 22
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "HTTP"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 443
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "HTTP"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 80
|
||||||
|
}],
|
||||||
|
"createDate": 1498470178000,
|
||||||
|
"updateDate": 1498470178000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"firstScanRange": 1,
|
||||||
|
"lastScanRange": 10000,
|
||||||
|
"name": "",
|
||||||
|
"ip": 3232235781,
|
||||||
|
"mac": 91754660625,
|
||||||
|
"os":"Windows",
|
||||||
|
"ports": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "SSH"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 22
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "HTTP"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 80
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "HTTP"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 1936
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": null,
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 443
|
||||||
|
}],
|
||||||
|
"createDate": 1498470178000,
|
||||||
|
"updateDate": 1498470178000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"firstScanRange": 1,
|
||||||
|
"lastScanRange": 10000,
|
||||||
|
"name": "",
|
||||||
|
"ip": 3232235797,
|
||||||
|
"mac": 91754662913,
|
||||||
|
"os":"Windows",
|
||||||
|
"target":true,
|
||||||
|
"ports": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "HTTP"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 80
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "SSH"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 22
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "HTTP"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 3343
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"services": [{
|
||||||
|
"createDate": -62135596800000,
|
||||||
|
"updateDate": -62135596800000,
|
||||||
|
"portType": "TCP",
|
||||||
|
"serviceName": "HTTP"
|
||||||
|
}],
|
||||||
|
"portType": "TCP",
|
||||||
|
"portNumber": 443
|
||||||
|
}],
|
||||||
|
"createDate": 1498470178000,
|
||||||
|
"updateDate": 1498470178000
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"firstScanRange": 1,
|
||||||
|
"lastScanRange": 10000,
|
||||||
|
"name": "",
|
||||||
|
"ip": 3232235877,
|
||||||
|
"mac": 75361038758387,
|
||||||
|
"os":"Windows",
|
||||||
|
"ports": null,
|
||||||
|
"createDate": 1498470179000,
|
||||||
|
"updateDate": 1498470179000
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
]}
|
@ -9,16 +9,10 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/crawler"
|
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/crawlerInputItem"
|
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/crawlerinputitemmapping"
|
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/member"
|
"git.loafle.net/overflow/overflow_service/proxy/member"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/noauthprobe"
|
"git.loafle.net/overflow/overflow_service/proxy/noauthprobe"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/sensor"
|
"git.loafle.net/overflow/overflow_service/proxy/sensor"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/sensorItem"
|
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/sensorItemCategory"
|
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/sensorItemMapping"
|
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/target"
|
"git.loafle.net/overflow/overflow_service/proxy/target"
|
||||||
//"google.golang.org/grpc/metadata"
|
//"google.golang.org/grpc/metadata"
|
||||||
)
|
)
|
||||||
@ -41,19 +35,11 @@ func InitServices() {
|
|||||||
g_services = make(map[string]interface{}, 0)
|
g_services = make(map[string]interface{}, 0)
|
||||||
|
|
||||||
// proxy services save
|
// proxy services save
|
||||||
//AddServices("Probe", probe.NewProbeService())
|
|
||||||
AddServices("Member", member.NewMemberService())
|
AddServices("Member", member.NewMemberService())
|
||||||
AddServices("NoAuthProbe", noauthprobe.NewNoAuthProbeService())
|
AddServices("NoAuthProbe", noauthprobe.NewNoAuthProbeService())
|
||||||
AddServices("Probe", probe.NewProbeService())
|
AddServices("Probe", probe.NewProbeService())
|
||||||
AddServices("Target", target.NewTargetService())
|
AddServices("Target", target.NewTargetService())
|
||||||
AddServices("Crawler", crawler.NewCrawlerService())
|
|
||||||
AddServices("CrawlerInputItem", crawlerInputItem.NewCrawlerInputItemService())
|
|
||||||
AddServices("CrawlerInputItemMapping", crawlerinputitemmapping.NewCrawlerInputItemMappingService())
|
|
||||||
AddServices("Sensor", sensor.NewSensorService())
|
AddServices("Sensor", sensor.NewSensorService())
|
||||||
AddServices("SensorItem", sensorItem.NewSensorItemService())
|
|
||||||
AddServices("SensorItemCategory", sensorItemCategory.NewSensorItemCategoryService())
|
|
||||||
AddServices("SensorItemMapping", sensorItemMapping.NewSensorItemMappingService())
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type ServiceImpl struct {
|
type ServiceImpl struct {
|
||||||
|
@ -1,59 +0,0 @@
|
|||||||
package crawler
|
|
||||||
|
|
||||||
//
|
|
||||||
//import (
|
|
||||||
// "encoding/json"
|
|
||||||
// "git.loafle.net/overflow/commons_go/model/timestamp"
|
|
||||||
// //"git.loafle.net/overflow/overflow_service/proxy"
|
|
||||||
// "git.loafle.net/overflow/overflow_service/proxy/utils"
|
|
||||||
//)
|
|
||||||
//
|
|
||||||
//type CrawlerService struct {
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func NewCrawlerService() *CrawlerService {
|
|
||||||
// return &CrawlerService{}
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//type Crawler struct {
|
|
||||||
// Id json.Number `json:"id,Number,omitempty"`
|
|
||||||
// Name string `json:"name,omitempty"`
|
|
||||||
// Description string `json:"description,omitempty"`
|
|
||||||
// CrawlerType string `json:"crawlerType,omitempty"`
|
|
||||||
// CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//func (c *CrawlerService)List() (string, error) {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// //out := proxy.InvokeDB("crawler", "findAll", nil)
|
|
||||||
//
|
|
||||||
// out, err := utils.InvokeDB("crawler", "findAll", nil)
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return out, nil
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//func (c *CrawlerService)Create(ct * Crawler) (string, error) {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// out, err := utils.InvokeDB("crawler", "create", ct)
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// return out, nil
|
|
||||||
//}
|
|
@ -1,15 +0,0 @@
|
|||||||
package crawler
|
|
||||||
|
|
||||||
//
|
|
||||||
//import "testing"
|
|
||||||
//
|
|
||||||
//func TestList(t *testing.T) {
|
|
||||||
//
|
|
||||||
// cs := NewCrawlerService()
|
|
||||||
//
|
|
||||||
// out := cs.List()
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// t.Log(out)
|
|
||||||
//
|
|
||||||
//}
|
|
@ -1,38 +0,0 @@
|
|||||||
package crawlerInputItem
|
|
||||||
|
|
||||||
//import (
|
|
||||||
// "git.loafle.net/overflow/commons_go/model/timestamp"
|
|
||||||
// "encoding/json"
|
|
||||||
// "git.loafle.net/overflow/overflow_service/proxy/utils"
|
|
||||||
//)
|
|
||||||
//
|
|
||||||
//type CrawlerInputItem struct {
|
|
||||||
// Id json.Number `json:"id,Number,omitempty"`
|
|
||||||
// Name string `json:"name,omitempty"`
|
|
||||||
// Description string `json:"description,omitempty"`
|
|
||||||
// DataType string `json:"dataType,omitempty"`
|
|
||||||
// CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//type CrawlerInputItemSerivce struct {
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func NewCrawlerInputItemService() *CrawlerInputItemSerivce {
|
|
||||||
// return &CrawlerInputItemSerivce{}
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//func (c *CrawlerInputItemSerivce)Create(cii * CrawlerInputItem) (string, error) {
|
|
||||||
//
|
|
||||||
// out, err := utils.InvokeDB("crawlerInputItem", "create", cii)
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// return out, nil;
|
|
||||||
//
|
|
||||||
//}
|
|
@ -1 +0,0 @@
|
|||||||
package crawlerInputItem
|
|
@ -1,55 +0,0 @@
|
|||||||
package crawlerinputitemmapping
|
|
||||||
|
|
||||||
//import (
|
|
||||||
// "git.loafle.net/overflow/commons_go/model/timestamp"
|
|
||||||
// "encoding/json"
|
|
||||||
// "git.loafle.net/overflow/overflow_service/proxy/crawler"
|
|
||||||
// "git.loafle.net/overflow/overflow_service/proxy/crawlerInputItem"
|
|
||||||
// "git.loafle.net/overflow/overflow_service/proxy/utils"
|
|
||||||
//)
|
|
||||||
//
|
|
||||||
//type CrawlerInputItemMapping struct {
|
|
||||||
// Id json.Number `json:"id,Number,omitempty"`
|
|
||||||
// Crawler crawler.Crawler `json:"crawler,omitempty"`
|
|
||||||
// CrawlerInputItem crawlerInputItem.CrawlerInputItem `json:"crawlerInputItem,omitempty"`
|
|
||||||
//
|
|
||||||
// Priority json.Number `json:"priority,Number,omitempty"`
|
|
||||||
// RequiredType bool `json:"requiredType,omitempty"`
|
|
||||||
// CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//type CrawlerInputItemMappingService struct {
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func NewCrawlerInputItemMappingService() *CrawlerInputItemMappingService {
|
|
||||||
// return &CrawlerInputItemMappingService{}
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (c *CrawlerInputItemMappingService)Create(ciim *CrawlerInputItemMapping) (string, error) {
|
|
||||||
//
|
|
||||||
// out, err := utils.InvokeDB("crawlerInputItemMapping", "create", ciim)
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// return out, nil;
|
|
||||||
//
|
|
||||||
//}
|
|
||||||
//
|
|
||||||
//func (c *CrawlerInputItemMappingService)List(cr *crawler.Crawler) (string, error) {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// out, err := utils.InvokeDBByModel("crawlerInputItemMapping", "findByCrawlerId", cr, "com.loafle.overflow.crawler.model.Crawler")
|
|
||||||
//
|
|
||||||
// if err != nil {
|
|
||||||
// return "", err
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// return out, nil;
|
|
||||||
//
|
|
||||||
//}
|
|
@ -1,25 +0,0 @@
|
|||||||
package crawlerinputitemmapping
|
|
||||||
|
|
||||||
//import (
|
|
||||||
// "testing"
|
|
||||||
//
|
|
||||||
// "git.loafle.net/overflow/overflow_service/proxy/crawler"
|
|
||||||
//)
|
|
||||||
//
|
|
||||||
//func TestListCrawler(t *testing.T) {
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// niin := NewCrawlerInputItemMappingService()
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// cc := &crawler.Crawler{}
|
|
||||||
//
|
|
||||||
// cc.Id = "1";
|
|
||||||
//
|
|
||||||
// out := niin.List(cc)
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// t.Log(out)
|
|
||||||
//
|
|
||||||
//}
|
|
@ -6,6 +6,7 @@ import (
|
|||||||
"git.loafle.net/overflow/overflow_service/proxy/meta"
|
"git.loafle.net/overflow/overflow_service/proxy/meta"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
type InfraService struct {
|
type InfraService struct {
|
||||||
@ -13,21 +14,53 @@ type InfraService struct {
|
|||||||
|
|
||||||
type Infra struct {
|
type Infra struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
MetaInfraType meta.MetaInfraType `json:"type,omitempty"`
|
MetaInfraType *meta.MetaInfraType `json:"type,omitempty"`
|
||||||
ChildId json.Number `json:"childId,omitempty"`
|
ChildId json.Number `json:"childId,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewInfra(id json.Number, o interface{}) *Infra {
|
||||||
|
|
||||||
|
ty := reflect.TypeOf(o)
|
||||||
|
|
||||||
|
var mit meta.MetaInfraType
|
||||||
|
|
||||||
|
strType := ty.String()
|
||||||
|
if strType == "*infra.InfraMachine" {
|
||||||
|
mit.Id = "1"
|
||||||
|
} else if strType == "*infra.InfraHost" {
|
||||||
|
mit.Id = "2"
|
||||||
|
} else if strType == "*infra.InfraOS" {
|
||||||
|
mit.Id = "3"
|
||||||
|
} else if strType == "*infra.InfraOSApplication" {
|
||||||
|
mit.Id = "4"
|
||||||
|
} else if strType == "*infra.InfraOSDaemon" {
|
||||||
|
mit.Id = "5"
|
||||||
|
} else if strType == "*infra.InfraOSPort" {
|
||||||
|
mit.Id = "6"
|
||||||
|
} else if strType == "*infra.InfraServiceApplication" {
|
||||||
|
mit.Id = "7"
|
||||||
|
} else {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return &Infra{
|
||||||
|
MetaInfraType:&mit,
|
||||||
|
ChildId:id,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type InfraMachine struct {
|
type InfraMachine struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
Probe probe.Probe `json:"probe,omitempty"`
|
Probe *probe.Probe `json:"probe,omitempty"`
|
||||||
Meta string `json:"meta,omitempty"`
|
Meta string `json:"meta,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InfraHost struct {
|
type InfraHost struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
InfraOS InfraOS `json:"os,omitempty"`
|
InfraOS *InfraOS `json:"os,omitempty"`
|
||||||
Ip json.Number `json:"ip,omitempty"`
|
Ip json.Number `json:"ip,omitempty"`
|
||||||
Mac json.Number `json:"mac,omitempty"`
|
Mac json.Number `json:"mac,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
@ -35,42 +68,42 @@ type InfraHost struct {
|
|||||||
|
|
||||||
type InfraOS struct {
|
type InfraOS struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
InfraMachine InfraMachine `json:"machine,omitempty"`
|
InfraMachine *InfraMachine `json:"machine,omitempty"`
|
||||||
Meta string `json:"meta,omitempty"`
|
Meta string `json:"meta,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
MetaInfraVendor meta.MetaInfraVendor `json:"vendor,omitempty"`
|
MetaInfraVendor *meta.MetaInfraVendor `json:"vendor,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InfraOSApplication struct {
|
type InfraOSApplication struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
InfraOS InfraOS `json:"os,omitempty"`
|
InfraOS *InfraOS `json:"os,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InfraOSDaemon struct {
|
type InfraOSDaemon struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
InfraOS InfraOS `json:"os,omitempty"`
|
InfraOS *InfraOS `json:"os,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InfraOSPort struct {
|
type InfraOSPort struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
InfraOS InfraOS `json:"os,omitempty"`
|
InfraOS *InfraOS `json:"os,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
Port json.Number `json:"port,omitempty"`
|
Port json.Number `json:"port,omitempty"`
|
||||||
PortType string `json:"portType,omitempty"`
|
PortType string `json:"portType,omitempty"`
|
||||||
MetaInfraVendor meta.MetaInfraVendor `json:"vendor,omitempty"`
|
MetaInfraVendor *meta.MetaInfraVendor `json:"vendor,omitempty"`
|
||||||
TlsType bool `json:"tlsType,omitempty"`
|
TlsType bool `json:"tlsType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InfraServiceApplication struct {
|
type InfraServiceApplication struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
InfraHost InfraHost `json:"host,omitempty"`
|
InfraHost *InfraHost `json:"host,omitempty"`
|
||||||
PortType string `json:"portType,omitempty"`
|
PortType string `json:"portType,omitempty"`
|
||||||
Port json.Number `json:"port,omitempty"`
|
Port json.Number `json:"port,omitempty"`
|
||||||
MetaInfraVendor meta.MetaInfraVendor `json:"vendor,omitempty"`
|
MetaInfraVendor *meta.MetaInfraVendor `json:"vendor,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
TlsType bool `json:"tlsType,omitempty"`
|
TlsType bool `json:"tlsType,omitempty"`
|
||||||
}
|
}
|
||||||
@ -110,7 +143,7 @@ func (is *InfraService) RegistHost(i *InfraHost) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (is *InfraService) RegistOS(i *InfraOS) (string, error) {
|
func (is *InfraService) RegistOS(i *InfraOS) (string, error) {
|
||||||
out, err := utils.InvokeDBByModel("InfraOS", "save", i, utils.MODEL_INFRA_OS)
|
out, err := utils.InvokeDBByModel("infraOS", "save", i, utils.MODEL_INFRA_OS)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -120,7 +153,7 @@ func (is *InfraService) RegistOS(i *InfraOS) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (is *InfraService) RegistOSApplication(i *InfraOSApplication) (string, error) {
|
func (is *InfraService) RegistOSApplication(i *InfraOSApplication) (string, error) {
|
||||||
out, err := utils.InvokeDBByModel("InfraOSApplication", "save", i, utils.MODEL_INFRA_OS_APPLICATION)
|
out, err := utils.InvokeDBByModel("infraOSApplication", "save", i, utils.MODEL_INFRA_OS_APPLICATION)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -130,7 +163,7 @@ func (is *InfraService) RegistOSApplication(i *InfraOSApplication) (string, erro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (is *InfraService) RegistOSDaemon(i *InfraOSDaemon) (string, error) {
|
func (is *InfraService) RegistOSDaemon(i *InfraOSDaemon) (string, error) {
|
||||||
out, err := utils.InvokeDBByModel("InfraOSDaemon", "save", i, utils.MODEL_INFRA_OS_DAEMON)
|
out, err := utils.InvokeDBByModel("infraOSDaemon", "save", i, utils.MODEL_INFRA_OS_DAEMON)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -140,7 +173,7 @@ func (is *InfraService) RegistOSDaemon(i *InfraOSDaemon) (string, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (is *InfraService) RegistOSPort(i *InfraOSPort) (string, error) {
|
func (is *InfraService) RegistOSPort(i *InfraOSPort) (string, error) {
|
||||||
out, err := utils.InvokeDBByModel("InfraOSPort", "save", i, utils.MODEL_INFRA_OS_PORT)
|
out, err := utils.InvokeDBByModel("infraOSPort", "save", i, utils.MODEL_INFRA_OS_PORT)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
@ -149,8 +182,8 @@ func (is *InfraService) RegistOSPort(i *InfraOSPort) (string, error) {
|
|||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (is *InfraService) RegistService(i *InfraService) (string, error) {
|
func (is *InfraService) RegistService(i *InfraServiceApplication) (string, error) {
|
||||||
out, err := utils.InvokeDBByModel("InfraService", "save", i, utils.MODEL_INFRA_SERVICE)
|
out, err := utils.InvokeDBByModel("infraService", "save", i, utils.MODEL_INFRA_SERVICE)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return "", err
|
return "", err
|
||||||
|
@ -3,11 +3,61 @@ package meta
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.loafle.net/overflow/commons_go/model/timestamp"
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
INFRA_VENDOR_TYPE_SERIVCE = 7
|
||||||
|
INFRA_VENDOR_START_IDX = 38
|
||||||
|
INFRA_VENDOR_MYSQL = INFRA_VENDOR_START_IDX + 1
|
||||||
|
INFRA_VENDOR_POSTGRESQL = INFRA_VENDOR_START_IDX + 2
|
||||||
|
INFRA_VENDOR_WMI = INFRA_VENDOR_START_IDX + 3
|
||||||
|
INFRA_VENDOR_SNMPV2 = INFRA_VENDOR_START_IDX + 4
|
||||||
|
|
||||||
|
INFRA_VENDOR_UNKNOWN = INFRA_VENDOR_START_IDX + 5
|
||||||
|
)
|
||||||
|
|
||||||
|
var metaInfraVendorMap = map[int]string{
|
||||||
|
INFRA_VENDOR_MYSQL: "MYSQL",
|
||||||
|
INFRA_VENDOR_POSTGRESQL: "POSTGRESQL",
|
||||||
|
INFRA_VENDOR_WMI: "WMI",
|
||||||
|
INFRA_VENDOR_SNMPV2: "SNMPV2",
|
||||||
|
INFRA_VENDOR_UNKNOWN:"UNKNOWN",
|
||||||
|
}
|
||||||
|
|
||||||
|
var metaInfraVendorMapStr map[string]int
|
||||||
|
|
||||||
|
func init() {
|
||||||
|
metaInfraVendorMapStr = make(map[string]int)
|
||||||
|
|
||||||
|
for k, v := range metaInfraVendorMap {
|
||||||
|
metaInfraVendorMapStr[v] = k
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
type MetaInfraVendor struct {
|
type MetaInfraVendor struct {
|
||||||
Id json.Number `json:"id,Number,omitempty"`
|
Id json.Number `json:"id,Number,omitempty"`
|
||||||
Name string `json:"name,omitempty"`
|
Name string `json:"name,omitempty"`
|
||||||
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
|
||||||
MetaInfraType MetaInfraType `json:"metaInfraType,omitempty"`
|
MetaInfraType MetaInfraType `json:"metaInfraType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewMetaInfraVendorByService(serviceName string) *MetaInfraVendor {
|
||||||
|
|
||||||
|
idx := metaInfraVendorMapStr[serviceName]
|
||||||
|
|
||||||
|
if idx <= 0 {
|
||||||
|
return &MetaInfraVendor{
|
||||||
|
Id: json.Number(strconv.Itoa(INFRA_VENDOR_UNKNOWN)),
|
||||||
|
Name: "UNKNOWN",
|
||||||
|
MetaInfraType: MetaInfraType{Id: json.Number(strconv.Itoa(INFRA_VENDOR_TYPE_SERIVCE))},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return &MetaInfraVendor{
|
||||||
|
Id: json.Number(strconv.Itoa(idx)),
|
||||||
|
Name: serviceName,
|
||||||
|
MetaInfraType: MetaInfraType{Id: json.Number(strconv.Itoa(INFRA_VENDOR_TYPE_SERIVCE))},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -64,3 +64,21 @@ func (ss *SensorService) Remove(s *Sensor) (string, error) {
|
|||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (ss *SensorService) Start(s *Sensor) (string, error) {
|
||||||
|
s.MetaSensorStatus = meta.NewMetaSensorStatus(meta.SENSOR_STATUS_RUNNING)
|
||||||
|
res, err := ss.Regist(s)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (ss *SensorService) Stop(s *Sensor) (string, error) {
|
||||||
|
s.MetaSensorStatus = meta.NewMetaSensorStatus(meta.SENSOR_STATUS_STOPPED)
|
||||||
|
res, err := ss.Regist(s)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
@ -3,9 +3,14 @@ package target
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.loafle.net/overflow/commons_go/model/timestamp"
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
||||||
|
"git.loafle.net/overflow/discovery/discovery/types"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/infra"
|
"git.loafle.net/overflow/overflow_service/proxy/infra"
|
||||||
|
"git.loafle.net/overflow/overflow_service/proxy/meta"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
"git.loafle.net/overflow/overflow_service/proxy/utils"
|
||||||
|
"strconv"
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Target struct {
|
type Target struct {
|
||||||
@ -15,6 +20,11 @@ type Target struct {
|
|||||||
Infra *infra.Infra `json:"infra,omitempty"`
|
Infra *infra.Infra `json:"infra,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type TargetInfo struct {
|
||||||
|
Hosts *[]*types.DiscoveryHost `json:"hosts,omitempty"`
|
||||||
|
Probe *probe.Probe `json:"probe,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type TargetService struct {
|
type TargetService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -68,3 +78,195 @@ func (t *TargetService) Remove(target *Target) (string, error) {
|
|||||||
|
|
||||||
return out, nil
|
return out, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//FIXME: Discovery Result
|
||||||
|
func (t *TargetService) RegistTarget(ti *TargetInfo) (string, error) {
|
||||||
|
|
||||||
|
is := infra.NewInfraService()
|
||||||
|
|
||||||
|
for _, host := range *ti.Hosts {
|
||||||
|
|
||||||
|
im := infra.InfraMachine{}
|
||||||
|
im.Probe = ti.Probe
|
||||||
|
|
||||||
|
out, err := is.RegistMachine(&im)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), &im)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
iim := infra.NewInfra(im.Id, &im)
|
||||||
|
_, err = is.Regist(iim)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
io := infra.InfraOS{}
|
||||||
|
io.InfraMachine = &im
|
||||||
|
miv := meta.MetaInfraVendor{}
|
||||||
|
if host.Os == "Windows" {
|
||||||
|
miv.Id = "25"
|
||||||
|
} else if host.Os == "Linux" {
|
||||||
|
miv.Id = "27"
|
||||||
|
}
|
||||||
|
io.MetaInfraVendor = &miv
|
||||||
|
|
||||||
|
out, err = is.RegistOS(&io)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), &io)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
iio := infra.NewInfra(io.Id, &io)
|
||||||
|
_, err = is.Regist(iio)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
ih := infra.InfraHost{}
|
||||||
|
ih.InfraOS = &io
|
||||||
|
ih.Ip = json.Number(strconv.FormatInt(host.Ip, 10))
|
||||||
|
ih.Mac = json.Number(strconv.FormatInt(host.Mac, 10))
|
||||||
|
|
||||||
|
out, err = is.RegistHost(&ih)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), &ih)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
iih := infra.NewInfra(ih.Id, &ih)
|
||||||
|
out, err = is.Regist(iih)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), iih)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
err = RegistTarget(host.Target, iih, ti.Probe)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for _, port := range host.Ports {
|
||||||
|
|
||||||
|
ip := infra.InfraOSPort{}
|
||||||
|
ip.InfraOS = &io
|
||||||
|
ip.Port = json.Number(strconv.FormatUint(uint64(port.Number), 10))
|
||||||
|
ip.PortType = port.PortType
|
||||||
|
//ip.MetaInfraVendor
|
||||||
|
//ip.TlsType
|
||||||
|
|
||||||
|
out, err = is.RegistOSPort(&ip)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), &ip)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
iip := infra.NewInfra(ip.Id, &ip)
|
||||||
|
out, err = is.Regist(iip)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), iip)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = RegistTarget(port.Target, iip, ti.Probe)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, service := range port.Services {
|
||||||
|
|
||||||
|
isa := infra.InfraServiceApplication{}
|
||||||
|
|
||||||
|
isa.InfraHost = &ih
|
||||||
|
isa.PortType = port.PortType
|
||||||
|
//isa.TlsType
|
||||||
|
isa.Port = json.Number(strconv.FormatUint(uint64(port.Number), 10))
|
||||||
|
//isa.MetaInfraVendor
|
||||||
|
isa.MetaInfraVendor = meta.NewMetaInfraVendorByService(service.ServiceName)
|
||||||
|
|
||||||
|
out, err = is.RegistService(&isa)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), &isa)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
iisa := infra.NewInfra(isa.Id, &isa)
|
||||||
|
out, err = is.Regist(iisa)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = json.Unmarshal([]byte(out), iisa)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
err = RegistTarget(service.Target, iisa, ti.Probe)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return "", nil
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
func RegistTarget(check bool, i *infra.Infra, p *probe.Probe) error {
|
||||||
|
|
||||||
|
if check == false {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
ttt := &Target{}
|
||||||
|
ttt.Infra = i
|
||||||
|
ttt.Probe = p
|
||||||
|
|
||||||
|
ts := NewTargetService()
|
||||||
|
_, err := ts.Regist(ttt)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
@ -6,6 +6,10 @@ import (
|
|||||||
"git.loafle.net/overflow/overflow_service/proxy/infra"
|
"git.loafle.net/overflow/overflow_service/proxy/infra"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
"git.loafle.net/overflow/overflow_service/proxy/probe"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
|
||||||
|
"io/ioutil"
|
||||||
|
"reflect"
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTargetRegist(t *testing.T) {
|
func TestTargetRegist(t *testing.T) {
|
||||||
@ -61,3 +65,42 @@ func TestTargetDelete(t *testing.T) {
|
|||||||
}
|
}
|
||||||
t.Log(res)
|
t.Log(res)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestTargetDiscovery(t *testing.T) {
|
||||||
|
|
||||||
|
contents,_ := ioutil.ReadFile("../../dh.json")
|
||||||
|
|
||||||
|
ti := TargetInfo{}
|
||||||
|
|
||||||
|
err := json.Unmarshal(contents, &ti)
|
||||||
|
|
||||||
|
if err != nil{
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log(ti)
|
||||||
|
|
||||||
|
ts := NewTargetService()
|
||||||
|
ppp := probe.Probe{}
|
||||||
|
ppp.Id = "1"
|
||||||
|
ti.Probe = &ppp
|
||||||
|
out, err := ts.RegistTarget(&ti)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
t.Log(out)
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestInterface(t *testing.T) {
|
||||||
|
|
||||||
|
aaa := &infra.InfraMachine{}
|
||||||
|
|
||||||
|
var o interface{} = aaa
|
||||||
|
|
||||||
|
tt := reflect.TypeOf(o)
|
||||||
|
t.Log(tt.Name())
|
||||||
|
t.Log(tt.String())
|
||||||
|
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user