Source
static int get_device_info(const char *dev_path, const char *dev_name, char *device_info, const char **name_subfolder)
/*
** Zabbix
** 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 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 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));
break;
case ZBX_DO_MIN:
*aggr = (1 == *cnt ? value : MIN(*aggr, value));
break;
}
}
}
/*********************************************************************************
* *
* Function: sysfs_read_attr *
* *
* Purpose: locate and read the name attribute of a sensor from sysfs *
* *
* Parameters: device - [IN] the path to sensor data in sysfs *
* attribute - [OUT] the sensor name *
* *
* Return value: Subfolder where the sensor name file was found or NULL *
* *
* Comments: attribute string must be freed by caller after it's been used. *
* *