Vous êtes sur la page 1sur 7

Integrating Selenium with Nagios XI

The Industry Standard in IT Infrastructure Monitoring


Purpose
The purpose of this document is to show how integrating Selenium into Nagios XI can be done. Selenium is a powerful tool for web
browser based testing and automation. In this document we will be testing the http://www.nagios.org navigation bar for flaws a user may
run into.

Target Audience
This document is designed for Nagios administrators interested in integrating Selenium web testing into Nagios XI.

Prerequisites
The following are basic prerequisites required for using Selenium. They will be gone over in their respective sections with brief guides
on installation.

A Nagios XI server with NRPE installed and functioning


A separate system with a GUI installed, in this example we will be using Fedora 17
Firefox installed on the test system Fedora 17 with the Selenium IDE addon
CPAN
Perl
Perl Modules: TimePerf2, Time HiRes
Selenium RC Server
Selenium IDE: Perl Formatter
Java

Installation of Firefox prerequisites and preparation for recording


We will start with the Fedora 17 system, open Firefox and install the Selenium IDE which
is located here:
http://release.seleniumhq.org/selenium-ide/2.4.0/selenium-ide-2.4.0.xpi
Once Firefox has installed and restarted install the Firefox addon Selenium IDE: Perl
Formatter located here:
https://addons.mozilla.org/en-US/firefox/addon/selenium-ide-perl-formatter/?src=search
And once again Firefox will install the addon and restart, once this is finished click on
Tools in the Firefox navigation bar, and select Selenium IDE.
We will be greeted by the addon's pop out window, in order to make use of the Perl
Formatter we must enable a setting located in Options, select the Options action bar link
and then Options from the dropdown. Near the bottom of the pane there will be a selection
of check boxes, check Enable experimental features, then click Ok at the bottom of the
pane.
If you wish to familiarize yourself with the Selenium IDE a documentation index from
Selenium may be found here:
http://seleniumhq.org/projects/ide/plugins.html

Nagios Enterprises, LLC US: 1-888-NAGIOS-1


P.O. Box 8154
Int'l: +1 651-204-9102
Saint Paul, MN 55108
Fax: +1 651-204-9103
USA

Web: www.nagios.com
Email: sales@nagios.com

Page 1
Copyright 2010-2011 Nagios Enterprises, LLC
Revision 1.0 October, 2013

Integrating Selenium with Nagios XI


Recording a Test Case
For the purpose of this documentation we will be creating a short Test Case based around the Nagios Enterprises .org website.
We will begin from the http://www.google.com/ search homepage. Open the Selenium IDE recorder as previously mentioned then
select the Google search pane, type Nagios and hit the Enter key. Once the search page has been brought up select the first result:
Nagios The Industry Standard in IT Infrastructure Monitoring
When the page loads click the News tab on the Nagios.org navigation panel, once that has loaded do the same for Products, and then
Documentation. Once the Documentation page has loaded exit Firefox (Not Selenium IDE) click the red record button on the Selenium
IDE to stop recording. Now from the IDE's action bar click File, Export Test Case As, Perl. The example file will be saved as simpletest.

Setting up the Selenium Server, and testing a script


From the Fedora 17 system, or your choice distribution. Open the terminal and run the following:
yum install cpan
cpan
Once CPAN loads type the following:
install Time::HiRes
install Test::WWW::Selenium
Once these have been installed exit CPAN by typing q and
hitting enter then install Java by running:
yum install java
Create a new directory for the Selenium server and Navigate
to the new directory (in this example usr/local/selenium) and download the stand alone Selenium server:
wget http://selenium.googlecode.com/files/selenium-server-standalone-2.35.0.jar
Since the server is stand alone all that needs to be done to initiate it is:
java -jar selenium-server-standalone-2.35.0.jar

Nagios Enterprises, LLC US: 1-888-NAGIOS-1


P.O. Box 8154
Int'l: +1 651-204-9102
Saint Paul, MN 55108
Fax: +1 651-204-9103
USA

Web: www.nagios.com
Email: sales@nagios.com

Page 2
Copyright 2010-2011 Nagios Enterprises, LLC
Revision 1.0 October, 2013

Integrating Selenium with Nagios XI


And exit by using Ctrl + C

Setting up the remote test on the Nagios server


Moving to the Nagios Server's terminal we must install Perl:
yum install perl
And also install CPAN:
yum install cpan
Once CPAN is installed enter the following:
cpan
install WWW::Selenium

A few modules do not correctly install via CPAN so we must install them by hand:

wget http://assets.nagios.com/downloads/nagiosxi/packages/Test-Mock-LWP-0.06.tar.gz
wget http://assets.nagios.com/downloads/nagiosxi/packages/Test-WWW-Selenium-1.36.tar.gz
wget http://assets.nagios.com/downloads/nagiosxi/packages/Time.tar
tar -zxf Test-WWW-Selenium-1.36.tar.gz
cd Test-WWW-Selenium-1.36
perl Makefile.PL
make
make test
make install
cd ../
And then the second file:
tar -xf Time.tar
cd TimePerf2
perl Makefile.PL
make
make test
make install
cd ../

Nagios Enterprises, LLC US: 1-888-NAGIOS-1


P.O. Box 8154
Int'l: +1 651-204-9102
Saint Paul, MN 55108
Fax: +1 651-204-9103
USA

Web: www.nagios.com
Email: sales@nagios.com

Page 3
Copyright 2010-2011 Nagios Enterprises, LLC
Revision 1.0 October, 2013

Integrating Selenium with Nagios XI

And the third:


tar -zxf Test-Mock-LPW-0.06.tar.gz
cd Test-Mock-LWP-0.06
perl Makefile.PL
make
make test
make install

Now navigate back one folder:


cd ../
The final step that must be completed before testing our Perl script is to install a script cleaner this script adds the TimePerf2 usability
to our scripts and cleans up the code a bit. The script may be found here:
wget http://assets.nagios.com/downloads/nagiosxi/packages/clean_selenium_script
Once downloaded to the /selenium directory run the following:
perl clean_selenium_script --filename=simpletest o=simpletest
This will edit and format the file named simpletest and rename the output as simpletest once again.
Now, we must set the values inside the Perl script to those of our Selenium server.
vi simpletest
And edit following lines by pressing i and arrow keying to them:
new(host => <selenium.server.ip.here>,
port => <port here>
browser => *firefox,

These values will undoubtedly be different for your situation based on which ports you use for traffic, the default port for instance is
4444 but for documentation 5555 was chosen , the default browser is chrome, which is not Google Chrome but a special version of
Firefox, we will be using Firefox so that must be changed accordingly.
Write and quit simpletest:

Nagios Enterprises, LLC US: 1-888-NAGIOS-1


P.O. Box 8154
Int'l: +1 651-204-9102
Saint Paul, MN 55108
Fax: +1 651-204-9103
USA

Web: www.nagios.com
Email: sales@nagios.com

Page 4
Copyright 2010-2011 Nagios Enterprises, LLC
Revision 1.0 October, 2013

Integrating Selenium with Nagios XI


Esc
:wq
Enter

Now we may test our script:


perl simpletest
And shortly after you run that command you will see output from the test coming through to the Nagios Server, you can also see the
browser open and the script run on the Fedora 17 system.

Using Nagios with Selenium scripts


Firstly we must add the Selenium check to our plugin directory usually /usr/local/nagios/libexec:
The check may be found here:
wget http://assets.nagios.com/downloads/nagiosxi/scripts/check_selenium
Once the plugin has been added, from the Nagios terminal make sure you are in the libexec directory and run the following:
chmod 755 check_selenium
./check_selenium script=/usr/local/nagios/libexec/simpletest
What the check_selenium script is doing is running
the simpletest script and returning the data all at
once at the end in a friendly way readable by Nagios.

Adding The Command And Service to Nagios XI


From the Nagios XI Navigation bar
select Configure > Core Config
Manager > Commands > Add New.
Here fill in the Command Management
boxes with the following:

Nagios Enterprises, LLC US: 1-888-NAGIOS-1


P.O. Box 8154
Int'l: +1 651-204-9102
Saint Paul, MN 55108
Fax: +1 651-204-9103
USA

Web: www.nagios.com
Email: sales@nagios.com

Page 5
Copyright 2010-2011 Nagios Enterprises, LLC
Revision 1.0 October, 2013

Integrating Selenium with Nagios XI


Command* Box:
Selenium Check
(Note: You can chose a name to match your requirements)
Command line* Box:
$USER1$/selenium_runner script=$USER1$/$ARG1$
Command Type Box:
check command
Then click Save.

Now while still in the Core Config Manager select Services from the Monitoring drop down on the left side and click Add New.
From the Common Settings tab we will fill in the boxes with the following:
Config Name* Box:
Selenium Nagios
(Note: You can chose a name to match your
requirements)
Hosts* Box:
Select the Host on which the Selenium Server is running, for
the purposes of this document the Fedora 17 Host will be
selected.

Service description* Box:


Web Interface Navigation Check
(Note: You can chose a name to match your requirements)
Check Command* Dropdown:
Selenium Check
(Note: Select the check name for the command that was specified earlier)
$ARG1$ Box:
simpletest
(Note: place the Selenium script's name here)
And finally select the generic-service Template and click Save.
You will be brought back to the Service Management selection and from here click Apply Configuration.

Nagios Enterprises, LLC US: 1-888-NAGIOS-1


P.O. Box 8154
Int'l: +1 651-204-9102
Saint Paul, MN 55108
Fax: +1 651-204-9103
USA

Web: www.nagios.com
Email: sales@nagios.com

Page 6
Copyright 2010-2011 Nagios Enterprises, LLC
Revision 1.0 October, 2013

Integrating Selenium with Nagios XI


Finishing Thoughts
The Selenium server should now be monitoring this Nagios check and reporting back as a Service which is viewable from Views >
Service Detail.

For any support related questions please visit the Nagios Support Forums at:
http://support.nagios.com/forum/

Nagios Enterprises, LLC US: 1-888-NAGIOS-1


P.O. Box 8154
Int'l: +1 651-204-9102
Saint Paul, MN 55108
Fax: +1 651-204-9103
USA

Web: www.nagios.com
Email: sales@nagios.com

Page 7
Copyright 2010-2011 Nagios Enterprises, LLC
Revision 1.0 October, 2013

Vous aimerez peut-être aussi