summaryrefslogtreecommitdiff
path: root/src/webstat_logger_main.cpp
diff options
context:
space:
mode:
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);
}