From 67ce1dd891504f815538870d1a6a6a220a065fac Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Sat, 1 May 2010 15:43:17 +0200 Subject: [PATCH 1/1] =?utf8?q?v5upgrade=20target:=20This=20new=20target=20?= =?utf8?q?can=20be=20used=20to=20fix=20some=20"legacy"=20identifiers=20?= =?utf8?q?=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit … on the fly. Just put it into the pre-cache chain to fix up some of the most common changes from 4.* to 5.*. This hopefully makes migration easier. --- configure.in | 2 ++ src/Makefile.am | 8 +++++ src/target_v5upgrade.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 101 insertions(+) create mode 100644 src/target_v5upgrade.c diff --git a/configure.in b/configure.in index c4350276..88ff302d 100644 --- a/configure.in +++ b/configure.in @@ -4342,6 +4342,7 @@ AC_PLUGIN([target_notification], [yes], [The notification target]) AC_PLUGIN([target_replace], [yes], [The replace target]) AC_PLUGIN([target_scale],[yes], [The scale target]) AC_PLUGIN([target_set], [yes], [The set target]) +AC_PLUGIN([target_v5upgrade], [yes], [The v5upgrade target]) AC_PLUGIN([tcpconns], [$plugin_tcpconns], [TCP connection statistics]) AC_PLUGIN([teamspeak2], [yes], [TeamSpeak2 server statistics]) AC_PLUGIN([ted], [$plugin_ted], [Read The Energy Detective values]) @@ -4658,6 +4659,7 @@ Configuration: target_replace . . . $enable_target_replace target_scale . . . . $enable_target_scale target_set . . . . . $enable_target_set + target_v5upgrade . . $enable_target_v5upgrade tcpconns . . . . . . $enable_tcpconns teamspeak2 . . . . . $enable_teamspeak2 ted . . . . . . . . . $enable_ted diff --git a/src/Makefile.am b/src/Makefile.am index 5290ab3b..d4aaac7a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1036,6 +1036,14 @@ collectd_LDADD += "-dlopen" target_set.la collectd_DEPENDENCIES += target_set.la endif +if BUILD_PLUGIN_TARGET_V5UPGRADE +pkglib_LTLIBRARIES += target_v5upgrade.la +target_v5upgrade_la_SOURCES = target_v5upgrade.c +target_v5upgrade_la_LDFLAGS = -module -avoid-version +collectd_LDADD += "-dlopen" target_v5upgrade.la +collectd_DEPENDENCIES += target_v5upgrade.la +endif + if BUILD_PLUGIN_TCPCONNS pkglib_LTLIBRARIES += tcpconns.la tcpconns_la_SOURCES = tcpconns.c diff --git a/src/target_v5upgrade.c b/src/target_v5upgrade.c new file mode 100644 index 00000000..9ae84b92 --- /dev/null +++ b/src/target_v5upgrade.c @@ -0,0 +1,91 @@ +/** + * collectd - src/target_set.c + * Copyright (C) 2008-2010 Florian Forster + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; only version 2.1 of the License is + * applicable. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + * Authors: + * Florian Forster + **/ + +#include "collectd.h" +#include "plugin.h" +#include "common.h" +#include "filter_chain.h" + +static void v5_swap_instances (value_list_t *vl) /* {{{ */ +{ + char tmp[DATA_MAX_NAME_LEN]; + + assert (sizeof (tmp) == sizeof (vl->plugin_instance)); + assert (sizeof (tmp) == sizeof (vl->type_instance)); + + memcpy (tmp, vl->plugin_instance, sizeof (tmp)); + memcpy (vl->plugin_instance, vl->type_instance, sizeof (tmp)); + memcpy (vl->type_instance, tmp, sizeof (tmp)); +} /* }}} void v5_swap_instances */ + +/* + * Interface plugin + * + * 4.* stores the interface in the type instance and leaves the plugin + * instance empty. If this is the case, put the interface name into the plugin + * instance and clear the type instance. + */ +static int v5_interface (const data_set_t *ds, value_list_t *vl) /* {{{ */ +{ + if ((vl->plugin_instance[0] != 0) || (vl->type_instance[0] == 0)) + return (FC_TARGET_CONTINUE); + + v5_swap_instances (vl); + return (FC_TARGET_CONTINUE); +} /* }}} int v5_interface */ + +static int v5_destroy (void **user_data) /* {{{ */ +{ + return (0); +} /* }}} int v5_destroy */ + +static int v5_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ +{ + *user_data = NULL; + return (0); +} /* }}} int v5_create */ + +static int v5_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */ + notification_meta_t __attribute__((unused)) **meta, void **user_data) +{ + if ((ds == NULL) || (vl == NULL) || (user_data == NULL)) + return (-EINVAL); + + if (strcmp ("interface", vl->plugin) == 0) + return (v5_interface (ds, vl)); + + return (FC_TARGET_CONTINUE); +} /* }}} int v5_invoke */ + +void module_register (void) +{ + target_proc_t tproc; + + memset (&tproc, 0, sizeof (tproc)); + tproc.create = v5_create; + tproc.destroy = v5_destroy; + tproc.invoke = v5_invoke; + fc_register_target ("v5upgrade", tproc); +} /* module_register */ + +/* vim: set sw=2 sts=2 tw=78 et fdm=marker : */ + -- 2.11.0