Monit http response content regex behavior - regex

I am using a Logstash + Elasticsearch stack to aggregate logs from a few interrelated apps.
I am trying to get Monit to alert whenever the word 'ERROR' is returned as part of an Elasticsearch REST query from Monit, but the 'content' regex check does not seem to be working for me. (I am sending email and SMS alerts from Monit via M/Monit.)
I know my Monit and M/Monit instances are configured properly because I can get alerts for server pings and file checksum changes, etc. just fine.
My Monit Elasticsearch HTTP query looks like this:
check host elasticsearch_error with address 12.34.56.789
if failed
url http://12.34.56.789:9200/_search?q=severity%3AERROR%20AND%20timestamp%3A>now-2d
and content = "ERROR"
then alert
BTW, %20 escapes 'space', %3A escapes ':'
My logstash only has error log entries that are between one and two days old. i.e., when I run
http://12.34.56.789:9200/_search?q=severity%3AERROR%20AND%20timestamp%3A>now-2d
in the browser, I see errors (with the word 'ERROR') in the response body, but when I run
http://12.34.56.789:9200/_search?q=severity%3AERROR%20AND%20timestamp%3A>now-1d
I do not. (Note the one-day difference.) This is expected behavior. Note: my response body is a JSON with the "ERROR" string in a child element a few levels down. I don't know if this affects how Monit processes the regex.
When I run the check as above I see
'elasticsearch_error' failed protocol test [HTTP] at
INET[12.34.56.789:9200/_search
q=severity%3AERROR%20AND%20timestamp%3A>now-2d]
via TCP -- HTTP error: Regular expression doesn't match:
regexec() failed to match
in the log. Good. Content == "ERROR" is true. I can alert from this (even though I find the Connection failed message in the Monit browser dashboard a little irritating...should be something like Regex failure.)
The Problem
When I 'monit reload' and run the check with
url http://12.34.56.789:9200/_search?q=severity%3AERROR%20AND%20timestamp%3A>now-1d
I STILL get the regexec() failed to match error as above. Note, I return no "ERROR" string in the response body. Content == "ERROR" is false. Why does this check fail? Any light shed on this issue will be appreciated!
The Answer
Turns out this problem is about URL encoding for the Elasticsearch query.
I used url http://12.34.56.789:9200/_search?q=severity:ERROR&timestamp:>now-36d in the check to get Monit to make a request that looks like 12.34.56.789:9200/_search?q=severity:ERROR&timestamp:%3Enow-36d. Note change in encoding. This seems to work.
The actual URL used by monit can be seen by starting monit in debug mode using monit -vI.
Side Question
The 'content' object seems to respect '=' and '==' and '!='. '=' is referenced in the documentation, but a lot of third-party examples use '=='. What is the most correct use?
Side Question Answer
The helpful folks on the M/Monit team advise that "=" is an alias for "==" in the Monit configuration file.

I added the solution I found to my question above.

Related

SimpleSAML_Error_Error: UNHANDLEDEXCEPTION --Destination in response doesn't match the current URL

I am receiving below error when i try to login from an IDP.
Caused by: Exception: Destination in response doesn't match the current URL. Destination is "http://example.com/simplesaml/module.php/saml/sp/saml2-acs.php/SP", current URL is "https://example.com:16116/simplesaml/module.php/saml/sp/saml2-acs.php/SP".
I am using Drupal 8 and simplesamlphp_auth module.
URL matching in SimpleSAML was very particular.
You do notice that one request is using the protocol prefix 'https, while the other is using 'http'.
Additionally, the port number being reflected could throw it off.
I last worked with this technology a year and a half ago, but we did make use of hostfile switching to target different environemnts, Dev, QA, Production, etc. Avoiding the use of custom ports we had few problems on that front.
Checking the source, you can observe that the Error thrown, stems from a very literal string comparison:
https://github.com/simplesamlphp/simplesamlphp/blob/4bbcdd84ebda4c876542af582cac53bbd7056160/modules/saml/lib/Message.php#L585
Check for baseurlpath value in config.php of SimpleSAMLPHP library.
Also cross verify the RelayState in authsources.php
If required metadata also need to be updated
ref: https://groups.google.com/g/simplesamlphp/c/AcWUojq2aWg

Sitecore 9 Page Test in "Experience Optimization"

Sitecore Experience Optimization Page Testing.
I am trying to test created simple page in Experience Optimization. Locally everything working fine. When i tried same steps in Azure environment it giving me errors like below.
HTTP400: BAD REQUEST - The request could not be processed by the server due to invalid syntax.
(XHR)POST - https://mc-4b5a2ea8-f571-4c60-bf02-50220a-cm.azurewebsites.net/api/sitecore/Settings/SetUserProfileKey
HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request.
(XHR)GET - https://mc-4b5a2ea8-f571-4c60-bf02-50220a-cm.azurewebsites.net/sitecore/shell/api/ct/ItemInfo/GetByUri?datauri=sitecore%3A%2F%2F%7BED7C2C82-114C-4FB1-96A7-6CCF1F37317B%7D%3Fver%3D2%26lang%3Den&_=1518266879976
HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request.
(XHR)GET - https://mc-4b5a2ea8-f571-4c60-bf02-50220a-cm.azurewebsites.net/sitecore/shell/api/ct/ItemInfo/GetByUri?datauri=sitecore%3A%2F%2F%7BED7C2C82-114C-4FB1-96A7-6CCF1F37317B%7D%3Fver%3D2%26lang%3Den&_=1518266879972
Please check attached screenshots for same.
Update for All viewers.
Thanks to #Pete Navarra for answer.
This is a stretch... But I think you are hitting the URL max length, with the length of your domain name. Can you shorten your machine names?
I will try and keep you update on same.

Jmeter- Load testing EC2 instance, only 50% request are successful

I am trying to load test Nginx installed on an EC2 instance via Jmeter, Everytime I try to load test, only 50% request are successful,
For Eg:
If I try with 10 users, only 5 response are OK
If I try with 100 users, only 50 response are OK
If I try with 500, only 250 response are OK
Any Idea, regarding this strange behavior?
This sounds weird. I would recommend the following troubleshooting techniques:
First of all always check jmeter.log file, it should contain enough information to get to the bottom of your test failure(s).
If JMeter log file doesn't contain any suspicious entries next step would be checking response messages using i.e. View Results In Table and/or View Results Tree listener. This should provide you some high-level information and trends, i.e. you will be able to see if some particular sampler(s) is(are) always failing.
If above steps don't give enough clue to resolve your issue you can temporary enable saving of request and response data to see what is wrong with the failing sampler(s). Add the next lines to user.properties file (located in JMeter's "bin" folder)
jmeter.save.saveservice.output_format=xml
jmeter.save.saveservice.response_data=true
jmeter.save.saveservice.samplerData=true
jmeter.save.saveservice.requestHeaders=true
jmeter.save.saveservice.responseHeaders=true
jmeter.save.saveservice.url=true
and next time your run JMeter test the .jtl results file will contain all the relevant data which can be analyzed using aforementioned View Results Tree listener. Don't forget to revert the change once you fix the script as JMeter listeners are very resource intensive per se and above settings greatly increase disk IO and it may ruin your test.
If none of above helps - check logs on the application under test side, most probably you will get something from them.

catching Talend error in web Application

I have created a Talend job and deployed it as a Axis Web Service.
I am calling this Web Service from my Web Application.
My application and web service are deployed over Tomcat server.
For Valid Inputs:
Runs Perfectly.
For Invalid Inputs:
It throws Error/exceptions in Tomcat Server.
I want this Errors into my application. I didn't get any error related information in the Response sent by web service.
Error message on Tomcat Server
XML response of Web service
If I understand your question you are not so much asking how to fix this error, but how to get feedback about your error. There are several ways but here is a simple method.
Add a tLogCatcher to your job, and point its output to a tSendMail component. You can run the output thru a tMap do things like adding HTML formatting. You can also create a joblet with these two components and use the joblet in every job so you do not have to recreate it every time.
The diagram below shows a real simple case where I add tLogCatcher and tSendMail directly to the job. When there is an error it will send me an email with the details. You can use any of the columns in row11, I am only using job and message in my example.
This error : For input string "fabrik"
is generated by the tFileInputExcel component when encountering a non valid field (expected : integer ; given : string). You can't directly catch this error with the tFileInputExcel component (it's just printed out on the console).
However, you can use a tSchemaComplianceCheck component after your tFileInputExcelComponent : it will throw an error if a data is not valid for your schema. This component has a reject link to catch the error.
tFileInputExcel->tSchemaComplianceCheck->tMap->tMSOutput
If you use tLogCatcher component to catch the error then, at the end of the flow, you can add a tBufferOutput component. Keep the fields with the information you want for.
component configuration
The result will be like this (note that they are shown in the same order):
result

Mapping Lambda output in API Gateway gives server error

I have an AWS API Gateway setup, served by a Python Lambda function. For successful responses the Lambda returns a response of the form:
"200:{\"somekey\": \"somevalue\"}"
By default, the Integration Response settings in the gateway console have just one rule configured with a Lambda Error Regex of .* mapping to a response status of 200. This works fine.
The problem is when I try to change that to 200.* (with a view to enabling more specific codes going forward). Now I get a
{"message": "Internal server error"}
every time I hit the gateway with any request (resulting in a 200 or not).
No error logs are written to CloudWatch.
I want to know how I can map Lambda outputs to HTTP status codes successfully in AWS API Gateway.
If you do a test run in API gateway, the test run log should show an error similar to:
Sat Nov 21 07:41:25 UTC 2015 : Execution failed due to configuration
error: No match for output mapping and no default output mapping
configured
The problem is there is no-longer a default mapping to catch a successful response. The intention of the error regex is to catch errors and map them to status codes. The error regex searches the errorMessage property of the failed json response. If you were to set the status code 400 to be the default (blank) - you would find your successful response always mapping to a status code of 400.
You'll be best off to leave 200 as a default (blank) regex. Then set specific regex values to check for your different error messages. For example, you can have multiple specific error regex status codes and a generic catch-all to result in 500's.
For those who tried everything put on this question and couldn't make this work (like me), check the thedevkit comment on this post (saved my day):
https://forums.aws.amazon.com/thread.jspa?threadID=192918
Reproducing it entirely below:
I've had issues with this myself, and I believe that the newline
characters are the culprit.
foo.* will match occurrences of "foo" followed by any characters
EXCEPT newline. Typically this is solved by adding the '/s' flag, i.e.
"foo.*/s", but the Lambda error regex doesn't seem to respect this.
As an alternative you can use something like: foo(.|\n)*