HEX
Server: LiteSpeed
System: Linux s3604.bom1.stableserver.net 4.18.0-513.11.1.lve.el8.x86_64 #1 SMP Thu Jan 18 16:21:02 UTC 2024 x86_64
User: dmstechonline (1480)
PHP: 7.4.33
Disabled: NONE
Upload Files
File: //lib64/nagios/plugins/check_a2_redis_opcache.shared
#!/bin/bash

# Ref: BFENG-1101
# To verify that redis and opcache extensions are available in the specified php versions.

# Exit if isn't cPanel
if [ ! -s "/usr/local/cpanel/version" ]; then
    exit
fi

_php_versions_list=("5.2" "5.3" "5.4" "5.5" "5.6" "7.0" "7.1" "7.2" "7.3" "7.4" "8.0" "8.1" "8.2" "8.3")
_php_missing_opcache=""
_php_missing_redis=""

for _php_version in "${_php_versions_list[@]}"
do
  _php_extensions=$(selectorctl --interpreter=php --list-extensions --version=$_php_version | grep -wE 'opcache|redis')
  if [[ $_php_extensions != *"+ opcache"* ]]; then
    _php_missing_opcache+="$_php_version, "
  fi
  if [[ $_php_extensions != *"+ redis"* ]]; then
    _php_missing_redis+="$_php_version, "
  fi
done

if [[ -z $_php_missing_opcache && -z $_php_missing_redis ]]; then
  echo "check_redis_opcache - All PHP versions have opcache and redis extensions enabled."
  exit 0
else
  if [[ -n $_php_missing_opcache && -n $_php_missing_redis ]]; then
    echo "check_redis_opcache - PHP ${_php_missing_opcache%, } missing opcache extension and PHP ${_php_missing_redis%, } missing redis extension."
    exit 2
  elif [[ -n $_php_missing_opcache ]]; then
    echo "check_redis_opcache - PHP ${_php_missing_opcache%, } missing opcache extension."
    exit 2
  elif [[ -n $_php_missing_redis ]]; then
    echo "check_redis_opcache - PHP ${_php_missing_redis%, } missing redis extension."
    exit 2
  fi
fi