From 2fea822b3984376e9b7ef58ed7d3f087bc65af8c Mon Sep 17 00:00:00 2001 From: Ivo De Decker Date: Mon, 7 Feb 2011 08:54:55 +0100 Subject: [PATCH] modbus plugin: Add documentation and rename to "datagroup". Florian, Attached is the updated version of the datagroup patch. The code itself didn't change (apart from the rename dataset -> datagroup). It should apply cleanly to the latest version of the master branch. I also attached a patch to the configure.in script to make pkg-config check for 'libmodbus' as well as 'modbus'. Different versions of the library use different names. Greetings, Ivo De Decker Signed-off-by: Florian Forster --- src/collectd.conf.pod | 39 +++++++++++++++++++++++++++++- src/modbus.c | 66 ++++++++++++++++++++++++++------------------------- 2 files changed, 72 insertions(+), 33 deletions(-) diff --git a/src/collectd.conf.pod b/src/collectd.conf.pod index b63f486b..f7ec2a8f 100644 --- a/src/collectd.conf.pod +++ b/src/collectd.conf.pod @@ -1904,6 +1904,11 @@ Synopsis: Instance "input-2" + + Address "192.168.0.42" Port "502" @@ -1914,6 +1919,11 @@ Synopsis: Collect "voltage-input-1" Collect "voltage-input-2" + + + Instance "power-supply" + Datagroup "device-type-1" + =over 4 @@ -1952,6 +1962,25 @@ unset, an empty string (no type instance) is used. =back +=item EB IE blocks + +Datagroup blocks define a group of B-definitions. Datagroups can be used +to collect the same data from a number of similar devices. + +Within EDatagroupE/E blocks, the following options are allowed: + +=over 4 + +=item B I + +Specifies which data to include in the datagroup. I must be the same +string as the I argument passed to a B block. You can specify this +option multiple times to include more than one value in the datagroup. All +values in the datagroup will be collected from the devices that use is. At +least one B option is mandatory. + +=back + =item EB IE blocks Host blocks are used to specify to which hosts to connect and what data to read @@ -1999,7 +2028,15 @@ By default "slave_I" is used. Specifies which data to retrieve from the device. I must be the same string as the I argument passed to a B block. You can specify this option multiple times to collect more than one value from a slave. At least one -B option is mandatory. +B or B option is mandatory. + +=item B I + +Specifies which data to retrieve from the device. I must be the +same string as the I argument passed to a B block. All data +specified in the Datagroup definition will be retrieved from the device. You +can specify this option multiple or combine it with the B option. At +least one B or B option is mandatory. =back diff --git a/src/modbus.c b/src/modbus.c index 7145c8a6..661ab11e 100644 --- a/src/modbus.c +++ b/src/modbus.c @@ -1,6 +1,7 @@ /** * collectd - src/modbus.c * Copyright (C) 2010 noris network AG + * Copyright (C) 2011 Universiteit Gent * * 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 @@ -18,6 +19,7 @@ * * Authors: * Florian Forster + * Ivo De Decker **/ #include "collectd.h" @@ -88,14 +90,14 @@ struct mb_data_s /* {{{ */ mb_data_t *next; }; /* }}} */ -struct mb_dataset_s; -typedef struct mb_dataset_s mb_dataset_t; -struct mb_dataset_s /* {{{ */ +struct mb_datagroup_s; +typedef struct mb_datagroup_s mb_datagroup_t; +struct mb_datagroup_s /* {{{ */ { char *name; mb_data_t *collect; - mb_dataset_t *next; + mb_datagroup_t *next; }; /* }}} */ struct mb_slave_s /* {{{ */ @@ -141,7 +143,7 @@ struct mb_data_group_s /* {{{ */ * Global variables */ static mb_data_t *data_definitions = NULL; -static mb_dataset_t *data_sets = NULL; +static mb_datagroup_t *data_groups = NULL; /* * Functions @@ -235,10 +237,10 @@ static int data_copy_by_name (mb_data_t **dst, mb_data_t *src, /* {{{ */ return (data_copy (dst, ptr)); } /* }}} int data_copy_by_name */ -static mb_dataset_t *dataset_get_by_name (mb_dataset_t *src, /* {{{ */ +static mb_datagroup_t *datagroup_get_by_name (mb_datagroup_t *src, /* {{{ */ const char *name) { - mb_dataset_t *ptr; + mb_datagroup_t *ptr; if (name == NULL) return (NULL); @@ -248,11 +250,11 @@ static mb_dataset_t *dataset_get_by_name (mb_dataset_t *src, /* {{{ */ return (ptr); return (NULL); -} /* }}} mb_dataset_t *dataset_get_by_name */ +} /* }}} mb_datagroup_t *datagroup_get_by_name */ -static int dataset_append (mb_dataset_t **dst, mb_dataset_t *src) /* {{{ */ +static int datagroup_append (mb_datagroup_t **dst, mb_datagroup_t *src) /* {{{ */ { - mb_dataset_t *ptr; + mb_datagroup_t *ptr; if ((dst == NULL) || (src == NULL)) return (EINVAL); @@ -271,12 +273,12 @@ static int dataset_append (mb_dataset_t **dst, mb_dataset_t *src) /* {{{ */ ptr->next = src; return (0); -} /* }}} int dataset_append */ +} /* }}} int datagroup_append */ -/* Copy a single mb_dataset_t and append it to another list. */ -static int dataset_copy (mb_dataset_t **dst, const mb_dataset_t *src) /* {{{ */ +/* Copy a single mb_datagroup_t and append it to another list. */ +static int datagroup_copy (mb_datagroup_t **dst, const mb_datagroup_t *src) /* {{{ */ { - mb_dataset_t *tmp; + mb_datagroup_t *tmp; int status; if ((dst == NULL) || (src == NULL)) @@ -296,7 +298,7 @@ static int dataset_copy (mb_dataset_t **dst, const mb_dataset_t *src) /* {{{ */ return (ENOMEM); } - status = dataset_append (dst, tmp); + status = datagroup_append (dst, tmp); if (status != 0) { sfree (tmp->name); @@ -305,7 +307,7 @@ static int dataset_copy (mb_dataset_t **dst, const mb_dataset_t *src) /* {{{ */ } return (0); -} /* }}} int dataset_copy */ +} /* }}} int datagroup_copy */ /* Read functions */ @@ -878,14 +880,14 @@ static int mb_config_add_slave (mb_host_t *host, oconfig_item_t *ci) /* {{{ */ data_copy_by_name (&slave->collect, data_definitions, buffer); status = 0; /* continue after failure. */ } - else if (strcasecmp ("Dataset", child->key) == 0) + else if (strcasecmp ("Datagroup", child->key) == 0) { char buffer[1024]; - mb_dataset_t *ds; + mb_datagroup_t *ds; status = cf_util_get_string_buffer (child, buffer, sizeof (buffer)); if (status == 0) { - ds = dataset_get_by_name (data_sets, buffer); + ds = datagroup_get_by_name (data_groups, buffer); if (ds) { mb_data_t *data; for (data = ds->collect; data != NULL; data = data->next) @@ -1006,18 +1008,18 @@ static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ } /* }}} int mb_config_add_host */ -static int mb_config_add_dataset (oconfig_item_t *ci) /* {{{ */ +static int mb_config_add_datagroup (oconfig_item_t *ci) /* {{{ */ { - mb_dataset_t dataset; + mb_datagroup_t datagroup; int status; int i; - memset (&dataset, 0, sizeof (dataset)); - dataset.name = NULL; - dataset.collect = NULL; - dataset.next = NULL; + memset (&datagroup, 0, sizeof (datagroup)); + datagroup.name = NULL; + datagroup.collect = NULL; + datagroup.next = NULL; - status = cf_util_get_string (ci, &dataset.name); + status = cf_util_get_string (ci, &datagroup.name); for (i = 0; i < ci->children_num; i++) { @@ -1029,7 +1031,7 @@ static int mb_config_add_dataset (oconfig_item_t *ci) /* {{{ */ char buffer[1024]; status = cf_util_get_string_buffer (child, buffer, sizeof (buffer)); if (status == 0) { - data_copy_by_name (&dataset.collect, data_definitions, buffer); + data_copy_by_name (&datagroup.collect, data_definitions, buffer); } status = 0; /* continue after failure. */ } @@ -1043,14 +1045,14 @@ static int mb_config_add_dataset (oconfig_item_t *ci) /* {{{ */ break; } /* for (i = 0; i < ci->children_num; i++) */ - if ((status == 0) && (dataset.collect == NULL)) + if ((status == 0) && (datagroup.collect == NULL)) status = EINVAL; if (status == 0) - dataset_copy (&data_sets, &dataset); + datagroup_copy (&data_groups, &datagroup); return (status); -} /* }}} int mb_config_add_dataset */ +} /* }}} int mb_config_add_datagroup */ static int mb_config (oconfig_item_t *ci) /* {{{ */ { @@ -1067,8 +1069,8 @@ static int mb_config (oconfig_item_t *ci) /* {{{ */ mb_config_add_data (child); else if (strcasecmp ("Host", child->key) == 0) mb_config_add_host (child); - else if (strcasecmp ("Dataset", child->key) == 0) - mb_config_add_dataset (child); + else if (strcasecmp ("Datagroup", child->key) == 0) + mb_config_add_datagroup (child); else ERROR ("Modbus plugin: Unknown configuration option: %s", child->key); } -- 2.11.0