Developing for Splunk Enterprise
Highlighted

Get events into splunk using Javascript SDK - Internet Explorer 8

Path Finder

Hi,

I'm trying to send data into splunk index, using splunkjs.Service.Index.submitEvent method, as shown in the example (look for "To add data directly to an index" paragraph). It works fine under FF and Chrome, but not in IE8.

When trying to execute myindexes.item("test_index"), the myindexes is null. I verified that it is OK and non-null before the fetch callback is executed.

In the console, I see an error saying "Error in parsing JSON", without any additional data/params.

Any ideas?


Edit:

I have no IE8 to reproduce it right now. When running in IE10 everything is working fine (like FF and Chrome). But, when choosing compatibility view (which simulates IE7), the problem does occur. This can be reproduced easily, no specific configuration is required.

the code is very simple (almost purely copied from the example):


var http = new splunkjs.ProxyHttp("/proxy");

// Create a Service instance and log in
var service = new splunkjs.Service(http, {
username: "admin",
password: "changeme",
scheme: "https",
host: "localhost",
port:"8089",
version:"5.0"
});

// Get the collection of indexes
var myindexes = service.indexes();
// Get an index to send events to
myindexes.fetch(function(err, myindexes) {
var myindex = myindexes.item("main");
// Submit an event to the index
myindex.submitEvent("A new event", {
sourcetype: "mysourcetype"
}, function(err, result, myindex) {
console.log("Submitted event: ", result);
});
});

The normal network traffic goes like this ("output_mode=json" is omitted for readability):


(1) POST /proxy/services/auth/login
request body contains username and password
response contains a sessionKey

(2) GET /proxy/services/data/indexes?count=0
response contains a list of indexes details

(3) POST /proxy/services/receivers/simple?sourcetype=mysourcetype&index=main
request body contains the text of the event to be indexed
response contains a confirmation about the indexed event

When fails, the network traffic stops after the first request. the response seems to be alright: {"sessionKey":"................................"}

Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

Splunk Employee
Splunk Employee

Can you put the code snippet that you are using? Also, does IE8 let you see what the network request/response is that it is making?

0 Karma
Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

Path Finder

ineeman,
pasting it here is limited in charcters amount, so I'll edit the original question, if you don't care.

0 Karma
Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

Path Finder

can somebody reproduce this, in order to confirm that it's not a special case of me?

0 Karma
Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

Path Finder

i'm able to reproduce it. where should I open a bug?

0 Karma
Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

New Member

Sorry I have no answer for you..but one question... I am doing the same thing but stacked in firs step... how do you attach splunk.js file (script) to application.js or site.. I tried quite everything but without success... I tried with in xml but nothing... I tried with

var head= document.getElementsByTagName('head')[0];
var script= document.createElement('script');
script.type= 'text/javascript';
script.src= 'C:/Program files/splunk/etc/apps/HCtest/appserver/static/splunk-sdk/client /splunk.min.js';
head.appendChild(script);

...in application.js

...and got script on page but also error "Not allowed to load local resource:"

thanks for advice.

0 Karma
Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

Path Finder

Do you try to run it under a web server, or a local html placed in file://...?

If using a web server, you should be able to open a Web Developer Console (F12 or something) and see whether the browser create a GET request for this js file or not. If yes, you should get HTTP "200 OK" or "404 Not Found".

0 Karma
Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

New Member

I try under web server.

If I add

0 Karma
Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

New Member

OK, i solved this one, script splunk.js is on the page and no error is shown. I solved by adding src in url... https://mycomp:8000/... (instead of C:/...).
But the joy was only for a short time... next error: Uncaught ReferenceError: splunkjs is not defined ....

is out there any detailed walkthrough of using Splunk SDK javascript?

0 Karma
Highlighted

Re: Get events into splunk using Javascript SDK - Internet Explorer 8

New Member

Ok, I solved this too ... but not shure if in most elegant way... ...ole! new error found 🙂 ... if you dont mind, could you be so kind to tell me exactly step by step what should I do to get this 'monster' work?

0 Karma