You can use a ZenCommand plugin (check_http) to check for specific content of a web page (implicitly checking for server/page 200 status as well).
An example of setting up a ZenCommand plugin to check specific content is:
-
1.Make sure you are the zenoss user.
-
Test the plugin from the command line. Once its working we will integrate it with Zenoss. check_http -h will display all plugin options. Here is the command to test the product directory.
$ZENHOME/libexec/check_http -H www.zenoss.com
If the check_http command is correct, the output will look similar to the following.
HTTP OK HTTP/1.0 200 OK - 0.723 second response time |time=0.722758s;;;0.000000 size=7932B;;;0
You can see that this command plugin returns a valid value we are ready for the next step.
-
-
Add the device you want to check (one running a www. website) to the Zenoss system setting the discovery protocol to 'none'.
-
Navigate to the device in the Zenoss system and use the page menu to select More and then Templates.
-
Click Create Local Copy button.
You have now overridden the default Device template with one specific to this device.
-
Drill into the template and remove the sysUpTime data source since we won’t be using SNMP for this device.
-
Add a new description to the template something like “Web testing template”.
-
Add a new Data Source called rootWebCheck.
-
Drill into rootWebCheck and set the following variables:
-
Source Type = COMMAND
-
Component = rootWebCheck
-
Cycle Time = 30
-
-
Debug your ZenCommand by running zencommand in the foreground with debugging on.
zencommand run -d www.website.com -v10
Where www.website.com is the site you are trying to monitor.
-
The command template field is a TALES expression so we can do some substitution in our command that will make it generic for any device we add to this class. First let’s set the -H flag to be the IP of the device against which this command will be run.
check_http -H ${here/manageIp}
-
Now let’s add a check looking for content on the page. The -r flag will run a regular expression against the web page to check for text. We will look for three pieces of text:
check_http -H ${here/manageIp}-r textstring1
Where textsrting1 is some text you know to be displayed on the resulting webpage.
-
For this example, you want this command to be generic, so make a custom field for the regex that can be changed per device. Set the default to “.*” which will match everything. Go to /Devices/Custom Schema and add a new field:
-
Label = Web Match Regex
-
Name = cWebMatchRegex
-
Type = string
-
Default = .*
-
Visible = True
-
-
Now go back our template and change the command to be.
check_http -H ${here/manageIp}-r ${here/cWebMatchRegex}
-
Now add the regex value into cWebMatchRegex that we used in the example above.
-
Test your ZenCommand from the command line.