Type "voltage"
Table false
Instance "input_line1"
+ Scale 0.1
Values "SNMPv2-SMI::enterprises.6050.5.4.1.1.2.1"
</Data>
<Data "hr_users">
Type "users"
Table false
Instance ""
+ Shift -1
Values "HOST-RESOURCES-MIB::hrSystemNumUsers.0"
</Data>
<Data "std_traffic">
value, e.E<nbsp>g. C<IF-MIB::ifInOctets.3> for the third counter of incoming
traffic.
+=item B<Scale> I<Value>
+
+The gauge-values returned by the SNMP-agent are multiplied by I<Value>. This
+is useful when values are transfered as a fixed point real number. For example,
+thermometers may transfer B<243> but actually mean B<24.3>, so you can specify
+a scale value of B<0.1> to correct this. The default value is of course B<1.0>.
+
+This value is not applied to counter-values.
+
+=item B<Shift> I<Value>
+
+I<Value> is added to gauge-values returned by the SNMP-agent after they have
+been multiplied by any B<Scale> value. If, for example, a thermometer returns
+degrees Kelvin you could specify a shift of B<273.15> here to store values in
+degrees Celsius. The default value is is course B<0.0>.
+
+This value is not applied to counter-values.
+
=back
=head2 The Host block
instance_t instance;
oid_t *values;
int values_len;
+ double scale;
+ double shift;
struct data_definition_s *next;
};
typedef struct data_definition_s data_definition_t;
return (0);
} /* int csnmp_config_add_data_instance */
+static int csnmp_config_add_data_shift (data_definition_t *dd, oconfig_item_t *ci)
+{
+ if ((ci->values_num != 1)
+ || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+ {
+ WARNING ("snmp plugin: The `Scale' config option needs exactly one number argument.");
+ return (-1);
+ }
+
+ dd->shift = ci->values[0].value.number;
+
+ return (0);
+} /* int csnmp_config_add_data_shift */
+
+static int csnmp_config_add_data_scale (data_definition_t *dd, oconfig_item_t *ci)
+{
+ if ((ci->values_num != 1)
+ || (ci->values[0].type != OCONFIG_TYPE_NUMBER))
+ {
+ WARNING ("snmp plugin: The `Scale' config option needs exactly one number argument.");
+ return (-1);
+ }
+
+ dd->scale = ci->values[0].value.number;
+
+ return (0);
+} /* int csnmp_config_add_data_scale */
+
static int csnmp_config_add_data (oconfig_item_t *ci)
{
data_definition_t *dd;
free (dd);
return (-1);
}
+ dd->scale = 1.0;
+ dd->shift = 0.0;
for (i = 0; i < ci->children_num; i++)
{
status = csnmp_config_add_data_instance (dd, option);
else if (strcasecmp ("Values", option->key) == 0)
status = csnmp_config_add_data_values (dd, option);
+ else if (strcasecmp ("Shift", option->key) == 0)
+ status = csnmp_config_add_data_shift (dd, option);
+ else if (strcasecmp ("Scale", option->key) == 0)
+ status = csnmp_config_add_data_scale (dd, option);
else
{
WARNING ("snmp plugin: Option `%s' not allowed here.", option->key);
}
} /* void csnmp_host_open_session */
-static value_t csnmp_value_list_to_value (struct variable_list *vl, int type)
+static value_t csnmp_value_list_to_value (struct variable_list *vl, int type,
+ double scale, double shift)
{
value_t ret;
uint64_t temp = 0;
{
ret.gauge = NAN;
if (defined != 0)
- ret.gauge = temp;
+ ret.gauge = (scale * temp) + shift;
}
return (ret);
}
else
{
- value_t val = csnmp_value_list_to_value (vb, DS_TYPE_COUNTER);
+ value_t val = csnmp_value_list_to_value (vb, DS_TYPE_COUNTER, 1.0, 0.0);
snprintf (il->instance, sizeof (il->instance),
"%llu", val.counter);
}
if (vt != NULL)
{
vt->subid = vb->name[vb->name_length - 1];
- vt->value = csnmp_value_list_to_value (vb, ds->ds[i].type);
+ vt->value = csnmp_value_list_to_value (vb, ds->ds[i].type,
+ data->scale, data->shift);
vt->next = NULL;
if (value_table_ptr[i] == NULL)
for (i = 0; i < data->values_len; i++)
if (snmp_oid_compare (data->values[i].oid, data->values[i].oid_len,
vb->name, vb->name_length) == 0)
- vl.values[i] = csnmp_value_list_to_value (vb, ds->ds[i].type);
+ vl.values[i] = csnmp_value_list_to_value (vb, ds->ds[i].type,
+ data->scale, data->shift);
} /* for (res->variables) */
snmp_free_pdu (res);