Skip to content

Commit

Permalink
Merge pull request #2 from Brain2000/master
Browse files Browse the repository at this point in the history
Fix issue where multiple grep matches cause SNMP getnext failure
  • Loading branch information
HackingM authored Jul 21, 2020
2 parents 06f6f24 + 4306945 commit bba8bb1
Showing 1 changed file with 8 additions and 33 deletions.
41 changes: 8 additions & 33 deletions usr/sbin/snmpd-smartctl-connector
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function send_device_info
DEVFNAME="${DEVFNAME}_info"

# Find the entry in above file
VALUE=$(grep "${1}" < "${DEVFNAME}")
VALUE=$(grep -m 1 "${1}" < "${DEVFNAME}")
VALUE=${VALUE#${1}}
VALUE="${VALUE#"${VALUE%%[![:space:]]*}"}"
VALUE="${VALUE%"${VALUE##*[![:space:]]}"}"
Expand Down Expand Up @@ -142,7 +142,7 @@ function send_device_attr

# Find the entry in above file
# shellcheck disable=SC2207
if VALUES=($(grep "${1}" < "${DEVFNAME}")); then
if VALUES=($(grep -m 1 -E ${1} < "${DEVFNAME}")); then
if [[ "${2}" == "R" ]]; then
if is_positive_integer "${VALUES[9]}"; then
send_gauge "${3}" "${VALUES[9]}"
Expand All @@ -163,31 +163,6 @@ function send_device_attr
fi
}

# Function to send device temperature - called: send_device_temp OID DEVICE
#
# @in_param $1 - The OID to send before this data
# @in_param $2 - The index value
#
function send_device_temp
{
local DEVFNAME VALUES

# Make the device info filename
get_device_file_basepath "${2}" DEVFNAME
DEVFNAME="${DEVFNAME}_attr"

# Find the entry in above file
# shellcheck disable=SC2207
VALUES=($(grep "Temperature_Celsius" < "${DEVFNAME}")) || \
VALUES=($(grep "Airflow_Temperature" < "${DEVFNAME}"))

if is_positive_integer "${VALUES[9]}"; then
send_gauge "${1}" "${VALUES[9]}"
else
send_gauge "${1}" -1
fi
}

# Function to get the next index value
#
# @in_param $1 - The (optional) starting index value
Expand Down Expand Up @@ -258,16 +233,16 @@ RTABLE[2]="#ETABLE"
FTABLE[6]="send_device_info 'User Capacity:'" # It is for the device user capacity.
FTABLE[7]="send_device_info 'ATA Version is:'" # It is for the device ATA version.
FTABLE[8]="send_device_hlth" # It is for the overall SMART health state.
FTABLE[9]="send_device_temp" # It is for the device temperature.
FTABLE[9]="send_device_attr 'Temperature_Cel|Airflow_Temp' R" # It is for the device temperature.
FTABLE[10]="send_device_attr 'Reallocated_Sector_Ct' R" # It is for the Reallocated Sector Count of this device.
FTABLE[11]="send_device_attr 'Current_Pending_Sector' R" # It is for the Current Pending Sector count of this device.
FTABLE[12]="send_device_attr 'Offline_Uncorrectable' R" # It is for the Off-line Uncorrectable count of this device.
FTABLE[13]="send_device_attr 'UDMA_CRC_Error_Count' R" # It is for the UDMA CRC Error count of this device.
FTABLE[11]="send_device_attr 'Current_Pending_Sector|Runtime_Bad_Block' R" # It is for the Current Pending Sector count of this device.
FTABLE[12]="send_device_attr 'Offline_Uncorrectable|Uncorrectable_Error' R" # It is for the Off-line Uncorrectable count of this device.
FTABLE[13]="send_device_attr 'CRC_Error_Count' R" # It is for the UDMA CRC Error count of this device.
FTABLE[14]="send_device_attr 'Read_Error_Rate' L" # It is for the Read Error Rate (lifetime) of this device.
FTABLE[15]="send_device_attr 'Seek_Error_Rate' L" # It is for the Seek Error Rate (lifetime) of this device.
FTABLE[16]="send_device_attr 'Hardware_ECC_Recovered' L" # It is for the Hardware ECC recovered (lifetime) of this device.
FTABLE[16]="send_device_attr 'Hardware_ECC_Recovered|ECC_Error_Rate' L" # It is for the Hardware ECC recovered (lifetime) of this device.
FTABLE[17]="send_device_info 'Firmware Version:'" # It is for the Firmware Version installed on this device.
FTABLE[18]="send_device_attr 'SSD_Life_Left' L" # It is for the SSD Life Left of this device.
FTABLE[18]="send_device_attr 'SSD_Life|Wear_Leveling' L" # It is for the SSD Life Left of this device.
FTABLE[19]="send_device_attr 'Power_Cycle_Count' R" # It is for the Power Cycle Count of this device.
FTABLE[20]="send_device_attr 'Power_On_Hours' R" # It is for the Power On Hours of this device.

Expand Down

0 comments on commit bba8bb1

Please sign in to comment.