Added port as performance output
This commit is contained in:
parent
d3d14a431e
commit
f35340ff25
1 changed files with 36 additions and 16 deletions
|
@ -29,12 +29,17 @@ while [[ $# -gt 0 ]]; do
|
||||||
echo "--input FILE: Read from this file. Default: /proc/mdstat"
|
echo "--input FILE: Read from this file. Default: /proc/mdstat"
|
||||||
exit 0
|
exit 0
|
||||||
;;
|
;;
|
||||||
|
*)
|
||||||
|
echoerr "Unknown argument: $1"
|
||||||
|
exit 3
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
shift
|
shift
|
||||||
done
|
done
|
||||||
|
|
||||||
if [ -z "$HOST" -a -z "$INPUT" ]; then
|
if [ -z "$HOST" -a -z "$INPUT" ]; then
|
||||||
echoerr "Missing host argument (-h)"
|
echoerr "Missing host argument (-h)"
|
||||||
|
exit 3
|
||||||
fi
|
fi
|
||||||
|
|
||||||
function log {
|
function log {
|
||||||
|
@ -83,7 +88,8 @@ function runNmap {
|
||||||
}
|
}
|
||||||
|
|
||||||
NOW_PORTS=false
|
NOW_PORTS=false
|
||||||
OPEN_PORTS=()
|
PORT_STATES=()
|
||||||
|
PORT_NAMES=()
|
||||||
function parseLine {
|
function parseLine {
|
||||||
local line="$1"
|
local line="$1"
|
||||||
if ! $NOW_PORTS; then
|
if ! $NOW_PORTS; then
|
||||||
|
@ -94,53 +100,67 @@ function parseLine {
|
||||||
if [ -z "$line" ]; then
|
if [ -z "$line" ]; then
|
||||||
NOW_PORTS=false
|
NOW_PORTS=false
|
||||||
else
|
else
|
||||||
local x=${line/\/*}
|
local split
|
||||||
OPEN_PORTS+=($x)
|
read -ra split <<< "$line"
|
||||||
|
local number=${split[0]/\/*}
|
||||||
|
local state=${split[1]}
|
||||||
|
local name=${split[2]}
|
||||||
|
PORT_STATES[$number]=$state
|
||||||
|
PORT_NAMES[$number]=$name
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
ERROR=false
|
ERROR=false
|
||||||
NEW_PORTS=()
|
UNEXP_OPEN_PORTS=()
|
||||||
function comparePorts {
|
function comparePorts {
|
||||||
log ${KNOWN_PORTS[@]}
|
log ${KNOWN_PORTS[@]}
|
||||||
KNOWN_PORTS=($(for each in ${KNOWN_PORTS[@]}; do echo $each; done | sort))
|
KNOWN_PORTS=($(for each in ${KNOWN_PORTS[@]}; do echo $each; done | sort))
|
||||||
log ${KNOWN_PORTS[@]}
|
log ${KNOWN_PORTS[@]}
|
||||||
|
|
||||||
for i in "${OPEN_PORTS[@]}"; do
|
for port in "${!PORT_STATES[@]}"; do
|
||||||
|
if [[ "${PORT_STATES[$port]}" != open* ]]; then
|
||||||
|
continue;
|
||||||
|
fi
|
||||||
|
|
||||||
skip=false
|
skip=false
|
||||||
for j in "${KNOWN_PORTS[@]}"; do
|
for j in "${KNOWN_PORTS[@]}"; do
|
||||||
if [ $j -eq $i ]; then
|
if [ $j -eq $port ]; then
|
||||||
skip=true
|
skip=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if ! $skip; then
|
if ! $skip; then
|
||||||
log Unexpected open port: $i
|
log Unexpected open port: $port
|
||||||
NEW_PORTS+=($i)
|
UNEXP_OPEN_PORTS+=($port)
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
if [ ${#NEW_PORTS[@]} -gt 0 ]; then
|
if [ ${#UNEXP_OPEN_PORTS[@]} -gt 0 ]; then
|
||||||
ERROR=true
|
ERROR=true
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
function print {
|
function print {
|
||||||
if $ERROR; then
|
if $ERROR; then
|
||||||
echo "CRITICAL - These ports should not be open: ${NEW_PORTS[@]}"
|
echo -n "CRITICAL - These ports should not be open: ${UNEXP_OPEN_PORTS[@]}"
|
||||||
else
|
else
|
||||||
echo "OK"
|
echo -n "OK"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
echo -n " | "
|
||||||
|
|
||||||
if $ERROR; then
|
for port in "${!PORT_STATES[@]}"; do
|
||||||
exit 2
|
echo -n "'${PORT_NAMES[$port]} ($port): ${PORT_STATES[$port]}'=0 "
|
||||||
else
|
done
|
||||||
exit 0
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
runNmap
|
runNmap
|
||||||
comparePorts
|
comparePorts
|
||||||
print
|
print
|
||||||
|
|
||||||
|
if $ERROR; then
|
||||||
|
exit 2
|
||||||
|
else
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue