Home > HowTo, Linux, Nagios > How to use selenium with nagios

How to use selenium with nagios

How to use selenium with nagios_server

1. Install mozilla firefox headless(no GUI)
yum install xorg-x11-server-Xvfb.x86_64 xfonts-base xfonts-75dpi xfonts-100dpi firefox ImageMagick.x86_64

— Starts firefox on virtual gui
DISPLAY=:1 firefox http://google.com &
— test and check
Xvfb :1 -screen 1 1024x768x24 &
ps -ef |grep firefox

— Uses imagemagic to get a printscreen, to make sure its working.
DISPLAY=:1 import -window root google.com.png

— (Optional) Set proxy in firefox profile
vi /root/.mozilla/firefox/ns11i9xo.default/prefs.js
user_pref(“network.proxy.http”, “proxyserver”);
user_pref(“network.proxy.http_port”, 8080);
user_pref(“network.proxy.no_proxies_on”, “localhost, 127.0.0.1, 172.17.0.0/16, 10.5.0.0/16”);

2. Using check_selenium.py

— start headless linux
Xvfb :1 -ac -noreset -screen 1 1024x768x24 &

–start Selenium Server in bg
export DISPLATY=1 && nohup java -jar /usr/local/nagios/libexec/check_selenium/selenium-server-standalone-2.24.1.jar -Dhttp.proxyHost=172.17.1.8 -Dhttp.proxyPort=8080 -debug -log /tmp/selenium.log -browserSessionReuse -trustAllSSLCertificates &

–Run the tests
edit the check_selenium.py with the data_dir
check_selenium.py -s test_google.py -w 40 -c 60 -d

————————————————————————
Troubleshooting:

Load Firefox profile
DISPLAY=:1 && nohup java -jar selenium-server-standalone-2.24.1.jar -Dhttp.proxyHost=172.17.35.188 -Dhttp.proxyPort=8080 -firefoxProfileTemplate /root/.mozilla/firefox/ns11i9xo.default/

If you have an error like Non-ASCII character.
Set the enconding inside the .py file will solve the problem, check http://www.python.org/peps/pep-0263.html

If it gets stuck on Launching Firefox…
When calling the selenium-server you must pass the complete path into it like /usr/local/selenium-server…

Firefox has problem recovering windows and tabs
Reinstall firefox
yum -y -v remove firefox && yum -y -v install firefox

Details on how to correctly start the Selenium Server standalone
java -jar selenium-server-standalone-2.24.1.jar -h

How to install pip python-pip
curl -O https://raw.github.com/pypa/pip/master/contrib/get-pip.py
python get-pip.py

Using using the check_selenium.sh script but It did not work
1. Compile Selenium Testcase to JUnit
–Download the check_selenium
wget “http://gitorious.org/nagios-community/plugins/blobs/raw/6ac08f2116e81e8d80bba988531d56df1870dbee/check_selenium/check_selenium.tar.gz”
–Download selenium-server.jar (2.24.1) July 2012
wge “http://selenium.googlecode.com/files/selenium-server-standalone-2.24.1.jar”
–Install a java compiler
yum install java-1.6.0-openjdk-devel.x86_64

–Complile it, should generate a .class files
javac -cp ./junit-4.8.1.jar:./selenium-server.jar test_selenium.java

–Start the Selenium server and leave it on the BG
nohup java -jar selenium-server.jar &
–Make sure its there, it should liste on port 4444 by default
ps -ef |grep selenium && netstat -anp |grep “:4444”

–Following the instrucions on README
“On your Nagis host extract the check_selenium.tar.gz file into your libexec path. Adjust the java home in the check_selenium.sh file. As the Selenium IDE puts the Java classes automatically in the package com.tests.examples, create a directory com/tests/examples on your filesystem. Put the compiled Java file into this directory.”
My check_selenium.sh
JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-1.6.0.0.x86_64
DIR=`pwd`
(DID NOT WORK!)

Reference:
http://old.nabble.com/SeleniumRC—Compilation-Error-td21345720.html
https://www.monitoringexchange.org/inventory/Check-Plugins/Software/HTTP-%2526-FTP/check_selenium-py
devops-abyss.blogspot.com.br/2010/06/selenium-and-nagios.html

  1. September 25th, 2014 at 14:52 | #1

    I have tried above but I could not find three packages xfonts-base xfonts-75dpi xfonts-100dpi.
    can you please help me to findout repository for the same.

  1. No trackbacks yet.

VAMOVE *

*