sensor model has added

This commit is contained in:
insanity 2018-07-02 16:42:40 +09:00
parent 7e2ff26648
commit de62e94cc6
28 changed files with 189 additions and 315 deletions

View File

@ -1,4 +1,10 @@
{
"editor.tabSize": 2,
"editor.insertSpaces": true,
"editor.formatOnSave": true,
"editor.formatOnPaste": true,
"editor.autoClosingBrackets": true,
"editor.trimAutoWhitespace": true,
"files.trimTrailingWhitespace": true,
"files.trimFinalNewlines": true,
}

View File

@ -0,0 +1,16 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaCollectionItem struct {
ID json.Number `json:"id,Number,omitempty"`
Key string `json:"key,omitempty"`
Item string `json:"item,omitempty"`
ItemClass bool `json:"itemClass,omitempty"`
MetaItemUnit *MetaItemUnit `json:"metaItemUnit,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,13 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaCollectionItemMapping struct {
ID json.Number `json:"id,Number,omitempty"`
MetaDisplayItemMapping *MetaDisplayItemMapping `json:"metaDisplayItemMapping,omitempty"`
MetaCollectionItem *MetaCollectionItem `json:"metaCollectionItem,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -2,7 +2,6 @@ package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
@ -10,6 +9,5 @@ type MetaCrawler struct {
ID json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
IsDefault bool `json:"isDefault,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,13 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaCrawlerContainer struct {
ID json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,13 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaCrawlerInputItem struct {
ID json.Number `json:"id,Number,omitempty"`
MetaInputType *MetaInputType `json:"metaInputType,omitempty"`
Key string `json:"key,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,15 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaCrawlerMapping struct {
ID json.Number `json:"id,Number,omitempty"`
MetaTargetType *MetaTargetType `json:"metaTargetType,Number,omitempty"`
MetaCrawler *MetaCrawler `json:"metaCrawler,omitempty"`
DefaultInterval json.Number `json:"defaultInterval,omitempty"`
IsDefault bool `json:"isDefault,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,13 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaDisplayItem struct {
ID json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,14 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaDisplayItemCategory struct {
ID json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,19 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaDisplayItemMapping struct {
ID json.Number `json:"id,Number,omitempty"`
MetaDisplayItem *MetaDisplayItem `json:"metaDisplayItem,omitempty"`
MetaCrawlerMapping *MetaCrawlerMapping `json:"metaCrawlerMapping,omitempty"`
MetaItemUnit *MetaItemUnit `json:"metaItemUnit,omitempty"`
MetaDisplayItemCategory *MetaDisplayItemCategory `json:"metaDisplayItemCategory,omitempty"`
IsDefault bool `json:"isDefault,omitempty"`
Formula string `json:"formula,omitempty"`
Priority json.Number `json:"priority,omitempty"`
IsRequired bool `json:"isRequired,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,14 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaInputType struct {
ID json.Number `json:"id,Number,omitempty"`
Name string `json:"name,omitempty"`
Key string `json:"key,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -0,0 +1,15 @@
package meta
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/core/util"
)
type MetaItemUnit struct {
ID json.Number `json:"id,Number,omitempty"`
Key string `json:"key,omitempty"`
Unit string `json:"unit,omitempty"`
Mark string `json:"mark,omitempty"`
CreateDate *util.Timestamp `json:"createDate,omitempty"`
}

View File

@ -1,15 +0,0 @@
package sensorconfig
import (
"encoding/json"
"git.loafle.net/overflow/commons-go/model/meta"
)
type Connection struct {
MetaIPType *meta.MetaIPType `json:"metaIPType,omitempty"`
IP string `json:"ip,omitempty"`
MetaPortType *meta.MetaPortType `json:"metaPortType,omitempty"`
Port json.Number `json:"port,Number,omitempty"`
MetaCryptoType *meta.MetaCryptoType `json:"metaCryptoType,omitempty"`
}

View File

@ -1,6 +0,0 @@
package sensorconfig
type Crawler struct {
Name string `json:"name,omitempty"`
Container string `json:"container,omitempty"`
}

View File

@ -1,7 +0,0 @@
package sensorconfig
type Item struct {
Keys []*Keys `json:"keys,omitempty"`
QueryInfo *QueryInfo `json:"queryInfo,omitempty"`
MappingInfo *MappingInfo `json:"mappingInfo,omitempty"`
}

View File

@ -1,17 +0,0 @@
package sensorconfig
type Keys struct {
Metric string `json:"metric,omitempty"`
Key string `json:"key,omitempty"`
}
func KeysToMap(keys []*Keys) map[string]string {
m := make(map[string]string)
for _, key := range keys {
m[key.Key] = key.Metric
}
return m
}

View File

@ -1,8 +0,0 @@
package sensorconfig
type MappingInfo struct {
ParseDirection string `json:"parseDirection,omitempty"`
ArrayColumns []string `json:"arrayColumns,omitempty"`
KeyColumns []string `json:"keyColumns,omitempty"`
ValueColumn string `json:"valueColumn,omitempty"`
}

View File

@ -1,6 +0,0 @@
package sensorconfig
type QueryInfo struct {
Query string `json:"query,omitempty"`
Extend map[string]interface{} `json:"extend,omitempty"`
}

View File

@ -1,46 +0,0 @@
package sensorconfig
import "encoding/json"
type ResultSetter interface {
AddRow(row []string)
GetMeta() map[string]json.Number
GetData() map[string]string
}
type ResultSet struct {
Item *Item `json:"item,omitempty"`
Rows [][]string `json:"rows,omitempty"`
Meta map[string]json.Number `json:"meta,omitempty"`
}
func (rs *ResultSet) AddRow(row []string) {
rs.Rows = append(rs.Rows, row)
}
func (rs *ResultSet) GetMeta() map[string]json.Number {
return rs.Meta
}
func NewResultSet(item *Item) ResultSetter {
if nil == item.MappingInfo {
item.MappingInfo = &MappingInfo{}
}
rs := &ResultSet{}
rs.Item = item
rs.Rows = make([][]string, 0)
switch item.MappingInfo.ParseDirection {
case "row":
rsr := &ResultSetRow{}
rsr.ResultSet = rs
rsr.setMeta()
return rsr
default:
rsc := &ResultSetCol{}
rsc.ResultSet = rs
rsc.setMeta()
return rsc
}
}

View File

@ -1,85 +0,0 @@
package sensorconfig
import (
"encoding/json"
"fmt"
"strconv"
"strings"
cuej "git.loafle.net/commons/util-go/encoding/json"
)
type ResultSetCol struct {
*ResultSet
}
func (rsc *ResultSetCol) setMeta() {
meta := rsc.Item.Keys
arrayColumns := rsc.Item.MappingInfo.ArrayColumns
if nil == rsc.Meta {
rsc.Meta = make(map[string]json.Number, 0)
}
for i := 0; i < len(meta); i++ {
rsc.Meta[meta[i].Key] = json.Number(strconv.Itoa(i))
}
if nil != arrayColumns {
for i := 0; i < len(arrayColumns); i++ {
if _, ok := rsc.Meta[arrayColumns[i]]; ok {
continue
}
rsc.Meta[arrayColumns[i]] = json.Number(strconv.Itoa(i + len(meta)))
}
}
}
func (rsc *ResultSetCol) GetData() map[string]string {
return rsc.parse()
}
func (rsc *ResultSetCol) parse() map[string]string {
metrics := rsc.Item.Keys
arrayColumns := rsc.Item.MappingInfo.ArrayColumns
rm := make(map[string]string, 0)
for i := 0; i < len(rsc.Rows); i++ {
row := rsc.Rows[i]
for j := 0; j < len(row); j++ {
arrayValue := make([]string, 0)
if nil != arrayColumns {
for k := 0; k < len(arrayColumns); k++ {
idxN := rsc.Meta[arrayColumns[k]]
idx, _ := cuej.NumberToInt(idxN)
arrayValue = append(arrayValue, row[idx])
}
}
for k := 0; k < len(metrics); k++ {
metric := metrics[k].Metric
metric = rsc.convertMetric(metric, arrayValue)
rm[metric] = row[k]
}
}
}
return rm
}
func (rsc *ResultSetCol) convertMetric(metric string, arrayValue []string) string {
if nil == arrayValue || 0 == len(arrayValue) {
return metric
}
convertChar := "$"
for i := 0; i < len(arrayValue); i++ {
convertStr := fmt.Sprintf("%s%d", convertChar, i)
metric = strings.Replace(metric, convertStr, arrayValue[i], -1)
}
return metric
}

View File

@ -1,105 +0,0 @@
package sensorconfig
import (
"encoding/json"
"fmt"
"strconv"
"strings"
cuej "git.loafle.net/commons/util-go/encoding/json"
)
type ResultSetRow struct {
*ResultSet
}
func (rsr *ResultSetRow) setMeta() {
meta := make([]string, 0)
arrayColumns := rsr.Item.MappingInfo.ArrayColumns
keyColumns := rsr.Item.MappingInfo.KeyColumns
valueColumn := rsr.Item.MappingInfo.ValueColumn
if nil != arrayColumns {
for _, c := range arrayColumns {
meta = append(meta, c)
}
}
if nil != keyColumns {
for _, c := range keyColumns {
meta = append(meta, c)
}
}
if "" != valueColumn {
meta = append(meta, valueColumn)
}
if nil == rsr.Meta {
rsr.Meta = make(map[string]json.Number, 0)
}
for i := 0; i < len(meta); i++ {
rsr.Meta[meta[i]] = json.Number(strconv.Itoa(i))
}
}
func (rsr *ResultSetRow) GetData() map[string]string {
return rsr.parse()
}
func (rsr *ResultSetRow) parse() map[string]string {
valueColumn := rsr.Item.MappingInfo.ValueColumn
rm := make(map[string]string, 0)
for _, row := range rsr.Rows {
key := rsr.makeKey(row)
if "" == key {
continue
}
idx, _ := cuej.NumberToInt(rsr.Meta[valueColumn])
rm[key] = row[idx]
}
return rm
}
func (rsr *ResultSetRow) makeKey(data []string) string {
metrics := rsr.Item.Keys
arrayColumns := rsr.Item.MappingInfo.ArrayColumns
keyColumns := rsr.Item.MappingInfo.KeyColumns
keys := rsr.Item.Keys
findIndex := -1
Loop:
for _, keyColumn := range keyColumns {
idx, _ := cuej.NumberToInt(rsr.Meta[keyColumn])
row := data[idx]
for i := 0; i < len(keys); i++ {
if row == keys[i].Key {
findIndex = i
break Loop
}
}
}
if 0 > findIndex {
return ""
}
metric := metrics[findIndex].Metric
convertChar := "$"
if nil != arrayColumns {
for i := 0; i < len(arrayColumns); i++ {
convertStr := fmt.Sprintf("%s%d", convertChar, i)
idx, _ := cuej.NumberToInt(rsr.Meta[arrayColumns[i]])
replaceString := data[idx]
metric = strings.Replace(metric, convertStr, "'"+replaceString+"'", -1)
}
}
return metric
}

View File

@ -1,5 +0,0 @@
package sensorconfig
type Schedule struct {
Interval string `json:"interval,omitempty"`
}

View File

@ -3,10 +3,10 @@ package sensorconfig
import "encoding/json"
type SensorConfig struct {
ID json.Number `json:"id,Number,omitempty"`
ConfigID string `json:"configID,omitempty"`
Target *Target `json:"target,omitempty"`
Schedule *Schedule `json:"schedule,omitempty"`
Crawler *Crawler `json:"crawler,omitempty"`
Items []*Item `json:"items,omitempty"`
SensorID json.Number `json:"id,Number,omitempty"`
Schedule *SensorConfigSchedule `json:"schedule,omitempty"`
Crawler *SensorConfigCrawler `json:"crawler,omitempty"`
Connection *SensorConfigConnection `json:"connection,omitempty"`
Items []*SensorConfigItems `json:"items,omitempty"`
}

View File

@ -0,0 +1,12 @@
package sensorconfig
import "encoding/json"
type SensorConfigConnection struct {
MetaIPTypeKey string `json:"metaIPTypeKey,omitempty"`
IP string `json:"metaCrawlerKey,omitempty"`
MetaPortTypeKey string `json:"metaPortTypeKey,omitempty"`
Port json.Number `json:"port,omitempty"`
MetaCryptoTypeKey string `json:"metaCryptoTypeKey,omitempty"`
credentials map[string]string `json:"credentials,omitempty"`
}

View File

@ -0,0 +1,6 @@
package sensorconfig
type SensorConfigCrawler struct {
MetaCrawlerContainerKey string `json:"metaCrawlerContainerKey,omitempty"`
MetaCrawlerKey string `json:"metaCrawlerKey,omitempty"`
}

View File

@ -0,0 +1,7 @@
package sensorconfig
import "git.loafle.net/overflow/commons-go/model/meta"
type SensorConfigItems struct {
metaCollectionItems []*meta.MetaCollectionItem `json:"metaCollectionItems,omitempty"`
}

View File

@ -0,0 +1,7 @@
package sensorconfig
import "encoding/json"
type SensorConfigSchedule struct {
Interval json.Number `json:"interval,omitempty"`
}

View File

@ -1,7 +0,0 @@
package sensorconfig
type Target struct {
Auth map[string]interface{} `json:"auth,omitempty"`
Connection *Connection `json:"connection,omitempty"`
Meta map[string]interface{} `json:"meta,omitempty"`
}