summaryrefslogtreecommitdiff
path: root/src/webstat_logger_main.cpp
diff options
context:
space:
mode:
authorDan Goodliffe <dan@randomdan.homeip.net>2025-08-23 17:06:01 +0100
committerDan Goodliffe <dan@randomdan.homeip.net>2025-08-25 16:02:34 +0100
commitb446381dfa3f4298262ad8c7ef942d4ec64bcbea (patch)
tree464418b6892a5c30611ef23922cc55c0c03ef116 /src/webstat_logger_main.cpp
parent2db6c4f42a20c0c2a9b32545f4d6fab90be2c26d (diff)
downloadwebstat-b446381dfa3f4298262ad8c7ef942d4ec64bcbea.tar.bz2
webstat-b446381dfa3f4298262ad8c7ef942d4ec64bcbea.tar.xz
webstat-b446381dfa3f4298262ad8c7ef942d4ec64bcbea.zip
Provide hostname to Ingestor
Store its Entity immediately for later use.
Diffstat (limited to 'src/webstat_logger_main.cpp')
-rw-r--r--src/webstat_logger_main.cpp20
1 files changed, 19 insertions, 1 deletions
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 <format>
#include <pq-connection.h>
+#include <sys/utsname.h>
+
+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<PQ::Connection>("dbname=webstat user=webstat");
- WebStat::Ingestor {dbconn}.ingestLog(stdin);
+ WebStat::Ingestor {getHostname(false), dbconn}.ingestLog(stdin);
}