check_http capturing or verifying certain property in JSON http response
Shijith Thomas <[email protected]> Mon, 22 Oct 2018 19:17:36 +0530
| Newsgroups | gmane.network.nagios.plugins |
|---|---|
| Message-ID | <CAMyA_fe9o0cghxNKO2o2CryZj_=cVd0Sc=PRNFFwKG=qD8WDHg__768.046713392501$1540215950$gmane$org@mail.gmail.com> |
--000000000000a042f90578d17f25
Content-Type: text/plain; charset="UTF-8"
Hello Team,
I'm using check_http plugin for nagios alerting. Till now, i was using the
http status code to raise the alerts.
but recently, i was asked to verify some json http response along with the
http status code where i need to modify my nrpe.cfg file.
check_http -H xxxxx.xxx -S -k 'Host: xxxx.xxx' -k 'Test: Test' -p 443 -j
> POST -T 'application/x-www-form-urlencoded' -P 'name:xyz' -a 'xyz123:
> 123xyz' -u '/a/b/c?Redirect_URL=https://www.google.com/' -e 'HTTP/1.1 200
> OK' -f follow -l -r 'operator:t-mobile'
Here the issue i face is, i am able to detect the status code, but i am not
able to match the regex pattern which i get in http response(JSON)
Sample response suing the curl is :
{
"a": 12332423452,
"response": {
"test": "test1",
"abc": "abc",
"operator": "t-mobile",
"country": "india",
"currency": "Rupee",
},
"id":
> "419E2BD429C1C8E7459911268513C9B5EE3C2AD0E4BE5C528952D6A89DE8D6E2C6623494ADA60C1AAF0462C30CB71874D86D1CFEBEBE26E59DA9654B5ABC9E0916CCD5D88097163AC9ED87B43E00549A86C818700C5B3E561CF0AB9ADC0AB7FA9C072175B4495034CF7F3313CA8D154DA086F9B86EFF3212"
}
I even tried using the -s flag where we can use expected string, but the id
field in the response will be keep changing, which made me to check for
regex.
*Output: *HTTP CRITICAL: Status line output matched "HTTP/1.1 200 OK" -
> HTTP/1.1 200 OK - pattern not found - 9987 bytes in 0.938 second response
> time |time=0.938158s;;;0.000000 size=9987B;;;0
Any suggestion/help would be appreciated. Thanks
--
Regards,
Shijith Thomas
Bangalore, Karnataka
India
--000000000000a042f90578d17f25
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
<div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div dir=3D"ltr"><div di=
r=3D"ltr"><div class=3D"gmail_default" style=3D"font-size:small">Hello Team=
,=C2=A0<br><br>I'm using check_http plugin for nagios alerting. Till no=
w, i was using the http status code to raise the alerts.=C2=A0<br>but recen=
tly, i was asked to verify some json http response along with the http stat=
us code where i need to modify my nrpe.cfg file.</div><div class=3D"gmail_d=
efault" style=3D"font-size:small"><br></div><blockquote style=3D"margin:0px=
0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex" cla=
ss=3D"gmail_quote">check_http -H <span class=3D"gmail_default" style=3D"fon=
t-size:small">xxxxx.xxx</span>=C2=A0-S -k 'Host: <span class=3D"gmail_d=
efault" style=3D"font-size:small">xxxx.xxx</span>' -k 'Test: Test&#=
39; -p 443 -j POST -T 'application/x-www-form-urlencoded' -P '<=
span class=3D"gmail_default" style=3D"font-size:small">name:xyz</span>'=
-a '<span class=3D"gmail_default" style=3D"font-size:small">xyz123</sp=
an>:<span class=3D"gmail_default" style=3D"font-size:small">123xyz</span>&#=
39; -u '/<span class=3D"gmail_default" style=3D"font-size:small">a/b/c<=
/span>?Redirect_URL=3D<a href=3D"https://www.google.com/">https://www.googl=
e.com/</a>' -e 'HTTP/1.1 200 OK' -f follow -l -r 'operator:=
<span class=3D"gmail_default" style=3D"font-size:small">t-mobile</span>'=
;</blockquote><blockquote style=3D"margin:0px 0px 0px 0.8ex;border-left:1px=
solid rgb(204,204,204);padding-left:1ex" class=3D"gmail_quote">=C2=A0</blo=
ckquote><div><br></div><div class=3D"gmail_default">Here the issue i face i=
s, i am able to detect the status code, but i am not able to match the rege=
x pattern which i get in http response(JSON)<br><br>Sample response suing t=
he curl is :=C2=A0<br><br><blockquote class=3D"gmail_quote" style=3D"margin=
:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"=
>{</blockquote><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px 0p=
x 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">=C2=A0 &qu=
ot;a": 12332423452,</blockquote><blockquote class=3D"gmail_quote" styl=
e=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);paddin=
g-left:1ex">=C2=A0 "response": {</blockquote><blockquote class=3D=
"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(2=
04,204,204);padding-left:1ex">=C2=A0 =C2=A0 "test": "test1&q=
uot;,</blockquote><blockquote class=3D"gmail_quote" style=3D"margin:0px 0px=
0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">=C2=A0 =
=C2=A0 "abc": "abc",</blockquote><blockquote class=3D"g=
mail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204=
,204,204);padding-left:1ex">=C2=A0 =C2=A0 "operator": "t-mob=
ile",</blockquote><blockquote class=3D"gmail_quote" style=3D"margin:0p=
x 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">=
=C2=A0 =C2=A0 "country": "india",</blockquote><blockquo=
te class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px =
solid rgb(204,204,204);padding-left:1ex">=C2=A0 =C2=A0 "currency"=
: "Rupee",</blockquote><blockquote class=3D"gmail_quote" style=3D=
"margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-le=
ft:1ex">=C2=A0 },</blockquote><blockquote class=3D"gmail_quote" style=3D"ma=
rgin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:=
1ex">=C2=A0 "id": "419E2BD429C1C8E7459911268513C9B5EE3C2AD0E=
4BE5C528952D6A89DE8D6E2C6623494ADA60C1AAF0462C30CB71874D86D1CFEBEBE26E59DA9=
654B5ABC9E0916CCD5D88097163AC9ED87B43E00549A86C818700C5B3E561CF0AB9ADC0AB7F=
A9C072175B4495034CF7F3313CA8D154DA086F9B86EFF3212"</blockquote><blockq=
uote class=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1p=
x solid rgb(204,204,204);padding-left:1ex">}</blockquote><blockquote class=
=3D"gmail_quote" style=3D"font-size:small;margin:0px 0px 0px 0.8ex;border-l=
eft:1px solid rgb(204,204,204);padding-left:1ex">=C2=A0</blockquote></div><=
div><br></div><div><div class=3D"gmail_default" style=3D"font-size:small">I=
even tried using the -s flag where we can use expected string, but the id =
field in the response will be keep changing, which made me to check for reg=
ex.=C2=A0<br><b><br></b><blockquote class=3D"gmail_quote" style=3D"margin:0=
px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><=
b>Output:=C2=A0</b>HTTP CRITICAL: Status line output matched "HTTP/1.1=
200 OK" - HTTP/1.1 200 OK - pattern not found - 9987 bytes in 0.938 s=
econd response time |time=3D0.938158s;;;0.000000 size=3D9987B;;;0</blockquo=
te></div><br></div><div><div class=3D"gmail_default" style=3D"font-size:sma=
ll">Any suggestion/help would be appreciated. Thanks</div><br></div><div><b=
r></div>-- <br><div dir=3D"ltr" class=3D"gmail_signature"><div dir=3D"ltr">=
<div><div><font color=3D"#0c343d" face=3D"verdana, sans-serif"><span style=
=3D"background-color:rgb(243,243,243)">Regards,</span></font></div><div><fo=
nt color=3D"#0c343d" face=3D"verdana, sans-serif"><span style=3D"background=
-color:rgb(243,243,243)">Shijith Thomas</span></font></div><div><font color=
=3D"#0c343d" face=3D"verdana, sans-serif"><span style=3D"background-color:r=
gb(243,243,243)">Bangalore, Karnataka</span></font></div><div><font color=
=3D"#0c343d" face=3D"verdana, sans-serif"><span style=3D"background-color:r=
gb(243,243,243)">India</span></font></div></div></div></div></div></div></d=
iv></div></div>
--000000000000a042f90578d17f25--