v5upgrade target: This new target can be used to fix some "legacy" identifiers …
[collectd.git] / src / target_v5upgrade.c
1 /**
2  * collectd - src/target_set.c
3  * Copyright (C) 2008-2010  Florian Forster
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation; only version 2.1 of the License is
8  * applicable.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  *
19  * Authors:
20  *   Florian Forster <octo at verplant.org>
21  **/
22
23 #include "collectd.h"
24 #include "plugin.h"
25 #include "common.h"
26 #include "filter_chain.h"
27
28 static void v5_swap_instances (value_list_t *vl) /* {{{ */
29 {
30   char tmp[DATA_MAX_NAME_LEN];
31
32   assert (sizeof (tmp) == sizeof (vl->plugin_instance));
33   assert (sizeof (tmp) == sizeof (vl->type_instance));
34
35   memcpy (tmp, vl->plugin_instance, sizeof (tmp));
36   memcpy (vl->plugin_instance, vl->type_instance, sizeof (tmp));
37   memcpy (vl->type_instance, tmp, sizeof (tmp));
38 } /* }}} void v5_swap_instances */
39
40 /*
41  * Interface plugin
42  *
43  * 4.* stores the interface in the type instance and leaves the plugin
44  * instance empty. If this is the case, put the interface name into the plugin
45  * instance and clear the type instance.
46  */
47 static int v5_interface (const data_set_t *ds, value_list_t *vl) /* {{{ */
48 {
49   if ((vl->plugin_instance[0] != 0) || (vl->type_instance[0] == 0))
50     return (FC_TARGET_CONTINUE);
51
52   v5_swap_instances (vl);
53   return (FC_TARGET_CONTINUE);
54 } /* }}} int v5_interface */
55
56 static int v5_destroy (void **user_data) /* {{{ */
57 {
58   return (0);
59 } /* }}} int v5_destroy */
60
61 static int v5_create (const oconfig_item_t *ci, void **user_data) /* {{{ */
62 {
63   *user_data = NULL;
64   return (0);
65 } /* }}} int v5_create */
66
67 static int v5_invoke (const data_set_t *ds, value_list_t *vl, /* {{{ */
68     notification_meta_t __attribute__((unused)) **meta, void **user_data)
69 {
70   if ((ds == NULL) || (vl == NULL) || (user_data == NULL))
71     return (-EINVAL);
72
73   if (strcmp ("interface", vl->plugin) == 0)
74     return (v5_interface (ds, vl));
75
76   return (FC_TARGET_CONTINUE);
77 } /* }}} int v5_invoke */
78
79 void module_register (void)
80 {
81         target_proc_t tproc;
82
83         memset (&tproc, 0, sizeof (tproc));
84         tproc.create  = v5_create;
85         tproc.destroy = v5_destroy;
86         tproc.invoke  = v5_invoke;
87         fc_register_target ("v5upgrade", tproc);
88 } /* module_register */
89
90 /* vim: set sw=2 sts=2 tw=78 et fdm=marker : */
91