config read test
This commit is contained in:
parent
bef2035b30
commit
6e4dc1a757
61
config_manager/config_test.go
Normal file
61
config_manager/config_test.go
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
package config_manager
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
"io/ioutil"
|
||||||
|
"log"
|
||||||
|
"encoding/json"
|
||||||
|
"github.com/stretchr/testify/assert"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestConfigRead(t *testing.T) {
|
||||||
|
|
||||||
|
|
||||||
|
b, err := ioutil.ReadFile("/root/gowork/src/loafle.com/overflow/agent_api/config_manager/test.json")
|
||||||
|
if err != nil {
|
||||||
|
log.Panic(err)
|
||||||
|
}
|
||||||
|
var m = Config{}
|
||||||
|
json.Unmarshal(b, &m)
|
||||||
|
|
||||||
|
assert.Equal(t, m.Id,"123980918237")
|
||||||
|
assert.Equal(t, m.Target.Connection.Ip,"192.168.1.103")
|
||||||
|
assert.Equal(t, m.Target.Connection.Port,"1433")
|
||||||
|
assert.Equal(t, m.Target.Connection.SSL,false)
|
||||||
|
assert.Equal(t, m.Target.Connection.PortType,"tcp")
|
||||||
|
|
||||||
|
assert.Equal(t, m.Target.Auth["url"],"jdbc:sqlserver://192.168.1.106:1433;")
|
||||||
|
assert.Equal(t, m.Target.Auth["id"],"sa")
|
||||||
|
assert.Equal(t, m.Target.Auth["pw"],"qwe123")
|
||||||
|
assert.Equal(t, m.Target.Auth["query"],"select * from master.dbo.sysprocesses")
|
||||||
|
|
||||||
|
assert.Equal(t, m.Schedule.Interval,"10")
|
||||||
|
|
||||||
|
assert.Equal(t, m.Crawler.Name,"health_activedirectory")
|
||||||
|
assert.Equal(t, m.Crawler.Container,"network_proxy")
|
||||||
|
|
||||||
|
item := m.Items[0]
|
||||||
|
|
||||||
|
assert.Equal(t, item.Keys[0].Metric,"object[$0].db[$1].datafile_size")
|
||||||
|
assert.Equal(t, item.Keys[0].Key,"Data File(s) Size (KB)")
|
||||||
|
|
||||||
|
assert.Equal(t, item.Keys[1].Metric,"object[$0].db[$1].logfile_size")
|
||||||
|
assert.Equal(t, item.Keys[1].Key,"Log File(s) Size (KB)")
|
||||||
|
|
||||||
|
assert.Equal(t, item.QueryInfo.Query,"select object_name,instance_name, counter_name, cntr_value from sys.dm_os_performance_counters where ( counter_name = 'Data File(s) Size (KB)' or counter_name = 'Log File(s) Size (KB)' ) AND object_name = 'SQLServer:Databases'")
|
||||||
|
assert.Equal(t, item.QueryInfo.Extend["test"],"test")
|
||||||
|
|
||||||
|
assert.Equal(t, item.MappingInfo.ParseDirection,"row")
|
||||||
|
assert.Equal(t, item.MappingInfo.ArrayColumns[0],"object_name")
|
||||||
|
assert.Equal(t, item.MappingInfo.ArrayColumns[1],"instance_name")
|
||||||
|
|
||||||
|
assert.Equal(t, item.MappingInfo.KeyColumns[0],"counter_name")
|
||||||
|
assert.Equal(t, item.MappingInfo.ValueColumn,"cntr_value")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
50
config_manager/test.json
Normal file
50
config_manager/test.json
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
{
|
||||||
|
"id" : "123980918237",
|
||||||
|
"target" : {
|
||||||
|
"connection" : {
|
||||||
|
"ip" : "192.168.1.103",
|
||||||
|
"port" : "1433",
|
||||||
|
"ssl" : false,
|
||||||
|
"portType" : "tcp"
|
||||||
|
},
|
||||||
|
"auth" : {
|
||||||
|
"url":"jdbc:sqlserver://192.168.1.106:1433;",
|
||||||
|
"id":"sa",
|
||||||
|
"pw":"qwe123",
|
||||||
|
"query" : "select * from master.dbo.sysprocesses"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"schedule" : {
|
||||||
|
"interval" : "10"
|
||||||
|
},
|
||||||
|
"crawler" : {
|
||||||
|
"name":"health_activedirectory",
|
||||||
|
"container":"network_proxy"
|
||||||
|
},
|
||||||
|
"items" : [
|
||||||
|
{
|
||||||
|
"keys" : [
|
||||||
|
{
|
||||||
|
"metric" : "object[$0].db[$1].datafile_size",
|
||||||
|
"key" : "Data File(s) Size (KB)"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"metric" : "object[$0].db[$1].logfile_size",
|
||||||
|
"key" : "Log File(s) Size (KB)"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"queryInfo" : {
|
||||||
|
"query": "select object_name,instance_name, counter_name, cntr_value from sys.dm_os_performance_counters where ( counter_name = 'Data File(s) Size (KB)' or counter_name = 'Log File(s) Size (KB)' ) AND object_name = 'SQLServer:Databases'",
|
||||||
|
"extend" : {
|
||||||
|
"test":"test"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"mappingInfo" : {
|
||||||
|
"parseDirection" : "row",
|
||||||
|
"arrayColumns" : [ "object_name","instance_name"],
|
||||||
|
"keyColumns" : ["counter_name"],
|
||||||
|
"valueColumn" : "cntr_value"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user