Dashboards & Visualizations
Highlighted

Adding javascript without restarting splunk

Path Finder

I'm looking at changing a javascript file on a Splunk6 instance which I can not bounce. I noticed that if I copy the original file to a new one, then reference the new file, it doesn't run.

Is there a way to force splunk to pickup this change?

<dashboard script="custom_viz.js">
  <row>
           <html>
            <h2>Zone</h2>
            <div id="custom"></div>
        </html>
    </row>
</dashboard>

If I

cp custom_viz.js test.js

and change the reference to test.js, nothing renders.

These aren't helping any

http://YOUR_SERVER:8000/en-US/debug/refresh?entity=/data/ui/views
http://YOUR_SERVER:8000/en-US/debug/refresh?entity=/data/ui/nav
http://YOUR_SERVER:8000/en-US/debug/refresh

Thanks

Highlighted

Re: Adding javascript without restarting splunk

Motivator

try holding down shift or ctrl while hitting the refresh button in your browser.

0 Karma
Highlighted

Re: Adding javascript without restarting splunk

Path Finder

Thanks- but this does not help. I know that the dashboard is trying to find the new js file because it renders the html block empty when I switch the reference to a file that was created. When I switch back it works without issue.

0 Karma
Highlighted

Re: Adding javascript without restarting splunk

Motivator

ah it may require a restart of splunk then, may be non avoidable if it's a new js file that you are adding.

If you were to modify the existing js file, you would not have to restart.

Highlighted

Re: Adding javascript without restarting splunk

Influencer

You have to restart splunkweb in order for new files to be picked up. The good news is that this is much quicker (typically a couple of seconds) than restarting the whole Splunk instance in (splunkweb + splunkd) and does not affect user sessions or running searches. You can restart splunkweb on the command line:

$ splunk restartss

or

$ splunk restart splunkweb

(The splunk command points to $SPLUNK_HOME/bin/splunk)

Highlighted

Re: Adding javascript without restarting splunk

Builder

@ziegfried, in 6.2 there's no separate splunkweb service anymore. Does that mean I need to do a full Splunk restart to pick up new JS files?

0 Karma
Highlighted

Re: Adding javascript without restarting splunk

Splunk Employee
Splunk Employee

@cphair, it's still the same command to restart the web UI portion.

0 Karma
Highlighted

Re: Adding javascript without restarting splunk

I tried the below with the splunk instance in my machine,
* Kept the js file inside "/appserver/static" folder of my application
* launched the url http://127.0.0.1:800/en-US/static/app/MyApp/src/js/karthi.js?123456
* It opens the content of my screit
* Now,I have modified my code and launched the url http://127.0.0.1:800/en-US/static/app/MyApp/src/js/karthi.js?**654321**
* it opens the new content...
* So you don't have to refresh or restart splunk.. Just have to change the url.. you can use Math.random() to do so..

E.G : http://127.0.0.1:800/en-US/static/app/MyApp/src/js/karthi.js? + Math.random()

... But in your case you should not hard code the JS file path in script tag...
you should add the script tag dynamically and it to head tag......

E.g: jQuery('<script src="/static/app/MyApp/karthi.js?' +Math.random()  + '"/>").appendTo("head");
Highlighted

Re: Adding javascript without restarting splunk

New Member

it Works... great job..

0 Karma
Highlighted

Re: Adding javascript without restarting splunk

Motivator

To reload any changes done to existing java script we can bump it and create new version.
Hit following url http://server name:8000/en-US/_bump. It will display page, showing current version and button. Click on the button and then all the java script changes will be applied. However, it may not work if you are adding new file.

0 Karma