3

Attempt

check_http -H www.example.com -f follow -p 8080 -u /hello/#/world -s "content"

Result

HTTP WARNING: HTTP/1.1 404 Not Found - X bytes in 0.00X second response time |time=0.00XYZ

Analysis

Although multiple sources have been read [1,2,3,4 ] and a Wget, i.e. wget www.example.com:8080/hello/#/world returns an OK it is unclear whether the check_http does not work.

Perhaps the # is causing an issue. According to this documentation the # is an anchor which means that if var x that x is #/world, but this does not help to solve the issue.

Downloading www.example.com using wget and subsequently inspect the world button indicates that this button is associated with a javascript source. This finding did not help to solve the issue either.


Attempt two

check_http -H www.example.com -f follow -p 8080 -u /hello/\#/world -v

Result two

GET /hello/#/world HTTP/1.1
User-Agent: check_http/vX (nagios-plugins X)
Connection: close
Host: www.example.com:8080


http://www.example.com:8080/hello/#/world is X characters
STATUS: HTTP/1.1 404 Not Found
**** HEADER ****
Server: Apache-Coyote/X
Content-Type: text/html;charset=utf-8
Content-Length: X
Date: Thu, Day Month Year Time GMT
Connection: close
**** CONTENT ****
<html><head><title>ApplicationServer - Error report</title><style></style> </head><body><h1>HTTP Status 404 - /hello/#/world</h1><p><b>type</b> Status report</p><p><b>message</b> <u>/hello/#/world</u></p><p><b>description</b> <u>The requested resource (/hello/#/world) is not available.</u></p><h3>ApplicationServer</h3></body></html>
HTTP WARNING: HTTP/1.1 404 Not Found - X bytes in 0.00X second response time |time=0.00Xs;;;0.000000 size=XB;;;0

Analysis Two

Functional

If one would like to view http://www.example.com:8080/hello/#/world, one has to navigate to http://www.example.com:8080/hello and click on the world button. The content can be viewed and inspected using firebug once the button has been clicked.

Technical

The URL is downloaded using Wget. The page contains multiple JavaScript sources which represent the buttons, e.g.:

<script src="button.js"></script>
<script src="world.js"></script>

There is a discrepancy between the Functional and Technical view. Content which can be viewed and inspected using Firebug is omitted in the page downloaded using Wget.

030
  • 5,901
  • 13
  • 68
  • 110
  • Are you actually receiving a redirect? What is really going on with this request? – Michael Hampton Oct 23 '14 at 17:58
  • @MichaelHampton it seems that the buttons are represented via JavaScript. – 030 Oct 23 '14 at 22:43
  • Hmm. And you aren't supposed to send the URL fragment to the server anyway. – Michael Hampton Oct 23 '14 at 22:45
  • @John I have tried to debug the issue using verbose logging and inspecting the URL by downloading it using Wget and viewing the elements and trying to understand what happens once the button `world` has been clicked. – 030 Oct 23 '14 at 22:47
  • @MichaelHampton When I view the page and click the button I can view the content and inspect it using firebug. However, if a Wget is issued and the page is inspected, there is a discrepancy. The information found using firebug seems to be omitted in the page downloaded using Wget. – 030 Oct 23 '14 at 22:50

3 Answers3

1

The # is in anchor, that's correct. Those are to be interpreted by the client, not the server. The anchor is part of the site,so one has to load the whole site and search for the anchor in it.

You should use the following check instead:

check_http -H www.example.com -f follow -p 8080 -u /hello/

Later you could add -s world to search for "world" in the HTML content (if it is there and not added via another layer of JavaScript).

zhenech
  • 1,492
  • 9
  • 13
  • Thank you for posting an answer. Executing the command returns an `HTTP OK: HTTP/1.1 200 OK`. Once the command has been issued the content of the page is displayed. Comparing this with the functional view, the `world` button is omitted and represented as ``. Grepping `world` using -s works, but the content which should be displayed once the `world` button has been clicked would like to be inspected. – 030 Oct 24 '14 at 06:51
  • The `check_http` command in the question has been updated. The question itself has been updated as well. – 030 Oct 24 '14 at 06:57
  • Regarding `if it is there and not added via another layer of JavaScript`. It looks like that the HTML content on `/hello` is added via a layer of JavaScript as well. – 030 Oct 24 '14 at 07:06
  • `check_http` is a mere HTTP client, not a full browser. As such it won't execute JavaScript and you have to get a bit creative here. A possible solution would be: first check with `-u /hello/` that `world.js` is included in the page, then use `-u /hello/world.js` to get the actual JavaScript and look if it contains either the needed content or the loader for the content. In the later case, issue `-u /whereever/content` to get and inspect the content. All two or three checks green → you are good (`check_multi` is your friend here). – zhenech Oct 24 '14 at 07:43
  • I have called the `world.js` using `check_http`, but the JavaScript function is shown instead that it is called. The discrepancy between the functional and technical view remains. – 030 Oct 24 '14 at 17:26
1

The check_http plugin will only see what wget/curl shows you, so it cannot check what you want it to check.

If you want a check that can actually run client-side javascript, you'll need to look into something like WebInject with check_webinject, Selenium with check_selenium (as discussed in this post), or maybe Sahi and Sakuli.

Keith
  • 4,637
  • 15
  • 25
0

I found the phantomjs-nagios plugin (check_http_load_time.rb) very helpful in such a scenario, where a web-application with JavaScript should be rendered.

The plugin uses phantomjs in the background to let the whole page render and therefore simulate a browser of an end-user. It will output the total render time and also shows the number of requests and loaded dom elements:

$ ./check_http_load_time.rb -u "https://myapp.example.com/#load" -P -w 5 -c 10
OK: https://myapp.example.com/#load load time: 1.14 | load_time=1142.0ms size=428013 requests=39 dom_elements=55 load_time_initial_req=194ms

The plugin also supports thresholds where you can for example define a threshold range for loaded elements, requests or the total size.

See https://github.com/hggh/phantomjs-nagios/blob/master/check_http_load_time.rb for more details.

Note 1: Phantomjs is not developed anymore.

Note 2: As this plugin relies on Phantomjs, the plugin development has stopped, too.

Note 3: Phantomjs package on Ubuntu 18.04 is broken and the plugin might throw a Could not parse JSON from phantomjs back at you. In this case install the newest version from https://phantomjs.org/download.html and tell the plugin to use an alternative path to phantomjs using the -p parameter.