This commit is contained in:
crusader 2018-07-04 17:25:36 +09:00
parent 904de16326
commit 1d13feb9ce
3 changed files with 73 additions and 21 deletions

19
Gopkg.lock generated
View File

@ -24,22 +24,21 @@
name = "git.loafle.net/commons/server-go"
packages = [
".",
"client",
"socket",
"socket/client",
"socket/web",
"socket/web/client"
]
revision = "1cae23cf7819d56fd399346a1dc30af6a82d1a93"
revision = "cbe8e30db48a21b33650c5ed7e7d8bbf4784c9d4"
[[projects]]
branch = "master"
name = "git.loafle.net/commons/util-go"
packages = [
"context",
"encoding/json",
"reflect"
]
revision = "4d4017d214d2a8fdde59d774254f421991fabe7e"
revision = "dd4f956c587b1947f84ad5eebd64722b3d6c5224"
[[projects]]
name = "github.com/BurntSushi/toml"
@ -60,8 +59,8 @@
"gzip",
"zlib"
]
revision = "6c8db69c4b49dd4df1fff66996cf556176d0b9bf"
version = "v1.2.1"
revision = "5fb1f31b0a61e9858f12f39266e059848a5f1cea"
version = "v1.3.0"
[[projects]]
name = "github.com/klauspost/cpuid"
@ -69,12 +68,6 @@
revision = "ae7887de9fa5d2db4eaa8174a7eff2c1ac00f2da"
version = "v1.1"
[[projects]]
name = "github.com/klauspost/crc32"
packages = ["."]
revision = "cb6bfca970f6908083f26f39a79009d608efd5cd"
version = "v1.1"
[[projects]]
name = "github.com/valyala/fasthttp"
packages = [
@ -118,6 +111,6 @@
[solve-meta]
analyzer-name = "dep"
analyzer-version = 1
inputs-digest = "80d314f2263e6dd751c17b988048abe6f8eeff450d7088f3fa98cc4873205681"
inputs-digest = "d416b3a82f6ebf912d00317b9f2cdf91db9d10dbaef9354ac4bfbdb34c25a63f"
solver-name = "gps-cdcl"
solver-version = 1

View File

@ -33,10 +33,6 @@
branch = "master"
name = "git.loafle.net/commons/server-go"
[[constraint]]
branch = "master"
name = "git.loafle.net/commons/util-go"
[[constraint]]
name = "github.com/google/gopacket"
version = "1.1.14"

View File

@ -1,9 +1,72 @@
package data
import "git.loafle.net/overflow/commons-go/core/util"
import (
"encoding/json"
"fmt"
"git.loafle.net/overflow/commons-go/core/util"
)
type Metric struct {
SensorConfigID string `json:"sensorConfigID,omitempty"`
Data map[string]string `json:"data,omitempty"`
CollectDate *util.Timestamp `json:"collectDate,omitempty"`
SensorID string `json:"sensorID,omitempty"`
StartDate *util.Timestamp `json:"startDate,omitempty"`
EndDate *util.Timestamp `json:"endDate,omitempty"`
Status MetricStatusEnum `json:"status,omitempty"`
Extra map[string]string `json:"extra,omitempty"`
Data map[string]string `json:"data,omitempty"`
}
type MetricStatusEnum int
const (
MetricStatusEnumOK MetricStatusEnum = iota + 1
MetricStatusEnumINFO
MetricStatusEnumWARN
MetricStatusEnumERROR
MetricStatusEnumCRITICAL
)
var (
metricStatusEnumID = map[MetricStatusEnum]string{
MetricStatusEnumOK: "OK",
MetricStatusEnumINFO: "INFO",
MetricStatusEnumWARN: "WARN",
MetricStatusEnumERROR: "ERROR",
MetricStatusEnumCRITICAL: "CRITICAL",
}
metricStatusEnumKey = map[string]MetricStatusEnum{
"OK": MetricStatusEnumOK,
"INFO": MetricStatusEnumINFO,
"WARN": MetricStatusEnumWARN,
"ERROR": MetricStatusEnumERROR,
"CRITICAL": MetricStatusEnumCRITICAL,
}
)
func (e MetricStatusEnum) String() string {
return metricStatusEnumID[e]
}
func (e MetricStatusEnum) MarshalJSON() ([]byte, error) {
value, ok := metricStatusEnumID[e]
if !ok {
return nil, fmt.Errorf("Invalid EnumType[%s] value", e)
}
return json.Marshal(value)
}
func (e MetricStatusEnum) UnmarshalJSON(b []byte) error {
var s string
err := json.Unmarshal(b, &s)
if err != nil {
return err
}
value, ok := metricStatusEnumKey[s]
if !ok {
return fmt.Errorf("Invalid EnumType[%s] value", s)
}
e = value
return nil
}