created
discovery target
This commit is contained in:
parent
2b3cbecb59
commit
0df9f8c75f
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
]}
|
@ -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
|
||||||
|
@ -4,22 +4,26 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"git.loafle.net/overflow/commons_go/model/timestamp"
|
"git.loafle.net/overflow/commons_go/model/timestamp"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
|
||||||
|
|
||||||
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
INFRA_VENDOR_TYPE_SERIVCE = 7
|
INFRA_VENDOR_TYPE_SERIVCE = 7
|
||||||
INFRA_VENDOR_START_IDX = 39
|
INFRA_VENDOR_START_IDX = 38
|
||||||
INFRA_VENDOR_MYSQL = INFRA_VENDOR_START_IDX + 1
|
INFRA_VENDOR_MYSQL = INFRA_VENDOR_START_IDX + 1
|
||||||
INFRA_VENDOR_POSTGRESQL = INFRA_VENDOR_START_IDX + 2
|
INFRA_VENDOR_POSTGRESQL = INFRA_VENDOR_START_IDX + 2
|
||||||
INFRA_VENDOR_WMI = INFRA_VENDOR_START_IDX + 3
|
INFRA_VENDOR_WMI = INFRA_VENDOR_START_IDX + 3
|
||||||
INFRA_VENDOR_SNMPV2 = INFRA_VENDOR_START_IDX + 4
|
INFRA_VENDOR_SNMPV2 = INFRA_VENDOR_START_IDX + 4
|
||||||
|
|
||||||
|
INFRA_VENDOR_UNKNOWN = INFRA_VENDOR_START_IDX + 5
|
||||||
)
|
)
|
||||||
|
|
||||||
var metaInfraVendorMap = map[int]string{
|
var metaInfraVendorMap = map[int]string{
|
||||||
INFRA_VENDOR_MYSQL: "MYSQL",
|
INFRA_VENDOR_MYSQL: "MYSQL",
|
||||||
INFRA_VENDOR_POSTGRESQL: "POSTGRESQL",
|
INFRA_VENDOR_POSTGRESQL: "POSTGRESQL",
|
||||||
INFRA_VENDOR_WMI: "WMI",
|
INFRA_VENDOR_WMI: "WMI",
|
||||||
INFRA_VENDOR_SNMPV2: "SNMPV2",
|
INFRA_VENDOR_SNMPV2: "SNMPV2",
|
||||||
|
INFRA_VENDOR_UNKNOWN:"UNKNOWN",
|
||||||
}
|
}
|
||||||
|
|
||||||
var metaInfraVendorMapStr map[string]int
|
var metaInfraVendorMapStr map[string]int
|
||||||
@ -27,7 +31,9 @@ var metaInfraVendorMapStr map[string]int
|
|||||||
func init() {
|
func init() {
|
||||||
metaInfraVendorMapStr = make(map[string]int)
|
metaInfraVendorMapStr = make(map[string]int)
|
||||||
|
|
||||||
//for
|
for k, v := range metaInfraVendorMap {
|
||||||
|
metaInfraVendorMapStr[v] = k
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type MetaInfraVendor struct {
|
type MetaInfraVendor struct {
|
||||||
@ -37,13 +43,21 @@ type MetaInfraVendor struct {
|
|||||||
MetaInfraType MetaInfraType `json:"metaInfraType,omitempty"`
|
MetaInfraType MetaInfraType `json:"metaInfraType,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewMetaInfraVendorByService(serviceName string) *MetaInfraVendor{
|
func NewMetaInfraVendorByService(serviceName string) *MetaInfraVendor {
|
||||||
|
|
||||||
idx := metaInfraVendorMapStr[serviceName]
|
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{
|
return &MetaInfraVendor{
|
||||||
Id: json.Number(strconv.Itoa(idx)),
|
Id: json.Number(strconv.Itoa(idx)),
|
||||||
Name:serviceName,
|
Name: serviceName,
|
||||||
MetaInfraType:MetaInfraType{Id:json.Number(strconv.Itoa(INFRA_VENDOR_TYPE_SERIVCE))},
|
MetaInfraType: MetaInfraType{Id: json.Number(strconv.Itoa(INFRA_VENDOR_TYPE_SERIVCE))},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,12 +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"
|
"strconv"
|
||||||
"git.loafle.net/overflow/overflow_service/proxy/meta"
|
|
||||||
"git.loafle.net/overflow/discovery/discovery/types"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type Target struct {
|
type Target struct {
|
||||||
@ -19,9 +21,8 @@ type Target struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type TargetInfo struct {
|
type TargetInfo struct {
|
||||||
|
Hosts *[]*types.DiscoveryHost `json:"hosts,omitempty"`
|
||||||
Hosts *[]*types.DiscoveryHost `json:"hosts,omitempty"`
|
Probe *probe.Probe `json:"probe,omitempty"`
|
||||||
Probe *probe.Probe `json:"probe,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
type TargetService struct {
|
type TargetService struct {
|
||||||
@ -86,7 +87,7 @@ func (t *TargetService) RegistTarget(ti *TargetInfo) (string, error) {
|
|||||||
for _, host := range *ti.Hosts {
|
for _, host := range *ti.Hosts {
|
||||||
|
|
||||||
im := infra.InfraMachine{}
|
im := infra.InfraMachine{}
|
||||||
im.Probe = *ti.Probe
|
im.Probe = ti.Probe
|
||||||
|
|
||||||
out, err := is.RegistMachine(&im)
|
out, err := is.RegistMachine(&im)
|
||||||
|
|
||||||
@ -99,50 +100,173 @@ func (t *TargetService) RegistTarget(ti *TargetInfo) (string, error) {
|
|||||||
return "", err
|
return "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
iim := infra.NewInfra(im.Id, &im)
|
||||||
|
_, err = is.Regist(iim)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
io := infra.InfraOS{}
|
io := infra.InfraOS{}
|
||||||
io.InfraMachine = im
|
io.InfraMachine = &im
|
||||||
miv := meta.MetaInfraVendor{}
|
miv := meta.MetaInfraVendor{}
|
||||||
if host.Os == "Windows" {
|
if host.Os == "Windows" {
|
||||||
miv.Id = "25"
|
miv.Id = "25"
|
||||||
} else if host.Os == "Linux" {
|
} else if host.Os == "Linux" {
|
||||||
miv.Id = "27"
|
miv.Id = "27"
|
||||||
}
|
}
|
||||||
io.MetaInfraVendor = miv
|
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 := infra.InfraHost{}
|
||||||
ih.InfraOS = io
|
ih.InfraOS = &io
|
||||||
ih.Ip = json.Number(strconv.FormatInt(host.Ip, 10))
|
ih.Ip = json.Number(strconv.FormatInt(host.Ip, 10))
|
||||||
ih.Mac = json.Number(strconv.FormatInt(host.Mac, 10))
|
ih.Mac = json.Number(strconv.FormatInt(host.Mac, 10))
|
||||||
|
|
||||||
//i := infra.Infra{}
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
for _, port := range host.Ports{
|
err = RegistTarget(host.Target, iih, ti.Probe)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
for _, port := range host.Ports {
|
||||||
|
|
||||||
ip := infra.InfraOSPort{}
|
ip := infra.InfraOSPort{}
|
||||||
ip.InfraOS = io
|
ip.InfraOS = &io
|
||||||
ip.Port = json.Number(strconv.FormatUint(uint64(port.Number), 10))
|
ip.Port = json.Number(strconv.FormatUint(uint64(port.Number), 10))
|
||||||
ip.PortType = port.PortType
|
ip.PortType = port.PortType
|
||||||
//ip.MetaInfraVendor
|
//ip.MetaInfraVendor
|
||||||
//ip.TlsType
|
//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 {
|
for _, service := range port.Services {
|
||||||
|
|
||||||
isa := infra.InfraServiceApplication{}
|
isa := infra.InfraServiceApplication{}
|
||||||
|
|
||||||
isa.InfraHost = ih
|
isa.InfraHost = &ih
|
||||||
isa.PortType = port.PortType
|
isa.PortType = port.PortType
|
||||||
//isa.TlsType
|
//isa.TlsType
|
||||||
isa.Port = json.Number(strconv.FormatUint(uint64(port.Number), 10))
|
isa.Port = json.Number(strconv.FormatUint(uint64(port.Number), 10))
|
||||||
//isa.MetaInfraVendor
|
//isa.MetaInfraVendor
|
||||||
isa.MetaInfraVendor = *meta.NewMetaInfraVendorByService(service.ServiceName)
|
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
|
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