Skip to content

Commit

Permalink
add global persistant broker storage
Browse files Browse the repository at this point in the history
This PR adds a global key/value storage which is persitant over reloads (but not restarts).
The storage could be used from neb modules to store data over reloads like this:

```c
// fetch global storage
struct kvvec *global_store = get_global_store();

// store string value
kvvec_addkv_str(global_store, "example_key", (char *)mkstr("%s", "example string value"));

// read string from storage
char *persistant = kvvec_fetch_str_str(global_store, "example_key");
```

Signed-off-by: Sven Nierlein <[email protected]>
  • Loading branch information
sni committed Oct 1, 2021
1 parent fa9c19d commit cae7c16
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/naemon/broker.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@
#include <string.h>
#include <sys/time.h>

static struct kvvec global_store = KVVEC_INITIALIZER;

struct kvvec *get_global_store(void)
{
return &global_store;
}

/* gets timestamp for use by broker */
static inline void get_broker_timestamp(struct timeval *timestamp)
Expand Down
1 change: 1 addition & 0 deletions src/naemon/broker.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@

NAGIOS_BEGIN_DECL

struct kvvec *get_global_store(void);
void broker_program_state(int, int, int);
void broker_log_data(int, int, int, char *, unsigned long, time_t);
int broker_event_handler(int, int, int, int, void *, int, int, struct timeval, struct timeval, double, int, int, int, char *, char *, char *);
Expand Down
6 changes: 6 additions & 0 deletions src/naemon/naemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ int main(int argc, char **argv)
nagios_macros *mac;
const char *worker_socket = NULL;
int i;
struct kvvec *global_store;

#ifdef HAVE_GETOPT_H
int option_index = 0;
Expand Down Expand Up @@ -227,6 +228,11 @@ int main(int argc, char **argv)
G_LOG_FLAG_RECURSION, nm_g_log_handler, NULL);
mac = get_global_macros();

global_store = get_global_store();
if (global_store && !kvvec_init(global_store, 0)) {
exit(ERROR);
}

/* if we're a worker we can skip everything below */
if (worker_socket) {
exit(nm_core_worker(worker_socket));
Expand Down

0 comments on commit cae7c16

Please sign in to comment.