There are couple of plugins available to check website response time and availability but lets check how webinject checks can be helpful.
Installing Webinject
1. Download webinject source and extract it in your Nagios plugins directory.
http://www.webinject.org/download.html
2. After you extract, you may need to install perl modules. I had to install below mentioned modules. I used "cpan" command to install modules. You may need to install additional modules according to your server setup.
Note: You can identify which modules needs to be install by running below command.
Look at text marked in bold. This shows missing perl modules. So you can simply run below cpan command.
3. Now you can check if webinject script will work or not using below command. Once you are done with verification, you can start creating webinject script.
You should not see any perl modules errors in above command's output. If everything goes fine, you will see result of testcase execution.
Creating Webinject Test script
In this example we will create script to check availability of www.sysadminhub.in and we will check if "System Administrator's Hub" text is available or not. If that text is not present then we can send generate error.
How to use with Nagios
Here apart from testcase we will have to create config file for each testcase. You can specify different globaltimeout option for different testcase. I have set below content for my script.
Installing Webinject
1. Download webinject source and extract it in your Nagios plugins directory.
http://www.webinject.org/download.html
2. After you extract, you may need to install perl modules. I had to install below mentioned modules. I used "cpan" command to install modules. You may need to install additional modules according to your server setup.
cpan
> install Crypt::SSLeay
Note: You can identify which modules needs to be install by running below command.
[root@ip-10-126-117-63 webinject]# ./webinject.pl -c testcases.xml
Can't locate Crypt/SSLeay.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at ./webinject.pl line 27.
BEGIN failed--compilation aborted at ./webinject.pl line 27.
Look at text marked in bold. This shows missing perl modules. So you can simply run below cpan command.
[root@ip-10-126-117-63 webinject]#cpan
cpan[1]> install Crypt::SSLeay
3. Now you can check if webinject script will work or not using below command. Once you are done with verification, you can start creating webinject script.
[root@ip-10-126-117-63 webinject]# ./webinject.pl -c testcases.xml
You should not see any perl modules errors in above command's output. If everything goes fine, you will see result of testcase execution.
Creating Webinject Test script
In this example we will create script to check availability of www.sysadminhub.in and we will check if "System Administrator's Hub" text is available or not. If that text is not present then we can send generate error.
<testcases repeat="1">
<case
id="1"
description1="Check if www.sysadminhub.in is available"
description2="This will check response code. If it is not 200 then it will show error"
method="get"
url="http://www.sysadminhub.in"
verifyresponsecode="200"
/>
<case
id="2"
description1="In this case we will check for text 'System Administrator's Hub'"
description2="If that text is missing in page then it will generate error"
method="get"
url="http://www.sysadminhub.in"
verifypositive="System Administrator's Hub"
/>
</testcases>
In above script we have used "get" method and verifyresponsecode & verifypositive are to check response code of site and check text from site respectively.
How to use with Nagios
Here apart from testcase we will have to create config file for each testcase. You can specify different globaltimeout option for different testcase. I have set below content for my script.
<testcasefile>testcase.xml</testcasefile>
<useragent>WebInject Application Tester</useragent>
<timeout>10</timeout>
<globaltimeout>20</globaltimeout>
<reporttype>nagios</reporttype>
Here "reporttype" is the important factor. This will produce output which Nagios can use to parse performance data. So after creating your testcase and config xml, you can use below mentioned command.
[root@ip-10-126-117-63 webinject]# ./webinject.pl -c config.xml testcases.xml WebInject OK - All tests passed successfully in 3.237 seconds |time=3.237;;;0