Updated so that sensord will syslog alarm occurrences at level

ALERT so you can pick them up in syslog.conf and fire them to
the console, etc. Added support for scanning only for alarms
in addition to scanning regular values, etc. Updated the man
file to reflect the new options, etc. Operation as "sensors"
command is undocumented.
-- merlin


git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@835 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Merlin Hughes committed 2000-07-07 16:23:17 +00:00
1 parent 490e66be76
commit bc41905095
6 files changed
+455 -201

No files matched your search

+34 -12
View File
@@ -33,9 +33,10 @@
int isDaemon = 0;
const char *sensorsCfgFile = "sensors.conf";
int sleepTime = 5 * 60;
int scanTime = 60;
int logTime = 30 * 60;
int syslogFacility = LOG_LOCAL4;
int doScan = 0;
int doSet = 0;
sensors_chip_name chipNames[MAX_CHIP_NAMES];
int numChipNames = 0;
@@ -86,15 +87,25 @@ parseFacility
return facilities[i].id;
}
/* TODO: -s, --set */
static const char *daemonSyntax =
" -i, --interval <time> -- interval between checking sensors (default 5m)\n"
" -i, --interval <time> -- interval between scanning alarms (default 60s)\n"
" -l, --log-interval <time> -- interval between logging sensors (default 30m)\n"
" -f, --syslog-facility <f> -- syslog facility to use (default local4)\n";
" -f, --syslog-facility <f> -- syslog facility to use (default local4)\n"
" -c, --config-file <file> -- configuration file (default sensors.conf)\n"
" -v, --version -- display version and exit\n"
" -h, --help -- display help and exit\n"
"\n"
"Specify a value of 0 for either interval to disable that operation;\n"
"for example, specify --log-interval 0 to only scan for alarms."
"\n"
"If no path is specified, a list of directories is examined for the config file;\n"
"specify the filename `-' to read the config file from stdin.\n"
"\n"
"If no chips are specified, all chip info will be printed.\n";
static const char *appSyntax =
" -s, --set -- execute set statements too (root only)\n";
static const char *commonSyntax =
" -a, --alarm-scan -- only scan for alarms\n"
" -s, --set -- execute set statements too (root only)\n"
" -c, --config-file <file> -- configuration file (default sensors.conf)\n"
" -v, --version -- display version and exit\n"
" -h, --help -- display help and exit\n"
@@ -116,9 +127,10 @@ static const struct option daemonLongOptions[] = {
{ NULL, 0, NULL, 0 }
};
static const char *appShortOptions = "sc:vh";
static const char *appShortOptions = "asc:vh";
static const struct option appLongOptions[] = {
{ "alarm-scan", no_argument, NULL, 'a' },
{ "set", no_argument, NULL, 's' },
{ "config-file", required_argument, NULL, 'c' },
{ "version", no_argument, NULL, 'v' },
@@ -140,7 +152,7 @@ parseArgs
while ((c = getopt_long (argc, argv, shortOptions, longOptions, NULL)) != EOF) {
switch(c) {
case 'i':
if ((sleepTime = parseTime (optarg)) < 0)
if ((scanTime = parseTime (optarg)) < 0)
return -1;
break;
case 'l':
@@ -151,6 +163,9 @@ parseArgs
if ((syslogFacility = parseFacility (optarg)) < 0)
return -1;
break;
case 'a':
doScan = 1;
break;
case 's':
doSet = 1;
break;
@@ -163,7 +178,7 @@ parseArgs
exit (EXIT_SUCCESS);
break;
case 'h':
printf ("Syntax: %s {options} {chips}\n%s%s", argv[0], isDaemon ? daemonSyntax : appSyntax, commonSyntax);
printf ("Syntax: %s {options} {chips}\n%s", argv[0], isDaemon ? daemonSyntax : appSyntax);
exit (EXIT_SUCCESS);
break;
case ':':
@@ -177,9 +192,16 @@ parseArgs
break;
}
}
if (doScan && doSet) {
fprintf (stderr, "Error: Incompatible --set and --alarm-scan.\n");
return -1;
}
if (logTime < sleepTime)
logTime = sleepTime;
if (!logTime && !scanTime) {
fprintf (stderr, "Error: No logging or alarm scanning.\n");
return -1;
}
return 0;
}
+70 -58
View File
@@ -33,103 +33,103 @@
static char buff[4096];
static char *
static const char *
fmtExtra
(int alarm, int beep) {
if (alarm)
sprintf (buff + strlen (buff), " [ALARM]");
if (beep)
sprintf (buff + strlen (buff), " [BEEP]");
sprintf (buff + strlen (buff), " (beep)");
return buff;
}
static char *
static const char *
fmtValu_0
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%.0f", values[0]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtTemps_0
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%.0f C (limit = %.0f C, hysteresis = %.0f C)", values[0], values[1], values[2]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtTemps_1
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%.1f C (limit = %.1f C, hysteresis = %.1f C)", values[0], values[1], values[2]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtVolt_2
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%+.2f V", values[0]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtVolts_2
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%+.2f V (min = %+.2f V, max = %+.2f V)", values[0], values[1], values[2]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtFans_0
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%.0f RPM (min = %.0f RPM, div = %.0f)", values[0], values[1], values[2]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtMHz_2
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%.2f MHz (min = %.2f MHz, max = %.2f MHz)", values[0], values[1], values[2]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtChassisIntrusionDetection
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "Chassis intrusion detection");
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtBoardTemperatureInput
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "Board temperature input"); /* N.B: "(usually LM75 chips)" */
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtSoundAlarm
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "Sound alarm %s", (values[0] < 0.5) ? "disabled" : "enabled");
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtInt
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%d", (int) values[0]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtIntCrossInt
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%dx%d", (int) values[0], (int) values[1]);
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtIntDashInt
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
sprintf (buff, "%d-%d", (int) values[0], (int) values[1]);
return fmtExtra (alarm, beep);
}
@@ -332,10 +332,10 @@ static const ChipDescriptor via686a_chip = {
/** LM80 **/
static char * /* N.B: in sensors the first temp is %.2f!! */
static const char *
fmtTemps_LM80
(double values[], int alarm, int beep) {
sprintf (buff, "%.0f C (hot limit = %.0f C, hot hysteresis = %.0f C, os limit = %.0f C, os hysteresis = %.0f C)", values[0], values[1], values[2], values[3], values[4]);
(const double values[], int alarm, int beep) {
sprintf (buff, "%.2f C (hot limit = %.0f C, hot hysteresis = %.0f C, os limit = %.0f C, os hysteresis = %.0f C)", values[0], values[1], values[2], values[3], values[4]);
return fmtExtra (alarm, beep);
}
@@ -378,9 +378,9 @@ static const ChipDescriptor lm80_chip = {
/** GL518 **/
/* N.B: sensors supports a "gl518sm-r00" but it is not picked up in main.c...
static char *
static const char *
fmtVolts_GL518_R00
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
if (values[0] == 0.0)
sprintf (buff, "n/a (min = %+.2f V, max = %+.2f V)", values[1], values[2]);
else
@@ -473,7 +473,7 @@ static const FeatureDescriptor w83781d_features[] = {
{ SENSORS_W83781D_FAN2, SENSORS_W83781D_FAN2_MIN, SENSORS_W83781D_FAN2_DIV, -1 } },
{ fmtFans_0, W83781D_ALARM_FAN3, W83781D_ALARM_FAN3,
{ SENSORS_W83781D_FAN3, SENSORS_W83781D_FAN3_MIN, SENSORS_W83781D_FAN3_DIV, -1 } },
{ fmtTemps_1, W83781D_ALARM_TEMP1, W83781D_ALARM_TEMP1,
{ fmtTemps_0, W83781D_ALARM_TEMP1, W83781D_ALARM_TEMP1,
{ SENSORS_W83781D_TEMP1, SENSORS_W83781D_TEMP1_OVER, SENSORS_W83781D_TEMP1_HYST, -1 } },
{ fmtTemps_1, W83781D_ALARM_TEMP2, W83781D_ALARM_TEMP2,
{ SENSORS_W83781D_TEMP2, SENSORS_W83781D_TEMP2_OVER, SENSORS_W83781D_TEMP2_HYST, -1 } },
@@ -483,7 +483,7 @@ static const FeatureDescriptor w83781d_features[] = {
{ SENSORS_W83781D_VID, -1 } },
{ fmtChassisIntrusionDetection, W83781D_ALARM_CHAS, W83781D_ALARM_CHAS,
{ SENSORS_W83781D_ALARMS, -1 } },
{ fmtSoundAlarm, 0, 0, /* N.B: Is this beep correct for as99127f? */
{ fmtSoundAlarm, 0, 0,
{ SENSORS_W83781D_BEEP_ENABLE, -1 } },
{ NULL }
};
@@ -494,9 +494,21 @@ static const ChipDescriptor w83781d_chip = {
/** W83782D **/
static char *
fmtTemps_W8378x
(double values[], int alarm, int beep) {
static const char *
fmtTemps_W8378x_0
(const double values[], int alarm, int beep) {
int sensorID = (int) values[3];
const char *sensor = (sensorID == 1) ? "PII/Celeron diode" :
(sensorID == 2) ? "3904 transistor" : "thermistor";
/* Is this still right? */
sprintf (buff, "%.0f C (limit = %.0f C, hysteresis = %.0f C, sensor = %s)",
values[0], values[1], values[2], sensor);
return fmtExtra (alarm, beep);
}
static const char *
fmtTemps_W8378x_1
(const double values[], int alarm, int beep) {
int sensorID = (int) values[3];
const char *sensor = (sensorID == 1) ? "PII/Celeron diode" :
(sensorID == 2) ? "3904 transistor" : "thermistor";
@@ -504,7 +516,7 @@ fmtTemps_W8378x
sprintf (buff, "%.1f C (limit = %.1f C, hysteresis = %.1f C, sensor = %s)",
values[0], values[1], values[2], sensor);
return fmtExtra (alarm, beep);
} /* N.B: TEMP1 in sensors is just %.0f.. */
}
static const char *w83782d_names[] = {
SENSORS_W83782D_PREFIX, SENSORS_W83627HF_PREFIX, NULL
@@ -533,11 +545,11 @@ static const FeatureDescriptor w83782d_features[] = {
{ SENSORS_W83782D_FAN2, SENSORS_W83782D_FAN2_MIN, SENSORS_W83782D_FAN2_DIV, -1 } },
{ fmtFans_0, W83781D_ALARM_FAN3, W83781D_ALARM_FAN3,
{ SENSORS_W83782D_FAN3, SENSORS_W83782D_FAN3_MIN, SENSORS_W83782D_FAN3_DIV, -1 } },
{ fmtTemps_W8378x, W83781D_ALARM_TEMP1, W83781D_ALARM_TEMP1,
{ fmtTemps_W8378x_0, W83781D_ALARM_TEMP1, W83781D_ALARM_TEMP1,
{ SENSORS_W83782D_TEMP1, SENSORS_W83782D_TEMP1_OVER, SENSORS_W83782D_TEMP1_HYST, SENSORS_W83782D_SENS1, -1 } },
{ fmtTemps_W8378x, W83781D_ALARM_TEMP2, W83781D_ALARM_TEMP2,
{ fmtTemps_W8378x_1, W83781D_ALARM_TEMP2, W83781D_ALARM_TEMP2,
{ SENSORS_W83782D_TEMP2, SENSORS_W83782D_TEMP2_OVER, SENSORS_W83782D_TEMP2_HYST, SENSORS_W83782D_SENS2, -1 } },
{ fmtTemps_W8378x, W83781D_ALARM_TEMP3, W83781D_ALARM_TEMP3,
{ fmtTemps_W8378x_1, W83781D_ALARM_TEMP3, W83781D_ALARM_TEMP3,
{ SENSORS_W83782D_TEMP3, SENSORS_W83782D_TEMP3_OVER, SENSORS_W83782D_TEMP3_HYST, SENSORS_W83782D_SENS3, -1 } },
{ fmtVolt_2, 0, 0,
{ SENSORS_W83782D_VID, -1 } },
@@ -575,9 +587,9 @@ static const FeatureDescriptor w83783s_features[] = {
{ SENSORS_W83783S_FAN2, SENSORS_W83783S_FAN2_MIN, SENSORS_W83783S_FAN2_DIV, -1 } },
{ fmtFans_0, W83781D_ALARM_FAN3, W83781D_ALARM_FAN3,
{ SENSORS_W83783S_FAN3, SENSORS_W83783S_FAN3_MIN, SENSORS_W83783S_FAN3_DIV, -1 } },
{ fmtTemps_W8378x, W83781D_ALARM_TEMP1, W83781D_ALARM_TEMP1,
{ fmtTemps_W8378x_0, W83781D_ALARM_TEMP1, W83781D_ALARM_TEMP1,
{ SENSORS_W83783S_TEMP1, SENSORS_W83783S_TEMP1_OVER, SENSORS_W83783S_TEMP1_HYST, SENSORS_W83783S_SENS1, -1 } },
{ fmtTemps_W8378x, W83781D_ALARM_TEMP2, W83781D_ALARM_TEMP2,
{ fmtTemps_W8378x_1, W83781D_ALARM_TEMP2, W83781D_ALARM_TEMP2,
{ SENSORS_W83783S_TEMP2, SENSORS_W83783S_TEMP2_OVER, SENSORS_W83783S_TEMP2_HYST, SENSORS_W83783S_SENS2, -1 } },
{ fmtVolt_2, 0, 0,
{ SENSORS_W83783S_VID, -1 } },
@@ -594,17 +606,17 @@ static const ChipDescriptor w83783s_chip = {
/** MAXILIFE **/
static char *
static const char *
fmtTemps_Maxilife
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
if (!values[0] && !values[1] && !values[2])
return NULL;
return fmtTemps_1 (values, alarm, beep);
}
static char *
static const char *
fmtFans_Maxilife
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
if (!values[0] && !values[1] && !values[2])
return NULL;
if (values[0] < 0) {
@@ -615,17 +627,17 @@ fmtFans_Maxilife
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtMHz_Maxilife
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
if (!values[0] && !values[1] && !values[2])
return NULL;
return fmtMHz_2 (values, alarm, beep);
}
static char *
static const char *
fmtVolts_Maxilife
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
if (!values[0] && !values[1] && !values[2])
return NULL;
return fmtVolts_2 (values, alarm, beep);
@@ -671,9 +683,9 @@ static const ChipDescriptor maxilife_chip = {
/** EEPROM **/
static char *
static const char *
fmtType_EEPROM
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
if ((int) values[0] == 4)
sprintf (buff, "SDRAM DIMM SPD");
else
@@ -681,9 +693,9 @@ fmtType_EEPROM
return fmtExtra (alarm, beep);
}
static char *
static const char *
fmtRowCol_EEPROM
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
int row = (int) values[0];
int col = (int) values[1];
int num = (int) values[2];
@@ -713,9 +725,9 @@ static const ChipDescriptor eeprom_chip = {
/** DDCMON **/
static char *
static const char *
fmtID_DDCMON
(double values[], int alarm, int beep) {
(const double values[], int alarm, int beep) {
int value = (int) values[0];
buff[0] = ((value >> 10) & 0x1f) + '@';
buff[1] = ((value >> 5) & 0x1f) + '@';
+115 -63
View File
@@ -28,6 +28,10 @@
#include "sensord.h"
#include "lib/error.h"
#define DO_READ 0
#define DO_SCAN 1
#define DO_SET 2
static int
getLabelAndValid
(sensors_chip_name name, int feature, char **label, int *valid) {
@@ -42,6 +46,34 @@ getLabelAndValid
return err;
}
static const char *
chipName
(const sensors_chip_name *chip) {
static char buffer[256];
if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA)
sprintf (buffer, "%s-isa-%04x", chip->prefix, chip->addr);
else
sprintf (buffer, "%s-i2c-%d-%02x", chip->prefix, chip->bus, chip->addr);
return buffer;
}
static int
idChip
(const sensors_chip_name *chip) {
const char *adapter, *algorithm;
sensorLog (LOG_INFO, "Chip: %s", chipName (chip));
adapter = sensors_get_adapter_name (chip->bus);
if (adapter)
sensorLog (LOG_INFO, "Adapter: %s", adapter);
algorithm = sensors_get_algorithm_name (chip->bus);
if (algorithm)
sensorLog (LOG_INFO, "Algorithm: %s", algorithm);
/* assert adapter || algorithm */
return 0;
}
static int
readUnknownChip
(const sensors_chip_name *chip) {
@@ -49,6 +81,8 @@ readUnknownChip
int index0 = 0, index1 = 0;
int ret = 0;
ret = idChip (chip);
while ((ret == 0) && ((sensor = sensors_get_all_features (*chip, &index0, &index1)) != NULL)) {
char *label = NULL;
int valid = 0;
@@ -65,7 +99,7 @@ readUnknownChip
sensorLog (LOG_ERR, "Error getting sensor data: %s/%s: %s", chip->prefix, sensor->name, sensors_strerror (ret));
ret = 21;
} else {
sensorLog (LOG_INFO, "%s%s: %.2f", (sensor->mapping == SENSORS_NO_MAPPING) ? "" : "-"/*, sensor->name*/, label, value);
sensorLog (LOG_INFO, " %s%s: %.2f", (sensor->mapping == SENSORS_NO_MAPPING) ? "" : "-", label, value);
}
if (label)
free (label);
@@ -75,14 +109,16 @@ readUnknownChip
}
static int
readKnownChip
(const sensors_chip_name *chip, const ChipDescriptor *descriptor) {
doKnownChip
(const sensors_chip_name *chip, const ChipDescriptor *descriptor, int action) {
const FeatureDescriptor *features = descriptor->features;
int alarms = 0, beeps = 0;
int index0, subindex;
int ret = 0;
double tmp;
if (action == DO_READ)
ret = idChip (chip);
if (!ret && descriptor->alarmNumber) {
if ((ret = sensors_get_feature (*chip, descriptor->alarmNumber, &tmp))) {
sensorLog (LOG_ERR, "Error getting sensor data: %s/#%d: %s", chip->prefix, descriptor->alarmNumber, sensors_strerror (ret));
@@ -102,16 +138,18 @@ readKnownChip
for (index0 = 0; (ret == 0) && features[index0].format; ++ index0) {
const FeatureDescriptor *feature = features + index0;
int labelNumber = feature->dataNumbers[0];
int alarm = alarms & feature->alarmMask;
int beep = beeps & feature->beepMask;
char *label = NULL;
int valid = 0;
if (getLabelAndValid (*chip, labelNumber, &label, &valid)) {
if ((action == DO_SCAN) && !alarm) {
continue;
} else if (getLabelAndValid (*chip, labelNumber, &label, &valid)) {
sensorLog (LOG_ERR, "Error getting sensor label: %s/#%d", chip->prefix, labelNumber);
ret = 22;
} else if (valid) {
double values[MAX_DATA];
int alarm = alarms & feature->alarmMask;
int beep = beeps & feature->beepMask;
for (subindex = 0; !ret && (feature->dataNumbers[subindex] >= 0); ++ subindex) {
if ((ret = sensors_get_feature (*chip, feature->dataNumbers[subindex], values + subindex))) {
@@ -120,9 +158,13 @@ readKnownChip
}
}
if (ret == 0) {
char *formatted = feature->format (values, alarm, beep);
const char *formatted = feature->format (values, alarm, beep);
if (formatted) {
sensorLog (LOG_INFO, " %s: %s"/*, sensor->name*/, label, formatted);
if (action == DO_READ) {
sensorLog (LOG_INFO, " %s: %s", label, formatted);
} else {
sensorLog (LOG_ALERT, "Sensor alarm: Chip %s: %s: %s", chipName (chip), label, formatted);
}
}
}
}
@@ -132,79 +174,89 @@ readKnownChip
return ret;
}
static void
idChip
(const sensors_chip_name *chip) {
const char *adapter, *algorithm;
if (chip->bus == SENSORS_CHIP_NAME_BUS_ISA)
sensorLog (LOG_INFO, "Chip: %s-isa-%04x", chip->prefix, chip->addr);
else
sensorLog (LOG_INFO, "Chip: %s-i2c-%d-%02x", chip->prefix, chip->bus, chip->addr);
adapter = sensors_get_adapter_name (chip->bus);
if (adapter)
sensorLog (LOG_INFO, "Adapter: %s", adapter);
algorithm = sensors_get_algorithm_name (chip->bus);
if (algorithm)
sensorLog (LOG_INFO, "Algorithm: %s", algorithm);
/* assert adapter || algorithm */
}
static int
setChip
(const sensors_chip_name *chip) {
int ret;
if ((ret = sensors_do_chip_sets (*chip))) {
int ret = 0;
if ((ret = idChip (chip))) {
sensorLog (LOG_ERR, "Error identifying chip: %s", chip->prefix);
} else if ((ret = sensors_do_chip_sets (*chip))) {
sensorLog (LOG_ERR, "Error performing chip sets: %s: %s", chip->prefix, sensors_strerror (ret));
ret = 20;
ret = 50;
} else {
sensorLog (LOG_INFO, "Set.");
}
return ret;
}
static int
readChip
(const sensors_chip_name *chip) {
int index0, subindex, chipindex = -1;
doChip
(const sensors_chip_name *chip, int action) {
int ret = 0;
for (index0 = 0; knownChips[index0]; ++ index0)
for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex)
if (!strcmp (chip->prefix, knownChips[index0]->names[subindex]))
chipindex = index0;
if (chipindex >= 0)
ret = readKnownChip (chip, knownChips[chipindex]);
else
ret = readUnknownChip (chip);
if (action == DO_SET) {
ret = setChip (chip);
} else {
int index0, subindex, chipindex = -1;
for (index0 = 0; knownChips[index0]; ++ index0)
for (subindex = 0; knownChips[index0]->names[subindex]; ++ subindex)
if (!strcmp (chip->prefix, knownChips[index0]->names[subindex]))
chipindex = index0;
if (chipindex >= 0)
ret = doKnownChip (chip, knownChips[chipindex], action);
else if (action == DO_READ)
ret = readUnknownChip (chip);
}
return ret;
}
static int
doChips
(int action) {
const sensors_chip_name *chip;
int i = 0, j, ret = 0;
while ((ret == 0) && ((chip = sensors_get_detected_chips (&i)) != NULL)) {
for (j = 0; j < numChipNames; ++ j) {
if (sensors_match_chip (*chip, chipNames[j])) {
ret = doChip (chip, action);
break;
}
}
}
}
int
readChips
(void) {
const sensors_chip_name *chip;
int i = 0, j, ret = 0;
int ret = 0;
sensorLog (LOG_DEBUG, "sensor read started");
ret = doChips (DO_READ);
sensorLog (LOG_DEBUG, "sensor read finished");
return ret;
}
int
scanChips
(void) {
int ret = 0;
sensorLog (LOG_DEBUG, "sensor scan started");
while ((ret == 0) && ((chip = sensors_get_detected_chips (&i)) != NULL)) {
for (j = 0; j < numChipNames; ++ j) {
if (sensors_match_chip (*chip, chipNames[j])) {
idChip (chip);
if (doSet)
ret = setChip (chip);
else
ret = readChip (chip);
break;
}
}
}
ret = doChips (DO_SCAN);
sensorLog (LOG_DEBUG, "sensor scan finished");
return ret;
}
int
setChips
(void) {
int ret = 0;
sensorLog (LOG_DEBUG, "sensor set started");
ret = doChips (DO_SET);
sensorLog (LOG_DEBUG, "sensor set finished");
return ret;
}
+203 -62
View File
@@ -1,4 +1,4 @@
.\" Copyright 1999 Merlin Hughes <merlin@merlin.org>
.\" Copyright 1999-2000 Merlin Hughes <merlin@merlin.org>
.\" sensord is distributed under the GPL
.\"
.\" Permission is granted to make and distribute verbatim copies of this
@@ -21,98 +21,239 @@
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\"
.TH sensord 8 "December 2, 1999" "Version 0.2.0" "Linux System Administration"
.TH sensord 8 "July 7, 2000" "Version 0.4.0" "Linux System Administration"
.SH NAME
sensord \- Sensor information logging daemon.
.SH SYNOPSIS
.B sensord [
.I options
.B ] [
.I chips
.B ]
.SH DESCRIPTION
.B Sensord
is a daemon that records in a log file the readings of all sensor chips at
an interval of thirty minutes, or as configured on the command line.
is a daemon that can be used to periodically log sensor readings from
hardware health-monitoring chips to
.BR syslog (3)
and to alert when a sensor alarm is signalled; for example, if a
fan fails, a temperature limit is exceeded, etc.
.B Sensord
knows about certain chips, and outputs nicely formatted readings for them; but
it can also display the information of unknown chips, as long as
.I libsensors
.BR libsensors
knows about them.
.SH OPTIONS
.IP "-c config-file"
Specify a configuration file. If no file is specified, the name `sensors.conf'
is used. If the name does not contain a leading directory slash, or this parameter
is not present, the following paths are examined:
.BR /etc ,
.BR /usr/lib/sensors ,
.BR /usr/local/lib/sensors ,
.BR /usr/lib ,
.BR /usr/local/lib .
.IP "-i interval"
Specifies the interval, in seconds, between sensor readings. The default
is 1800 seconds (30 minutes).
.IP "-l log-file"
Specify the log file to which to append. If no file is specified, the
default log file `/var/log/sensors' is created. Note that this file is
interpreted relative to the root directory `/', not the current directory.
.IP -h
Prints a help message and exits.
.IP -v
Displays the program version and exits.
.SH SIGNALS
Upon receipt of a SIGHUP (see
.BR signal (7)
for details) this daemon closes and reopens its log file. Use this to rotate
log-files: Rename the old log file and then HUP this daemon; it will
commence writing to a new log file.
.IP "-i, --interval time"
Specify the interval between scanning for sensor alarms; the default is to
scan every minute.
The time should be specified as a raw integer (seconds) or with a suffix
`s' for seconds, `m' for minutes or `h' for hours; for example, the
default interval is `60' or `1m'.
Specify an interval of zero to suppress scanning explicitly for alarms.
.IP "-l, --log-interval time"
Specify the interval between logging all sensor readings; the default is
to log all readings every half hour.
The time is specified as before; e.g., `30m'.
Specify an interval of zero to suppress logging of regular sensor
readings.
.IP "-f, --syslog-facility facility"
Specify the
.BR syslog (3)
facility to use when logging sensor readings and alarms; the default is
to use
.IR local4 .
Other possibile facilities include
.IR local0
through
.IR local7 ,
.IR daemon
or
.IR user .
.IP "-c, --config-file file"
Specify a
.BR libsensors
configuration file. If no file is specified, the name `sensors.conf'
is used.
If the sensors configuration name does not contain a directory separator,
the following paths are searched for the file:
`/etc', `/usr/lib/sensors', `/usr/local/lib/sensors', `/usr/lib', `/usr/local/lib'.
.IP "-h, --help"
Prints a help message and exits.
.IP "-v, --version"
Displays the program version and exits.
.SH CHIPS
To restrict the devices that are scanned by this daemon, you may
optionally specify a list of chip names. By default, all available
chips are scanned.
A typical chip name would be `w83782d-*' (you may want to escape the
`*' for your shell) which would scan any W83782D chips on any bus. See
.BR sensors.conf (5)
for more details. Another option is to simply not load the sensor
modules for chips in which you have no interest.
.SH SIGNALS
Upon receipt of a SIGTERM (see
.BR signal (7)
for details) this daemon should gracefully shut down.
.SH LOGGING
All messages from this daemon are logged to
.BR syslog (3)
under the program name `sensord' and facility
.IR local4 ,
or whatever is specified on the command line.
Regular sensor readings are logged at the level
.IR info .
Alarms are logged at the level
.IR alert .
Inconsequential status messages are logged at
the minimum level,
.IR debug .
You can use an appropriate `/etc/syslog.conf'
file to direct these messages in a useful manner. See
.BR syslog.conf (5)
for full details, however the following is a sample configuration:
.IP
.nf
# Sample syslog.conf entries
*.info;...;local4.none;local4.warn /var/log/messages
local4.debug -/var/log/sensors
local4.alert /dev/console
local4.alert *
.fi
.PP
The first line ensures that regular sensor readings do not clutter
`/var/log/messages'; we first say `local4.none' to eliminate
informational messages; then `local4.warn' to enable warnings and
above. The second line says to log all regular sensor readings to
`/var/log/sensors'; the leading hyphen `-' means that this file
is not flushed after every message. The final two lines ensure
that alarms are printed to the system console as well as
to all connected users (in addition to `/var/log/messages' and
`/var/log/sensors').
.SH LOG ROTATION
On a typical system with a good sensor chip, expect about 2KB per sensor
reading in the log file. This works out at about 3MB per month. You
should be rotating your syslog files anyway, but just to be sure you'll
want to use something like
.BR logrotate (8)
or equivalent. You might, for example, want an entry in
`/etc/logrotate.d/syslog' containing:
.IP
.nf
# Sample logrotate.d entry
/var/log/sensors {
postrotate
/usr/sbin/killall -HUP syslogd
endscript
}
.fi
.PP
Note, of course, that you want to restart
.BR syslogd (8)
and not
.BR sensord (8)
.
.SH ALARMS
Alarms generally indicate a critical condition; for example, a fan
failure or an unacceptable temperature or voltage. However, some
sensor chips do not support alarms, while others are incorrectly
configured and may signal alarms incorrectly.
Typically, an alarm will only be signaled once,
even if the critical condition persists. This means that it is very
easy to miss an alarm!
In other cases, however,
uninteresting alarms (e.g., chassis intrusion detection) will be
repeated continuously. You can configure
.BR libsensors
to ignore unwanted sensor reading such as these by placing an
`ignore' entry in the appropriate chip-specific section of the
.BR sensors.conf (5)
configuration file.
For example, I have the following entry:
.IP
.nf
# Sample /etc/sensors.conf entry
chip "w83782d-*"
ignore "alarms"
.fi
.PP
In this case, `alarms' was the sensor label reported in
the relevant sensor log message.
Alternatively, you may be able to reset the alarm with your
BIOS.
.SH BEEPS
If you see `(beep)' beside any sensor reading, that just means that
your system is configured to issue an audio warning from the
motherboard if an alarm is signalled on that sensor.
.SH MODULES
It is expected that all required sensor modules are loaded prior to
this daemon being started. Typically, this is achieved with an entry
in `/etc/rc.d/...' containing
.BR modprobe (1)
commands to load the required modules before starting the daemon.
For example, on my box I have a `sensord' initialization script
containing (among others) the following commands:
.IP
.nf
# Sample /etc/rc.d/init.d scriptlet
echo -n "Loading AMD756 module: "
modprobe i2c-amd756 || { failure ; echo ; exit 1 ; }
echo_success
echo
echo -n "Loading W83781D module: "
modprobe w83781d || { failure ; echo ; exit 1 ; }
echo_success
echo
echo -n "Starting sensord: "
daemon sensord
RETVAL=$?
echo
.fi
.PP
Ignore the platform-specific shell functions; the general idea
should be fairly clear.
.SH ERRORS
Errors encountered by this daemon are logged to
.BR syslogd (8)
under the program name `sensord', after which the daemon aborts
with a failure note in its own log file.
.SH NOTES
It is expected that all required modules are loaded prior to this daemon
being started. Typically, this is achieved with an entry in
`/etc/rc.d/...' containing
.BR modprobe (1)
commands to load the required modules before starting the daemon.
.SH WARNING
On a typical system with one sensor chip, expect about 1KB per sensor
entry in the log file. This works out at about 1.5MB per month. You
must rotate the sensor log files, using something like
.BR logrotate (8)
or equivalent. You might, for example, create `/etc/logrotate.d/sensord'
containing:
.IP
.nf
# Sample logrotate.d entry
/var/log/sensors {
missingok
postrotate
/usr/sbin/killall -HUP sensord
endscript
}
.fi
.PP
after which the daemon will exit.
.SH BUGS
.B Sensord
does not currently support reading alarm events from sensor devices.
doesn't yet cope with the flipped alarm bits on
.IR AS99127F
chips.
.SH FILES
.I /etc/sensors.conf
.RS
The system wide configuration file. See
The system-wide
.BR libsensors
configuration file. See
.BR sensors.conf (5)
for further details.
.RE
.I /var/log/sensors
.I /etc/syslog.conf
.RS
The default sensor log file.
The system-wide
.BR syslog (3)
/
.BR syslogd (8)
configuration file. See
.BR syslog.conf (5)
for further details.
.RE
.SH "CONFORMING TO"
lm_sensors-2.x
+27 -3
View File
@@ -68,16 +68,35 @@ static int
sensord
(void) {
int ret = 0;
int scanValue = 0, logValue = 0;
sensorLog (LOG_INFO, "sensord started");
while (!done && (ret == 0)) {
if (ret == 0)
ret = reloadLib ();
if (ret == 0)
if ((ret == 0) && scanTime) {
ret = scanChips ();
if (scanValue <= 0)
scanValue += scanTime;
}
if ((ret == 0) && logTime && (logValue <= 0)) {
ret = readChips ();
if (!done && (ret == 0))
logValue += logTime;
}
if (!done && (ret == 0)) {
int sleepTime;
if (!logTime) {
sleepTime = scanValue;
} else if (!scanTime) {
sleepTime = logValue;
} else {
sleepTime = (scanValue < logValue) ? scanValue : logValue;
}
sleep (sleepTime);
scanValue -= sleepTime;
logValue -= sleepTime;
}
}
sensorLog (LOG_INFO, "sensord %s", ret ? "failed" : "stopped");
@@ -146,7 +165,12 @@ main
ret = sensord ();
undaemonize ();
} else {
ret = readChips ();
if (doSet)
ret = setChips ();
else if (doScan)
ret = scanChips ();
else
ret = readChips ();
}
if (unloadLib ())
+6 -3
View File
@@ -20,7 +20,7 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#define version "0.3.0"
#define version "0.4.0"
#include "lib/sensors.h"
@@ -30,9 +30,10 @@ extern void sensorLog (int priority, const char *fmt, ...);
extern int isDaemon;
extern const char *sensorsCfgFile;
extern int sleepTime;
extern int scanTime;
extern int logTime;
extern int syslogFacility;
extern int doScan;
extern int doSet;
extern sensors_chip_name chipNames[];
extern int numChipNames;
@@ -50,12 +51,14 @@ extern int unloadLib (void);
/* from sense.c */
extern int readChips (void);
extern int scanChips (void);
extern int setChips (void);
/* from chips.c */
#define MAX_DATA 5
typedef char * (*FormatterFN) (double values[], int alarm, int beep);
typedef const char * (*FormatterFN) (const double values[], int alarm, int beep);
typedef struct {
FormatterFN format;