From 46db6509b05fe9e32dcf47d4b394f3006940ffd3 Mon Sep 17 00:00:00 2001 From: crusader Date: Mon, 17 Sep 2018 22:55:38 +0900 Subject: [PATCH] ing --- discovery/Host.go | 2 +- discovery/Port.go | 2 +- discovery/Service.go | 2 +- discovery/Zone.go | 2 +- meta/MetaDiscovererType.go | 89 ++++++++++++++++++++++++++++++++++++++ 5 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 meta/MetaDiscovererType.go diff --git a/discovery/Host.go b/discovery/Host.go index 7061225..0a7a6a1 100644 --- a/discovery/Host.go +++ b/discovery/Host.go @@ -28,7 +28,7 @@ type Host struct { HostModel string `json:"hostModel,omitempty"` Meta map[string]map[string]string `json:"meta,omitempty"` - DiscoveredBy []string `json:"discoveredBy,omitempty"` + DiscoveredBy []*meta.MetaDiscovererType `json:"discoveredBy,omitempty"` DiscoveredDate *util.Timestamp `json:"discoveredDate,omitempty"` Zone *Zone `json:"zone,omitempty"` diff --git a/discovery/Port.go b/discovery/Port.go index 338274c..d546f40 100644 --- a/discovery/Port.go +++ b/discovery/Port.go @@ -14,7 +14,7 @@ type Port struct { PortNumber json.Number `json:"portNumber,omitempty"` Meta map[string]map[string]string `json:"meta,omitempty"` - DiscoveredBy []string `json:"discoveredBy,omitempty"` + DiscoveredBy []*meta.MetaDiscovererType `json:"discoveredBy,omitempty"` DiscoveredDate *util.Timestamp `json:"discoveredDate,omitempty"` Host *Host `json:"host,omitempty"` diff --git a/discovery/Service.go b/discovery/Service.go index 5742013..d06bab3 100644 --- a/discovery/Service.go +++ b/discovery/Service.go @@ -26,7 +26,7 @@ type Service struct { ServiceVersion string `json:"serviceVersion,omitempty"` Meta map[string]map[string]string `json:"meta,omitempty"` - DiscoveredBy []string `json:"discoveredBy,omitempty"` + DiscoveredBy []*meta.MetaDiscovererType `json:"discoveredBy,omitempty"` DiscoveredDate *util.Timestamp `json:"discoveredDate,omitempty"` Port *Port `json:"port,omitempty"` diff --git a/discovery/Zone.go b/discovery/Zone.go index 190d89e..7bef950 100644 --- a/discovery/Zone.go +++ b/discovery/Zone.go @@ -15,7 +15,7 @@ type Zone struct { Mac string `json:"mac,omitempty"` Meta map[string]map[string]string `json:"meta,omitempty"` - DiscoveredBy []string `json:"discoveredBy,omitempty"` + DiscoveredBy []*meta.MetaDiscovererType `json:"discoveredBy,omitempty"` DiscoveredDate *util.Timestamp `json:"discoveredDate,omitempty"` mtx sync.RWMutex `json:"-"` diff --git a/meta/MetaDiscovererType.go b/meta/MetaDiscovererType.go new file mode 100644 index 0000000..26871db --- /dev/null +++ b/meta/MetaDiscovererType.go @@ -0,0 +1,89 @@ +package meta + +import ( + "encoding/json" + + "git.loafle.net/overflow/model/util" +) + +type MetaDiscovererType struct { + ID json.Number `json:"id,Number,omitempty"` + Name string `json:"name,omitempty"` + Key string `json:"key,omitempty"` + CreateDate *util.Timestamp `json:"createDate,omitempty"` +} + +type MetaDiscovererTypeEnum int + +const ( + MetaDiscovererTypeEnumUNKNOWN MetaDiscovererTypeEnum = iota + 1 + MetaDiscovererTypeEnumARP + MetaDiscovererTypeEnumICMP + MetaDiscovererTypeEnumMDNS + MetaDiscovererTypeEnumNDP + MetaDiscovererTypeEnumSNMP + MetaDiscovererTypeEnumTCPACK + MetaDiscovererTypeEnumTCPFIN + MetaDiscovererTypeEnumTCPNULL + MetaDiscovererTypeEnumTCPXmas + MetaDiscovererTypeEnumTCPSyn + MetaDiscovererTypeEnumTCPConnection + MetaDiscovererTypeEnumTCPMatcher + MetaDiscovererTypeEnumUDPConnection + MetaDiscovererTypeEnumUDPMatcher + MetaDiscovererTypeEnumUPnP +) + +var ( + metaDiscovererTypeEnumID = map[MetaDiscovererTypeEnum]string{ + MetaDiscovererTypeEnumUNKNOWN: "UNKNOWN", + MetaDiscovererTypeEnumARP: "ARP", + MetaDiscovererTypeEnumICMP: "ICMP", + MetaDiscovererTypeEnumMDNS: "MDNS", + MetaDiscovererTypeEnumNDP: "NDP", + MetaDiscovererTypeEnumSNMP: "SNMP", + MetaDiscovererTypeEnumTCPACK: "TCPACK", + MetaDiscovererTypeEnumTCPFIN: "TCPFIN", + MetaDiscovererTypeEnumTCPNULL: "TCPNULL", + MetaDiscovererTypeEnumTCPXmas: "TCPXmas", + MetaDiscovererTypeEnumTCPSyn: "TCPSyn", + MetaDiscovererTypeEnumTCPConnection: "TCPConnection", + MetaDiscovererTypeEnumTCPMatcher: "TCPMatcher", + MetaDiscovererTypeEnumUDPConnection: "UDPConnection", + MetaDiscovererTypeEnumUDPMatcher: "UDPMatcher", + MetaDiscovererTypeEnumUPnP: "UPnP", + } + + metaDiscovererTypeEnumKey = map[string]MetaDiscovererTypeEnum{ + "UNKNOWN": MetaDiscovererTypeEnumUNKNOWN, + "ARP": MetaDiscovererTypeEnumARP, + "ICMP": MetaDiscovererTypeEnumICMP, + "MDNS": MetaDiscovererTypeEnumMDNS, + "NDP": MetaDiscovererTypeEnumNDP, + "SNMP": MetaDiscovererTypeEnumSNMP, + "TCPACK": MetaDiscovererTypeEnumTCPACK, + "TCPFIN": MetaDiscovererTypeEnumTCPFIN, + "TCPNULL": MetaDiscovererTypeEnumTCPNULL, + "TCPXmas": MetaDiscovererTypeEnumTCPXmas, + "TCPSyn": MetaDiscovererTypeEnumTCPSyn, + "TCPConnection": MetaDiscovererTypeEnumTCPConnection, + "TCPMatcher": MetaDiscovererTypeEnumTCPMatcher, + "UDPConnection": MetaDiscovererTypeEnumUDPConnection, + "UDPMatcher": MetaDiscovererTypeEnumUDPMatcher, + "UPnP": MetaDiscovererTypeEnumUPnP, + } +) + +func (e MetaDiscovererTypeEnum) String() string { + return metaDiscovererTypeEnumID[e] +} + +func ToMetaDiscovererTypeEnum(v *MetaDiscovererType) MetaDiscovererTypeEnum { + return metaDiscovererTypeEnumKey[v.Key] +} + +func ToMetaDiscovererType(v MetaDiscovererTypeEnum) *MetaDiscovererType { + return &MetaDiscovererType{ + Key: metaDiscovererTypeEnumID[v], + } +}