From 62835519000f929445124b15550341aafe9750cc Mon Sep 17 00:00:00 2001 From: mh Date: Mon, 5 Oct 2020 21:29:20 +0200 Subject: [PATCH] zbx-smart.ps1: Remove trailing garbage --- zbx-smart.ps1 | 150 +------------------------------------------------- 1 file changed, 1 insertion(+), 149 deletions(-) diff --git a/zbx-smart.ps1 b/zbx-smart.ps1 index d8b37e9..dd3310f 100755 --- a/zbx-smart.ps1 +++ b/zbx-smart.ps1 @@ -1,4 +1,5 @@ #!/usr/bin/pwsh +# # By MH 2020, MIT-License # TODO: Logging (Sucess, Error), Windows-Support @@ -215,152 +216,3 @@ if ( $smart_check ) { Write-Output "Done" exit $exitcode - -and here is the original Bash-version: - -#!/bin/bash - -# By MH 2020, MIT-License - - -_smart_is_usb() -{ - rem=$(lsblk -d "$1" -o SUBSYSTEMS | grep "usb" | wc -l) - if [[ "${rem}" == "0" ]]; then - echo 0 - else - echo 1 - fi -} - -_smart_getval() -{ - echo -e "$1" | grep -i "^${2} = " | cut -d "=" -f 2 | cut -d '"' -f 2 -} - -_smart_getval_i() -{ - res=$(echo -e "$1" | grep -i "^${2} = " | cut -d "=" -f 2 | cut -d ' ' -f 2 | tr -d ";") - if [[ "$res" == "" ]]; then - res=0 - fi - echo "${res}" -} - - -smart_disco() { - c=0 - devs="" - while read ln; do - dev=$(echo ${ln} | cut -d " " -f 1 | sed -e "s/\/dev\///g") - typ=$(echo ${ln} | cut -d " " -f 3) - - - # Removable - # rem=$(lsblk -d /dev/${dev} -o SUBSYSTEMS | grep "usb" | wc -l) - rem=$(_smart_is_usb "/dev/${dev}") - - if [[ "${rem}" == "0" ]]; then - smart="$(smartctl -n standby -a /dev/${dev} --json=g)" - model="$(_smart_getval "${smart}" "json.model_name")" - sn="$(_smart_getval "${smart}" "json.serial_number")" - rot="$(_smart_getval_i "${smart}" "json.rotation_rate")" - lbs="$(_smart_getval_i "${smart}" "json.logical_block_size")" - - #SSD: TODO - isSSD=0 - fi - - if (( c == 1 )); then - devs="${devs},\n" - fi - c=1 - - devs="${devs} {\n" - - if [[ "${rem}" == "0" ]]; then - devs="${devs} \"name\": \"${dev}\",\n" - devs="${devs} \"type\": \"${typ}\",\n" - devs="${devs} \"model\": \"${model}\",\n" - devs="${devs} \"sn\": \"${sn}\",\n" - devs="${devs} \"rotations\": ${rot},\n" - devs="${devs} \"lbs\": ${lbs},\n" - devs="${devs} \"isExternal\": ${rem},\n" - devs="${devs} \"isSSD\": ${isSSD}\n" - else - devs="${devs} \"name\": \"${dev}\",\n" - devs="${devs} \"isExternal\": ${rem}\n" - fi - devs="${devs} }" - - done < <(smartctl -n standby --scan) - - - - json2="\n{" - json2="${json2} \"devices\": [\n" - json2="${json2} ${devs}\n" - json2="${json2} ]\n" - json2="${json2}}" - echo -e "$json2" - - # Remove newline for use as parameter - sentval="$(echo -e $json2)" - - #json=$(smartctl --json --scan) - #json=$(echo "${json}" | sed -e "s/\/dev\///g") - #echo $json - - zabbix_sender -vv -k "8o_smartcheck.disco_devs" -o "${sentval}" -c /etc/zabbix/zabbix_agentd.conf 2>&1 | logger -t "zabbix-smart_disco" -} - - -smart_check() { - (for dev in $(smartctl --scan | sed -e "s/\/dev\///g" | cut -d " " -f 1 ); do - - rem=$(_smart_is_usb "/dev/${dev}") - if [[ "${rem}" == "1" ]] && [[ "${SMART_WITH_EXTERNAL}" == "0" ]]; then - #echo "X" 1>&2 - continue; - fi - - smartctl -s on /dev/${dev} > /dev/null - status="$(smartctl -n standby -q errorsonly -H /dev/${dev})" - if [[ "${status}" == "" ]]; then - status="OK" - fi - - smart="$(smartctl -n standby -a /dev/${dev} --json=g)" - - poh="$(_smart_getval_i "${smart}" "json.power_on_time.hours")" - poc="$(_smart_getval_i "${smart}" "json.power_cycle_count")" - temp="$(_smart_getval_i "${smart}" "json.temperature.current")" - - - - #zabbix_sender -vv -k "8o_smartcheck.[${dev}.health]" -o "${status}" -c /etc/zabbix/zabbix_agentd.conf \ - # 2>&1 | logger -t "zabbix-smart_health" - - echo "- 8o_smartcheck.[${dev}.health] ${status}" - echo "- 8o_smartcheck.[${dev}.power_on_hours] ${poh}" - echo "- 8o_smartcheck.[${dev}.power_cycle_count] ${poc}" - echo "- 8o_smartcheck.[${dev}.temperature] ${temp}" - - #echo "8o_smartcheck.[${dev}.health]" - #echo ${dev} - done) | zabbix_sender -vv -i - -c /etc/zabbix/zabbix_agentd.conf 2>&1 | logger -t "zabbix-smart_health" - -} - - -SMART_WITH_EXTERNAL=0 - -if [ "$1" == "--smart-with-external" ]; then - SMART_WITH_EXTERNAL=1 -fi - -if [ "$1" == "--disco" ]; then - smart_disco -else - smart_check -fi \ No newline at end of file