Adding upstream version 1.34.4.
Signed-off-by: Daniel Baumann <daniel@debian.org>
This commit is contained in:
parent
e393c3af3f
commit
4978089aab
4963 changed files with 677545 additions and 0 deletions
55
plugins/inputs/dpdk/dpdk_cmds.go
Normal file
55
plugins/inputs/dpdk/dpdk_cmds.go
Normal file
|
@ -0,0 +1,55 @@
|
|||
//go:build linux
|
||||
|
||||
package dpdk
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type linkStatus int64
|
||||
|
||||
const (
|
||||
down linkStatus = iota
|
||||
up
|
||||
)
|
||||
|
||||
const (
|
||||
ethdevLinkStatusCommand = "/ethdev/link_status"
|
||||
linkStatusStringFieldName = "status"
|
||||
linkStatusIntegerFieldName = "link_status"
|
||||
)
|
||||
|
||||
var (
|
||||
linkStatusMap = map[string]linkStatus{
|
||||
"down": down,
|
||||
"up": up,
|
||||
}
|
||||
)
|
||||
|
||||
func processCommandResponse(command string, data map[string]interface{}) error {
|
||||
if command == ethdevLinkStatusCommand {
|
||||
return processLinkStatusCmd(data)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func processLinkStatusCmd(data map[string]interface{}) error {
|
||||
status, ok := data[linkStatusStringFieldName].(string)
|
||||
if !ok {
|
||||
return fmt.Errorf("can't find or parse %q field", linkStatusStringFieldName)
|
||||
}
|
||||
|
||||
parsedLinkStatus, ok := parseLinkStatus(status)
|
||||
if !ok {
|
||||
return fmt.Errorf("can't parse linkStatus: unknown value: %q", status)
|
||||
}
|
||||
|
||||
data[linkStatusIntegerFieldName] = int64(parsedLinkStatus)
|
||||
return nil
|
||||
}
|
||||
|
||||
func parseLinkStatus(s string) (linkStatus, bool) {
|
||||
value, ok := linkStatusMap[strings.ToLower(s)]
|
||||
return value, ok
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue