X-Git-Url: https://arthur.barton.de/gitweb/?a=blobdiff_plain;f=charts.d%2Fhddtemp.chart.sh;h=15895c5e160a71a845a586ab1f602492b26b3061;hb=54ea4803f2b9ea02838b6287ca7846c51cf996b7;hp=704ab9d02b37ae7cccf2934a33149d032f1586fd;hpb=6a5e711816e1803ef8e9fd12afcc766d2d148d4b;p=netdata.git diff --git a/charts.d/hddtemp.chart.sh b/charts.d/hddtemp.chart.sh index 704ab9d0..15895c5e 100755 --- a/charts.d/hddtemp.chart.sh +++ b/charts.d/hddtemp.chart.sh @@ -1,4 +1,11 @@ -#!/bin/bash +# no need for shebang - this file is loaded from charts.d.plugin + +# netdata +# real-time performance and health monitoring, done right! +# (C) 2016 Costa Tsaousis +# GPL v3+ +# +# contributed by @paulfantom with PR #511 # if this chart is called X.chart.sh, then all functions and global variables # must start with X_ @@ -13,7 +20,8 @@ hddtemp_priority=90000 # _check is called once, to find out if this chart should be enabled or not hddtemp_check() { - nc $hddtemp_host $hddtemp_port &>/dev/null && return 0 || return 1 + require_cmd nc || return 1 + run nc $hddtemp_host $hddtemp_port && return 0 || return 1 } # _create is called once, to create the charts @@ -41,9 +49,16 @@ hddtemp_count=0 hddtemp_update() { # local all=( `nc $hddtemp_host $hddtemp_port | sed -e 's/||/\n/g;s/^|//' | cut -d '|' -f3` ) # local all=( `nc $hddtemp_host $hddtemp_port | awk 'BEGIN { FS="|" };{i=4; while (i <= NF) {print $i+0;i+=5;};}'` ) + OLD_IFS=$IFS set -f - IFS="|" all=( $(nc $hddtemp_host $hddtemp_port) ) + IFS="|" all=( $(nc $hddtemp_host $hddtemp_port 2>/dev/null) ) set +f + IFS=$OLD_IFS + + # check if there is some data + if [ -z "${all[3]}" ]; then + return 1 + fi # write the result of the work. echo "BEGIN hddtemp.temperature $1"