From 28daf07d1ad727826ae360987a4436794953df4b Mon Sep 17 00:00:00 2001 From: Frederik Lindenaar <jfl@schutler.net> Date: Sun, 3 Mar 2019 20:47:38 +0100 Subject: [PATCH] fixed scaling issue for Raspberry Pi CPU temperature --- plugins/check_temperature | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/plugins/check_temperature b/plugins/check_temperature index 450758a..3a96d06 100755 --- a/plugins/check_temperature +++ b/plugins/check_temperature @@ -1,6 +1,6 @@ #! /usr/bin/env python # -# check_temperature - Nagios temperature check for DS18B20 sensor on RaspberryPi +# check_temperature - Nagios temperature check for RaspberryPi-connected sensors # # Version 1.2, latest version, documentation and bugtracker available at: # https://gitlab.lindenaar.net/scripts/nagios-plugins @@ -32,11 +32,13 @@ PROG_NAME=splitext(basename(__file__))[0] PROG_VERSION=PROG_NAME + ' ' + VERSION CPU_SENSOR_DEV = '/sys/class/thermal/thermal_zone0/temp' +CPU_SENSOR_SCALE=1000 I2C_MCP9808_CONFIG_ADDR=0x1 I2C_MCP9808_CONFIG = [ 0x00, 0x00 ] # continuous conversion (power-up default) I2C_MCP9808_PRECISION_ADDR=0x08 I2C_MCP9808_PRECISION=3 # 0=0.5, 1=0.25, 2=0.125, 3=0.0625 degr. C I2C_MCP9808_TEMP_ADDR=0x05 +I2C_MCP9808_SENSOR_SCALE=16 W1_SENSOR_DEV_DIR = '/sys/bus/w1/devices/' W1_SENSOR_DEV_PREFIX = '28-' W1_SENSOR_DEV_SUFFIX = '/w1_slave' @@ -116,9 +118,9 @@ def read_rpi_cpu_temp(args): logger.debug('Temperature sensor data read from %s: %s', f.name, lines) temp_read = int(lines[0]) - temp = args.converter[0](temp_read) + temp = args.converter[0](temp_read, CPU_SENSOR_SCALE) logger.debug('Temperature sensor value %d is %.2f%s', temp_read, - temp, args.converter[1]) + temp, args.converter[1]) return temp, 1 @@ -157,7 +159,7 @@ def read_i2c_mcp9808_temp(args): if temp_read > 4095 : temp_read -= 8192 - temp = args.converter[0](temp_read, 16) + temp = args.converter[0](temp_read, I2C_MCP9808_SENSOR_SCALE) logger.debug('Temperature sensor value %d is %.2f%s', temp_read, temp, args.converter[1]) return temp, 1 -- libgit2 0.22.2