summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ingestor.cpp6
-rw-r--r--src/ingestor.hpp3
-rw-r--r--src/webstat_logger_main.cpp20
3 files changed, 26 insertions, 3 deletions
diff --git a/src/ingestor.cpp b/src/ingestor.cpp
index a5a2e57..4084d2e 100644
--- a/src/ingestor.cpp
+++ b/src/ingestor.cpp
@@ -41,7 +41,11 @@ namespace WebStat {
}
}
- Ingestor::Ingestor(DB::ConnectionPtr dbconn) : dbconn {std::move(dbconn)} { }
+ Ingestor::Ingestor(const std::string_view hostname, DB::ConnectionPtr dbconn) :
+ hostnameId {crc32(hostname)}, dbconn {std::move(dbconn)}
+ {
+ storeEntity({hostnameId, hostname});
+ }
Ingestor::ScanResult
Ingestor::scanLogLine(std::string_view input)
diff --git a/src/ingestor.hpp b/src/ingestor.hpp
index a7a57a6..892cc9c 100644
--- a/src/ingestor.hpp
+++ b/src/ingestor.hpp
@@ -9,7 +9,7 @@
namespace WebStat {
class Ingestor {
public:
- Ingestor(DB::ConnectionPtr dbconn);
+ Ingestor(std::string_view hostname, DB::ConnectionPtr dbconn);
virtual ~Ingestor() = default;
SPECIAL_MEMBERS_DEFAULT_MOVE_NO_COPY(Ingestor);
@@ -33,6 +33,7 @@ namespace WebStat {
size_t linesDiscarded = 0;
private:
+ uint32_t hostnameId;
DB::ConnectionPtr dbconn;
};
}
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);
}