VMware Cloud Community
watership
Contributor
Contributor

Monitor HTTP content

Hi,

How can you monitor the HTML content of a response from a HTTP service? In HQ (4.6.6, open source), I created a HTTP service to fetch the HTML (which is dynamically created by python).

  • The HTML specificies the service' status. If one of its components is malfunctioning it will put the text 'ERROR' into the html.
  • The service will always return a HTTP 200, so the status code cannot be used for monitoring.

The HTTP service is configured as follows:
  • GET Method
  • Pattern field: empty
  • service.log_track.enable: true
  • service.log_track.level: ERROR         (Is this relevant? It's not a log file but an unstructured html)

The alert definition:

  • If condition: Events/logs Level ANY and match substring ERROR

It's unclear if the log settings in the HTTP service and alert definition also apply to filtering HTTP content. I tried several combinations but none seem to work.

Egon

0 Kudos
1 Reply
watership
Contributor
Contributor

I created a workaround: a script plugin that calls a shell script which in turn calls a Python script that fetches and filters the html page. See the files below. Hopefully somebody knows how to perform the test via the HTTP service because this workaround is a bit kludgy.

htmlfilter.sh  (to be called by the Hyperic script plugin)
--------------------------------------------------------------------------------------
#!/bin/bash
url=$1
filter=$2
status=`python /home/hyperic/script/htmlfilter.py $url $filter`
echo $status

htmlfilter.py  (to be called by the htmlfilter shell script)
--------------------------------------------------------------------------------------
## Python 2.7
import sys,urllib
url = sys.argv[1]
searchstr = sys.argv[2]
response = urllib.urlopen(url)
html = str(response.read())
response.close()
if html.find(searchstr) == -1:
        print("status=0")
else:
        print("status=1")

htmlfilter-plugin.xml   (Hyperic script plugin)
-----------------------------------------------------------------------
<plugin>
  <service name="HtmlFilter">
  <config>
    <option name="script"
            description="HTML page filter"
            default="/home/hyperic/script/htmlfilter.sh"/>
    <option name="url"
            description="URL"/>
    <option name="filter"
            description="Filter"
            default="ERROR"/>
  </config>
  <filter name="template-exec"
          value="exec:file=%script%,args=%url% %filter%"/>
  <metric name="HtmlFilter"
          category="PERFORMANCE"
          indicator="true"
          interval="600000"
          template="${template-exec}:status"/>
</service>
</plugin>
0 Kudos