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!

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...