WARNING=${1}
CRITICAL=${2}
echo ${OUTPUT} | gawk -F'[=,]' ' {
V[++n] = $2
R[n] = $0
} END {
for ( i = 1; i <= n; i++) {
if((V > 0) && (V < V[i+1]))
print R, ((V[i+1] - V) / V) * 100
else if ((V > V[i+1]) && (V[i+1] > 0))
print R, ((V[i+1] - V) / V) * 100
else if ((V == V[i+1]) && (V[i+1] > 0))
print R, (V[i+1] - V)
else if ((V == 0) && (V[i+1] > 0))
print R, (V[i+1] + 1 - V + 1 / 1 * 100)
else if ((V[i+1] == 0) && (V > 0))
print R, ((V - V[i+1]) / V) * -100
else if ((V == 0) && (V[i+1] == 0))
print R, (V + V[i+1])
else
print R
}
} ' OFS=, | gawk -F'[=,]' '{if(($4>='"$WARNING"') && ($4<='"$CRITICAL"')) {print $0} }'
so i have the above command which works wonderfully. but i found myself in a situation i didn't expect.
first, i believe the code I bolded above can be incorporated into the preceding awk calculations. any ideas on how to do that?
second, i need to find a way to only show output if and only if the numbers in field 4 ($4), after the calculations are done, is above two interesting numbers.
so the interesting numbers would be something like:
WARNING=-2
CRITICAL=2
so i want to alert if the numbers is either greater than and/or equal to -2 (negative 2) or greater than or equal to 2 (positive 2).
so in this context, for example, -3 should be considered greater than or equal to -2. and 3 of course should be considered greater than or equal to 2 as well.
any ideas on how to modify the above code to do that, efficiently?