heartbeat

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

commit f966b137279ee388aef1422f0f26724d0dabfaa2
parent be690bc5eb12fd7280b1ebf73d7b82113db7f94c
Author: Remy Noulin <loader2x@gmail.com>
Date:   Sun, 23 Jul 2023 07:55:16 +0200

add flexible timeout and call selInit

heartbeat.c         | 14 +++++++++++++-
heartbeatConfig.yml |  2 ++
2 files changed, 15 insertions(+), 1 deletion(-)

Diffstat:
Mheartbeat.c | 14+++++++++++++-
MheartbeatConfig.yml | 2++
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/heartbeat.c b/heartbeat.c @@ -7,6 +7,8 @@ #include "shpPackages/short/short.h" #include "shpPackages/termbox/termbox.h" +// In monitor, do not clear port state when c is pressed +// >> when port state is on, a service is not running and it needs to be fixed /* Commands: @@ -176,6 +178,10 @@ void printHelp(void) { void config(smallJsont *cfg) { //lv(cfg); + if (not selInit()) { + logE("selInit failed"); + XFailure; + } // generate agent configs: agentNameConfig.yml // add shell commands to copyScript @@ -597,6 +603,11 @@ void probe(char *cfgfile, char *secretFile, char *publicFile, char *loggerPublic // send mail // when agent is not logger, forward message + if (not selInit()) { + logE("selInit failed"); + XFailure; + } + u64 counter = 0; cleanCharP(counterfn) = expandHome(uHome home counterFilename); if (isPath(counterfn)) { @@ -963,7 +974,8 @@ void probe(char *cfgfile, char *secretFile, char *publicFile, char *loggerPublic if (!isOSmallDict(D)) continue; cast(smallDictt*,d,D); if (eqG($(d, "state"), "down")) continue; - if (getCurrentUnixTime() - u$(d, "time") < agentTimeOut) continue; + u64 timeout = u$(d, "timeout") ? u$(d, "timeout") : agentTimeOut; + if (getCurrentUnixTime() - u$(d, "time") < timeout) continue; // send mail when agent is down cleanCharP(s) = formatS("%s is down, previous state was %s", iK(completeCfg)/*agent name*/, $(d,"state")); pushG(mailMsg, s); diff --git a/heartbeatConfig.yml b/heartbeatConfig.yml @@ -20,6 +20,8 @@ agent1: bridge: "logger" mails: - 'admin@example.com' + timeout: 90 # time after which the agent is down if no packet is received + # TODO sleep time between messages - period: 300 agent2: address: "192.168.1.4" probes: