Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nagios parser to parse all perfdata and report info message. #5601

Merged
merged 6 commits into from
Mar 25, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use service_output, long_service_output names. Use '\n' concatenator.
  • Loading branch information
Sergey Khegay committed Mar 21, 2019
commit cf33a0098c28043dbffbaf702c03cafcf5adc7b7
10 changes: 5 additions & 5 deletions plugins/parsers/nagios/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (p *NagiosParser) Parse(buf []byte) ([]telegraf.Metric, error) {
if bytes.Contains(s.Bytes(), []byte{'|'}) {
parts := bytes.Split(s.Bytes(), []byte{'|'})
if longmsg.Len() != 0 {
longmsg.WriteByte(' ')
longmsg.WriteByte('\n')
}
longmsg.Write(bytes.TrimSpace(parts[0]))

Expand All @@ -141,7 +141,7 @@ func (p *NagiosParser) Parse(buf []byte) ([]telegraf.Metric, error) {
break
}
if longmsg.Len() != 0 {
longmsg.WriteByte(' ')
longmsg.WriteByte('\n')
}
longmsg.Write(bytes.TrimSpace((s.Bytes())))
}
Expand All @@ -161,11 +161,11 @@ func (p *NagiosParser) Parse(buf []byte) ([]telegraf.Metric, error) {

// Create nagios state.
fields := map[string]interface{}{
"state": state,
"msg": msg.String(),
"state": state,
"service_output": msg.String(),
}
if longmsg.Len() != 0 {
fields["longmsg"] = longmsg.String()
fields["long_service_output"] = longmsg.String()
}

m, err := metric.New("nagios_state", nil, fields, ts)
Expand Down
32 changes: 16 additions & 16 deletions plugins/parsers/nagios/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ with three lines
}, metrics[1].Fields())

assertNagiosState(t, metrics[2], map[string]interface{}{
"state": int64(0),
"msg": "PING OK - Packet loss = 0%, RTA = 0.30 ms",
"longmsg": "This is a long output with three lines",
"state": int64(0),
"service_output": "PING OK - Packet loss = 0%, RTA = 0.30 ms",
"long_service_output": "This is a long output\nwith three lines",
})
},
},
Expand All @@ -175,8 +175,8 @@ with three lines
}, metrics[0].Fields())

assertNagiosState(t, metrics[1], map[string]interface{}{
"state": int64(0),
"msg": "TCP OK - 0.008 second response time on port 80",
"state": int64(0),
"service_output": "TCP OK - 0.008 second response time on port 80",
})
},
},
Expand All @@ -195,8 +195,8 @@ with three lines
}, metrics[0].Fields())

assertNagiosState(t, metrics[1], map[string]interface{}{
"state": int64(0),
"msg": "TCP OK - 0.008 second response time on port 80",
"state": int64(0),
"service_output": "TCP OK - 0.008 second response time on port 80",
})
},
},
Expand Down Expand Up @@ -246,8 +246,8 @@ with three lines
}, metrics[2].Fields())

assertNagiosState(t, metrics[3], map[string]interface{}{
"state": int64(0),
"msg": "OK: Load average: 0.00, 0.01, 0.05",
"state": int64(0),
"service_output": "OK: Load average: 0.00, 0.01, 0.05",
})
},
},
Expand All @@ -259,8 +259,8 @@ with three lines
require.Len(t, metrics, 1)

assertNagiosState(t, metrics[0], map[string]interface{}{
"state": int64(0),
"msg": "PING OK - Packet loss = 0%, RTA = 0.30 ms",
"state": int64(0),
"service_output": "PING OK - Packet loss = 0%, RTA = 0.30 ms",
})
},
},
Expand All @@ -272,8 +272,8 @@ with three lines
require.Len(t, metrics, 1)

assertNagiosState(t, metrics[0], map[string]interface{}{
"state": int64(0),
"msg": "PING OK - Packet loss = 0%, RTA = 0.30 ms",
"state": int64(0),
"service_output": "PING OK - Packet loss = 0%, RTA = 0.30 ms",
})
},
},
Expand Down Expand Up @@ -351,9 +351,9 @@ with three lines
}, metrics[3].Fields())

assertNagiosState(t, metrics[4], map[string]interface{}{
"state": int64(0),
"msg": "DISK OK - free space: / 3326 MB (56%);",
"longmsg": "/ 15272 MB (77%); /boot 68 MB (69%); /home 69357 MB (27%); /var/log 819 MB (84%);",
"state": int64(0),
"service_output": "DISK OK - free space: / 3326 MB (56%);",
"long_service_output": "/ 15272 MB (77%);\n/boot 68 MB (69%);\n/home 69357 MB (27%);\n/var/log 819 MB (84%);",
})
},
},
Expand Down