target create
This commit is contained in:
snoop 2017-06-27 12:11:38 +09:00
parent 6f375272a0
commit 6476e82b2a
2 changed files with 114 additions and 0 deletions

View File

@ -3,11 +3,47 @@ package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons_go/model/timestamp"
"strconv"
)
const (
INFRA_VENDOR_TYPE_SERIVCE = 7
INFRA_VENDOR_START_IDX = 39
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
)
var metaInfraVendorMap = map[int]string{
INFRA_VENDOR_MYSQL: "MYSQL",
INFRA_VENDOR_POSTGRESQL: "POSTGRESQL",
INFRA_VENDOR_WMI: "WMI",
INFRA_VENDOR_SNMPV2: "SNMPV2",
}
var metaInfraVendorMapStr map[string]int
func init() {
metaInfraVendorMapStr = make(map[string]int)
//for
}
type MetaInfraVendor struct {
Id json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
CreateDate timestamp.Timestamp `json:"createDate,omitempty"`
MetaInfraType MetaInfraType `json:"metaInfraType,omitempty"`
}
func NewMetaInfraVendorByService(serviceName string) *MetaInfraVendor{
idx := metaInfraVendorMapStr[serviceName]
return &MetaInfraVendor{
Id: json.Number(strconv.Itoa(idx)),
Name:serviceName,
MetaInfraType:MetaInfraType{Id:json.Number(strconv.Itoa(INFRA_VENDOR_TYPE_SERIVCE))},
}
}

View File

@ -6,6 +6,9 @@ import (
"git.loafle.net/overflow/overflow_service/proxy/infra"
"git.loafle.net/overflow/overflow_service/proxy/probe"
"git.loafle.net/overflow/overflow_service/proxy/utils"
"strconv"
"git.loafle.net/overflow/overflow_service/proxy/meta"
"git.loafle.net/overflow/discovery/discovery/types"
)
type Target struct {
@ -15,6 +18,12 @@ type Target struct {
Infra *infra.Infra `json:"infra,omitempty"`
}
type TargetInfo struct {
Hosts *[]*types.DiscoveryHost `json:"hosts,omitempty"`
Probe *probe.Probe `json:"probe,omitempty"`
}
type TargetService struct {
}
@ -68,3 +77,72 @@ func (t *TargetService) Remove(target *Target) (string, error) {
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
}
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
ih := infra.InfraHost{}
ih.InfraOS = io
ih.Ip = json.Number(strconv.FormatInt(host.Ip, 10))
ih.Mac = json.Number(strconv.FormatInt(host.Mac, 10))
//i := infra.Infra{}
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
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)
}
}
}
return "", nil
}