From: Florian Forster Date: Mon, 24 Mar 2008 10:29:46 +0000 (+0100) Subject: src/utils_cmd_listval.[ch]: Added a new module which implements the `LISTVAL' command. X-Git-Tag: collectd-4.4.0~78 X-Git-Url: https://git.octo.it/?a=commitdiff_plain;h=bf46dad7cb3402921a2fb96b5194783ab12b3dc6;p=collectd.git src/utils_cmd_listval.[ch]: Added a new module which implements the `LISTVAL' command. It's done using the global cache implemented in `src/utils_cache.[ch]'. --- diff --git a/src/Makefile.am b/src/Makefile.am index 194e118a..618ef0a2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -597,6 +597,7 @@ pkglib_LTLIBRARIES += unixsock.la unixsock_la_SOURCES = unixsock.c \ utils_cmd_flush.h utils_cmd_flush.c \ utils_cmd_getval.h utils_cmd_getval.c \ + utils_cmd_listval.h utils_cmd_listval.c \ utils_cmd_putval.h utils_cmd_putval.c \ utils_cmd_putnotif.h utils_cmd_putnotif.c unixsock_la_LDFLAGS = -module -avoid-version -lpthread diff --git a/src/utils_cmd_listval.c b/src/utils_cmd_listval.c new file mode 100644 index 00000000..644a67cc --- /dev/null +++ b/src/utils_cmd_listval.c @@ -0,0 +1,64 @@ +/** + * collectd - src/utils_cms_listval.c + * Copyright (C) 2008 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. + * + * 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. + * + * 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 + * + * Author: + * Florian octo Forster + **/ + +#include "collectd.h" +#include "common.h" +#include "plugin.h" + +#include "utils_cmd_listval.h" +#include "utils_cache.h" + +int handle_listval (FILE *fh, char **fields, int fields_num) +{ + char **names = NULL; + time_t *times = NULL; + size_t number = 0; + size_t i; + int status; + + if (fields_num != 1) + { + DEBUG ("command listval: us_handle_listval: Wrong number of fields: %i", + fields_num); + fprintf (fh, "-1 Wrong number of fields: Got %i, expected 1.\n", + fields_num); + fflush (fh); + return (-1); + } + + status = uc_get_names (&names, ×, &number); + if (status != 0) + { + DEBUG ("command listval: uc_get_names failed with status %i", status); + fprintf (fh, "-1 uc_get_names failed.\n"); + fflush (fh); + return (-1); + } + + fprintf (fh, "%i Values found\n", (int) number); + for (i = 0; i < number; i++) + fprintf (fh, "%u %s\n", (unsigned int) times[i], names[i]); + fflush (fh); + + return (0); +} /* int handle_listval */ + +/* vim: set sw=2 sts=2 ts=8 : */ diff --git a/src/utils_cmd_listval.h b/src/utils_cmd_listval.h new file mode 100644 index 00000000..c9187962 --- /dev/null +++ b/src/utils_cmd_listval.h @@ -0,0 +1,29 @@ +/** + * collectd - src/utils_cms_listval.h + * Copyright (C) 2008 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. + * + * 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. + * + * 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 + * + * Author: + * Florian octo Forster + **/ + +#ifndef UTILS_CMD_LISTVAL_H +#define UTILS_CMD_LISTVAL_H 1 + +int handle_listval (FILE *fh, char **fields, int fields_num); + +#endif /* UTILS_CMD_LISTVAL_H */ + +/* vim: set sw=2 sts=2 ts=8 : */