D7net
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
lib64
/
nagios
/
plugins
/
nccustom
/
Filename :
check-lscache-version.sh
back
Copy
#!/bin/bash # Nagios script for LiteSpeed cache version check; # Nagios status codes (Nagios expects one of these to be returned); # OK = 0; # WARNING = 1; # CRITICAL = 2; # UNKNOWN = 3; function check_command_result() { if [ $? -eq 0 ]; then return else echo "CRITICAL: can't run command [${1}]" exit 2 fi } VERBOSE=0 PROGNAME=${0##*/} print_usage() { echo "" echo "Usage: ${PROGNAME} [-v be Verbose]" echo "Usage: ${PROGNAME} -h | --help" } print_help() { print_usage echo "" echo "This script checks latest version of LScache plugin" echo "" echo "-v be Verbose (should be last argument)" echo "--help Print this help screen" echo "" exit 3 } while [ $# -gt 0 ]; do case "$1" in --help) print_help exit 3 ;; -h) print_help exit 3 ;; -v) VERBOSE=1; shift;shift ;; *) echo >&2 "Unknown argument: $1" print_usage exit 3 ;; esac shift done #!/bin/bash # Nagios script for LiteSpeed cache version check; # Nagios status codes (Nagios expects one of these to be returned); # OK = 0; # WARNING = 1; # CRITICAL = 2; # UNKNOWN = 3; function check_command_result() { if [ $? -eq 0 ]; then return else echo "CRITICAL: can't run command [${1}]" exit 2 fi } VERBOSE=0 PROGNAME=${0##*/} print_usage() { echo "" echo "Usage: ${PROGNAME} [-v be Verbose]" echo "Usage: ${PROGNAME} -h | --help" } print_help() { print_usage echo "" echo "This script checks latest version of LScache plugin" echo "" echo "-v be Verbose (should be last argument)" echo "--help Print this help screen" echo "" exit 3 } while [ $# -gt 0 ]; do case "$1" in --help) print_help exit 3 ;; -h) print_help exit 3 ;; -v) VERBOSE=1; shift;shift ;; *) echo >&2 "Unknown argument: $1" print_usage exit 3 ;; esac shift done # Get current LScache version; CURRENT_VERSION=$(/usr/local/lsws/admin/misc/lscmctl setversion) check_command_result "/usr/local/lsws/admin/misc/lscmctl" # Get available latest LScache version; AVAILABLE_VERSIONS=$(/usr/local/lsws/admin/misc/lscmctl setversion --list) check_command_result "/usr/local/lsws/admin/misc/lscmctl" # Get version from common current LScache string; RESULT_CURRENT_VERSION=$(awk -F" " 'END{print $NF}' <<< ${CURRENT_VERSION}) check_command_result "awk" # Get version from common all versions for LScache string; RESULT_AVAILABLE_VERSION=$(echo "${AVAILABLE_VERSIONS}"| grep -oP '\d+\.\d+(\.\d+)*' | head -n 1) check_command_result "awk" # Delete waste point from result; str_len=${#RESULT_CURRENT_VERSION} if [ "${RESULT_CURRENT_VERSION:$((${str_len}-1)):1}" = "." ] then RESULT_CURRENT_VERSION=${RESULT_CURRENT_VERSION:0:$((${str_len}-1))} fi if [[ ${VERBOSE} == 1 ]]; then echo -e "\n\t[VERBOSE INFORMATION, begin]\n" echo "Current version, full string: [${CURRENT_VERSION}]" echo "Available versions, full list: [${AVAILABLE_VERSIONS}]" echo "Parsed current version string: [${RESULT_CURRENT_VERSION}]" echo "Parsed all versions string: [${RESULT_AVAILABLE_VERSION}]" echo -e "\n\t[ VERBOSE INFORMATION, end ]\n" fi # Final check; if [[ "${RESULT_CURRENT_VERSION}" == "${RESULT_AVAILABLE_VERSION}" ]]; then echo "OK: LScache plugin is updated: [${RESULT_AVAILABLE_VERSION}]" exit 0 else echo "CRITICAL: LScache plugin is outdated, latest version: [${RESULT_AVAILABLE_VERSION}]" exit 2 fi