Omit power_failed and power_restored when the Apex provides invalid timestamps (#5896)
This commit is contained in:
parent
3c451a1f25
commit
0535dc92ed
|
@ -59,8 +59,8 @@ programming. These tags are clearly marked in the list below and should be consi
|
||||||
- amp (float, Ampere) is the amount of current flowing through the 120V outlet.
|
- amp (float, Ampere) is the amount of current flowing through the 120V outlet.
|
||||||
- watt (float, Watt) represents the amount of energy flowing through the 120V outlet.
|
- watt (float, Watt) represents the amount of energy flowing through the 120V outlet.
|
||||||
- xstatus (string) indicates the xstatus of an outlet. Found on wireless Vortech devices.
|
- xstatus (string) indicates the xstatus of an outlet. Found on wireless Vortech devices.
|
||||||
- power_failed (int64, Unix epoch in ns) when the controller last lost power.
|
- power_failed (int64, Unix epoch in ns) when the controller last lost power. Omitted if the apex reports it as "none"
|
||||||
- power_restored (int64, Unix epoch in ns) when the controller last powered on.
|
- power_restored (int64, Unix epoch in ns) when the controller last powered on. Omitted if the apex reports it as "none"
|
||||||
- serial (string, serial number)
|
- serial (string, serial number)
|
||||||
- time:
|
- time:
|
||||||
- The time used for the metric is parsed from the status.xml page. This helps when cross-referencing events with
|
- The time used for the metric is parsed from the status.xml page. This helps when cross-referencing events with
|
||||||
|
|
|
@ -110,27 +110,21 @@ func (n *NeptuneApex) parseXML(acc telegraf.Accumulator, data []byte) error {
|
||||||
err, data)
|
err, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mainFields := map[string]interface{}{
|
||||||
|
"serial": r.Serial,
|
||||||
|
}
|
||||||
var reportTime time.Time
|
var reportTime time.Time
|
||||||
var powerFailed, powerRestored int64
|
|
||||||
if reportTime, err = parseTime(r.Date, r.Timezone); err != nil {
|
if reportTime, err = parseTime(r.Date, r.Timezone); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if val, err := parseTime(r.PowerFailed, r.Timezone); err != nil {
|
if val, err := parseTime(r.PowerFailed, r.Timezone); err == nil {
|
||||||
return err
|
mainFields["power_failed"] = val.UnixNano()
|
||||||
} else {
|
|
||||||
powerFailed = val.UnixNano()
|
|
||||||
}
|
}
|
||||||
if val, err := parseTime(r.PowerRestored, r.Timezone); err != nil {
|
if val, err := parseTime(r.PowerRestored, r.Timezone); err == nil {
|
||||||
return err
|
mainFields["power_restored"] = val.UnixNano()
|
||||||
} else {
|
|
||||||
powerRestored = val.UnixNano()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
mainFields := map[string]interface{}{
|
|
||||||
"serial": r.Serial,
|
|
||||||
"power_failed": powerFailed,
|
|
||||||
"power_restored": powerRestored,
|
|
||||||
}
|
|
||||||
acc.AddFields(Measurement, mainFields,
|
acc.AddFields(Measurement, mainFields,
|
||||||
map[string]string{
|
map[string]string{
|
||||||
"source": r.Hostname,
|
"source": r.Hostname,
|
||||||
|
|
|
@ -226,7 +226,22 @@ func TestParseXML(t *testing.T) {
|
||||||
`<status><date>12/22/2018 21:55:37</date>
|
`<status><date>12/22/2018 21:55:37</date>
|
||||||
<timezone>-8.0</timezone><power><failed>a</failed>
|
<timezone>-8.0</timezone><power><failed>a</failed>
|
||||||
<restored>12/22/2018 22:55:37</restored></power></status>`),
|
<restored>12/22/2018 22:55:37</restored></power></status>`),
|
||||||
wantErr: true,
|
wantMetrics: []*testutil.Metric{
|
||||||
|
{
|
||||||
|
Measurement: Measurement,
|
||||||
|
Time: goodTime,
|
||||||
|
Tags: map[string]string{
|
||||||
|
"source": "",
|
||||||
|
"type": "controller",
|
||||||
|
"hardware": "",
|
||||||
|
"software": "",
|
||||||
|
},
|
||||||
|
Fields: map[string]interface{}{
|
||||||
|
"serial": "",
|
||||||
|
"power_restored": int64(1545548137000000000),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Power restored time failure",
|
name: "Power restored time failure",
|
||||||
|
@ -234,7 +249,22 @@ func TestParseXML(t *testing.T) {
|
||||||
`<status><date>12/22/2018 21:55:37</date>
|
`<status><date>12/22/2018 21:55:37</date>
|
||||||
<timezone>-8.0</timezone><power><restored>a</restored>
|
<timezone>-8.0</timezone><power><restored>a</restored>
|
||||||
<failed>12/22/2018 22:55:37</failed></power></status>`),
|
<failed>12/22/2018 22:55:37</failed></power></status>`),
|
||||||
wantErr: true,
|
wantMetrics: []*testutil.Metric{
|
||||||
|
{
|
||||||
|
Measurement: Measurement,
|
||||||
|
Time: goodTime,
|
||||||
|
Tags: map[string]string{
|
||||||
|
"source": "",
|
||||||
|
"type": "controller",
|
||||||
|
"hardware": "",
|
||||||
|
"software": "",
|
||||||
|
},
|
||||||
|
Fields: map[string]interface{}{
|
||||||
|
"serial": "",
|
||||||
|
"power_failed": int64(1545548137000000000),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Power failed failure",
|
name: "Power failed failure",
|
||||||
|
|
Loading…
Reference in New Issue