Feature #2569

add nebmodule version / name check for idomod within core, set module info in idomod, deny to load old idomod.o

Added by dnsmichi almost 2 years ago. Updated almost 2 years ago.

Status:ResolvedStart date:04/30/2012
Priority:NormalDue date:
Assignee:dnsmichi% Done:

100%

Category:Event Broker
Target version:Icinga 1.x - 1.7

Description

as shown in helloworld.c the nebmodule_init function should call neb_set_module_info in order to populate the info array with some more specifics on the module.

the core does not do anything with that currently. since the recent changes with idomod.o transition to idomod.so such an information would be pretty awesome to be checked. furthermore, it will allow required versions to be set, meaning to allow a forced unload if not matching.

/* this function gets called when the module is loaded by the event broker */
int nebmodule_init(int flags, char *args, nebmodule *handle) {
        char temp_buffer[1024];
        time_t current_time;
        unsigned long interval;

        /* save our handle */
        helloworld_module_handle = handle;

        /* set some info - this is completely optional, as Icinga doesn't do anything with this data */
        neb_set_module_info(helloworld_module_handle, NEBMODULE_MODINFO_TITLE, "helloworld");
        neb_set_module_info(helloworld_module_handle, NEBMODULE_MODINFO_AUTHOR, "Ethan Galstad");
        neb_set_module_info(helloworld_module_handle, NEBMODULE_MODINFO_TITLE, "Copyright (c) 2003-2007 Ethan Galstad");
        neb_set_module_info(helloworld_module_handle, NEBMODULE_MODINFO_VERSION, "noversion");
        neb_set_module_info(helloworld_module_handle, NEBMODULE_MODINFO_LICENSE, "GPL v2");
        neb_set_module_info(helloworld_module_handle, NEBMODULE_MODINFO_DESC, "A simple example to get you started with Icinga Event Broker modules.");

        /* log module info to the Icinga log file */
        write_to_all_logs("helloworld: Copyright (c) 2003-2007 Ethan Galstad (egalstad@nagios.org)", NSLOG_INFO_MESSAGE);

        /* log a message to the Icinga log file */
        snprintf(temp_buffer, sizeof(temp_buffer) - 1, "helloworld: Hello world!\n");
        temp_buffer[sizeof(temp_buffer)-1] = '\x0';
        write_to_all_logs(temp_buffer, NSLOG_INFO_MESSAGE);

        /* log a reminder message every 15 minutes (how's that for annoying? :-)) */
        time(&current_time);
        interval = 900;
        schedule_new_event(EVENT_USER_FUNCTION, TRUE, current_time + interval, TRUE, interval, NULL, TRUE, (void *)helloworld_reminder_message, "How about you?", 0);

        /* register to be notified of certain events... */
        neb_register_callback(NEBCALLBACK_AGGREGATED_STATUS_DATA, helloworld_module_handle, 0, helloworld_handle_data);

        return 0;
}

within nebmodule_init in idomod.c being set, this information can be fetched after dlopen as well as dlsym fetched the function pointer to the init function of the neb module - plus a call onto it. after that the validation information is shared in memory and can be accessed for further (version) comparison.

        /* run the module's init function */
        initfunc = mod->init_func;
        result = (*initfunc)(NEBMODULE_NORMAL_LOAD, mod->args, mod->module_handle);

        /* if the init function returned an error, unload the module */
        if (result != OK) {

                logit(NSLOG_RUNTIME_ERROR, FALSE, "Error: Function nebmodule_init() in module '%s' returned an error.  Module will be unloaded.\n", mod->filename);

                neb_unload_module(mod, NEBMODULE_FORCE_UNLOAD, NEBMODULE_ERROR_BAD_INIT);

                return ERROR;
        }


Related issues

Related to Core - Feature #2354: change idomod extension from .o to .so, make .so the defa... Resolved 02/24/2012
Related to Core - Bug #524: Sun Studio / Solaris: helloworld.o: unknown file type Resolved 06/21/2010
Related to Icinga 1.x - Feature #2568: todo list for release 1.7 Resolved 04/27/2012
Related to Core - Support #2558: warn users to read Changelog after install Resolved 04/26/2012

Associated revisions

Revision 732cf300
Added by dnsmichi almost 2 years ago

core/idomod: add nebmodule version/name check for idomod within core, set module info in idomod, deny to load old idomod.o #2354 #2569

first off, this will deny and unload modules named "idomod.o" as we have
in 1.6.x
furthermore, the newly introduced 1.7.0 idomod neb module will export
its name plus version with neb_set_module_info. this information can be
parsed from the core after calling nebmodule_init and will allow us to
check the idomod version a bit after being loaded (this might already
connect to ido2db, but we can't get any sooner there). if the idomod
version does not match the core's version, the neb module loader will
bail out. this adds more or less the same version dependency as the
packages do already. could be lowered to minimum version requirements
somehow as well, if idomod_version == icinga_version is set too hard.

refs #2354
refs #2569

Revision bf4d0f82
Added by dnsmichi almost 2 years ago

move check for deprecated idomod.o after loading it, removing wrong error msg

refs #2569

History

#1 Updated by dnsmichi almost 2 years ago

for testing, i've set IDO_VERSION to 1.7.0-foo and installed that.

Apr 30 16:38:50 icinga-dev icinga: Icinga 1.7.0-dev starting... (PID=23423)
Apr 30 16:38:50 icinga-dev icinga: Local time is Mon Apr 30 16:38:50 CEST 2012
Apr 30 16:38:50 icinga-dev icinga: LOG VERSION: 2.0
Apr 30 16:38:50 icinga-dev icinga: idomod: IDOMOD 1.7.0-foo (05-15-2012) Copyright(c) 2005-2008 Ethan Galstad, Copyright(c) 2009-2012 Icinga Development Team (https://www.icinga.org)
Apr 30 16:38:50 icinga-dev ido2db: Client connected, data available.
Apr 30 16:38:50 icinga-dev icinga: idomod: Successfully connected to data sink.  0 queued items to flush.
Apr 30 16:38:50 icinga-dev ido2db: Handling client connection...
Apr 30 16:38:50 icinga-dev icinga: Error: Module '/usr/lib/idomod.so' exports version '1.7.0-foo' different to '1.7.0-dev'.  Module will be unloaded.
Apr 30 16:38:50 icinga-dev icinga: Event broker module '/usr/lib/idomod.so' deinitialized successfully.

so this allows implicit version dependencies for the future, as we keep idomod updated with that version info.

for the old module with 1.6.x which does not export the version explicitely, we will deny to load 'idomod.o' for now.

#2 Updated by dnsmichi almost 2 years ago

  • Tracker changed from Bug to Feature
  • Subject changed from add nebmodule version / name check to nebmods.c and idomod.c to add nebmodule version / name check for idomod within core, set module info in idomod

#3 Updated by dnsmichi almost 2 years ago

  • Subject changed from add nebmodule version / name check for idomod within core, set module info in idomod to add nebmodule version / name check for idomod within core, set module info in idomod, deny to load old idomod.o

#4 Updated by dnsmichi almost 2 years ago

  • Status changed from Assigned to Feedback
  • % Done changed from 0 to 100

#5 Updated by Tommi almost 2 years ago

looks good.

May  3 21:39:20 xxx icinga: idomod: IDOMOD 1.6.1 (05-15-2012) Copyright(c) 2005-2008 Ethan Galstad, Copyright(c) 2009-2012 Icinga Development Team (https://www.icinga.org)
May  3 21:39:20 xxx icinga: idomod: Could not open data sink!  I'll keep trying, but some output may get lost. Is ido2db running and processing data?
May  3 21:39:20 xxx icinga: Error: Module '/opt/icinga/lib/idomod.so' exports version '1.6.1' different to core version '1.7.0'.  Module will be unloaded.

But i think we need also a check if the version supplied by idomod is the same as ido2db. This (more exact:the datastructures) must match. Maybe a feature for the next release.

#6 Updated by dnsmichi almost 2 years ago

  • Status changed from Feedback to Resolved

dunno how that could be checkable - unless you change the initial handshake marker where it already exposes and checkes the api version. so you might add a feature request to the idoutils section then.

the initial check works for me - with the slight adaption of unloading idomod.o after it has been loaded - otherwise the called unload neb module functionality could cause regression.

Also available in: Atom PDF