diff --git a/check_onevm b/check_onevm index 720959ed036724972c6b5366ae97e386d859aca0..14e4e2b7c98063a8113739ec870b6f847d42efdf 100755 --- a/check_onevm +++ b/check_onevm @@ -128,51 +128,54 @@ ph.perfadd "fail" "${iFail}" ph.perfadd "unknown" "${iUnknown}" ph.perfadd "other" "${iOther}" -if [ $iUnknown -ne 0 ]; then - ph.setStatus "warning" - out+="WARNING: a vm with status [Unknown] was found.${NL}" -fi - -if [ $iOther -ne 0 ]; then - ph.setStatus "warning" - out+="WARNING: There is a VM that has another status than [running].${NL}" -fi - -if [ $iFail -ne 0 ]; then - ph.setStatus "critical" - out+="ERROR: a vm with status [Failed] was found.${NL}" -fi - -out+=$( -echo '>>>>>> By state' -grep "^# STAT:" "$0" | while read -r line -do - IFS=':' read -r prefix statusS statusL descr <<<"$line" - data=$( grep ",${statusS}," <<< "$csvdata" ) - typeset -i count; count=$( wc -l <<< "$data" ) - if [ -n "$data" ]; then - echo "--- $statusL ($statusS): $count" - echo "$descr" - if [ $showData -ne 0 ] || [ "${statusS}" != "runn" ]; then - echo "$data" +if [ $iTotal -gt 0 ]; then + if [ $iUnknown -ne 0 ]; then + ph.setStatus "warning" + out+="WARNING: a vm with status [Unknown] was found.${NL}" + fi + + if [ $iOther -ne 0 ]; then + ph.setStatus "warning" + out+="WARNING: There is a VM that has another status than [running].${NL}" + fi + + if [ $iFail -ne 0 ]; then + ph.setStatus "critical" + out+="ERROR: a vm with status [Failed] was found.${NL}" + fi + + out+=$( + echo '>>>>>> By state' + grep "^# STAT:" "$0" | while read -r line + do + IFS=':' read -r prefix statusS statusL descr <<<"$line" + data=$( grep ",${statusS}," <<< "$csvdata" ) + typeset -i count; count=$( wc -l <<< "$data" ) + if [ -n "$data" ]; then + echo "--- $statusL ($statusS): $count" + echo "$descr" + if [ $showData -ne 0 ] || [ "${statusS}" != "runn" ]; then + echo "$data" + fi fi - fi -done -echo -) - -out+=$( -echo -echo '>>>>>> By host:' -for onehost in $( cut -f 8 -d ',' <<< "$csvdata" | sort -u ) -do - echo -n "--- $onehost: " - grep -c ",${onehost}," <<< "$csvdata" - test $showData -ne 0 && grep ",${onehost}," <<< "$csvdata" | nl -done -echo -) - + done + echo + ) + + out+=$( + echo + echo '>>>>>> By host:' + for onehost in $( cut -f 8 -d ',' <<< "$csvdata" | sort -u ) + do + echo -n "--- $onehost: " + grep -c ",${onehost}," <<< "$csvdata" + test $showData -ne 0 && grep ",${onehost}," <<< "$csvdata" | nl + done + echo + ) +else + out+="Info: no vm was created yet." +fi ph.status "OpenNebula VMs - Total: $iTotal .. running: $iRunning, Fail: $iFail, unknown: $iUnknown .. other: $iOther" echo "$out"