(_dd->type ? !strcmp(_dd->type, _t) : 0) && \
(_dd->type_instance ? !strcmp(_dd->type_instance, _ti) : 1)
+static int snmp_agent_shutdown(void);
static void *snmp_agent_thread_run(void *arg);
static int snmp_agent_register_oid(oid_t *oid, Netsnmp_Node_Handler *handler);
static int snmp_agent_set_vardata(void *dst_buf, size_t *dst_buf_len,
char *oid_str_ptr[MAX_OID_LEN];
for (size_t i = 0; i < o->oid_len; i++) {
- ssnprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]);
+ snprintf(oid_str[i], sizeof(oid_str[i]), "%lu", (unsigned long)o->oid[i]);
oid_str_ptr[i] = oid_str[i];
}
DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance);
for (size_t i = 0; i < dd->oids_len; i++) {
snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]);
- DEBUG(PLUGIN_NAME ": OID[%zu]: %s", i, oid_str);
+ DEBUG(PLUGIN_NAME ": OID[%" PRIsz "]: %s", i, oid_str);
}
DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale);
DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift);
DEBUG(PLUGIN_NAME ": TypeInstance: %s", dd->type_instance);
for (size_t i = 0; i < dd->oids_len; i++) {
snmp_agent_oid_to_string(oid_str, sizeof(oid_str), &dd->oids[i]);
- DEBUG(PLUGIN_NAME ": OID[%zu]: %s", i, oid_str);
+ DEBUG(PLUGIN_NAME ": OID[%" PRIsz "]: %s", i, oid_str);
}
DEBUG(PLUGIN_NAME ": Scale: %g", dd->scale);
DEBUG(PLUGIN_NAME ": Shift: %g", dd->shift);
return 0;
}
-static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset, char *key) {
+static void snmp_agent_generate_oid2string(oid_t *oid, size_t offset,
+ char *key) {
int key_len = oid->oid[offset];
int i;
.severity = NOTIF_WARNING, .time = cdtime(), .plugin = PLUGIN_NAME};
sstrncpy(n.host, hostname_g, sizeof(n.host));
sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance));
- ssnprintf(n.message, sizeof(n.message),
- "Removed data row from table %s instance %s index %d", td->name,
- ins, (index != NULL) ? *index : -1);
+ snprintf(n.message, sizeof(n.message),
+ "Removed data row from table %s instance %s index %d", td->name, ins,
+ (index != NULL) ? *index : -1);
plugin_dispatch_notification(&n);
if (td->index_oid.oid_len) {
if (dd->is_instance) {
requests->requestvb->type = ASN_OCTET_STR;
- snmp_set_var_typed_value(requests->requestvb,
- requests->requestvb->type, (const u_char *)instance,
- strlen((instance)));
+ snmp_set_var_typed_value(
+ requests->requestvb, requests->requestvb->type,
+ (const u_char *)instance, strlen((instance)));
pthread_mutex_unlock(&g_agent->lock);
}
}
- llentry_t *entry = llentry_create(td->name, td);
- if (entry == NULL) {
- snmp_agent_free_table(&td);
- return -ENOMEM;
- }
-
td->instance_index =
c_avl_create((int (*)(const void *, const void *))strcmp);
if (td->instance_index == NULL) {
return -ENOMEM;
}
+ llentry_t *entry = llentry_create(td->name, td);
+ if (entry == NULL) {
+ snmp_agent_free_table(&td);
+ return -ENOMEM;
+ }
llist_append(g_agent->tables, entry);
return 0;
.severity = NOTIF_OKAY, .time = cdtime(), .plugin = PLUGIN_NAME};
sstrncpy(n.host, hostname_g, sizeof(n.host));
sstrncpy(n.plugin_instance, ins, sizeof(n.plugin_instance));
- ssnprintf(n.message, sizeof(n.message),
- "Data row added to table %s instance %s index %d", td->name, ins,
- (index != NULL) ? *index : -1);
+ snprintf(n.message, sizeof(n.message),
+ "Data row added to table %s instance %s index %d", td->name, ins,
+ (index != NULL) ? *index : -1);
plugin_dispatch_notification(&n);
return 0;
static int snmp_agent_init(void) {
int ret;
- ret = snmp_agent_preinit();
- if (ret != 0)
- return ret;
+ if (g_agent == NULL || ((llist_head(g_agent->scalars) == NULL) &&
+ (llist_head(g_agent->tables) == NULL))) {
+ ERROR(PLUGIN_NAME ": snmp_agent_init: plugin not configured");
+ return -EINVAL;
+ }
+
+ plugin_register_shutdown(PLUGIN_NAME, snmp_agent_shutdown);
ret = snmp_agent_register_scalar_oids();
if (ret != 0)
return ret;
}
+ if (llist_head(g_agent->tables) != NULL) {
+ plugin_register_write(PLUGIN_NAME, snmp_agent_collect, NULL);
+ plugin_register_missing(PLUGIN_NAME, snmp_agent_clear_missing, NULL);
+ }
+
return 0;
}
void module_register(void) {
plugin_register_init(PLUGIN_NAME, snmp_agent_init);
plugin_register_complex_config(PLUGIN_NAME, snmp_agent_config);
- plugin_register_write(PLUGIN_NAME, snmp_agent_collect, NULL);
- plugin_register_missing(PLUGIN_NAME, snmp_agent_clear_missing, NULL);
- plugin_register_shutdown(PLUGIN_NAME, snmp_agent_shutdown);
}