5 #include <spdlog/fmt/ostr.h>
6 #include <spdlog/spdlog.h>
11 shared_ptr<spdlog::logger> logger =
nullptr;
14 logger->info(
"obmon-broker -i tcp://*:5000 -o tcp://*:5001");
17 int main(
int argc,
char **argv) {
20 auto console = spdlog::stdout_logger_mt(
"console");
21 logger = spdlog::get(
"console");
23 char *short_options = strdup(
"i:o:h");
24 struct option long_options[] = {{
"in", 1, NULL,
'i'},
25 {
"out", 1, NULL,
'o'},
26 {
"help", 0, NULL,
'h'},
29 string in =
"@tcp://*:5000";
30 string out =
"@tcp://*:5001";
31 char nextOption = getopt_long(argc, argv, short_options, long_options, NULL);
32 while (nextOption != -1) {
50 nextOption = getopt_long(argc, argv, short_options, long_options, NULL);
55 if (getenv(
"OBMON_LOG")) {
56 int rc = sscanf(getenv(
"OBMON_LOG"),
"%d", &debugLevel);
58 logger->error(
"salsa: OBMON_LOG is not a number: {}",
70 "Setting log level to '{}' ...",
71 spdlog::level::to_str((spdlog::level::level_enum)(6 - debugLevel)));
72 spdlog::set_level((spdlog::level::level_enum)(6 - debugLevel));
75 map<string, string> state;
76 logger->info(
"Connected to in={} out={}", in, out);
78 zsock_t *sub = zsock_new_sub(in.data(),
"");
81 zsock_t *pub = zsock_new_pub(out.data());
83 while (!zsys_interrupted) {
84 zmsg_t *msg_in = zmsg_recv(sub);
88 char *sub_str = zmsg_popstr(msg_in);
89 char *cluster = zmsg_popstr(msg_in);
90 char *host = zmsg_popstr(msg_in);
91 char *json_str = zmsg_popstr(msg_in);
92 zmsg_destroy(&msg_in);
94 state[host] = json_str;
97 for (
auto &kv : state) {
99 json +=
"{ \"name\" : \"";
101 json +=
"\", \"data\" : { ";
107 if (json.back() ==
',')
112 logger->trace(
"{}", json);
114 zmsg_t *msg_out = zmsg_new();
115 zmsg_addstr(msg_out, sub_str);
116 zmsg_addstr(msg_out, cluster);
117 zmsg_addstr(msg_out, host);
118 zmsg_addstr(msg_out, json.data());
120 zmsg_send(&msg_out, pub);
127 zmsg_destroy(&msg_out);