Skip to content

Synthetic website monitoring with Selenium and Docker.

License

Notifications You must be signed in to change notification settings

PawelSuwinski/check_selenium_docker

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

check_selenium_docker

Overview

Synthetic website monitoring with Selenium and Docker.

check_selenium_docker is a Nagios based plugin that spins up a Docker container, executes the test and, once the test is finished and the result has been reported back to the monitoring solution, removes the Docker container.

Highlights

Workflow

Install Selenium IDE for Chrome (https://selenium.dev/downloads).

Record your test.

Export the test and copy the .side file to the server that will run the docker image.

A Docker container will execute the test and report the test results back to the monitoring system.

Workflow

System requirements

The following prerequisites must be installed on the server that will execute the plugin.

  • Python 3 with the docker module
  • docker-ce

ITRS OP5 Monitor example

# Install docker-ce
yum install -y yum-utils \
  device-mapper-persistent-data \
  lvm2

yum-config-manager \
    --add-repo \
    https://download.docker.com/linux/centos/docker-ce.repo

yum install docker-ce

# Add user 'monitor' to group 'docker'
usermod -aG docker monitor

# Start and enable docker
systemctl start docker && systemctl enable docker

# Install the docker Python 3 module
pip-3 install docker

# (Optional) Add versionlock to docker-ce
yum install yum-plugin-versionlock
yum versionlock docker-ce

# (Optional) Remove versionlock from docker-ce
yum versionlock clear

Docker image

Build the Docker image:

git clone https://github.com/opsdis/check_selenium_docker
cd check_selenium_docker/dockerimage/
docker build . --tag opsdis/selenium-chrome-node-with-side-runner

Image for an alternative supported browser:

sed 's/chrome/firefox/' Dockerfile | docker build --tag opsdis/selenium-firefox-node-with-side-runner -

Plugin

Copy the plugin to the plugin directory and make it executable:

cp check_selenium_docker.py /opt/plugins/custom/
chmod +x /opt/plugins/custom/check_selenium_docker.py

Add a new check_command to Monitor:

check_selenium_docker
$USER1$/custom/check_selenium_docker.py $ARG1$

Add new test scenarios

Create a new main directory (/opt/plugins/custom/selenium) in the main directory create a new directory preferably named as the URL used in the test (/opt/plugins/custom/selenium/opsdis.com):

mkdir /opt/plugins/custom/selenium
mkdir /opt/plugins/custom/selenium/opsdis.com

Create two subdirectories, out and sides:

mkdir /opt/plugins/custom/selenium/opsdis.com/{out,sides}

Add the side-file to the sides subdirectory and modify the permissions:

chmod 777 /opt/plugins/custom/selenium/opsdis.com/out/
chmod 755 /opt/plugins/custom/selenium/opsdis.com/sides/opsdis.com.side

Optionally add a runner local configuration file or additional command-line arguments to pass, for example:

cat <<EOT > /opt/plugins/custom/selenium/opsdis.com/sides/.options
--filter MyTestSuite
EOT

cat <<EOT > /opt/plugins/custom/selenium/opsdis.com/sides/.side.yml
capabilities:
  acceptInsecureCerts: true
EOT

See Command-line Runner / Run-time configuration.

The directory structure should look like this:

├── opsdis.com
│   ├── out
│   └── sides
│       └── opsdis.com.side
│       └── .side.yml
│       └── .options

Execute the plugin

/opt/plugins/custom/check_selenium_docker.py /opt/plugins/custom/selenium/opsdis.com
OK: Passed 2 of 2 tests. | 'passed'=2;;2:;0;2 'failed'=0;;~:0;0;2 'exec_time'=6s;;;;

Performance metrics

Console output (Selenium IDE echo command) is parsed for additional custom metrics marked with PERFDATA: prefix and guidelines compliant expression for Performance data, i.e., PERFDATA: First Response Time = ${calculatedTime}s;120 could give for calculatedTime = 150 (as a results of exec script SIDE command):

/opt/plugins/custom/check_selenium_docker.py -vv /opt/plugins/custom/selenium/opsdis.com
WARNING: Passed 2 of 2 tests with 0 critical and 1 warning alerts. Warning: First Response Time. | 'passed'=2;;2:;0;2 'failed'=0;;~:0;0;2 'exec_time'=6s;;;; 'First Response Time'=150s;120

License

check_selenium_docker is licensed under GPL version 3.

About

Synthetic website monitoring with Selenium and Docker.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 87.3%
  • Dockerfile 12.7%