Status Config::mergeConfig(const std::string& source, ConfigData& conf) { pt::ptree tree; try { std::stringstream json_data; json_data << source; pt::read_json(json_data, tree); } catch (const pt::json_parser::json_parser_error& e) { LOG(WARNING) << "Error parsing config JSON: " << e.what(); return Status(1, e.what()); } if (tree.count("additional_monitoring") > 0) { LOG(INFO) << RLOG(903) << "config 'additional_monitoring' is deprecated"; for (const auto& node : tree.get_child("additional_monitoring")) { tree.add_child(node.first, node.second); } tree.erase("additional_monitoring"); } for (const auto& item : tree) { // Iterate over each top-level configuration key. auto key = std::string(item.first.data()); if (key == "scheduledQueries") { LOG(INFO) << RLOG(903) << "config 'scheduledQueries' is deprecated"; for (const auto& node : item.second) { auto query_name = node.second.get<std::string>("name", ""); mergeScheduledQuery(query_name, node, conf); } } else if (key == "schedule") { for (const auto& node : item.second) { mergeScheduledQuery(node.first.data(), node, conf); } } else if (key == "options") { for (const auto& option : item.second) { mergeOption(option, conf); } } else if (key == "file_paths") { for (const auto& category : item.second) { mergeFilePath(key, category, conf); } } else { mergeExtraKey(key, item, conf); } } return Status(0, "OK"); }
void Config::mergeConfig(const std::string& source, ConfigData& conf) { std::stringstream json_data; json_data << source; pt::ptree tree; try { pt::read_json(json_data, tree); } catch (const pt::ptree_error& e) { VLOG(1) << "There was an error parsing the JSON read from a file: " << e.what(); return; } // Legacy query schedule vector support. if (tree.count("scheduledQueries") > 0) { LOG(INFO) << RLOG(903) << "config 'scheduledQueries' is deprecated"; for (const auto& node : tree.get_child("scheduledQueries")) { auto query_name = node.second.get<std::string>("name", ""); mergeScheduledQuery(query_name, node, conf); } } // Key/value query schedule map support. if (tree.count("schedule") > 0) { for (const auto& node : tree.get_child("schedule")) { mergeScheduledQuery(node.first.data(), node, conf); } } if (tree.count("additional_monitoring") > 0) { for (const auto& node : tree.get_child("additional_monitoring")) { mergeAdditional(node, conf); } } if (tree.count("options") > 0) { for (const auto& option : tree.get_child("options")) { mergeOption(option, conf); } } }