Browse Source

Adds mail server and dns check + enhance ping

- Add ipv4|v6 selection for ping
- Add dns field check
- Add imaps and smtp checks
Yann Weber 11 months ago
parent
commit
d129a9257c
1 changed files with 73 additions and 1 deletions
  1. 73
    1
      check.sh

+ 73
- 1
check.sh View File

@@ -401,11 +401,20 @@ check_audiostream_mpv() {
401 401
 check_ping() {
402 402
 	ns=$1
403 403
 	count=$2
404
+	proto="$3"
404 405
 	if [ -z "$count" ]
405 406
 	then
406 407
 		count=5
407 408
 	fi
408
-	ping -i 0.2 -c $count $ns 2>/dev/null >/dev/null
409
+	case "$proto" in
410
+		ipv4)
411
+			proto="-4";;
412
+		ipv6)
413
+			proto="-6";;
414
+		*)
415
+			proto="";;
416
+	esac
417
+	ping $proto -i 0.2 -c $count $ns 2>/dev/null >/dev/null
409 418
 	res=$?
410 419
 	if [ "$res" -ne 0 ]
411 420
 	then
@@ -415,6 +424,69 @@ check_ping() {
415 424
 	fi
416 425
 }
417 426
 
427
+check_dns() {
428
+	hostname=$1
429
+	field=$2
430
+	expt=$3
431
+	result=$(dig +short "$hostname" "$field")
432
+	if echo "$result" | grep -e "$expt" >/dev/null
433
+	then
434
+		success "DNS replied '$expt' for '$field $hostname'"
435
+	else
436
+		fail "Unexpected DNS reply '$result' expecting '$expt' for '$hostname $field'"
437
+	fi
438
+}
439
+
440
+check_smtp() {
441
+	hostname=$1
442
+	port=$2
443
+	if [ -z "$port" ]
444
+	then
445
+		port=587
446
+	fi
447
+	code=$(nc -q0 "$hostname" "$port" < /dev/null | cut -d " " -f1)
448
+	if [ "$code" = "220" ]
449
+	then
450
+		success "SMTP@$hostname server replied 220 status"
451
+	else
452
+		fail "Unexpected reply from smtp@$hostname '$code'"
453
+	fi
454
+}
455
+
456
+check_smtp_id() {
457
+	hostname=$1
458
+	idstr=$2
459
+	port=$3
460
+	if [ -z "$port" ]
461
+	then
462
+		port=587
463
+	fi
464
+	rep=$(nc -q0 "$hostname" "$port" < /dev/null)
465
+	if echo "$rep" | grep -e "^220 $idstr" > /dev/null
466
+	then
467
+		success "SMTP@$hostname server replie '$idstr'"
468
+	else
469
+		fail "Unexpected reply from smtp@$hostname '$rep'"
470
+	fi
471
+}
472
+
473
+check_imaps() {
474
+	hostname=$1
475
+	port=$2
476
+	if [ -z "$port" ]
477
+	then
478
+		port=993
479
+	fi
480
+	rep=$(echo "01 LOGOUT" | openssl s_client -quiet -verify_quiet -connect "${hostname}:$port" -servername "$hostname")
481
+
482
+	if echo "$rep" | grep "^01 OK" > /dev/null
483
+	then
484
+		success "IMAPS@$hostname '$(echo "$rep" | grep "^01 OK")'"
485
+	else
486
+		fail "Unexpected reply from imaps@$hostname '$rep'"
487
+	fi
488
+}
489
+
418 490
 check_git_repo() {
419 491
 	tmpdir=$(mktemp -d -t check_git.XXXXXXXXX)
420 492
 	git clone $1 $tmpdir 2>/dev/null 1>/dev/null

Loading…
Cancel
Save