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
];
71 nebstruct_process_data proc_start
;
75 linfo("Loading %s", SELF
);
77 if (read_config(arg
) < 0)
86 proc_start
.type
= NEBTYPE_PROCESS_START
;
87 proc_start
.timestamp
.tv_sec
= time(NULL
);
88 if (hook_process_data(NEBCALLBACK_PROCESS_DATA
, &proc_start
) < 0)
91 /* make sure we can catch whatever we want */
92 event_broker_options
= BROKER_EVERYTHING
;
94 ldebug("Forcing coredumps");
95 daemon_dumps_core
= 1;
96 home
= getenv("HOME");
100 signal(SIGSEGV
, SIG_DFL
);
103 * if flags == -1, we're running from nebtest, so make sure
104 * coredumps end up in cwd. This *shouldn't* affect anything
105 * (famous last words, no?)
109 getcwd(cwd
, sizeof(cwd
));
110 linfo("Coredumps end up in %s", cwd
);
112 for (i
= 0; i
< ARRAY_SIZE(callback_table
); i
++) {
113 struct callback_struct
*cb
= &callback_table
[i
];
115 neb_register_callback(cb
->type
, neb_handle
, 0, cb
->hook
);
121 int nebmodule_deinit(int flags
, int reason
)
124 linfo("Unloading %s", SELF
);
126 /* flush junk to disk */
131 for (i
= 0; i
< ARRAY_SIZE(callback_table
); i
++) {
132 struct callback_struct
*cb
= &callback_table
[i
];
133 neb_deregister_callback(cb
->type
, cb
->hook
);