heartbeat

Simple server monitor system using encrypted messages over udp
git clone https://noulin.net/git/heartbeat.git
Log | Files | Refs | README

commit 5849b2d91c7a62767c3ef21cb89eed487fa39a2a
parent c61c11faea964884aee8fdfbc5030d7df27ce0a9
Author: Remy Noulin <loader2x@gmail.com>
Date:   Sat,  8 Jul 2023 07:48:14 +0200

set correct monitor port

heartbeat.c | 42 +++++++++++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 11 deletions(-)

Diffstat:
Mheartbeat.c | 42+++++++++++++++++++++++++++++++-----------
1 file changed, 31 insertions(+), 11 deletions(-)

diff --git a/heartbeat.c b/heartbeat.c @@ -364,6 +364,9 @@ void probe(char *cfgfile) { // send mail // when agent is not logger, forward message + // complete configuration in logger + cleanSmallJsonP(completeCfg) = null; + // load agent config cleanAllocateSmallJson(cfg); readFileG(cfg, cfgfile); @@ -396,8 +399,33 @@ void probe(char *cfgfile) { u32 id = u$(agent, "id"); bool logger = hasG(agent, "logger"); if (logger) { + // load complete configuration to get monitorPort + completeCfg = allocG(rtSmallJsont); + cleanCharP(p) = expandHome(uHome home "/" cfgFile); + smallJsont *r = readFileG(completeCfg, p); + if (!r) { + logE("Missing %s", p); + XFailure; + } + delElemG(completeCfg, "port"); + + // find logger config + const char *loggerName = null; + iter(cfg, D) { + cast(smallDictt*, d, D); + if (hasG(d, "logger")) { + loggerName = iK(cfg); + break; + } + } + cleanFinishSmallDictP(logger) = getG(cfg, rtSmallDictt, loggerName); + // set monitor port - port = u$(agent, "monitorPort"); + port = u$(logger, "monitorPort"); + if (!port) { + logE("monitorPort missing in logger configuration"); + XFailure; + } } char *dst = logger ? "localhost" /*TODO add monitorIp*/ : $(agent, "bridge"); if (!dst) { @@ -417,7 +445,6 @@ void probe(char *cfgfile) { //lv(period); // setup logger - cleanSmallJsonP(completeCfg) = null; // agent names cleanListP(agents) = null; // agent db filenames @@ -429,15 +456,6 @@ void probe(char *cfgfile) { if (logger) { startTime = getCurrentUnixTime(); - completeCfg = allocG(rtSmallJsont); - cleanCharP(p) = expandHome(uHome home "/" cfgFile); - smallJsont *r = readFileG(completeCfg, p); - if (!r) { - logE("Missing %s", p); - XFailure; - } - delElemG(completeCfg, "port"); - // create filename with path in ~/.heartbeat/ agents = keysG(completeCfg); agentdbs = keysG(completeCfg); @@ -686,6 +704,8 @@ void probe(char *cfgfile) { // send to monitor //lv(completeCfg); cleanCharP(monitorData) = toStringG(completeCfg); + size_t size = lenG(monitorData)+1; + lv(size); if (sendto(sock, monitorData, lenG(monitorData)+1, 0, (const struct sockaddr *)&server, sizeof(server)) < 0) { logE("monitor send failed: %s", strerror(errno)); close(sock);