2020-07-06 22:21:18 +02:00
|
|
|
#!/bin/bash
|
|
|
|
#Ramil Valitov ramilvalitov@gmail.com
|
|
|
|
#https://github.com/rvalitov/zabbix-php-fpm
|
|
|
|
#This script is used for testing
|
|
|
|
|
2020-07-29 03:16:44 +02:00
|
|
|
# Used for section folding in Travis CI
|
|
|
|
SECTION_UNIQUE_ID=""
|
|
|
|
|
|
|
|
# ----------------------------------
|
|
|
|
# Colors
|
|
|
|
# ----------------------------------
|
|
|
|
NOCOLOR='\033[0m'
|
|
|
|
RED='\033[0;31m'
|
|
|
|
GREEN='\033[0;32m'
|
|
|
|
ORANGE='\033[0;33m'
|
|
|
|
BLUE='\033[0;34m'
|
|
|
|
PURPLE='\033[0;35m'
|
|
|
|
CYAN='\033[0;36m'
|
|
|
|
LIGHTGRAY='\033[0;37m'
|
|
|
|
DARKGRAY='\033[1;30m'
|
|
|
|
LIGHTRED='\033[1;31m'
|
|
|
|
LIGHTGREEN='\033[1;32m'
|
|
|
|
YELLOW='\033[1;33m'
|
|
|
|
LIGHTBLUE='\033[1;34m'
|
|
|
|
LIGHTPURPLE='\033[1;35m'
|
|
|
|
LIGHTCYAN='\033[1;36m'
|
|
|
|
WHITE='\033[1;37m'
|
|
|
|
|
|
|
|
function printYellow() {
|
|
|
|
local info=$1
|
|
|
|
echo -e "${YELLOW}$info${NOCOLOR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function printRed() {
|
|
|
|
local info=$1
|
|
|
|
echo -e "${RED}$info${NOCOLOR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function printGreen() {
|
|
|
|
local info=$1
|
|
|
|
echo -e "${LIGHTGREEN}$info${NOCOLOR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function printSuccess() {
|
|
|
|
local name=$1
|
|
|
|
printGreen "✓ OK: test '$name' passed"
|
|
|
|
}
|
|
|
|
|
|
|
|
function printDebug() {
|
|
|
|
local info=$1
|
|
|
|
echo -e "${DARKGRAY}$info${NOCOLOR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function printAction() {
|
|
|
|
local info=$1
|
|
|
|
echo -e "${LIGHTBLUE}$info${NOCOLOR}"
|
|
|
|
}
|
|
|
|
|
|
|
|
function travis_fold_start() {
|
|
|
|
local name=$1
|
|
|
|
local info=$2
|
|
|
|
local CURRENT_TIMING
|
|
|
|
CURRENT_TIMING=$(date +%s%3N)
|
|
|
|
SECTION_UNIQUE_ID="$name.$CURRENT_TIMING"
|
|
|
|
echo -e "travis_fold:start:${SECTION_UNIQUE_ID}\033[33;1m${info}\033[0m"
|
|
|
|
}
|
|
|
|
|
|
|
|
function travis_fold_end() {
|
|
|
|
echo -e "\ntravis_fold:end:${SECTION_UNIQUE_ID}\r"
|
|
|
|
}
|
|
|
|
|
2020-07-06 22:21:18 +02:00
|
|
|
oneTimeSetUp() {
|
2020-07-29 03:16:44 +02:00
|
|
|
printAction "Started job $TRAVIS_JOB_NAME"
|
|
|
|
|
|
|
|
travis_fold_start "host_info" "ⓘ Host information"
|
2020-07-06 22:21:18 +02:00
|
|
|
nslookup localhost
|
|
|
|
sudo ifconfig
|
|
|
|
sudo cat /etc/hosts
|
2020-07-29 03:16:44 +02:00
|
|
|
travis_fold_end
|
|
|
|
|
|
|
|
printAction "Copying Zabbix files..."
|
2020-07-06 22:21:18 +02:00
|
|
|
#Install files:
|
|
|
|
sudo cp "$TRAVIS_BUILD_DIR/zabbix/zabbix_php_fpm_discovery.sh" "/etc/zabbix"
|
|
|
|
sudo cp "$TRAVIS_BUILD_DIR/zabbix/zabbix_php_fpm_status.sh" "/etc/zabbix"
|
|
|
|
sudo cp "$TRAVIS_BUILD_DIR/zabbix/userparameter_php_fpm.conf" "$(find /etc/zabbix/ -name 'zabbix_agentd*.d' -type d | head -n1)"
|
|
|
|
sudo chmod +x /etc/zabbix/zabbix_php_fpm_discovery.sh
|
|
|
|
sudo chmod +x /etc/zabbix/zabbix_php_fpm_status.sh
|
|
|
|
|
2020-07-29 03:16:44 +02:00
|
|
|
printAction "All done, starting tests..."
|
2020-07-06 22:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
testMissingPackagesDiscoveryScript() {
|
2020-09-21 15:43:24 +02:00
|
|
|
local DATA
|
|
|
|
local IS_OK
|
|
|
|
|
2020-07-06 22:21:18 +02:00
|
|
|
DATA=$(sudo bash "/etc/zabbix/zabbix_php_fpm_discovery.sh" "/php-fpm-status")
|
|
|
|
IS_OK=$(echo "$DATA" | grep -F ' not found.')
|
2020-07-06 22:58:36 +02:00
|
|
|
assertNotNull "Discovery script didn't report error on missing utilities $DATA" "$IS_OK"
|
2020-07-29 03:16:44 +02:00
|
|
|
printSuccess "${FUNCNAME[0]}"
|
2020-07-06 22:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
testMissingPackagesStatusScript() {
|
2020-09-21 15:43:24 +02:00
|
|
|
local DATA
|
|
|
|
local IS_OK
|
|
|
|
|
2020-07-06 22:21:18 +02:00
|
|
|
DATA=$(sudo bash "/etc/zabbix/zabbix_php_fpm_status.sh" "localhost:9000" "/php-fpm-status")
|
|
|
|
IS_OK=$(echo "$DATA" | grep -F ' not found.')
|
2020-07-06 22:58:36 +02:00
|
|
|
assertNotNull "Status script didn't report error on missing utilities $DATA" "$IS_OK"
|
2020-07-29 03:16:44 +02:00
|
|
|
printSuccess "${FUNCNAME[0]}"
|
2020-07-06 22:21:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
# Load shUnit2.
|
|
|
|
. shunit2
|