Added string output. Create metrics with timestamp by default.
This commit is contained in:
parent
2aea120e2d
commit
412df15265
|
@ -15,35 +15,36 @@ import (
|
||||||
|
|
||||||
// ZabbixMetric class.
|
// ZabbixMetric class.
|
||||||
type ZabbixMetric struct {
|
type ZabbixMetric struct {
|
||||||
Host string `json:"host"`
|
Host string
|
||||||
Key string `json:"key"`
|
Key string
|
||||||
Value string `json:"value"`
|
Value string
|
||||||
Clock int64 `json:"clock"`
|
Timestamp int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZabbixMetric class constructor.
|
// ZabbixMetric class constructor.
|
||||||
func NewZabbixMetric(host, key, value string, clock ...int64) *ZabbixMetric {
|
func NewZabbixMetric(host, key, value string) *ZabbixMetric {
|
||||||
m := &ZabbixMetric{Host: host, Key: key, Value: value}
|
m := &ZabbixMetric{
|
||||||
// use current time, if `clock` is not specified
|
Host: host,
|
||||||
if m.Clock = time.Now().Unix(); len(clock) > 0 {
|
Key: key,
|
||||||
m.Clock = int64(clock[0])
|
Value: value,
|
||||||
|
Timestamp: time.Now().Unix()
|
||||||
}
|
}
|
||||||
return m
|
return m
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZabbixPacket class.
|
// ZabbixPacket class.
|
||||||
type ZabbixPacket struct {
|
type ZabbixPacket struct {
|
||||||
Request string `json:"request"`
|
Request string
|
||||||
Data []*ZabbixMetric `json:"data"`
|
Data []*ZabbixMetric
|
||||||
Clock int64 `json:"clock"`
|
Timestamp int64
|
||||||
}
|
}
|
||||||
|
|
||||||
// ZabbixPacket class cunstructor.
|
// ZabbixPacket class cunstructor.
|
||||||
func NewZabbixPacket(data []*ZabbixMetric, clock ...int64) *ZabbixPacket {
|
func NewZabbixPacket(data []*ZabbixMetric) *ZabbixPacket {
|
||||||
p := &ZabbixPacket{Request: `sender data`, Data: data}
|
p := &ZabbixPacket{
|
||||||
// use current time, if `clock` is not specified
|
Request: `sender data`,
|
||||||
if p.Clock = time.Now().Unix(); len(clock) > 0 {
|
Data: data,
|
||||||
p.Clock = int64(clock[0])
|
Timestamp: time.Now().Unix()
|
||||||
}
|
}
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
@ -157,6 +158,8 @@ func buildValue(v interface{}) (string, error) {
|
||||||
retv = UIntToString(uint64(p))
|
retv = UIntToString(uint64(p))
|
||||||
case float64:
|
case float64:
|
||||||
retv = FloatToString(float64(p))
|
retv = FloatToString(float64(p))
|
||||||
|
case string:
|
||||||
|
retv = p
|
||||||
default:
|
default:
|
||||||
return retv, fmt.Errorf("unexpected type %T with value %v for Zabbix", v, v)
|
return retv, fmt.Errorf("unexpected type %T with value %v for Zabbix", v, v)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue