Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/rb_message_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ rb_message_array_t *new_messages_array(size_t s);
void message_array_done(rb_message_array_t *msgs);

/// List of message array
typedef TAILQ_HEAD(, rb_message_array) rb_message_list;
typedef TAILQ_HEAD(, rb_message_array_s) rb_message_list;
#define rb_message_list_init(msg_list) TAILQ_INIT(msg_list)
#define rb_message_list_push(msg_list, msg_array) \
TAILQ_INSERT_TAIL(msg_list, msg_array, entry)
Expand Down
13 changes: 3 additions & 10 deletions src/rb_sensor_monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -486,19 +486,12 @@ rb_monitor_get_external_value(const rb_monitor_t *monitor,
monitor->cmd_arg);

if (0 == strlen(value_buf)) {
rdlog(LOG_WARNING, "Not seeing %s value.", monitor->name);
return false;
rdlog(LOG_WARNING, "Not seeing %s value. Forcing to 0.", monitor->name);
snprintf(value_buf, sizeof(value_buf), "0");
number = 0;
}

if (!monitor->splittok) {
if (!ok) {
rdlog(LOG_WARNING,
"Value '%s' of [%s:%s] is not a number",
value_buf,
monitor->cmd_arg,
monitor->name);
return false;
}
ret = process_novector_monitor(value_buf, number, time(NULL));
} else /* We have a vector here */ {
ret = process_vector_monitor(monitor, value_buf, time(NULL));
Expand Down
37 changes: 28 additions & 9 deletions src/rb_sensor_monitor_array.c
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,10 @@ process_monitor_value(const rb_monitor_t *monitor,
NULL == old_mv ||
!rb_monitor_timestamp_provided(monitor) ||
(monitor_value->type == MONITOR_VALUE_T__VALUE &&
rb_monitor_value_cmp_timestamp(old_mv, monitor_value) <
0);
(rb_monitor_value_cmp_timestamp(old_mv, monitor_value) <
0 ||
rd_dne(old_mv->value.value,
monitor_value->value.value)));

if (update_value) {
if (rb_monitor_send(monitor)) {
Expand Down Expand Up @@ -259,27 +261,42 @@ bool process_monitors_array(struct _worker_info *worker_info,
process_ctx = new_process_sensor_monitor_ctx(snmp_sessp);
}

rb_monitor_value_array_t *current_iteration_values =
rb_monitor_value_array_new(monitors->count);
if (NULL == current_iteration_values) {
aok = false;
} else {
current_iteration_values->count = monitors->count;
memcpy(current_iteration_values->elms,
last_known_monitor_values->elms,
monitors->count * sizeof(void *));
}

for (size_t i = 0; aok && i < monitors->count; ++i) {
rb_monitor_value_array_t *op_vars =
rb_monitor_value_array_select(
last_known_monitor_values,
current_iteration_values,
monitors_deps[i]);

const rb_monitor_t *monitor =
rb_monitors_array_elm_at(monitors, i);
struct monitor_value *value = process_sensor_monitor(
process_ctx, monitor, op_vars);

if (value) {
struct monitor_value *last_known_monitor_value_i =
last_known_monitor_values->elms[i];

last_known_monitor_values
->elms[i] = process_monitor_value(
monitor,
value,
last_known_monitor_value_i,
ret);
last_known_monitor_values->elms[i] =
process_monitor_value(
monitor,
value,
last_known_monitor_value_i,
ret);
}

current_iteration_values->elms[i] =
last_known_monitor_values->elms[i];

rb_monitor_value_array_done(op_vars);

Expand All @@ -290,6 +307,8 @@ bool process_monitors_array(struct _worker_info *worker_info,
}
}

rb_monitor_value_array_done(current_iteration_values);

if (process_ctx) {
destroy_process_sensor_monitor_ctx(process_ctx);
}
Expand Down
25 changes: 16 additions & 9 deletions src/rb_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,17 @@ bool snmp_solve_response(char *value_buf,
assert(value_buf);
assert(number);

if (status != STAT_SUCCESS) {
if (status != STAT_SUCCESS || NULL == response) {
rdlog(LOG_ERR,
"Snmp error: %s",
snmp_api_errstring(snmp_sess_session(session->sessp)
->s_snmp_errno));
// rdlog(LOG_ERR,"Error in packet.Reason:
// %s\n",snmp_errstring(response->errstat));
} else if (NULL == response) {
rdlog(LOG_ERR, "No SNMP response given.");
status != STAT_SUCCESS
? snmp_api_errstring(
snmp_sess_session(session->sessp)
->s_snmp_errno)
: "No SNMP response given.");
snprintf(value_buf, value_buf_len, "0");
*number = 0;
ret = 1;
} else {
rdlog(LOG_DEBUG,
"SNMP OID %s response type %d: %s\n",
Expand All @@ -127,7 +129,9 @@ bool snmp_solve_response(char *value_buf,
break;
case ASN_OCTET_STR:
if (effective_len == 0) {
ret = 0;
snprintf(value_buf, value_buf_len, "0");
*number = 0;
ret = 1;
break;
}

Expand All @@ -140,7 +144,7 @@ bool snmp_solve_response(char *value_buf,
*number = strtod(value_buf, NULL);
ret = 1;
break;
case 65: //counter32 TODO: replace by ASN_COUNTER32 if exists
case 65: //counter32 TODO: replace by ASN_COUNTER32 if exists
snprintf(value_buf, value_buf_len, "%ld", *response->variables->val.integer);
*number = *response->variables->val.integer;
ret = 1;
Expand All @@ -155,6 +159,9 @@ bool snmp_solve_response(char *value_buf,
rdlog(LOG_WARNING,
"Unknow variable type %d in SNMP response",
response->variables->type);
snprintf(value_buf, value_buf_len, "0");
*number = 0;
ret = 1;
};
}

Expand Down
8 changes: 7 additions & 1 deletion src/rb_system.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static bool system_solve_response(char *buff,
rdlog(LOG_ERR, "Cannot get system command.");
} else {
if (NULL == fgets(buff, buff_size, fp)) {
rdlog(LOG_ERR, "Cannot get buffer information");
rdlog(LOG_ERR, "Cannot get buffer information for %s", command);
} else {
trim_end(buff);
char *endPtr;
Expand All @@ -73,5 +73,11 @@ static bool system_solve_response(char *buff,
pclose(fp);
}

if (!ret) {
snprintf(buff, buff_size, "0");
*number = 0;
ret = true;
}

return ret;
}