2 * Author: Andreas Ericsson <ae@op5.se>
4 * Copyright(C) 2005 op5 AB
16 #include <nagios/nebstructs.h>
17 #include <nagios/objects.h>
18 #include <nagios/statusdata.h>
20 /* Nagios stuff goes below */
21 NEB_API_VERSION(CURRENT_NEB_API_VERSION
);
23 int cb_handler(int, void *);
25 static nebmodule
*neb_handle
;
26 extern int daemon_dumps_core
;
27 extern int event_broker_options
;
29 static struct callback_struct
{
31 int (*hook
)(int, void *);
32 } callback_table
[] = {
33 { NEBCALLBACK_PROCESS_DATA
, hook_process_data
},
34 // { NEBCALLBACK_LOG_DATA, cb_handler },
35 // { NEBCALLBACK_SYSTEM_COMMAND_DATA, cb_handler },
36 // { NEBCALLBACK_EVENT_HANDLER_DATA, cb_handler },
37 // { NEBCALLBACK_NOTIFICATION_DATA, cb_handler },
38 { NEBCALLBACK_SERVICE_CHECK_DATA
, hook_service_result
},
39 { NEBCALLBACK_HOST_CHECK_DATA
, hook_host_result
},
40 // { NEBCALLBACK_COMMENT_DATA, cb_handler },
41 { NEBCALLBACK_DOWNTIME_DATA
, hook_downtime
},
42 // { NEBCALLBACK_FLAPPING_DATA, cb_handler },
43 // { NEBCALLBACK_PROGRAM_STATUS_DATA, cb_handler },
44 // { NEBCALLBACK_HOST_STATUS_DATA, cb_handler },
45 // { NEBCALLBACK_SERVICE_STATUS_DATA, cb_handler },
50 static int read_config(const char *arg
)
52 struct cfg_comp
*config
;
56 if (!arg
|| !*arg
|| !(config
= cfg_parse_file(arg
))) {
57 lerr("Failed to read config from %s", arg
? arg
: "(no file)");
61 while ((v
= next_var(config
)))
62 ret
|= sql_config(v
->key
, v
->value
);
67 int nebmodule_init(int flags
, char *arg
, nebmodule
*handle
)
69 char *home
= NULL
, cwd
[PATH_MAX
];
74 linfo("Loading %s", SELF
);
76 if (read_config(arg
) < 0)
85 /* make sure we can catch whatever we want */
86 event_broker_options
= BROKER_EVERYTHING
;
88 ldebug("Forcing coredumps");
89 daemon_dumps_core
= 1;
90 home
= getenv("HOME");
94 signal(SIGSEGV
, SIG_DFL
);
97 * if flags == -1, we're running from nebtest, so make sure
98 * coredumps end up in cwd. This *shouldn't* affect anything
99 * (famous last words, no?)
103 getcwd(cwd
, sizeof(cwd
));
104 linfo("Coredumps end up in %s", cwd
);
106 for (i
= 0; i
< ARRAY_SIZE(callback_table
); i
++) {
107 struct callback_struct
*cb
= &callback_table
[i
];
109 neb_register_callback(cb
->type
, neb_handle
, 0, cb
->hook
);
115 int nebmodule_deinit(int flags
, int reason
)
118 linfo("Unloading %s", SELF
);
120 /* flush junk to disk */
123 for (i
= 0; i
< ARRAY_SIZE(callback_table
); i
++) {
124 struct callback_struct
*cb
= &callback_table
[i
];
125 neb_deregister_callback(cb
->type
, cb
->hook
);