Dashboards & Visualizations

How to set a Django web framework view as the default on an app?

asieira
Path Finder

So I have discovered that if you build an app entirely using web framework Django binding views, Splunk won't load any of them when the user first enters the app. Instead, it will open the Alerts page below the menu bar. Also, if you have at least one XML-based view, it will be used as the default regardless of the default setting or the ordering in default.xml.

So I was wondering how to build an XML view under data/default/ui/views that would redirect the user to /dj/redirector/some_django_page/.

Has anyone ever managed to do that and care to share?

0 Karma
1 Solution

asieira
Path Finder

So after a bit of testing I have solved this myself. I'll assume the app name is my_app an that the django view that needs to be loaded by default is called dashboard.

First, create appserver/static/redirect.html that will perform the redirect:

<script type="text/javascript">
window.location="/dj/redirector/my_app/dashboard";
</script>

Then, create default/data/ui/views/redirect.xml that loads the HTML file:

<view template="dashboard.html" isVisible="false">
    <module name="ServerSideInclude" layoutPanel="panel_row1_col1">
        <param name="src">redirect.html</param>
    </module>
</view>

Notice that this view is flagged as not visible so that it won't show up on the app menu bar. Finally, all you need to do is make this view the default on default/data/ui/nav/default.xml:

<nav>
    <view default="true" name="redirect"/>
    <a href="/dj/redirector/my_app/dashboard">Dashboard</a>
</nav>

Following the steps above will ensure that when an user enters your app, he/she will be shown the django-based Dashboard page first.

This is a simple if rather ugly hack, but the ideal solution would be for Splunk to allow django-based views to be set as the default view directly. Oh, well, life's not perfect.

View solution in original post

asieira
Path Finder

So after a bit of testing I have solved this myself. I'll assume the app name is my_app an that the django view that needs to be loaded by default is called dashboard.

First, create appserver/static/redirect.html that will perform the redirect:

<script type="text/javascript">
window.location="/dj/redirector/my_app/dashboard";
</script>

Then, create default/data/ui/views/redirect.xml that loads the HTML file:

<view template="dashboard.html" isVisible="false">
    <module name="ServerSideInclude" layoutPanel="panel_row1_col1">
        <param name="src">redirect.html</param>
    </module>
</view>

Notice that this view is flagged as not visible so that it won't show up on the app menu bar. Finally, all you need to do is make this view the default on default/data/ui/nav/default.xml:

<nav>
    <view default="true" name="redirect"/>
    <a href="/dj/redirector/my_app/dashboard">Dashboard</a>
</nav>

Following the steps above will ensure that when an user enters your app, he/she will be shown the django-based Dashboard page first.

This is a simple if rather ugly hack, but the ideal solution would be for Splunk to allow django-based views to be set as the default view directly. Oh, well, life's not perfect.

Get Updates on the Splunk Community!

Optimize Cloud Monitoring

  TECH TALKS Optimize Cloud Monitoring Tuesday, August 13, 2024  |  11:00AM–12:00PM PST   Register to ...

What's New in Splunk Cloud Platform 9.2.2403?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.2.2403! Analysts can ...

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

Dive into our sizzling summer lineup for July and August Community Office Hours and Tech Talks. Scroll down to ...