Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
#include "collectd.h"
#include "common.h"
 
#define PLUGIN_NAME "my_plugin"
 
static _Bool g_enable_option1;
static char g_option2 [DATA_MAX_NAME_LEN];
 
static int my_config_function(oconfig_item_t *ci) {
  int ret = 0;
 
  INFO (PLUGIN_NAME ": %s:%d", __FUNCTION__, __LINE__);
 
  for (int i = 0; i < ci->children_num; i++) {
    oconfig_item_t *child = ci->children + i;
 
    if (strcasecmp("Option1", child->key) == 0) {
      ret = cf_util_get_boolean(child, & g_enable_option1);
    } else if (strcasecmp("Option2 ", child->key) == 0) {
      ret = cf_util_get_string_buffer(child, g_option2,
                                sizeof(g_option2));
 
    }else {
      ERROR(PLUGIN_NAME ": Unknown configuration parameter \"%s\".", child->key);
      ret = (-1);
    }
 
    if (ret != 0) {
      INFO (PLUGIN_NAME ": %s:%d ret=%d", __FUNCTION__, __LINE__, ret);
      return ret;
    }
  }
 
  return (0);
}
 
 
static int my_read_function(__attribute__((unused)) user_data_t *ud) {
 
  INFO (PLUGIN_NAME ": %s:%d", __FUNCTION__, __LINE__);
  /*  In order to dispatch values to the collectd daemon you need to fill out a value list and use plugin_dispatch_values() An example is provided below
   *
   *  value_list_t vl = VALUE_LIST_INIT;
   *
   *  vl.values = &(value_t){.derive = value}; //NOTE please change value to the actual value and use an appropriate type: checkout https://wiki.opnfv.org/display/fastpath/Collectd+101 for more info
   *
   *  vl.values_len = 1;
   *  sstrncpy(vl.host, hostname_g, sizeof(vl.host));
   *  sstrncpy(vl.plugin, PLUGIN_NAME, sizeof(vl.plugin));
   *  sstrncpy(vl.plugin_instance, "my_plugin_instance", sizeof(vl.plugin_instance)); // replace my_plugin_instance with an appropriate string/instance... see the end of this wiki
   *  sstrncpy(vl.type, "my_plugin_type", sizeof(vl.type));// replace my_plugin_type with an appropriate string... see the end of this wiki
   *
   *  plugin_dispatch_values(&vl);
   *
   *
   * To dispatch a notification you need to fill out a notification structure and use plugin_dispatch_notification()
   *  notification_t n = {
   *      .severity = severity, // where severity is one of NOTIF_OKAY, NOTIF_WARNING, NOTIF_FAILURE
   *      .time = cdtime(), 
   *      .message = "Some message",
   *      .plugin = PLUGIN_NAME}; 
   *
   *  sstrncpy(n.host, hostname_g, sizeof(n.host));
   *  sstrncpy(n.plugin_instance, "my_plugin_instance", sizeof(n.plugin_instance)); // replace my_plugin_instance with an appropriate string... see the end of this wiki
   *
   *  plugin_dispatch_notification(&n);
   */


  return (0);
}
 
 
static int my_shutdown_function (void) {
 
  INFO (PLUGIN_NAME ": %s:%d", __FUNCTION__, __LINE__);
 
  return (0);
}
 
static int my_init_function(void) {
  INFO(PLUGIN_NAME ": %s:%d", __FUNCTION__, __LINE__);
 
  return (0);
}
 
 
void module_register(void) {
 plugin_register_init("my_plugin", my_init_function);
  plugin_register_complex_config("my_plugin", my_config_function);
  plugin_register_complex_read(NULL, "my_plugin", my_read_function, 0, NULL);
  plugin_register_shutdown("my_plugin", my_shutdown_function);
}
 

...

Code Block
$ ./build.sh
$ ./configure --prefix=$HOME/clct --enable-debug
$ make
$ make -j install

 

...