/* * internal helper functions */ static int mt_create (const oconfig_item_t *ci, void **user_data) /* {{{ */ { mt_match_t *m; int status; int i; m = (mt_match_t *) malloc (sizeof (*m)); if (m == NULL) { ERROR ("mt_create: malloc failed."); return (-ENOMEM); } memset (m, 0, sizeof (*m)); m->future = 0; m->past = 0; status = 0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Future", child->key) == 0) status = cf_util_get_cdtime (child, &m->future); else if (strcasecmp ("Past", child->key) == 0) status = cf_util_get_cdtime (child, &m->past); else { ERROR ("timediff match: The `%s' configuration option is not " "understood and will be ignored.", child->key); status = 0; } if (status != 0) break; } /* Additional sanity-checking */ while (status == 0) { if ((m->future == 0) && (m->past == 0)) { ERROR ("timediff match: Either `Future' or `Past' must be configured. " "This match will be ignored."); status = -1; } break; } if (status != 0) { free (m); return (status); } *user_data = m; return (0); } /* }}} int mt_create */
static int ctail_config_add_file(oconfig_item_t *ci) { cu_tail_match_t *tm; cdtime_t interval = 0; char *plugin_name = NULL; char *plugin_instance = NULL; int num_matches = 0; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING("tail plugin: `File' needs exactly one string argument."); return -1; } tm = tail_match_create(ci->values[0].value.string); if (tm == NULL) { ERROR("tail plugin: tail_match_create (%s) failed.", ci->values[0].value.string); return -1; } for (int i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; int status = 0; if (strcasecmp("Plugin", option->key) == 0) status = cf_util_get_string(option, &plugin_name); else if (strcasecmp("Instance", option->key) == 0) status = cf_util_get_string(option, &plugin_instance); else if (strcasecmp("Interval", option->key) == 0) cf_util_get_cdtime(option, &interval); else if (strcasecmp("Match", option->key) == 0) { status = ctail_config_add_match(tm, plugin_name, plugin_instance, option); if (status == 0) num_matches++; /* Be mild with failed matches.. */ status = 0; } else { status = -1; } if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ sfree(plugin_name); sfree(plugin_instance); if (num_matches == 0) { ERROR("tail plugin: No (valid) matches found for file `%s'.", ci->values[0].value.string); tail_match_destroy(tm); return -1; } char str[255]; snprintf(str, sizeof(str), "tail-%zu", tail_file_num++); plugin_register_complex_read( NULL, str, ctail_read, interval, &(user_data_t){.data = tm, .free_func = ctail_match_free});
/** * Read configuration. */ static int cgps_config (oconfig_item_t *ci) { int i; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Host", child->key) == 0) cf_util_get_string (child, &cgps_config_data.host); else if (strcasecmp ("Port", child->key) == 0) cf_util_get_service (child, &cgps_config_data.port); else if (strcasecmp ("Timeout", child->key) == 0) cf_util_get_cdtime (child, &cgps_config_data.timeout); else if (strcasecmp ("PauseConnect", child->key) == 0) cf_util_get_cdtime (child, &cgps_config_data.pause_connect); else WARNING ("gps plugin: Ignoring unknown config option \"%s\".", child->key); } // Controlling the value for timeout: // If set too high it blocks the reading (> 5 s), too low it gets not reading (< 500 us). // To avoid any issues we replace "out of range" value by the default value. if ( cgps_config_data.timeout > TIME_T_TO_CDTIME_T(5) || cgps_config_data.timeout < US_TO_CDTIME_T(500) ) { WARNING ("gps plugin: timeout set to %.6f sec. setting to default (%.6f).", CDTIME_T_TO_DOUBLE(cgps_config_data.timeout), CDTIME_T_TO_DOUBLE(CGPS_DEFAULT_TIMEOUT) ); cgps_config_data.timeout = CGPS_DEFAULT_TIMEOUT; } return (0); }
/* <File /> block */ static int tcsv_config_add_file(oconfig_item_t *ci) { instance_definition_t* id; int status = 0; int i; /* Registration variables */ char cb_name[DATA_MAX_NAME_LEN]; user_data_t cb_data; id = malloc(sizeof(*id)); if (id == NULL) return (-1); memset(id, 0, sizeof(*id)); id->instance = NULL; id->path = NULL; id->metric_list = NULL; id->time_from = -1; id->next = NULL; status = cf_util_get_string (ci, &id->path); if (status != 0) { sfree (id); return (status); } /* Use default interval. */ id->interval = plugin_get_interval(); for (i = 0; i < ci->children_num; ++i){ oconfig_item_t *option = ci->children + i; status = 0; if (strcasecmp("Instance", option->key) == 0) status = cf_util_get_string(option, &id->instance); else if (strcasecmp("Collect", option->key) == 0) status = tcsv_config_add_instance_collect(id, option); else if (strcasecmp("Interval", option->key) == 0) cf_util_get_cdtime(option, &id->interval); else if (strcasecmp("TimeFrom", option->key) == 0) status = tcsv_config_get_index (option, &id->time_from); else { WARNING("tail_csv plugin: Option `%s' not allowed here.", option->key); status = -1; } if (status != 0) break; } if (status != 0){ tcsv_instance_definition_destroy(id); return (-1); } /* Verify all necessary options have been set. */ if (id->path == NULL){ WARNING("tail_csv plugin: Option `Path' must be set."); status = -1; } else if (id->metric_list == NULL){ WARNING("tail_csv plugin: Option `Collect' must be set."); status = -1; } if (status != 0){ tcsv_instance_definition_destroy(id); return (-1); } ssnprintf (cb_name, sizeof (cb_name), "tail_csv/%s", id->path); memset(&cb_data, 0, sizeof(cb_data)); cb_data.data = id; cb_data.free_func = tcsv_instance_definition_destroy; status = plugin_register_complex_read(NULL, cb_name, tcsv_read, id->interval, &cb_data); if (status != 0){ ERROR("tail_csv plugin: Registering complex read function failed."); tcsv_instance_definition_destroy(id); return (-1); } return (0); }
static int c_psql_config_database (oconfig_item_t *ci) { c_psql_database_t *db; char cb_name[DATA_MAX_NAME_LEN]; struct timespec cb_interval = { 0, 0 }; user_data_t ud; int i; if ((1 != ci->values_num) || (OCONFIG_TYPE_STRING != ci->values[0].type)) { log_err ("<Database> expects a single string argument."); return 1; } memset (&ud, 0, sizeof (ud)); db = c_psql_database_new (ci->values[0].value.string); if (db == NULL) return -1; for (i = 0; i < ci->children_num; ++i) { oconfig_item_t *c = ci->children + i; if (0 == strcasecmp (c->key, "Host")) cf_util_get_string (c, &db->host); else if (0 == strcasecmp (c->key, "Port")) cf_util_get_service (c, &db->port); else if (0 == strcasecmp (c->key, "User")) cf_util_get_string (c, &db->user); else if (0 == strcasecmp (c->key, "Password")) cf_util_get_string (c, &db->password); else if (0 == strcasecmp (c->key, "Instance")) cf_util_get_string (c, &db->instance); else if (0 == strcasecmp (c->key, "SSLMode")) cf_util_get_string (c, &db->sslmode); else if (0 == strcasecmp (c->key, "KRBSrvName")) cf_util_get_string (c, &db->krbsrvname); else if (0 == strcasecmp (c->key, "Service")) cf_util_get_string (c, &db->service); else if (0 == strcasecmp (c->key, "Query")) udb_query_pick_from_list (c, queries, queries_num, &db->queries, &db->queries_num); else if (0 == strcasecmp (c->key, "Interval")) cf_util_get_cdtime (c, &db->interval); else log_warn ("Ignoring unknown config key \"%s\".", c->key); } /* If no `Query' options were given, add the default queries.. */ if (db->queries_num == 0) { for (i = 0; i < def_queries_num; i++) udb_query_pick_from_list_by_name (def_queries[i], queries, queries_num, &db->queries, &db->queries_num); } if (db->queries_num > 0) { db->q_prep_areas = (udb_query_preparation_area_t **) calloc ( db->queries_num, sizeof (*db->q_prep_areas)); if (db->q_prep_areas == NULL) { log_err ("Out of memory."); c_psql_database_delete (db); return -1; } } for (i = 0; (size_t)i < db->queries_num; ++i) { c_psql_user_data_t *data; data = udb_query_get_user_data (db->queries[i]); if ((data != NULL) && (data->params_num > db->max_params_num)) db->max_params_num = data->params_num; db->q_prep_areas[i] = udb_query_allocate_preparation_area (db->queries[i]); if (db->q_prep_areas[i] == NULL) { log_err ("Out of memory."); c_psql_database_delete (db); return -1; } } ud.data = db; ud.free_func = c_psql_database_delete; ssnprintf (cb_name, sizeof (cb_name), "postgresql-%s", db->instance); CDTIME_T_TO_TIMESPEC (db->interval, &cb_interval); plugin_register_complex_read ("postgresql", cb_name, c_psql_read, /* interval = */ (db->interval > 0) ? &cb_interval : NULL, &ud); return 0; } /* c_psql_config_database */
static int cj_config_add_url (oconfig_item_t *ci) /* {{{ */ { cj_t *db; int status = 0; int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("curl_json plugin: The `URL' block " "needs exactly one string argument."); return (-1); } db = (cj_t *) malloc (sizeof (*db)); if (db == NULL) { ERROR ("curl_json plugin: malloc failed."); return (-1); } memset (db, 0, sizeof (*db)); if (strcasecmp ("URL", ci->key) == 0) status = cf_util_get_string (ci, &db->url); else if (strcasecmp ("Sock", ci->key) == 0) status = cf_util_get_string (ci, &db->sock); else { ERROR ("curl_json plugin: cj_config: " "Invalid key: %s", ci->key); return (-1); } if (status != 0) { sfree (db); return (status); } /* Fill the `cj_t' structure.. */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Instance", child->key) == 0) status = cf_util_get_string (child, &db->instance); else if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &db->host); else if (db->url && strcasecmp ("User", child->key) == 0) status = cf_util_get_string (child, &db->user); else if (db->url && strcasecmp ("Password", child->key) == 0) status = cf_util_get_string (child, &db->pass); else if (strcasecmp ("Digest", child->key) == 0) status = cf_util_get_boolean (child, &db->digest); else if (db->url && strcasecmp ("VerifyPeer", child->key) == 0) status = cf_util_get_boolean (child, &db->verify_peer); else if (db->url && strcasecmp ("VerifyHost", child->key) == 0) status = cf_util_get_boolean (child, &db->verify_host); else if (db->url && strcasecmp ("CACert", child->key) == 0) status = cf_util_get_string (child, &db->cacert); else if (db->url && strcasecmp ("Header", child->key) == 0) status = cj_config_append_string ("Header", &db->headers, child); else if (db->url && strcasecmp ("Post", child->key) == 0) status = cf_util_get_string (child, &db->post_body); else if (strcasecmp ("Key", child->key) == 0) status = cj_config_add_key (db, child); else if (strcasecmp ("Interval", child->key) == 0) status = cf_util_get_cdtime(child, &db->interval); else { WARNING ("curl_json plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } if (status == 0) { if (db->tree == NULL) { WARNING ("curl_json plugin: No (valid) `Key' block within `%s' \"`%s'\".", db->url ? "URL" : "Sock", db->url ? db->url : db->sock); status = -1; } if (status == 0 && db->url) status = cj_init_curl (db); } /* If all went well, register this database for reading */ if (status == 0) { user_data_t ud; char *cb_name; struct timespec interval = { 0, 0 }; CDTIME_T_TO_TIMESPEC (db->interval, &interval); if (db->instance == NULL) db->instance = strdup("default"); DEBUG ("curl_json plugin: Registering new read callback: %s", db->instance); memset (&ud, 0, sizeof (ud)); ud.data = (void *) db; ud.free_func = cj_free; cb_name = ssnprintf_alloc ("curl_json-%s-%s", db->instance, db->url ? db->url : db->sock); plugin_register_complex_read (/* group = */ NULL, cb_name, cj_read, /* interval = */ (db->interval > 0) ? &interval : NULL, &ud); sfree (cb_name); } else { cj_free (db); return (-1); } return (0); }
static int cdbi_config_add_database (oconfig_item_t *ci) /* {{{ */ { cdbi_database_t *db; int status; int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("dbi plugin: The `Database' block " "needs exactly one string argument."); return (-1); } db = calloc (1, sizeof (*db)); if (db == NULL) { ERROR ("dbi plugin: calloc failed."); return (-1); } status = cf_util_get_string (ci, &db->name); if (status != 0) { sfree (db); return (status); } /* Fill the `cdbi_database_t' structure.. */ for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; if (strcasecmp ("Driver", child->key) == 0) status = cf_util_get_string (child, &db->driver); else if (strcasecmp ("DriverOption", child->key) == 0) status = cdbi_config_add_database_driver_option (db, child); else if (strcasecmp ("SelectDB", child->key) == 0) status = cf_util_get_string (child, &db->select_db); else if (strcasecmp ("Query", child->key) == 0) status = udb_query_pick_from_list (child, queries, queries_num, &db->queries, &db->queries_num); else if (strcasecmp ("Host", child->key) == 0) status = cf_util_get_string (child, &db->host); else if (strcasecmp ("Interval", child->key) == 0) status = cf_util_get_cdtime(child, &db->interval); else { WARNING ("dbi plugin: Option `%s' not allowed here.", child->key); status = -1; } if (status != 0) break; } /* Check that all necessary options have been given. */ while (status == 0) { if (db->driver == NULL) { WARNING ("dbi plugin: `Driver' not given for database `%s'", db->name); status = -1; } if (db->driver_options_num == 0) { WARNING ("dbi plugin: No `DriverOption' given for database `%s'. " "This will likely not work.", db->name); } break; } /* while (status == 0) */ while ((status == 0) && (db->queries_num > 0)) { size_t j; db->q_prep_areas = calloc (db->queries_num, sizeof (*db->q_prep_areas)); if (db->q_prep_areas == NULL) { WARNING ("dbi plugin: calloc failed"); status = -1; break; } for (j = 0; j < db->queries_num; ++j) { db->q_prep_areas[j] = udb_query_allocate_preparation_area (db->queries[j]); if (db->q_prep_areas[j] == NULL) { WARNING ("dbi plugin: udb_query_allocate_preparation_area failed"); status = -1; break; } } break; } /* If all went well, add this database to the global list of databases. */ if (status == 0) { cdbi_database_t **temp; temp = realloc (databases, sizeof (*databases) * (databases_num + 1)); if (temp == NULL) { ERROR ("dbi plugin: realloc failed"); status = -1; } 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 = */ (db->interval > 0) ? db->interval : 0, /* user_data = */ &ud); free (name); } } if (status != 0) { cdbi_database_free (db); return (-1); } return (0); } /* }}} int cdbi_config_add_database */
static int mb_config_add_host (oconfig_item_t *ci) /* {{{ */ { mb_host_t *host; int status; int i; host = malloc (sizeof (*host)); if (host == NULL) return (ENOMEM); memset (host, 0, sizeof (*host)); host->slaves = NULL; status = cf_util_get_string_buffer (ci, host->host, sizeof (host->host)); if (status != 0) return (status); if (host->host[0] == 0) return (EINVAL); for (i = 0; i < ci->children_num; i++) { oconfig_item_t *child = ci->children + i; status = 0; if (strcasecmp ("Address", child->key) == 0) { char buffer[NI_MAXHOST]; status = cf_util_get_string_buffer (child, buffer, sizeof (buffer)); if (status == 0) status = mb_config_set_host_address (host, buffer); } else if (strcasecmp ("Port", child->key) == 0) { host->port = cf_util_get_port_number (child); if (host->port <= 0) status = -1; } else if (strcasecmp ("Interval", child->key) == 0) status = cf_util_get_cdtime (child, &host->interval); else if (strcasecmp ("Slave", child->key) == 0) /* Don't set status: Gracefully continue if a slave fails. */ mb_config_add_slave (host, child); else { ERROR ("Modbus plugin: Unknown configuration option: %s", child->key); status = -1; } if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ assert (host->host[0] != 0); if (host->host[0] == 0) { ERROR ("Modbus plugin: Data block \"%s\": No type has been specified.", host->host); status = -1; } if (status == 0) { user_data_t ud; char name[1024]; struct timespec interval = { 0, 0 }; ud.data = host; ud.free_func = host_free; ssnprintf (name, sizeof (name), "modbus-%s", host->host); CDTIME_T_TO_TIMESPEC (host->interval, &interval); plugin_register_complex_read (/* group = */ NULL, name, /* callback = */ mb_read, /* interval = */ (host->interval > 0) ? &interval : NULL, &ud); } else { host_free (host); } return (status); } /* }}} int mb_config_add_host */
static int csnmp_config_add_host (oconfig_item_t *ci) { host_definition_t *hd; int status = 0; int i; /* Registration stuff. */ char cb_name[DATA_MAX_NAME_LEN]; user_data_t cb_data; hd = (host_definition_t *) malloc (sizeof (host_definition_t)); if (hd == NULL) return (-1); memset (hd, '\0', sizeof (host_definition_t)); hd->version = 2; C_COMPLAIN_INIT (&hd->complaint); status = cf_util_get_string(ci, &hd->name); if (status != 0) { sfree (hd); return status; } hd->sess_handle = NULL; hd->interval = 0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; status = 0; if (strcasecmp ("Address", option->key) == 0) status = cf_util_get_string(option, &hd->address); else if (strcasecmp ("Community", option->key) == 0) status = cf_util_get_string(option, &hd->community); else if (strcasecmp ("Version", option->key) == 0) status = csnmp_config_add_host_version (hd, option); else if (strcasecmp ("Collect", option->key) == 0) csnmp_config_add_host_collect (hd, option); else if (strcasecmp ("Interval", option->key) == 0) cf_util_get_cdtime (option, &hd->interval); else if (strcasecmp ("Username", option->key) == 0) status = cf_util_get_string(option, &hd->username); else if (strcasecmp ("AuthProtocol", option->key) == 0) status = csnmp_config_add_host_auth_protocol (hd, option); else if (strcasecmp ("PrivacyProtocol", option->key) == 0) status = csnmp_config_add_host_priv_protocol (hd, option); else if (strcasecmp ("AuthPassphrase", option->key) == 0) status = cf_util_get_string(option, &hd->auth_passphrase); else if (strcasecmp ("PrivacyPassphrase", option->key) == 0) status = cf_util_get_string(option, &hd->priv_passphrase); else if (strcasecmp ("SecurityLevel", option->key) == 0) status = csnmp_config_add_host_security_level (hd, option); else if (strcasecmp ("Context", option->key) == 0) status = cf_util_get_string(option, &hd->context); else { WARNING ("snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.", option->key); status = -1; } if (status != 0) break; } /* for (ci->children) */ while (status == 0) { if (hd->address == NULL) { WARNING ("snmp plugin: `Address' not given for host `%s'", hd->name); status = -1; break; } if (hd->community == NULL && hd->version < 3) { WARNING ("snmp plugin: `Community' not given for host `%s'", hd->name); status = -1; break; } if (hd->version == 3) { if (hd->username == NULL) { WARNING ("snmp plugin: `Username' not given for host `%s'", hd->name); status = -1; break; } if (hd->security_level == 0) { WARNING ("snmp plugin: `SecurityLevel' not given for host `%s'", hd->name); status = -1; break; } if (hd->security_level == SNMP_SEC_LEVEL_AUTHNOPRIV || hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV) { if (hd->auth_protocol == NULL) { WARNING ("snmp plugin: `AuthProtocol' not given for host `%s'", hd->name); status = -1; break; } if (hd->auth_passphrase == NULL) { WARNING ("snmp plugin: `AuthPassphrase' not given for host `%s'", hd->name); status = -1; break; } } if (hd->security_level == SNMP_SEC_LEVEL_AUTHPRIV) { if (hd->priv_protocol == NULL) { WARNING ("snmp plugin: `PrivacyProtocol' not given for host `%s'", hd->name); status = -1; break; } if (hd->priv_passphrase == NULL) { WARNING ("snmp plugin: `PrivacyPassphrase' not given for host `%s'", hd->name); status = -1; break; } } } break; } /* while (status == 0) */ if (status != 0) { csnmp_host_definition_destroy (hd); return (-1); } DEBUG ("snmp plugin: hd = { name = %s, address = %s, community = %s, version = %i }", hd->name, hd->address, hd->community, hd->version); ssnprintf (cb_name, sizeof (cb_name), "snmp-%s", hd->name); memset (&cb_data, 0, sizeof (cb_data)); cb_data.data = hd; cb_data.free_func = csnmp_host_definition_destroy; status = plugin_register_complex_read (/* group = */ NULL, cb_name, csnmp_read_host, hd->interval, /* user_data = */ &cb_data); if (status != 0) { ERROR ("snmp plugin: Registering complex read function failed."); csnmp_host_definition_destroy (hd); return (-1); } return (0); } /* int csnmp_config_add_host */
static int ctail_config_add_file (oconfig_item_t *ci) { cu_tail_match_t *tm; cdtime_t interval = 0; char *plugin_instance = NULL; int num_matches = 0; int i; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("tail plugin: `File' needs exactly one string argument."); return (-1); } tm = tail_match_create (ci->values[0].value.string); if (tm == NULL) { ERROR ("tail plugin: tail_match_create (%s) failed.", ci->values[0].value.string); return (-1); } for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; int status = 0; if (strcasecmp ("Instance", option->key) == 0) status = cf_util_get_string (option, &plugin_instance); else if (strcasecmp ("Interval", option->key) == 0) cf_util_get_cdtime (option, &interval); else if (strcasecmp ("Match", option->key) == 0) { status = ctail_config_add_match (tm, plugin_instance, option, interval); if (status == 0) num_matches++; /* Be mild with failed matches.. */ status = 0; } else { status = -1; } if (status != 0) break; } /* for (i = 0; i < ci->children_num; i++) */ sfree (plugin_instance); if (num_matches == 0) { ERROR ("tail plugin: No (valid) matches found for file `%s'.", ci->values[0].value.string); tail_match_destroy (tm); return (-1); } else { cu_tail_match_t **temp; temp = realloc (tail_match_list, sizeof (cu_tail_match_t *) * (tail_match_list_num + 1)); if (temp == NULL) { ERROR ("tail plugin: realloc failed."); tail_match_destroy (tm); return (-1); } tail_match_list = temp; tail_match_list[tail_match_list_num] = tm; tail_match_list_intervals[tail_match_list_num] = interval; tail_match_list_num++; } return (0); } /* int ctail_config_add_file */
static int csnmp_config_add_host (oconfig_item_t *ci) { host_definition_t *hd; int status = 0; int i; /* Registration stuff. */ char cb_name[DATA_MAX_NAME_LEN]; user_data_t cb_data; struct timespec cb_interval; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("snmp plugin: `Host' needs exactly one string argument."); return (-1); } hd = (host_definition_t *) malloc (sizeof (host_definition_t)); if (hd == NULL) return (-1); memset (hd, '\0', sizeof (host_definition_t)); hd->version = 2; C_COMPLAIN_INIT (&hd->complaint); hd->name = strdup (ci->values[0].value.string); if (hd->name == NULL) { free (hd); return (-1); } hd->sess_handle = NULL; hd->interval = 0; for (i = 0; i < ci->children_num; i++) { oconfig_item_t *option = ci->children + i; status = 0; if (strcasecmp ("Address", option->key) == 0) status = csnmp_config_add_host_address (hd, option); else if (strcasecmp ("Community", option->key) == 0) status = csnmp_config_add_host_community (hd, option); else if (strcasecmp ("Version", option->key) == 0) status = csnmp_config_add_host_version (hd, option); else if (strcasecmp ("Collect", option->key) == 0) csnmp_config_add_host_collect (hd, option); else if (strcasecmp ("Interval", option->key) == 0) cf_util_get_cdtime (option, &hd->interval); else { WARNING ("snmp plugin: csnmp_config_add_host: Option `%s' not allowed here.", option->key); status = -1; } if (status != 0) break; } /* for (ci->children) */ while (status == 0) { if (hd->address == NULL) { WARNING ("snmp plugin: `Address' not given for host `%s'", hd->name); status = -1; break; } if (hd->community == NULL) { WARNING ("snmp plugin: `Community' not given for host `%s'", hd->name); status = -1; break; } break; } /* while (status == 0) */ if (status != 0) { csnmp_host_definition_destroy (hd); return (-1); } DEBUG ("snmp plugin: hd = { name = %s, address = %s, community = %s, version = %i }", hd->name, hd->address, hd->community, hd->version); ssnprintf (cb_name, sizeof (cb_name), "snmp-%s", hd->name); memset (&cb_data, 0, sizeof (cb_data)); cb_data.data = hd; cb_data.free_func = csnmp_host_definition_destroy; CDTIME_T_TO_TIMESPEC (hd->interval, &cb_interval); status = plugin_register_complex_read (/* group = */ NULL, cb_name, csnmp_read_host, /* interval = */ &cb_interval, /* user_data = */ &cb_data); if (status != 0) { ERROR ("snmp plugin: Registering complex read function failed."); csnmp_host_definition_destroy (hd); return (-1); } return (0); } /* int csnmp_config_add_host */