Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 6 additions & 1 deletion src/go/plugin/go.d/collector/rabbitmq/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ func (c *Collector) getClusterMeta() (id string, name string, err error) {
return "", "", fmt.Errorf("unexpected response: whoami: user name n is empty")
}

if !slices.Contains(user.Tags, "administrator") {
// In RabbitMQ < 3.8.3 the `tags` field may be returned as a single string
// (e.g. "administrator,management") instead of an array. We intentionally
// treat it as one tag and do not split on commas here.
if !slices.ContainsFunc(user.Tags, func(s string) bool {
return strings.Contains(s, "administrator")
}) {
c.Warningf("user %s lacks 'administrator' tag: cluster ID and name cannot be collected.", user.Name)
return "", "", nil
}
Expand Down
27 changes: 25 additions & 2 deletions src/go/plugin/go.d/collector/rabbitmq/restapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

package rabbitmq

import (
"encoding/json"
"fmt"
)

const (
urlPathAPIWhoami = "/api/whoami"
urlPathAPIDefinitions = "/api/definitions"
Expand All @@ -12,8 +17,26 @@ const (
)

type apiWhoamiResp struct {
Name string `json:"name"`
Tags []string `json:"tags"`
Name string `json:"name"`
Tags apiWhoamiTags `json:"tags"`
}

type apiWhoamiTags []string

func (a *apiWhoamiTags) UnmarshalJSON(data []byte) error {
var multi []string
if err := json.Unmarshal(data, &multi); err == nil {
*a = multi
return nil
}

var single string
if err := json.Unmarshal(data, &single); err == nil {
*a = []string{single}
return nil
}

return fmt.Errorf("unexpected tags format: %s", string(data))
}

type apiDefinitionsResp struct {
Expand Down
1 change: 1 addition & 0 deletions src/plugins.d/plugins_d.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ static bool is_plugin(char *dst, size_t dst_size, const char *filename) {
".plugin.exe",
"_plugin.exe",
"-plugin.exe",
".plugin",
NULL
};
#else
Expand Down
Loading