+ TCP/UDP port checks
This commit is contained in:
parent
8dbd07bb12
commit
bf4dadd8d6
|
@ -61,3 +61,7 @@ function notify() {
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function cleanup() {
|
||||||
|
unset label label_sha json_res json addr res status res_parsed
|
||||||
|
}
|
||||||
|
|
|
@ -6,6 +6,7 @@ json="$(jq -r '.[] | select(.type == "ping") | "\(.label)<29>\(.data.addr)"' < st
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for i in $json; do
|
for i in $json; do
|
||||||
label="$(awk -F<> '{print $1}' <<< "$i")"
|
label="$(awk -F<> '{print $1}' <<< "$i")"
|
||||||
|
if [[ "$label" != '' ]]; then
|
||||||
label_sha="$(shasum <<< "$label" | cut -c 1-16)"
|
label_sha="$(shasum <<< "$label" | cut -c 1-16)"
|
||||||
addr="$(awk -F<> '{print $2}' <<< "$i")"
|
addr="$(awk -F<> '{print $2}' <<< "$i")"
|
||||||
res="$(ping -c 1 $addr > >(grep icmp_seq | sed -E 's/.*icmp_seq=.//'))"
|
res="$(ping -c 1 $addr > >(grep icmp_seq | sed -E 's/.*icmp_seq=.//'))"
|
||||||
|
@ -36,4 +37,7 @@ for i in $json; do
|
||||||
notify="$(jq -r '.[] | select(.label == "'"$label"'").notify[]' < storage/appconfig/$1.json)"
|
notify="$(jq -r '.[] | select(.label == "'"$label"'").notify[]' < storage/appconfig/$1.json)"
|
||||||
notify "$notify" 0
|
notify "$notify" 0
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
33
code/port.sh
Executable file
33
code/port.sh
Executable file
|
@ -0,0 +1,33 @@
|
||||||
|
#!/bin/bash
|
||||||
|
source "${cfg[namespace]}/code/func.sh"
|
||||||
|
|
||||||
|
json="$(jq -r '.[] | select(.type == "port") | "\(.label)<29>\(.data.addr)<29>\(.data.port)"' < storage/appconfig/$1.json)"
|
||||||
|
|
||||||
|
IFS=$'\n'
|
||||||
|
for i in $json; do
|
||||||
|
label="$(awk -F<> '{print $1}' <<< "$i")"
|
||||||
|
if [[ "$label" != '' ]]; then
|
||||||
|
label_sha="$(shasum <<< "$label" | cut -c 1-16)"
|
||||||
|
addr="$(awk -F<> '{print $2}' <<< "$i")"
|
||||||
|
port="$(awk -F<> '{print $3}' <<< "$i")"
|
||||||
|
res="$(timeout 1 nc -zv $addr $port)"
|
||||||
|
status=$?
|
||||||
|
|
||||||
|
unset json_res
|
||||||
|
declare -A json_res
|
||||||
|
json_res[type]="port"
|
||||||
|
json_res[label]="$label"
|
||||||
|
json_res[status]="$status"
|
||||||
|
json_res[res]="$res"
|
||||||
|
json_res[date]="$(date "+%T %d.%m.%y")"
|
||||||
|
|
||||||
|
json_object json_res >> "storage/data/$(shasum <<< "$label" | cut -c 1-16)"
|
||||||
|
if [[ "$status" == 0 && -f "storage/reports/$label_sha" ]]; then
|
||||||
|
rm "storage/reports/$label_sha"
|
||||||
|
notify="$(jq -r '.[] | select(.label == "'"$label"'").notify[]' < storage/appconfig/$1.json)"
|
||||||
|
notify "$notify" 0
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
cleanup
|
|
@ -6,6 +6,7 @@ json="$(jq -r '.[] | select(.type == "request") | "\(.label)<29>\(.data.url)<29>\(
|
||||||
IFS=$'\n'
|
IFS=$'\n'
|
||||||
for i in $json; do
|
for i in $json; do
|
||||||
label="$(awk -F<> '{print $1}' <<< "$i")"
|
label="$(awk -F<> '{print $1}' <<< "$i")"
|
||||||
|
if [[ "$label" != '' ]]; then
|
||||||
label_sha="$(shasum <<< "$label" | cut -c 1-16)"
|
label_sha="$(shasum <<< "$label" | cut -c 1-16)"
|
||||||
url="$(awk -F<> '{print $2}' <<< "$i")"
|
url="$(awk -F<> '{print $2}' <<< "$i")"
|
||||||
method="$(awk -F<> '{print $3}' <<< "$i")"
|
method="$(awk -F<> '{print $3}' <<< "$i")"
|
||||||
|
@ -40,4 +41,7 @@ for i in $json; do
|
||||||
notify="$(jq -r '.[] | select(.label == "'"$label"'").notify[]' < storage/appconfig/$1.json)"
|
notify="$(jq -r '.[] | select(.label == "'"$label"'").notify[]' < storage/appconfig/$1.json)"
|
||||||
notify "$notify" 0
|
notify "$notify" 0
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
cleanup
|
||||||
|
|
|
@ -14,21 +14,35 @@ label="$(jq -r '.label' < $data | head -n 1 | tr ' ' '_')"
|
||||||
start_date="$(jq -r '.date' < $data | tail -n $lim | head -n1)"
|
start_date="$(jq -r '.date' < $data | tail -n $lim | head -n1)"
|
||||||
end_date="$(jq -r '.date' < $data | tail -n1)"
|
end_date="$(jq -r '.date' < $data | tail -n1)"
|
||||||
tmp="$(mktemp)"
|
tmp="$(mktemp)"
|
||||||
|
type="$(jq -r '.type' < $data | head -n 1)"
|
||||||
|
|
||||||
if [[ "$(jq -r '.type' < $data | head -n 1)" == "ping" ]]; then
|
if [[ "$type" == "ping" ]]; then
|
||||||
timedata="$(jq -r '.time' < $data | tail -n $lim)"
|
timedata="$(jq -r '.time' < $data | tail -n $lim)"
|
||||||
|
|
||||||
while read line; do
|
while read line; do
|
||||||
echo -n 's@'"'"'></circle@'"'"'><title>'"$line"'</title></circle@;'
|
echo -n 's@'"'"'></circle@'"'"'><title>'"$line"'</title></circle@;'
|
||||||
done <<< "$(jq -r '"Name: \(.label)\\\\nPing time: \(.time)ms\\\\nDate: \(.date)"' < "$data" | tail -n $lim)" > $tmp
|
done <<< "$(jq -r '"Name: \(.label)\\\\nPing time: \(.time)ms\\\\nDate: \(.date)"' < "$data" | tail -n $lim)" > $tmp
|
||||||
|
|
||||||
elif [[ "$(jq -r '.type' < $data | head -n 1)" == "req" ]]; then
|
elif [[ "$type" == "req" ]]; then
|
||||||
timedata="$(jq -r '.status' < $data | tail -n $lim)"
|
timedata="$(jq -r '.status' < $data | tail -n $lim)"
|
||||||
a=""
|
a=""
|
||||||
for i in $timedata; do
|
for i in $timedata; do
|
||||||
if [[ "$i" -gt 0 ]]; then
|
if [[ "$i" -gt 0 ]]; then
|
||||||
a="${a}0#"
|
a="${a}0#"
|
||||||
elif [[ "$i" == "0" ]]; then
|
elif [[ "$i" == 0 ]]; then
|
||||||
|
a="${a}1#"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
timedata="$(tr '#' '\n' <<< "$a")"
|
||||||
|
while read line; do
|
||||||
|
echo -n 's@'"'"'></circle@'"'"'><title>'"$line"'</title></circle@;'
|
||||||
|
done <<< "$(jq -r '"Name: \(.label)\\\\nDate: \(.date)"' < "$data" | tail -n $lim)" > $tmp
|
||||||
|
elif [[ "$type" == "port" ]]; then
|
||||||
|
timedata="$(jq -r '.status' < $data | tail -n $lim)"
|
||||||
|
for i in $timedata; do
|
||||||
|
if [[ "$i" -gt 0 ]]; then
|
||||||
|
a="${a}0#"
|
||||||
|
elif [[ "$i" == 0 ]]; then
|
||||||
a="${a}1#"
|
a="${a}1#"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
|
@ -12,15 +12,18 @@ fi
|
||||||
|
|
||||||
source "${cfg[namespace]}/code/ping.sh" every_1min
|
source "${cfg[namespace]}/code/ping.sh" every_1min
|
||||||
source "${cfg[namespace]}/code/req.sh" every_1min
|
source "${cfg[namespace]}/code/req.sh" every_1min
|
||||||
|
source "${cfg[namespace]}/code/port.sh" every_1min
|
||||||
|
|
||||||
if [[ $counter30 == 30 ]]; then
|
if [[ $counter30 == 30 ]]; then
|
||||||
source "${cfg[namespace]}/code/ping.sh" every_30min
|
source "${cfg[namespace]}/code/ping.sh" every_30min
|
||||||
source "${cfg[namespace]}/code/req.sh" every_30min
|
source "${cfg[namespace]}/code/req.sh" every_30min
|
||||||
|
source "${cfg[namespace]}/code/port.sh" every_30min
|
||||||
counter30=0
|
counter30=0
|
||||||
fi
|
fi
|
||||||
if [[ $counter5 == 5 ]]; then
|
if [[ $counter5 == 5 ]]; then
|
||||||
source "${cfg[namespace]}/code/ping.sh" every_5min
|
source "${cfg[namespace]}/code/ping.sh" every_5min
|
||||||
source "${cfg[namespace]}/code/req.sh" every_5min
|
source "${cfg[namespace]}/code/req.sh" every_5min
|
||||||
|
source "${cfg[namespace]}/code/port.sh" every_5min
|
||||||
counter5=0
|
counter5=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue