Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't send payload #6

Closed
akzReekoh opened this issue May 5, 2016 · 10 comments
Closed

Can't send payload #6

akzReekoh opened this issue May 5, 2016 · 10 comments
Assignees

Comments

@akzReekoh
Copy link

Here's the code I'm using (got it directly from your npmjs page):

var SplunkLogger = require('splunk-logging').Logger;

var config = {
token: '',
url: ''
};

var Logger = new SplunkLogger(config);

var payload = {
// Message can be anything; doesn't have to be an object
message: {
temperature: "70F",
chickenCount: 500
}
};

console.log("Sending payload", payload);
Logger.send(payload, function(err, resp, body) {
// If successful, body will be { text: 'Success', code: 0 }
console.log("Response from Splunk", body);
});

And I always get this error:
/home/adinglasan/Desktop/splunk/node_modules/splunk-logging/splunklogger.js:466
if (!requestError && body && body.code.toString() !== "0") {
^

TypeError: Cannot read property 'toString' of undefined
at Request._callback (/home/adinglasan/Desktop/splunk/node_modules/splunk-logging/splunklogger.js:466:55)

@shakeelmohamed
Copy link
Contributor

Thanks for the bug report @akzReekoh! Can you try adding console.log(body); on line 464 in splunklogger.js and let us know the output?

@akzReekoh
Copy link
Author

Hi,

This is the output:

<!doctype html><title>303 See Other</title><script type="text/javascript">
var hashTag = '', hashPos = document.location.href.indexOf('#');
if (hashPos > -1) { hashTag = document.location.href.substr(hashPos); }
document.location = "http://54.174.219.239:8000/en-US/services/collector/event/1.0" + hashTag;
</script>

See Other

The resource has moved temporarily here.

From: Shakeel Mohamed [email protected]
Sent: Friday, May 6, 2016 3:20:12 AM
To: splunk/splunk-javascript-logging
Cc: Achilles Dinglasan; Mention
Subject: Re: [splunk/splunk-javascript-logging] Can't send payload (#6)

Thanks for the bug report @akzReekohhttps://github.com/akzReekoh! Can you try adding console.log(body); on line 464 in splunklogger.js and let us know the output?

You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHubhttps://github.com//issues/6#issuecomment-217250723

_The information transmitted is intended only for the person or entity to which it is addressed and may contain confidential and/or privileged material. Any review, re-transmission, dissemination or other use of, or taking of any action in reliance upon, this information by persons or entities other than the intended recipient is prohibited. If you received this in error, please contact the sender and delete the material from any computer._

@shakeelmohamed
Copy link
Contributor

Thanks @akzReekoh, it looks like you're using the splunkweb port (8000 by default) instead of the HTTP Event Collector port (8088 by default). Try changing the port and let us know if that helps

shakeelmohamed pushed a commit that referenced this issue May 6, 2016
@calvinlfer
Copy link

calvinlfer commented Nov 3, 2016

Hello @shakeelmohamed
9cb0149 should be merged in ASAP as it prevents situations where the Splunk Forwarder becomes unresponsive and results in exceptions being thrown due to body.code being undefined and the toString method is being invoked on an undefined method causing an exception to be thrown. We ran into this issue and it was not fun to debug.

Are there any immediate plans to cut a release for this?

@shakeelmohamed
Copy link
Contributor

Hi @calvinlfer,

What's the response you get when the forwarder is under heavy load?
We'd like to get a release out next week with a fix for #9 also.

@calvinlfer
Copy link

Hey @shakeelmohamed, we get a type-error exception thrown because the Splunk forwarder fails to return a JSON response under heavy load. So body exists but body.code is undefined and toString is called on body.code. I can provide you the exact response shortly

@hackmad
Copy link

hackmad commented Nov 3, 2016

@shakeelmohamed @calvinlfer Sanitized private IDs and URLs but its returning a 504 with some HTML content:

{
  "statusCode": 504,
  "body": "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\n<HTML><HEAD><META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=iso-8859-1\">\n<TITLE>ERROR: The request could not be satisfied</TITLE>\n</HEAD><BODY>\n<H1>ERROR</H1>\n<H2>The request could not be satisfied.</H2>\n<HR noshade size=\"1px\">\nCloudFront attempted to establish a connection with the origin, but either the attempt failed or the origin closed the connection.\n<BR clear=\"all\">\n<HR noshade size=\"1px\">\n<PRE>\nGenerated by cloudfront (CloudFront)\nRequest ID: ***********\n</PRE>\n<ADDRESS>\n</ADDRESS>\n</BODY></HTML>",
  "headers": {
    "content-type": "text/html",
    "content-length": "669",
    "connection": "close",
    "server": "CloudFront",
    "date": "Thu, 03 Nov 2016 16:41:31 GMT",
    "x-cache": "Error from cloudfront",
    "via": "1.1 "**************" (CloudFront)",
    "x-amz-cf-id": "**************"
  },
  "request": {
    "uri": {
      "protocol": "https:",
      "slashes": true,
      "auth": null,
      "host": "******:443",
      "port": "443",
      "hostname": "******",
      "hash": null,
      "search": null,
      "query": null,
      "pathname": "/services/collector/event/1.0",
      "path": "/services/collector/event/1.0",
      "href": "https://**************:443/services/collector/event/1.0"
    },
    "method": "POST",
    "headers": {
      "Authorization": "Splunk ***********",
      "Content-Type": "application/x-www-form-urlencoded",
      "accept": "application/json",
      "content-length": 181
    }
  }
}

@shakeelmohamed
Copy link
Contributor

Thanks @hackmad this is very helpful

shakeelmohamed pushed a commit that referenced this issue Nov 8, 2016
For #6: catch errors when parsing the server response.
For #9: manually parse JSON responses, and omitting the urlencoded header.
shakeelmohamed pushed a commit that referenced this issue Nov 8, 2016
@shakeelmohamed
Copy link
Contributor

We've just released v0.9.2 with this fix. Give it a try!

@calvinlfer
Copy link

Thanks a lot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants