Source
xxxxxxxxxx
SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for \"sensordev\" structure."));
/*
** Zabbix
** Copyright (C) 2001-2023 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
**/
static void count_sensor(int do_task, const struct sensor *sensor, double *aggr, int *cnt)
{
double value = sensor->value;
switch (sensor->type)
{
case SENSOR_TEMP:
value = (value - 273150000) / 1000000;
break;
case SENSOR_VOLTS_DC:
case SENSOR_VOLTS_AC:
case SENSOR_AMPS:
case SENSOR_LUX:
value /= 1000000;
break;
case SENSOR_TIMEDELTA:
value /= 1000000000;
break;
default:
break;
}
(*cnt)++;
switch (do_task)
{
case ZBX_DO_ONE:
*aggr = value;
break;
case ZBX_DO_AVG:
*aggr += value;
break;
case ZBX_DO_MAX:
*aggr = (1 == *cnt ? value : MAX(*aggr, value));
break;
case ZBX_DO_MIN:
*aggr = (1 == *cnt ? value : MIN(*aggr, value));
break;
}
}
static int get_device_sensors(int do_task, int *mib, const struct sensordev *sensordev, const char *name,
double *aggr, int *cnt)
{
if (ZBX_DO_ONE == do_task)
{
int i, len = 0;
struct sensor sensor;
size_t slen = sizeof(sensor);
for (i = 0; i < SENSOR_MAX_TYPES; i++)
{
if (0 == strncmp(name, sensor_type_s[i], len = strlen(sensor_type_s[i])))
break;
}
if (i == SENSOR_MAX_TYPES)
return FAIL;
if (SUCCEED != zbx_is_uint31(name + len, &mib[4]))
return FAIL;