-
Notifications
You must be signed in to change notification settings - Fork 12
/
discovery.go
51 lines (37 loc) · 1005 Bytes
/
discovery.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"encoding/json"
"fmt"
rabbithole "github.com/michaelklishin/rabbit-hole"
)
func discovery(
rmqc *rabbithole.Client,
allQueues map[string][]rabbithole.QueueInfo,
aggGroup string,
aggregate bool,
) error {
discoveryData := make(map[string][]map[string]string)
var discoveredItems []map[string]string
for vhost, queues := range allQueues {
for _, queue := range queues {
discoveredItem := make(map[string]string)
if aggregate {
discoveredItem["{#GROUPNAME}"] = aggGroup
discoveredItem["{#AGGQUEUENAME}"] = queue.Name
discoveredItem["{#AGGVHOST}"] = vhost
discoveredItems = append(discoveredItems, discoveredItem)
continue
}
discoveredItem["{#QUEUENAME}"] = queue.Name
discoveredItem["{#VHOST}"] = vhost
discoveredItems = append(discoveredItems, discoveredItem)
}
}
discoveryData["data"] = discoveredItems
out, err := json.Marshal(discoveryData)
if err != nil {
return err
}
fmt.Printf("%s\n", out)
return nil
}