#!/bin/bash
alertC="" monitor_type="" iftype=false check_ip="" usage() { cat << EOF Usage:$(basename $0) options This script use for test zte server status OPTIONS: -H, IP address -h Show this message -c NUM set any value of CRITICAL <-p | -s> -s check SMPP port, -p check POST port EOF } typeusage() { echo "Can't specify 's' and 'h' at the same time!!!" exit 1 } while getopts "w:c:sphH:" opt;do case $opt in 'H') check_ip=$OPTARG ;; 'h') usage exit 0 ;; 'c') alertC=$OPTARG ;; 'p') if ! $iftype; then monitor_type="http" iftype=true else typeusage fi ;; 's') if ! $iftype; then monitor_type="smpp" iftype=true else typeusage fi ;; *) echo usage ;; esac done [ -z $check_ip ] && echo "Must specify a address" && exit 0 case $monitor_type in 'http') if nc -w 5 -z $check_ip 7002 &>/dev/null ;then echo "HTTP OK: HTTP check was ok" exit 0 else echo "HTTP CRITICAL: HTTP check was failed" exit 2 fi ;; 'smpp') if nc -w 5 -z $check_ip 3200 &>/dev/null ;then echo "SMPP OK: SMPP check was ok" exit 0 else echo "SMPP CRITICAL: SMPP check was failed" exit 2 fi ;; esac