Selenium and Nagios


I've implemented a Nagios check for Selenium test cases. With this check it is possible to put your recorded test cases from your Selenium IDE into Nagios to use them for monitoring.

In my opinion this has the following advantages:
  • You can transfer your test cases to monitoring without making any changes.
  • You can run the test cases with multiple browsers. This means, you use the JavaScript and rendering engine of the browser not any other HTML/HTTP library.
  • You are more flexible, when monitoring more complex scenarios.
To get this working, you need the following components:
There are two possible scenarios how you could put this to work:
  • Install the Selinium RC server on your Nagios host.
  • Install the Selinum RC server on a different host.
I will only explain how you can set up the Selenium RC server on your Nagios host. When you want to install it on a different server you currently have to use nrpe/nsca to get it going. This is the only difference, the rest stays the same. You can contact the Selenium RC server directly on another server, but this is not yet implemented.

First record your test case with the Selenium IDE. When you've done this before, take a look at the Selenium IDE documentation. After recording it, export it to a Java file (File -> Export Test Case As ... -> Java (JUnit) - Selenium RC). Compile this Java file with javac or your favorite IDE. For compilation you already need the JUnit library and the file selenium-server.jar:
javac -cp ./junit.jar:./selenium-server.jar [your test case file]
 On your Nagios host, put check_selenium into your libexec path, add the files CallSeleniumTest.class, junit.jar and selenium-server.jar somewhere. Adjust the classpath in the check_selenium 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 and add it to the classpath. Put the compiled Java file into this directory.

Add the definition to your nagios configuration and test it. When your nagios server is a headless linux system, you can also run Selenium RC headless with Xvfb. Take a look at this post, how to set it up.

Hope this all gives you new ways how to monitor your web applications or make the already established way a bit easier.

The plugin also returns performance data for the test cases, but be aware the returned time also contains the startup time for the browser.

This plugin is written with Java and the Selenium test case is integrated with reflection. I'm sure you could also write this in Perl, Ruby or something different. I did it in Java because I had a bit of a mess with the needed Perl modules. Perhaps I will do a Perl version later.

Update 2011/07:
Some people asked for a more detailed explanation on integrating check_selenium into Nagios. Here are two possible solutions how to integrate it. The first one is with NRPE. The check runs on a different host. With the second possibility, the check runs on your Nagios host.
define command {
  command_name  nrpe_check_selenium
  command_line  $USER1$/check_nrpe -t 60 -H $HOSTADDRESS$ -p 5666 -c check_selenium -a "$ARG1$" "$ARG2$" "$ARG3$"

define command {
  command_name  local_check_selenium
  command_line  $USER1$/check_selenium "$ARG1$" "$ARG2$" "$ARG3$"
After that, you can define your service and asign it to a host:
define service {
  service_description   nrpe_selenium_Google
  use   service-check-05min
  check_command  nrpe_check_selenium!com.example.tests.GoogleTestCase!!*iexplore

define service {
  service_description  selenium_Google
  use  service-check-05min
  check_command    local_check_selenium!com.example.tests.GoogleTestCase!!*firefox

When executing the check via NRPE, add a line like this to your nrpe.cfg file on your remote host:

command[check_selenium]=/usr/local/nagios/libexec/ --class "$ARG1$" --baseUrl "$ARG2$" --browsertype "$ARG3$"
Hope this will help some people to get faster results.


Anonymous said...

This is great! I can't wait to check it out.

Anonymous said...

check_selenium nagios plugin is not available for download via the link listed above. Please advise, only the JAVA classes are available

Christian said...


thanks for your interest and the comments. I updated the git repository with a bash wrapper script and documentation. I hope it will help you to get the plugin running in your environment.


michael4715 said...

Hi Christian..

Thanks for this good idea, really been missing it in Nagios. I have tried to get it to work over the last couple of days, and I got the script to run but every test I try is reported critical, even the test script you have provided with google. Do you have any idea what could be wrong.
./check_selenium "com.example.tests.GoogleSeleniumTestCase" "" "*firefox"
CRITICAL - com.example.tests.GoogleSeleniumTestCase: com/thoughtworks/selenium/SeleneseTestCase |;;;;

with reards Michael

Anonymous said...

my testscript cannot start the firefox browser. is there any reason for that ?

Christian said...

Hi Anonymous,

my first guess is a wrong PATH env variable. When you have more questions feel free to send me an e-mail.


Yann said...

Thanks for this nice plugin !

I only had a small problem : I had to put my testcase class in a jar file, otherwise, selenium wouldn't find the class (NoClassDefFoundError).

The other thing I'm wondering : why do I have to put the base URL in the args of the check, whereas this URL is already present into the script (setUp method) ?

I've created a script to compile and create the jar archive, so users unfamiliar with Java can use the plugin. I post it there just in case it could be useful :

# Compile all java files in java_checks dir
for i in `ls java_checks/*.java`
javac -classpath lib/junit-4.8.1.jar:lib/selenium-java-client-driver.jar $i

# Move class files in right dir
rm -f com/example/tests/*.class
mv java_checks/*.class com/example/tests/

# Create jar if not present
touch lib/my_checks.jar

# Add .class files to the jar archive
jar -uvf lib/digora_checks.jar com/example/tests/*.class

Christian said...

Hi Yann,

thanks for posting your experience and your script.

There are two reasons for the url parameter. The first tests I generated had the wrong url in the setUp method. The other reason is, this way you can run the same testcase againt different environment, e.g. testing and production.

Anonymous said...

do you know how i can install the selenium RC on a linux based OS???

Christian said...

As it is only a jar file you can run it with java -jar ... Take a look, at the plugin, it contains a script to start selenium RC as a service on Linux.

Anonymous said...


How did you reference your testcase class in a jar file? I am having the same error message (NoClassDefFoundError).

Anonymous said...


I had to play around a bit with the CLASSPATH until getting all the jars at the right position and so on, but now that I am finally able to start the check I have a new problem which I cannot figure out what went wrong:

bin/ -c "com.example.tests.TestOp5Com" -b "" -t "*firefox"
UNKNOWN - com.example.tests.TestOp5Com: org/openqa/selenium/WebDriver |;;;;

Would be great if anybody could help me...


Werm said...

I could never get it to work,

th123@mon-console-dev-02 [development] ~/selenium $ /home/th123/jdk1.7.0_03/bin/java -cp /home/th123/selenium/selenium-java-client-driver.jar:/home/th123/selenium/commons-cli-1.2.jar:/home/th123/selenium/junit-4.8.1.jar:/home/th123/selenium/:/home/th123/selenium/com/example/tests/.:/home/th123/selenium/check-selenium.jar:/home/th123/selenium/selenium-example-tests.jar info.devopsabyss.CallSeleniumTest -c "com.example.tests.sisscitrix" -v
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(
at sun.reflect.DelegatingMethodAccessorImpl.invoke(
at java.lang.reflect.Method.invoke(
at info.devopsabyss.CallSeleniumTest.startTest(
at info.devopsabyss.CallSeleniumTest.main(
CRITICAL - com.example.tests.sisscitrix: null |;;;;

Christian said...

Hi Christian,

from your output, it seems you are using check_selenium with webdriver. The version you are using isn't working with webdriver. Just pushed a new version to github.


K S V said...

I am struggling to make it work. After recording my test session IDE, I tried exporting it as "Java/ Junit 4/ Remote Controller" according to your instructions. But the resultant java code contained deprecated classes and methods. So I had to export as "Java / Junit 4/ Webdriver" to get clean code. Now, I am not sure how to execute this code as the instruction is for Selenium RC where as the code has been executed as webdriver. Also I am not able to download the file. When I click on the download link, All I am getting a blank webpage.

Could you please guide me on this?


Christian said...

Hi Vishnu,

it seems the download link on Nagios Exchange is broken. Please use the github repository:
Just build the plugin on your own. The repository also includes an ant build file.

When I remember correctly, the version on github also works with webdriver.


K S V said...

Hi Christian,

I found build.xml in the main folder. But I am a beginner when it comes to development. Could you please let me know how to build the plugin using this build.xml?

Thank you,

Post a Comment