From e892a2e3b0833ddefae5d519c1c07bdc7333a786 Mon Sep 17 00:00:00 2001 From: "Markus Kitsinger (SwooshyCueb)" Date: Wed, 7 Sep 2022 15:05:46 -0400 Subject: [PATCH] [#95] use boost to get hostname --- libirods_rule_engine_plugin-audit_amqp.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/libirods_rule_engine_plugin-audit_amqp.cpp b/libirods_rule_engine_plugin-audit_amqp.cpp index c6c2e7741..0fa1f774f 100644 --- a/libirods_rule_engine_plugin-audit_amqp.cpp +++ b/libirods_rule_engine_plugin-audit_amqp.cpp @@ -12,6 +12,7 @@ // boost includes #include +#include #include #include #include @@ -317,16 +318,13 @@ namespace nlohmann::json json_obj; - char host_name[MAX_NAME_LEN]; - gethostname(host_name, MAX_NAME_LEN); - std::string msg_str; std::string log_file; try { std::uint64_t time_ms = ts_clock::now().time_since_epoch() / std::chrono::milliseconds(1); json_obj["@timestamp"] = time_ms; - json_obj["hostname"] = host_name; + json_obj["hostname"] = boost::asio::ip::host_name(); pid_t pid = getpid(); json_obj["pid"] = pid; @@ -379,9 +377,7 @@ namespace std::uint64_t time_ms = ts_clock::now().time_since_epoch() / std::chrono::milliseconds(1); json_obj["@timestamp"] = time_ms; - char host_name[MAX_NAME_LEN]; - gethostname(host_name, MAX_NAME_LEN); - json_obj["hostname"] = host_name; + json_obj["hostname"] = boost::asio::ip::host_name(); pid_t pid = getpid(); json_obj["pid"] = pid; @@ -467,11 +463,7 @@ namespace try { std::uint64_t time_ms = ts_clock::now().time_since_epoch() / std::chrono::milliseconds(1); json_obj["@timestamp"] = time_ms; - - char host_name[MAX_NAME_LEN]; - gethostname(host_name, MAX_NAME_LEN); - json_obj["hostname"] = host_name; - + json_obj["hostname"] = boost::asio::ip::host_name(); json_obj["pid"] = getpid(); json_obj["rule_name"] = _rn;