Source
SET_MSG_RESULT(result, zbx_strdup(NULL, "Agent was compiled without support for \"sensordev\" structure."));
/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** 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 Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
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;
mib[3] = i;
if (-1 == sysctl(mib, 5, &sensor, &slen, NULL, 0))
return FAIL;
count_sensor(do_task, &sensor, aggr, cnt);