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!

Join Us for Splunk University and Get Your Bootcamp Game On!

If you know, you know! Splunk University is the vibe this summer so register today for bootcamps galore ...

.conf24 | Learning Tracks for Security, Observability, Platform, and Developers!

.conf24 is taking place at The Venetian in Las Vegas from June 11 - 14. Continue reading to learn about the ...

Announcing Scheduled Export GA for Dashboard Studio

We're excited to announce the general availability of Scheduled Export for Dashboard Studio. Starting in ...