X-Git-Url: https://git.octo.it/?p=collectd.git;a=blobdiff_plain;f=src%2Fdbi.c;h=7fec73c549c5249feef63ae4dd194a3071aa3ab6;hp=80488d8478f6df99c748de2e4e39e872b1236701;hb=633c3966f770e4d46651a2fe219a18d8a9907a9f;hpb=bc389fa32a48a64306f7ec008f4548f05fdb7c80 diff --git a/src/dbi.c b/src/dbi.c index 80488d84..7fec73c5 100644 --- a/src/dbi.c +++ b/src/dbi.c @@ -2,18 +2,23 @@ * collectd - src/dbi.c * Copyright (C) 2008-2013 Florian octo Forster * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License as published by the - * Free Software Foundation; only version 2 of the License is applicable. + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: * - * 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 - * General Public License for more details. + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. * - * You should have received a copy of the GNU 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 + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER + * DEALINGS IN THE SOFTWARE. * * Authors: * Florian octo Forster @@ -68,6 +73,8 @@ static size_t queries_num = 0; static cdbi_database_t **databases = NULL; static size_t databases_num = 0; +static int cdbi_read_database (user_data_t *ud); + /* * Functions */ @@ -369,9 +376,24 @@ static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ } else { + user_data_t ud; + char *name = NULL; + databases = temp; databases[databases_num] = db; databases_num++; + + memset (&ud, 0, sizeof (ud)); + ud.data = (void *) db; + ud.free_func = NULL; + name = ssnprintf_alloc("dbi:%s", db->name); + + plugin_register_complex_read (/* group = */ NULL, + /* name = */ name ? name : db->name, + /* callback = */ cdbi_read_database, + /* interval = */ NULL, + /* user_data = */ &ud); + free (name); } } @@ -398,7 +420,7 @@ static int cdbi_config (oconfig_item_t *ci) /* {{{ */ cdbi_config_add_database (child); else { - WARNING ("snmp plugin: Ignoring unknown config option `%s'.", child->key); + WARNING ("dbi plugin: Ignoring unknown config option `%s'.", child->key); } } /* for (ci->children) */ @@ -758,8 +780,9 @@ static int cdbi_connect_database (cdbi_database_t *db) /* {{{ */ return (0); } /* }}} int cdbi_connect_database */ -static int cdbi_read_database (cdbi_database_t *db) /* {{{ */ +static int cdbi_read_database (user_data_t *ud) /* {{{ */ { + cdbi_database_t *db = (cdbi_database_t *) ud->data; size_t i; int success; int status; @@ -798,29 +821,6 @@ static int cdbi_read_database (cdbi_database_t *db) /* {{{ */ return (0); } /* }}} int cdbi_read_database */ -static int cdbi_read (void) /* {{{ */ -{ - size_t i; - int success = 0; - int status; - - for (i = 0; i < databases_num; i++) - { - status = cdbi_read_database (databases[i]); - if (status == 0) - success++; - } - - if (success == 0) - { - ERROR ("dbi plugin: No database could be read. Will return an error so " - "the plugin will be delayed."); - return (-1); - } - - return (0); -} /* }}} int cdbi_read */ - static int cdbi_shutdown (void) /* {{{ */ { size_t i; @@ -848,7 +848,6 @@ void module_register (void) /* {{{ */ { plugin_register_complex_config ("dbi", cdbi_config); plugin_register_init ("dbi", cdbi_init); - plugin_register_read ("dbi", cdbi_read); plugin_register_shutdown ("dbi", cdbi_shutdown); } /* }}} void module_register */