From df69b00d717b3a4c6c0c8b9a968516c444d2664c Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sat, 28 Jan 2006 19:54:54 +0000 Subject: Clean up our value storage. --- daemon/config.c | 2 +- daemon/rrd-update.c | 7 +++++-- daemon/rrdbotd.h | 17 ++++++++++++----- daemon/snmp-engine.c | 25 +++++++++++++++++-------- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/daemon/config.c b/daemon/config.c index ce6e397..33fc5fa 100644 --- a/daemon/config.c +++ b/daemon/config.c @@ -295,7 +295,7 @@ parse_item(const char* field, char* uri, config_ctx *ctx) ritem->host = rhost; ritem->poller = NULL; /* Set later in config_done */ ritem->req = NULL; - ritem->value = RB_UNKNOWN; + ritem->vtype = VALUE_UNSET; /* And parse the OID */ if(rb_snmp_parse_mib(path, &(ritem->snmpfield)) == -1) diff --git a/daemon/rrd-update.c b/daemon/rrd-update.c index ca8d71b..f052c31 100644 --- a/daemon/rrd-update.c +++ b/daemon/rrd-update.c @@ -97,11 +97,14 @@ void rb_rrd_update(rb_poller *poll) strlcat(template, it->rrdfield, tlen); - if(it->value == RB_UNKNOWN) + if(it->vtype == VALUE_UNSET) strlcat(items, "U", ilen); else { - snprintf(buf, MAX_NUMLEN, "%.4lf", it->value); + if(it->vtype == VALUE_FLOAT) + snprintf(buf, MAX_NUMLEN, "%.4lf", it->v.f_value); + else + snprintf(buf, MAX_NUMLEN, "%lld", it->v.i_value); buf[MAX_NUMLEN - 1] = 0; strlcat(items, buf, ilen); } diff --git a/daemon/rrdbotd.h b/daemon/rrdbotd.h index b211007..0b7b0e1 100644 --- a/daemon/rrdbotd.h +++ b/daemon/rrdbotd.h @@ -39,7 +39,6 @@ #ifndef __RRDBOTD_H__ #define __RRDBOTD_H__ -#include #include #include @@ -53,7 +52,6 @@ */ typedef uint64_t mstime; -#define RB_UNKNOWN -DBL_MAX struct _rb_item; struct _rb_poller; @@ -67,14 +65,23 @@ struct _rb_request; typedef struct _rb_item { - struct _rb_request* req; - /* Specific to this item */ const char* rrdfield; struct snmp_value snmpfield; /* The last value / current request */ - double value; + union + { + int64_t i_value; + double f_value; + } v; + + #define VALUE_UNSET 0 + #define VALUE_REAL 1 + #define VALUE_FLOAT 2 + int vtype; + + struct _rb_request* req; /* Pointers to related */ const struct _rb_poller* poller; diff --git a/daemon/snmp-engine.c b/daemon/snmp-engine.c index 37637ab..24274b8 100644 --- a/daemon/snmp-engine.c +++ b/daemon/snmp-engine.c @@ -300,7 +300,7 @@ timeout_req(rb_request* req, mstime when) { rb_messagex(LOG_DEBUG, "value for field '%s' timed out", it->rrdfield); - it->value = RB_UNKNOWN; + it->vtype = VALUE_UNSET; it->req = NULL; } @@ -353,18 +353,21 @@ respond_req(rb_request* req, struct snmp_pdu* pdu, mstime when) switch(value->syntax) { case SNMP_SYNTAX_NULL: - item->value = RB_UNKNOWN; + item->vtype = VALUE_UNSET; break; case SNMP_SYNTAX_INTEGER: - item->value = value->v.integer; + item->v.i_value = value->v.integer; + item->vtype = VALUE_REAL; break; case SNMP_SYNTAX_COUNTER: case SNMP_SYNTAX_GAUGE: case SNMP_SYNTAX_TIMETICKS: - item->value = value->v.uint32; + item->v.i_value = value->v.uint32; + item->vtype = VALUE_REAL; break; case SNMP_SYNTAX_COUNTER64: - item->value = value->v.counter64; + item->v.i_value = value->v.counter64; + item->vtype = VALUE_REAL; break; case SNMP_SYNTAX_OCTETSTRING: case SNMP_SYNTAX_OID: @@ -383,9 +386,15 @@ respond_req(rb_request* req, struct snmp_pdu* pdu, mstime when) if(msg) rb_messagex(LOG_WARNING, msg, item->rrdfield); + else if(item->vtype == VALUE_REAL) + rb_messagex(LOG_DEBUG, "got value for field '%s': %lld", + item->rrdfield, item->v.i_value); + else if(item->vtype == VALUE_FLOAT) + rb_messagex(LOG_DEBUG, "got value for field '%s': %lld", + item->rrdfield, item->v.f_value); else - rb_messagex(LOG_DEBUG, "got value for field '%s': %0.2f", - item->rrdfield, item->value); + rb_messagex(LOG_DEBUG, "got value for field '%s': U", + item->rrdfield); /* Mark this value as done */ item->req = NULL; @@ -491,7 +500,7 @@ poller_timer(mstime when, void* arg) /* Mark item as active by this request */ it->req = req; - it->value = RB_UNKNOWN; + it->vtype = VALUE_UNSET; } if(req) -- cgit v1.2.3