Coder Social home page Coder Social logo

opsdis / check_selenium_docker Goto Github PK

View Code? Open in Web Editor NEW
8.0 4.0 6.0 102 KB

Synthetic website monitoring with Selenium and Docker.

License: GNU General Public License v3.0

Python 78.15% Dockerfile 21.85%
selenium dockerfile op5-monitor icinga2 nagios-plugin

check_selenium_docker's Introduction

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

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

The directory structure should look like this:

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

Execute the plugin

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

License

check_selenium_docker is licensed under GPL version 3.

check_selenium_docker's People

Contributors

msafdal avatar pawelsuwinski avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

check_selenium_docker's Issues

PermissionError: [Errno 13] Permission denied

Im trying to create a selenium check, but keep getting the error
PermissionError: [Errno 13] Permission denied '/opt/plugins/custom/selenium/qaLogin/out/QALogin.json'
when I run it through the Nagios website. The QALogin.json file is set to:
-rw-r--r--. 1 nagios nagios 886 Aug 6 23:17 QALogin.json
I can run it manually as the nagios user and verified the out and sides directories are being mapped to during the docker container run.
It just wont work during the nagios checks and I cannot figure out why. Any help will be appreciated.

Here is the complete error.

(No output on stdout) stderr: Traceback (most recent call last):
File "/usr/lib64/nagios/plugins/check_selenium_docker.py", line 39, in
os.remove(result)
PermissionError: [Errno 13] Permission denied: '/opt/plugins/custom/selenium/qaLogin/out/QALogin.json'

[1596757748.377441] [016.2] [pid=848] Parsing check output...
Short Output: (No output on stdout) stderr: Traceback (most recent call last):
Long Output: File "/usr/lib64/nagios/plugins/check_selenium_docker.py", line 39, in \n os.remove(result)\nPermissionError: [Errno 13] Permission denied: '/opt/plugins/custom/selenium/qaLogin/out/QALogin.json'

inconsistent test running and output processing

At entry_point.sh all side files are processed by runner

selenium-side-runner (...)  /sides/*.side

But plugin script check_selenium_docker.py wait for and process only the first json output:

side = glob.glob(path + '/sides/*.side')
side_file = open(side[0],'r')
(...)
result = path + '/out/' + side_json['name'] + '.json'
(...)
while not os.path.isfile(result) and waitedfor <= timeout:

It also calculates exec_time and prints failureMessage based only on the first failed test. If side file contains more than one Test Suite then could be more failed tests:

int(str(json_input['testResults'][0]['endTime'])[:-3]) - int(str(json_input['startTime'])[:-3])
(...)
  " tests. Error message: " + str(json_input['testResults'][0]['message']) +

And finally runner's output failure messages are quite long and multi-line which is a bit in a contrary with a Nagions Guidelines that encourages brevity.

I fixed it all in my fork. I will do a PR if you would like to merge it.

ps. Good job with this plugin :).

exec_time calculation error in the absence of tests

Traceback (most recent call last):
  File "./check_selenium_docker.py", line 70, in <module>
    exec_time = int(str(json_input['testResults'][0]['endTime'])[:-3]) - int(str(json_input['startTime'])[:-3])
IndexError: list index out of range

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.