如何使mad-hacking支持sas的扫描

以下红色字体为添加或修改的信息,其中因为sas与sata的信息结构不一样,为了是程序正常运行,所以需要删除最后一行红字的内容。

#!/bin/bash -u


# Include snmpd-connector-lib.sh or die.
[[ ! -r ${SNMPD_CONNECTOR_LIB:=/usr/lib/snmpd-connector-lib.sh} ]] && echo "Unable to find ${SNMPD_CONNECTOR_LIB}" && exit 1
source ${SNMPD_CONNECTOR_LIB}

# judge the disk's type is sas or sata
#
#    @in_param    $1 - The disk's device name (/dev/sda)
#    @out_param    $2 - The result whether the disk's type is sata
#                0 is that the disk's type is sata
#                1 is that the disk's type is sas
#
function judge
{
    temp=`smartctl -d test $1|grep ATA`
    echo $?
}

# Helper function to get the device path from the devices array using a 1 based index
#
#    @in_param    $1 - The 1 based index of the device
#    @out_param    $2 - The path of this device
#
function get_device_path
{
    local AINDEX=$((${1} - 1))
    eval $2=${DEVICES[${AINDEX}]}    
}

# Helper function to get the device file base path from the devices array using a 1 based index
#
#    @in_param    $1 - The 1 based index of the device
#    @out_param    $2 - The path of this device
#                                $3-The disk's device name
function get_device_file_basepath
{
    local DEVPATH DEVFILE
    
    # Make the device info filename
    get_device_path ${1} DEVPATH
    
    DEVFILE=${DEVPATH##\/}
    DEVFILE=${CACHEDIR}/${DEVFILE//\//_}
    
    eval $2=${DEVFILE}
     eval $3=${DEVPATH}
}

# Function to send the index value
#
#    @in_param    $1 - The OID to send before this data
#    @in_param    $2 - The index value
#
function send_index
{
    # If the index is in range...
    if (( $# > 1 )); then
        if (( ${2} <= ${#DEVICES[@]} )); then
            # Send the OID and the index number.
            send_integer ${1} ${2}
            return
        fi
    fi

    # Send the OID and NONE.
    send_none ${1}
}

# Function to send the device path
#
#    @in_param    $1 - The OID to send before this data
#    @in_param    $2 - The index value
#
function send_device_path
{
    local DEVPATH
    get_device_path ${2} DEVPATH
    send_string ${1} ${DEVPATH}
}

# Function to send device info - called: send_device_info OID DEVICE "Info String"
#
#    @in_param    $1 - The STRING to search for
#    @in_param    $2 - The OID to send before this data
#    @in_param    $3 - The index value
function send_device_info
{
    local DEVFNAME VALUE DEV
    
    # Make the device info filename
    get_device_file_basepath ${3} DEVFNAME DEV
    DEVFNAME="${DEVFNAME}_info"
     ernum=`judge $DEV`
    if [ $ernum = 1 ];then
        case "$1" in
        "Model Family:")
                device=$1
        ;;
        "Device Model:")
                device="Device:"
        ;;
        "Serial Number:")
                device="Serial number:"
        ;;
        "User Capacity:")
            device=$1
        ;;
        "ATA Version is:")
            device=$1
        ;;
        *)
            device=$1
        ;;
        esac
    else
        device=$1
    fi
    VALUE=$(grep "${device}" < ${DEVFNAME})
    VALUE=${VALUE#${device}}
    send_string ${2} "${VALUE}"

    # Find the entry in above file
    #VALUE=$(grep "${1}" < ${DEVFNAME})
    #VALUE=${VALUE#${1}}
    #send_string ${2} "${VALUE}"
}

# Function to send device health - called: send_device_hlth OID DEVICE
#
#    @in_param    $1 - The OID to send before this data
#    @in_param    $2 - The index value
#
function send_device_hlth
{
    local DEVFNAME VALUES DEV
    
    # Make the device info filename
    get_device_file_basepath ${2} DEVFNAME DEV
    DEVFNAME="${DEVFNAME}_state"
    ernum=`judge $DEV`

    # Find the entry in above file
    if [ $ernum = 0 ];then
        VALUES=($(grep "result:" < ${DEVFNAME}))
        [[ "${VALUES[5]}" == "PASSED" ]] && send_boolean ${1} "T" || send_boolean ${1} "F"
    else
        VALUES=($(grep "Status:" < ${DEVFNAME}))
        [[ "${VALUES[3]}" == "OK" ]] && send_boolean ${1} "T" || send_boolean ${1} "F"
    fi
}

# Function to send device attribute - called: send_device_attr OID DEVICE "Attribute String" R[aw]|L[ife]
#
#    @in_param    $1 - The STRING to search for
#    @in_param    $2 - R to send RAW value, L to send LIFETIME value
#    @in_param    $3 - The OID to send before this data
#    @in_param    $4 - The index value
#
function send_device_attr
{
    local DEVFNAME VALUES DEV
    
    # Make the device info filename
    get_device_file_basepath ${4} DEVFNAME DEV
    DEVFNAME="${DEVFNAME}_attr"
        ernum=`judge $DEV`
    
        if [ $ernum = 0 ];then
                value=$1
        else
                case "$1" in
                "Reallocated_Sector_Ct")
                      value="Elements in grown defect list:"
                      ;;
                *)
                      value="Current Drive Temperature:"
                     ;;
                esac
        fi
    # Find the entry in above file
    VALUES=($(grep "${value}" < ${DEVFNAME}))
    case ${2} in
        "R")
                if [ $ernum = 0 ];then
                    send_gauge ${3} ${VALUES[9]}
                else
                    send_gauge ${3} ${VALUES[3]}
                fi
        ;;
        
        "L")
        send_gauge ${3} $((${VALUES[3]##0} - ${VALUES[5]##0}))
        ;;
        
        *)
        send_gauge ${3} -1        
        ;;    
    esac
}

# Function to get the next index value
#
#    @in_param    $1 - The (optional) starting index value
#    @echo           - The new index or nothing if out of range
#
function get_next_index
{
    debug_function_enter "get_next_index" ${@}
    
    # If we still have more than one element in the request array then something
    # is wrong so log an error and return 0.
    if (( $# > 1 )); then
        error_echo "get_next_index: called with $# request array elements!"
        debug_function_return
        return
    fi
    
    # If we were passed a starting index...
    if (( $# > 0 )); then
        # If the passed index is less than the number of devices then return it +1,
        # otherwise return 0 to indicate that the index would be out of range.
        if (( ${1} < ${#DEVICES[@]} )); then
            RETVAL=$(( ${1} + 1 ))
            debug_echo "next index is in range, returning ${RETVAL}"
            echo "${RETVAL}"
            debug_function_return
            return
        else
            debug_echo "next index would be out of range, returning zero"
            debug_function_return
            return
        fi
    fi    
    
    # If we got this far then we were not passed an index so return the first
    # available index.
    debug_echo "no index supplied, returning first index"
    echo "1"
    debug_function_return
    return
}

# Init local vars
CMDNAME=$(basename ${0})
CONFIG="/etc/snmpd-smartctl-connector"
DEVICES=""
CACHEDIR=""
SNMP_TRANSLATE=""

# Read the config file if we can
[[ -r ${CONFIG} ]] && source ${CONFIG} || die "Unable to read configuration file [${CONFIG}]"

# Check for config values.
[[ -z "${DEVICES}" ]] && die "No DEVICES configured in ${CONFIG}"
[[ -z "${CACHEDIR}" ]] && die "No CACHEDIR configured in ${CONFIG}"
[[ ! -d "${CACHEDIR}" ]] && die "Cache directory [${CACHEDIR}] is not a directory"
[[ ! -r "${CACHEDIR}" ]] && die "Cache directory [${CACHEDIR}] is not readable by $(whoami)"
[[ -z "${SNMP_TRANSLATE}" ]] && die "No SNMP_TRANSLATE command configured in ${CONFIG}"

# Configure base address
BASE_MIB="SMARTCTL-MIB::smartCtl"

# Declare the tables
RTABLE[2]="#ETABLE"
    ETABLE[1]="#FTABLE"
        FTABLE_INDEX="get_next_index"                                # Internal function to get next index
        FTABLE[1]="send_index"                                        # It is an index request.
        FTABLE[2]="send_device_path"                                 # It is for the mapped device path.
        FTABLE[3]="send_device_info 'Model Family:'"                 # It is for the device model-family.
        FTABLE[4]="send_device_info 'Device Model:'"                # It is for the device device-model.
        FTABLE[5]="send_device_info 'Serial Number:'"                 # It is for the device serial number.
        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_attr 'Temperature_Celsius' 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[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.

# Start the loop
the_loop


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值