Module: check_mk
Branch: master
Commit: 4796c25ce8d216e4fe0daa3270c9a5819770bfd1
URL:
http://git.mathias-kettner.de/git/?p=check_mk.git;a=commit;h=4796c25ce8d216…
Author: Sven Panne <sp(a)mathias-kettner.de>
Date: Mon Aug 8 13:20:58 2016 +0200
Convert our Nagios event broker to C++.
Doing this is trivial and opens up tons of simplifications: We just needed
to specify "C" linkage for the NEB (de)init functions and fix a handful of
trivial C vs. C++ incompatibilities.
---
livestatus/src/Makefile.am | 2 +-
livestatus/src/{module.c => module.cc} | 20 +++++++++++---------
2 files changed, 12 insertions(+), 10 deletions(-)
diff --git a/livestatus/src/Makefile.am b/livestatus/src/Makefile.am
index 82a144b..9690b97 100644
--- a/livestatus/src/Makefile.am
+++ b/livestatus/src/Makefile.am
@@ -147,7 +147,7 @@ livestatus_so_SOURCES = \
logger.c \
mk_inventory.cc \
mk_logwatch.cc \
- module.c \
+ module.cc \
opids.cc \
pnp4nagios.cc \
store_c.cc \
diff --git a/livestatus/src/module.c b/livestatus/src/module.cc
similarity index 98%
rename from livestatus/src/module.c
rename to livestatus/src/module.cc
index 5640b23..22eefca 100644
--- a/livestatus/src/module.c
+++ b/livestatus/src/module.cc
@@ -101,8 +101,8 @@ int g_group_authorization = AUTH_STRICT;
int g_data_encoding = ENCODING_UTF8;
/* simple statistics data for TableStatus */
-extern struct host *host_list;
-extern struct service *service_list;
+extern host *host_list;
+extern service *service_list;
extern scheduled_downtime *scheduled_downtime_list;
extern int log_initial_states;
@@ -429,7 +429,7 @@ int broker_program(int event_type __attribute__((__unused__)),
return 0;
}
-char *get_downtime_comment(char *host_name, char *svc_desc) {
+const char *get_downtime_comment(char *host_name, char *svc_desc) {
char *comment;
int matches = 0;
scheduled_downtime *dt_list = scheduled_downtime_list;
@@ -491,8 +491,10 @@ int broker_event(int event_type __attribute__((__unused__)), void
*data) {
if (g_thread_running == 1) {
livestatus_log_initial_states();
} else if (log_initial_states == 1) {
- write_to_all_logs("logging initial states",
- LG_INFO); // initial info during startup
+ // initial info during startup
+ // TODO(sp) The Nagios headers are (once again) not const-correct...
+ write_to_all_logs(const_cast<char *>("logging initial
states"),
+ LG_INFO);
}
}
update_timeperiods_cache(ts->timestamp.tv_sec);
@@ -853,8 +855,8 @@ void omd_advertize() {
/* this function gets called when the module is loaded by the event broker */
/* cppcheck-suppress unusedFunction */
-int nebmodule_init(int flags __attribute__((__unused__)), char *args,
- void *handle) {
+extern "C" int nebmodule_init(int flags __attribute__((__unused__)), char
*args,
+ void *handle) {
g_nagios_handle = handle;
livestatus_parse_arguments(args);
open_logfile();
@@ -902,8 +904,8 @@ int nebmodule_init(int flags __attribute__((__unused__)), char *args,
}
/* cppcheck-suppress unusedFunction */
-int nebmodule_deinit(int flags __attribute__((__unused__)),
- int reason __attribute__((__unused__))) {
+extern "C" int nebmodule_deinit(int flags __attribute__((__unused__)),
+ int reason __attribute__((__unused__))) {
logger(LG_INFO, "deinitializing");
terminate_threads();
close_unix_socket();