Source
static void get_device_sensors(int do_task, const char *device, const char *name, double *aggr, int *cnt)
/*
** Copyright (C) 2001-2024 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 const char *locations[] = {"", "/device", NULL};
static void count_sensor(int do_task, const char *filename, double *aggr, int *cnt)
{
FILE *f;
char line[MAX_STRING_LEN];
double value;
if (NULL == (f = fopen(filename, "r")))
return;
if (NULL == fgets(line, sizeof(line), f))
{
zbx_fclose(f);
return;
}
zbx_fclose(f);
if (1 == sscanf(line, "%*f\t%*f\t%lf\n", &value))
{
if (1 == sscanf(line, "%lf", &value))
{
if (NULL == strstr(filename, "fan"))
value = value / 1000;
(*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));