From b446381dfa3f4298262ad8c7ef942d4ec64bcbea Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Sat, 23 Aug 2025 17:06:01 +0100 Subject: Provide hostname to Ingestor Store its Entity immediately for later use. --- src/webstat_logger_main.cpp | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'src/webstat_logger_main.cpp') diff --git a/src/webstat_logger_main.cpp b/src/webstat_logger_main.cpp index 8f2d45a..e4f871e 100644 --- a/src/webstat_logger_main.cpp +++ b/src/webstat_logger_main.cpp @@ -1,9 +1,27 @@ #include "ingestor.hpp" +#include #include +#include + +namespace { + [[nodiscard]] + std::string + getHostname(bool fqdn) + { + utsname uts {}; + if (uname(&uts)) { + throw std::runtime_error(std::format("Failed to get hostname (uts: {}:{})", errno, strerror(errno))); + } + if (fqdn) { + return std::format("{}.{}", uts.nodename, uts.domainname); + } + return uts.nodename; + } +} int main(int, char **) { auto dbconn = std::make_shared("dbname=webstat user=webstat"); - WebStat::Ingestor {dbconn}.ingestLog(stdin); + WebStat::Ingestor {getHostname(false), dbconn}.ingestLog(stdin); } -- cgit v1.2.3