HttpMonitor

The HTTP monitor tests the response of an HTTP server on a specific HTTP 'GET' command. During the poll, an attempt is made to connect on the specified port(s). The monitor can test web server on multiple ports. By default the test is made against port 80, 8080 and 8888. If the connection request is successful, an HTTP 'GET' command is sent to the interface. The response is parsed and a return code extracted and verified. This monitor implements placeholder substitution in parameter values.

Monitor Facts

Class Name

org.opennms.netmgt.poller.monitors.HttpMonitor

Remote Enabled

true

Configuration and Use

Table 1. Monitor specific parameters for the HttpMonitor
Parameter Description Required Default value Placeholder substitution

basic-authentication

Authentication credentials to perform basic authentication.
Credentials should comply to RFC1945 section 11.1, without the Base64 encoding part. That’s: be a string made of the concatenation of:
1- the user ID;
2- a colon;
3- the password.
basic-authentication takes precedence over the user and password parameters.

optional

-

Yes

header[0-9]+

Additional headers to be sent along with the request.
Example of valid parameter’s names are
header0, header1 and header180. header is not a valid parameter name.

optional

-

No

host-name

Specify the Host header’s value.

optional

-

No

nodelabel-host-name

If the host-name parameter isn’t set and the resolve-ip parameter is set to false, then Horizon will use the node’s label to set the Host header’s value if this parameter is set to true. Otherwise, Horizon will fall back using the node interface’s IP address as Host header value.

optional

false

No

password

This parameter is meant to be used together with the user parameter to perform basic
authentication. This parameter specifies the password to be used. The user and password
parameters are ignored when the basic-authentication parameter is defined.

optional

empty string

Yes

port

A list of TCP ports to which connection shall be tried.

optional

80,8080,8888

No

retry

Number of attempts to get a valid HTTP response/response-text

optional

0

No

resolve-ip

If the host-name parameter isn’t set and this parameter is set to true, Horizon will use DNS to resolve the node interface’s IP address, and use the result to set the Host header’s value. When set to false and the host-name parameter isn’t set, Horizon will try to use the nodelabel-host-name parameter to set the Host header’s value.

optional

false

No

response

A comma-separated list of acceptable HTTP response code ranges. Example: 200-202,299

optional

If the url parameter is set to /, the default
value for this parameter is 100-499, otherwise it’s 100-399.

No

response-text

Text to look for in the response body. This will be matched against every line, and it will be considered a success at the first match. If there is a ~ at the beginning of the parameter, the rest of the string will be used as a regular expression pattern match, otherwise the match will be a substring match. The regular expression match is anchored at the beginning and end of the line, so you will likely need to put a .* on both sides of your pattern unless you are going to be matching on the entire line.

optional

-

No

url

URL to be retrieved via the HTTP 'GET' command

optional

/

Yes

user

This parameter is meant to be used together with the password parameter to perform basic authentication. This parameter specifies the user ID to be used. The user and password parameters are ignored when the basic-authentication parameter is defined.

optional

-

Yes

user-agent

Specifies the User-Agent HTTP header. (Also see RFC2616 section 14.43.)

optional

OpenNMS HttpMonitor

Yes

verbose

When set to true, full communication between client and the webserver will be logged (with a log level of DEBUG).

optional

-

No

This monitor implements the Common Configuration Parameters.

Examples

<!-- Test HTTP service on port 80 only -->
<service name="HTTP" interval="300000" user-defined="false" status="on">
  <parameter key="retry" value="2"/>
  <parameter key="timeout" value="3000"/>
  <parameter key="port" value="80"/>
  <parameter key="url" value="/"/>
</service>

<!-- Test for virtual host opennms.com running -->
<service name="OpenNMSdotCom" interval="300000" user-defined="false" status="on">
  <parameter key="retry" value="1"/>
  <parameter key="timeout" value="3000"/>
  <parameter key="port" value="80"/>
  <parameter key="host-name" value="opennms.com"/>
  <parameter key="url" value="/solutions"/>
  <parameter key="response" value="200-202,299"/>
  <parameter key="response-text" value="~.*[Cc]onsulting.*"/>
</service>

<!-- Test for instance of OpenNMS 1.2.9 running -->
<service name="OpenNMS-129" interval="300000" user-defined="false" status="on">
  <parameter key="retry" value="1"/>
  <parameter key="timeout" value="3000"/>
  <parameter key="port" value="8080"/>
  <parameter key="url" value="/opennms/event/list"/>
  <parameter key="basic-authentication" value="admin:admin"/>
  <parameter key="response" value="200"/>
</service>

<!-- Test for instance of OpenNMS 1.2.9 with parameter substitution in basic-authentication parameter -->
<service name="OpenNMS-22" interval="300000" user-defined="false" status="on">
  <parameter key="retry" value="1"/>
  <parameter key="timeout" value="3000"/>
  <parameter key="port" value="8080"/>
  <parameter key="url" value="/opennms/event/list"/>
  <parameter key="basic-authentication" value="\{username\}:{password}"/>
  <parameter key="response" value="200"/>
</service>
<monitor service="HTTP" class-name="org.opennms.netmgt.poller.monitors.HttpMonitor" />
<monitor service="OpenNMSdotCom" class-name="org.opennms.netmgt.poller.monitors.HttpMonitor" />
<monitor service="OpenNMS-129" class-name="org.opennms.netmgt.poller.monitors.HttpMonitor" />
<monitor service="OpenNMS-22" class-name="org.opennms.netmgt.poller.monitors.HttpMonitor" />

Testing filtering proxies with HttpMonitor

In case a filtering proxy server is set up to allow retrieval of some URLs but deny others, the HttpMonitor can be used to verify this behavior.

As an example a proxy server is running on TCP port 3128, and serves http://www.opennms.org/ but never http://www.myspace.com/. To test this behaviour, the HttpMonitor can be configured as the following:

<service name="HTTP-Allow-opennms.org" interval="300000" user-defined="false" status="on">
  <parameter key="retry" value="1"/>
  <parameter key="timeout" value="3000"/>
  <parameter key="port" value="3128"/>
  <parameter key="url" value="http://www.opennms.org/"/>
  <parameter key="response" value="200-399"/>
</service>

<service name="HTTP-Block-myspace.com" interval="300000" user-defined="false" status="on">
  <parameter key="retry" value="1"/>
  <parameter key="timeout" value="3000"/>
  <parameter key="port" value="3128"/>
  <parameter key="url" value="http://www.myspace.com/"/>
  <parameter key="response" value="400-599"/>
</service>

<monitor service="HTTP-Allow-opennms.org" class-name="org.opennms.netmgt.poller.monitors.HttpMonitor"/>
<monitor service="HTTP-Block-myspace.com" class-name="org.opennms.netmgt.poller.monitors.HttpMonitor"/>