Splunk Dev

Is there a better way of generating the URL prefix without using Javascript?

skisoccer13
Explorer

I can't use CSS to reference images stored in the static directory and have to use raw Javascript.

I couldn't find the answer to this but ended up figuring out a weird way to discover and use the Splunk generated URL prefix local to each app e.g. "/static/@2b5b15c4ee.156/app/app_name"

using this in Javascript:

Splunk.util.make_url("/static/app/app_name/").replace(":0", "")

Is there a better way to do this?

0 Karma

skisoccer13
Explorer

Great, the make_url() function from util.js is just what I'll have to use. Just wanted to confirm that that was the right way to go.

0 Karma

niketn
Legend

@skisoccer13, are you trying to generate the dynamic path for static file based on current app?

Please refer to answer: https://answers.splunk.com/answers/552333/how-do-i-add-a-picture-to-my-dashboard-v-66.html

Here is an example to use path with $env:app$ to refer to static folder path: https://answers.splunk.com/answers/585907/how-to-shift-image-inside-an-image-in-splunk-on-th.html

If this is not what you need can you add more details of what you are trying to do?

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

skisoccer13
Explorer

I did see that but I need a purely Javascript only solution. This app uses Javascript libraries that need to be passed URLs of images for use. I can't use CSS or the standard HTML.

0 Karma

niketn
Legend

@skisoccer13, your question says without JavaScript however the comment says purely JavaScript solution. This is confusing.

You have mentioned the app uses JavaScript Libraries. Is this Splunk App or something else? Please elaborate a bit more on use case as to what you have and what you want to do, so that community members can assist you better.

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma

skisoccer13
Explorer

This is an app that uses the three.js Javascript library for a 3D globe rendering. It was designed for v6 of Splunk but I am on v7. I don't know if there was a change in the SDK or not.

It is working right now with my solution after I rewrote it with the Splunk.util call. I just don't know if this is the correct method to obtain the generated app prefix so the Javascript library can properly access the images stored in the appserver/static folder

0 Karma

niketn
Legend

Are you trying to pass on the image path to the following in three.js: THREE.ImageUtils.loadTexture(imgDir+'world.jpg');

If you are able to access Splunk Utils using splunkjs/mv/utils.js then you can use Splunk.util.getCurrentApp(); to get the current app name.

You can also refer to make_url() documentation for utils.js : https://docs.splunk.com/Documentation/Splunk/latest/ModuleRef/Splunk.util#Synopsis_26

Alternatively, a longer route would be to build a Custom Visualization in Splunk using three.js. http://docs.splunk.com/Documentation/Splunk/latest/AdvancedDev/CustomVizTutorial

____________________________________________
| makeresults | eval message= "Happy Splunking!!!"
0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...