[dev.icinga.com #2569] add nebmodule version / name check for idomod within core, set module info in idomod, deny to load old idomod.o #955

Closed
icinga-migration opened this Issue Apr 30, 2012 · 6 comments

Projects

None yet

1 participant

@icinga-migration
Member

This issue has been migrated from Redmine: https://dev.icinga.com/issues/2569

Created by mfriedrich on 2012-04-30 14:09:42 +00:00

Assignee: mfriedrich
Status: Resolved (closed on 2012-05-05 10:03:22 +00:00)
Target Version: 1.7
Last Update: 2012-05-05 10:03:22 +00:00 (in Redmine)


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;
        }

Changesets

2012-04-30 14:58:11 +00:00 by mfriedrich 732cf30

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

2012-05-03 09:35:33 +00:00 by mfriedrich bf4d0f8

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

refs #2569

Relations:

@icinga-migration
Member

Updated by mfriedrich on 2012-04-30 14:40:49 +00:00

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.

@icinga-migration
Member

Updated by mfriedrich on 2012-04-30 14:47:27 +00:00

  • 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
@icinga-migration
Member

Updated by mfriedrich on 2012-04-30 14:53:32 +00:00

  • 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
@icinga-migration
Member

Updated by mfriedrich on 2012-04-30 16:05:30 +00:00

  • Status changed from Assigned to Feedback
  • Done % changed from 0 to 100
@icinga-migration
Member

Updated by Tommi on 2012-05-03 19:54:50 +00:00

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.

@icinga-migration
Member

Updated by mfriedrich on 2012-05-05 10:03:22 +00:00

  • 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.

@icinga-migration icinga-migration added this to the 1.7 milestone Jan 17, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment