Reading object config from within nebmodule_init()


#1

I’m working on a NEB module and would like to access host and service objects during the module init to build a list of all hosts and associated services from the start, rather than waiting for the EB to send object information as things happen.

I’ve tried to use;

extern host *host_list;
extern service *service_list;
extern char *config_file;
read_all_object_data(config_file);

Which will allow me to use;
for (temp_host=host_list ; temp_host!=NULL ; temp_host=temp_host->next) {

for (temp_service=service_list ; temp_service!=NULL ; temp_service=temp_service->next) {

}
}

However once I do this it apparently messes up the data already read in by Nagios on start up so I get errors like;

[1199996860] Done.
[1199996860] Event broker module ‘/opt/nagios/bin/statechange_neb.o’ initialized successfully.
[1199996860] Error: Timeperiod ‘24x7’ has already been defined
[1199996860] Error: Could not register timeperiod (config file ‘/opt/nagios/etc/timeperiods.cfg’
, starting on line 7)
[1199996860] Bailing out due to one or more errors encountered in the configuration files. Run
Nagios from the command line with the -v option to verify your config before restarting. (PID=32
539)
[1199996860] Unloading STATECHANGE Module…
[1199996860] Event broker module ‘/opt/nagios/bin/statechange_neb.o’ deinitialized successfully.

How can I get to the host_list and service_list structs without messing with the variables?

Thanks,
Don


#2

If anyone is interested…

I figured out that the object lists are not populated until after Nagios finishes loading, after all NEB modules are loaded.
However the lists are available once Nagios is fully loaded so subscribing to the NEBCALLBACK_PROCESS_DATA and finishing the rest of the “init” routine upon receipt of NEBTYPE_PROCESS_EVENTLOOPSTART event type will suffice.

It’s a hack, IMO, but it works.

I guess the question should be; why are the NEB modules loaded before the object data is read.

Don