Initial demo for Promo-Operation

This commit is contained in:
Gustice authored and Jakob Gegeniger committed 2026-09-08 23:23:37 +02:00
1 parent 55b7909717
commit eb1c84cf05
25 files changed
+24615 -2

No files matched your search

+2
View File
@@ -0,0 +1,2 @@
create_interface()
File diff suppressed because it is too large. Load diff
+1
View File
@@ -0,0 +1 @@
https://github.com/yhirose/cpp-httplib
+80
View File
@@ -0,0 +1,80 @@
#pragma once
#include "../extern/httplib.h"
#include <fmt/core.h>
#include <fmt/chrono.h>
#include <nlohmann/json.hpp>
class SeqLogger {
public:
SeqLogger(std::string logUrl, std::string apiKey, std::string name)
: cli(logUrl),
ApiKey(apiKey),
AppName(name) {
}
void sendBootUp(std::string version, std::string mode) {
std::string timestamp = createTimestamp();
nlohmann::json json_payload = {
{"Events", nlohmann::json::array({
{
{"Level", "Information"},
{"Timestamp", timestamp},
{"MessageTemplate", "[{App}] Firing up in {Mode}! Version {Ver}"},
{"Properties", {
{"App", AppName},
{"Ver", version},
{"Mode", mode}
}}
}
})}
};
sendPayload(json_payload.dump());
}
void sendEvent(std::string event, std::string message) {
std::string timestamp = createTimestamp();
nlohmann::json json_payload = {
{"Events", nlohmann::json::array({
{
{"Level", "Information"},
{"Timestamp", timestamp},
{"MessageTemplate", "[{App}]: Got {Event}; " + message},
{"Properties", {
{"App", AppName},
{"Event", Version}
}}
}
})}
};
sendPayload(json_payload.dump());
}
private:
httplib::Client cli;
const std::string ApiKey;
const std::string AppName;
const std::string Version;
static std::string createTimestamp() {
auto now = std::chrono::system_clock::now();
return fmt::format("{:%Y-%m-%dT%H:%M:%SZ}", now);
}
void sendPayload(std::string payload) {
httplib::Headers headers = {
{"X-Seq-ApiKey", ApiKey}};
auto res = cli.Post("/api/events/raw", headers, payload, "application/json");
if (res) {
if (res->status == 201) {
fmt::println("Success! Log accepted by Seq.");
} else {
fmt::println("Seq rejected the log.");
fmt::println(" HTTP Status: {}", res->status);
fmt::println(" Server Response: {}", res->body);
}
} else {
fmt::println(stderr, "Failed to connect to Seq server. Error: {}", httplib::to_string(res.error()));
}
}
};