I am trying to monitor a website so that if this XML content is not present then I need Nagios to send out a notification. I can get Nagios to return the text withing the <>text</> but not the <item> stuff.
For example if I access the site URL I get a long listing, XML format. I want to monitor to see if <AgentId> is present. If I monitor CL00053167 it works or if I just monitor CL or CINCINNATI any of the data between the values it works. This is all dynamic so I just want to monitor to validate there is data appearing. I figured it would be easier to check for <AgentId> but can't get it to work.
This XML file does not appear to have any style information associated with it. The document tree is shown below.
<ArrayOfAgentLocation xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07 ... MVC.Models">
<AgentLocation>
<AgentId>CL00053167</AgentId>
<City>CINCINNATI</City>
<DistanceInKilometers>14.59196</DistanceInKilometers>
<DistanceInMiles>9.067023</DistanceInMiles>
<Email>[email protected]</Email>
<Latitude>39.0688</Latitude>
<LocationId>239</LocationId>
<Longitude>-84.35329</Longitude>
<Name>AGENCY DEVELOPMENT CORPORATION</Name>
<Phone>5134698999</Phone>
<State>OH</State>
<StreetAddress1>1080 NIMITZVIEW DR STE 301</StreetAddress1>
<StreetAddress2 i:nil="true"/>
<StreetAddress3 i:nil="true"/>
<StreetAddress4 i:nil="true"/>
<Zip>45230</Zip>
Here is the check I am using:
./check_http -H <host> -s "CINCINNATI" -f ok -u "/api/agent/getByZip?zipcode=45102&maximumAgents=10" -S -p 443
HTTP OK: HTTP/1.1 200 OK - 4076 bytes in 0.571 second response time |time=0.571009s;;;0.000000 size=4076B;;;0
./check_http -H <host> -s "<AgentId>" -f ok -u "/api/agent/getByZip?zipcode=45102&maximumAgents=10" -S -p 443
HTTP CRITICAL: HTTP/1.1 200 OK - string '<AgentId>' not found on 'https://columbuslife.com:443/api/agent/ ... mAgents=10' - 4076 bytes in 0.358 second response time |time=0.358072s;;;0.000000 size=4076B;;;0
Check website content
Re: Check website content
You could try a regex match. It might look like this (if i'm using your provided XML):
And if I remove that element:
The regex i'm using assumes only alpha-numeric values for AgentId.
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ArrayOfAgentLocation xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WSFG.CLIC.Public.MVC.Models">
<AgentLocation>
<AgentId>CL00053167</AgentId>
<City>CINCINNATI</City>
<DistanceInKilometers>14.59196</DistanceInKilometers>
<DistanceInMiles>9.067023</DistanceInMiles>
<Email>[email protected]</Email>
<Latitude>39.0688</Latitude>
<LocationId>239</LocationId>
<Longitude>-84.35329</Longitude>
<Name>AGENCY DEVELOPMENT CORPORATION</Name>
<Phone>5134698999</Phone>
<State>OH</State>
<StreetAddress1>1080 NIMITZVIEW DR STE 301</StreetAddress1>
<StreetAddress2 i:nil="true"/>
<StreetAddress3 i:nil="true"/>
<StreetAddress4 i:nil="true"/>
<Zip>45230</Zip>
...
[root@xi-stable html]# /usr/local/nagios/libexec/check_http -H 192.168.67.1 -u /nagiosxi/response.xml -r '(<AgentId>)[a-zA-Z0-9]*(<\/AgentId>)'
HTTP OK: HTTP/1.1 200 OK - 1019 bytes in 0.000 second response time |time=0.000370s;;;0.000000 size=1019B;;;0
Code: Select all
<?xml version="1.0" encoding="UTF-8"?>
<ArrayOfAgentLocation xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/WSFG.CLIC.Public.MVC.Models">
<AgentLocation>
<City>CINCINNATI</City>
<DistanceInKilometers>14.59196</DistanceInKilometers>
<DistanceInMiles>9.067023</DistanceInMiles>
<Email>[email protected]</Email>
<Latitude>39.0688</Latitude>
<LocationId>239</LocationId>
<Longitude>-84.35329</Longitude>
<Name>AGENCY DEVELOPMENT CORPORATION</Name>
<Phone>5134698999</Phone>
<State>OH</State>
<StreetAddress1>1080 NIMITZVIEW DR STE 301</StreetAddress1>
<StreetAddress2 i:nil="true"/>
<StreetAddress3 i:nil="true"/>
<StreetAddress4 i:nil="true"/>
<Zip>45230</Zip>
...
[root@xi-stable html]# /usr/local/nagios/libexec/check_http -H 192.168.67.1 -u /nagiosxi/response.xml -r '(<AgentId>)[a-zA-Z0-9]*(<\/AgentId>)'
HTTP CRITICAL: HTTP/1.1 200 OK - pattern not found - 989 bytes in 0.000 second response time |time=0.000311s;;;0.000000 size=989B;;;0Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: Check website content
This isn't working for me. The web url is which I believe you should be able to access.
Code: Select all
https://www.columbuslife.com/api/agent/getByZip?zipCode=45102&maximumAgents=10 Re: Check website content
Ah, I think this API is returning JSON for CURL calls rather than XML:
We'll need to alter the regex in this case. Also, it looks as if there's a 301 redirect forcing HTTPS so we'll need to account for that with the -S argument.
Try revising your command like so:
Code: Select all
[root@xi-stable scripts]# /usr/local/nagios/libexec/check_http -H www.columbuslife.com -u '/api/agent/getByZip?zipCode=45102&maximumAgents=10' -S -r '(<AgentId>)[a-zA-Z0-9]*(<\/AgentId>)'
HTTP CRITICAL: HTTP/1.1 200 OK - pattern not found - 4076 bytes in 0.540 second response time |time=0.539503s;;;0.000000 size=4076B;;;0
[root@xi-stable scripts]# /usr/local/nagios/libexec/check_http -H www.columbuslife.com -u '/api/agent/getByZip?zipCode=45102&maximumAgents=10' -S -r '(<AgentId>)[a-zA-Z0-9]*(<\/AgentId>)' -v
GET /api/agent/getByZip?zipCode=45102&maximumAgents=10 HTTP/1.1
User-Agent: check_http/v2.0.3 (nagios-plugins 2.0.3)
Connection: close
Host: www.columbuslife.com
Accept: */*
https://www.columbuslife.com:443/api/agent/getByZip?zipCode=45102&maximumAgents=10 is 4076 characters
STATUS: HTTP/1.1 200 OK
**** HEADER ****
Content-Length: 3821
Content-Type: application/json; charset=utf-8
Server: Microsoft-IIS/8.5
X-Powered-By: ASP.NET
Access-Control-Allow-Origin: http://wswebcms.app.wsfgrp.net
Date: Mon, 30 Jan 2017 17:59:42 GMT
Connection: close
**** CONTENT ****
[{"agentId":"CL00053167","name":"AGENCY DEVELOPMENT CORPORATION","streetAddress1":"1080 NIMITZVIEW DR STE 301","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"CINCINNATI","state":"OH","zip":"45230","latitude":39.0688,"longitude":-84.35329,"locationId":239,"phone":"5134698999","email":"[email protected]","distanceInMiles":9.067023,"distanceInKilometers":14.59196},{"agentId":"CL00051047","name":"REGINA BRUMLEY-REBHOLZ","streetAddress1":"8914 CONSTABLE DRIVE","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"ALEXANDRIA","state":"KY","zip":"41001","latitude":38.94528,"longitude":-84.39078,"locationId":190,"phone":"8594480261","email":"[email protected]","distanceInMiles":11.6840935,"distanceInKilometers":18.8037262},{"agentId":"CL00053875","name":"JERRY TAYLOR JR","streetAddress1":"258 VAN VOAST AVE","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"BELLEVUE","state":"KY","zip":"41073","latitude":39.10704,"longitude":-84.47947,"locationId":558,"phone":"5135493555","email":"[email protected]","distanceInMiles":16.3376884,"distanceInKilometers":26.2929611},{"agentId":"CL00053818","name":"SOLIDO INSURANCE LLC","streetAddress1":"5076 VILLAGE DR","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"CINCINNATI","state":"OH","zip":"45244","latitude":39.12098,"longitude":-84.33235,"locationId":264,"phone":"5133210069","email":"[email protected]","distanceInMiles":10.0751143,"distanceInKilometers":16.214325},{"agentId":"CL00023680","name":"GARY PERKINS","streetAddress1":"5143 WINTERS LANE","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"COLD SPRING","state":"KY","zip":"41076","latitude":39.03047,"longitude":-84.43647,"locationId":31,"phone":"8597503653","email":"[email protected]","distanceInMiles":12.922677,"distanceInKilometers":20.7970333},{"agentId":"CL00059956","name":"OJM GROUP LLC","streetAddress1":"8044 MONTGOMERY RD STE 440","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"CINCINNATI","state":"OH","zip":"45236","latitude":39.20123,"longitude":-84.37081,"locationId":524,"phone":"5137917525","email":"[email protected]","distanceInMiles":15.6088552,"distanceInKilometers":25.120018},{"agentId":"CL00055581","name":"WILSON BROKERAGE SERVICES INC","streetAddress1":"8040 HOSBROOK RD STE 300","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"CINCINNATI","state":"OH","zip":"45236","latitude":39.20506,"longitude":-84.37084,"locationId":343,"phone":"5138916600","email":"[email protected]","distanceInMiles":15.8223295,"distanceInKilometers":25.4635715},{"agentId":"CL00047571","name":"MCF ADVISORS LLC","streetAddress1":"50 E RIVERCENTER BLVD STE 300","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"COVINGTON","state":"KY","zip":"41011","latitude":39.09007,"longitude":-84.51028,"locationId":131,"phone":"8593921371","email":"[email protected]","distanceInMiles":17.5327148,"distanceInKilometers":28.21617},{"agentId":"CL00040491","name":"ANTHONY BUTZ","streetAddress1":"1 W 4TH ST STE 110","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"CINCINNATI","state":"OH","zip":"45202","latitude":39.09961,"longitude":-84.51293,"locationId":92,"phone":"5136216030","email":"[email protected]","distanceInMiles":17.8590145,"distanceInKilometers":28.7412968},{"agentId":"CL00051268","name":"GEORGE NIKIAS","streetAddress1":"12125 VILLAGE WOODS DR","streetAddress2":null,"streetAddress3":null,"streetAddress4":null,"city":"CINCINNATI","state":"OH","zip":"45241","latitude":39.2937,"longitude":-84.3871,"locationId":207,"phone":"5137331255","email":"[email protected]","distanceInMiles":21.4759865,"distanceInKilometers":34.56225}]
HTTP CRITICAL: HTTP/1.1 200 OK - pattern not found - 4076 bytes in 1.118 second response time |time=1.117549s;;;0.000000 size=4076B;;;0
Try revising your command like so:
Code: Select all
[root@xi-stable scripts]# /usr/local/nagios/libexec/check_http -H www.columbuslife.com -u '/api/agent/getByZip?zipCode=45102&maximumAgents=10' -S -r '("agentId":")[a-zA-Z0-9]*(")'
HTTP OK: HTTP/1.1 200 OK - 4076 bytes in 0.476 second response time |time=0.476318s;;;0.000000 size=4076B;;;0
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
Re: Check website content
Awesome...that did the trick.
This is the first check I've had with RegEx so it is nice to see how that is done.
Thanks again and feel free to lock this one at your convenience.
This is the first check I've had with RegEx so it is nice to see how that is done.
Thanks again and feel free to lock this one at your convenience.
-
dwhitfield
- Former Nagios Staff
- Posts: 4583
- Joined: Wed Sep 21, 2016 10:29 am
- Location: NoLo, Minneapolis, MN
- Contact:
Re: Check website content
Glad to hear it is resolved. I am going to lock the thread. Please feel free to post again if you have you another issue. Thank you for using the Nagios forums!