Dashboards & Visualizations

how to create dashboard/view using splunk java sdk?

ranjithjosephd
Explorer

I tried a lot but couldn’t figure out the way to CREATE DASHBOARDS using splunk SDK.
Here is the snapshot of the code I tried. Can someone please help me in code to create dashboards using splunk sdk.

            JobArgs jobargs = new JobArgs();
    jobargs.put("name", "TestAutomation1");
    jobargs.put("eai:data", "<dashboard><label>the_Automation_new_label</label></dashboard>");
    jobargs.put("eai:type", "views");
    jobargs.put("eai:userName", "admin");
    jobargs.put("isDashboard", true);
    jobargs.put("isVisible", true);
    jobargs.put("label", "the_Automation_new_label");
    jobargs.put("rootNode", "dashboard");

            HttpService httpService = new HttpService(splunk_host);
    ResponseMessage response = httpService.post("/servicesNS/admin/search/data/ui/views/_new",jobargs);

When i run this code, it always ends up as 401--unauthorized exception. I am establish connection prior to this code which executes perfectly. Am i doing it right? Can some one please help me to create dashboards/views using java sdk. Thank you!

1 Solution

ranjithjosephd
Explorer

I could crack this. Now using splunk sdk i could create dashboards as well!!

View solution in original post

0 Karma

markbarber21
Path Finder

I had great success with the following:

    Service service = getSplunkService();

    String dashboardName = "rest_dashboard";

    String dashboardXml = "<dashboard>\n" +
        "  <label>temp</label>\n" +
        "  <row>\n" +
        "    <panel>\n" +
        "      <chart>\n" +
        "        <search>\n" +
        "          <query>index=_internal\n" +
        "                  |  timechart count</query>\n" +
        "          <earliest>-1h@h</earliest>\n" +
        "          <latest>now</latest>\n" +
        "          <sampleRatio>1</sampleRatio>\n" +
        "        </search>\n" +
        "      </chart>\n" +
        "    </panel>\n" +
        "  </row>\n" +
        "</dashboard>";

    JobArgs jobargs = new JobArgs();
    jobargs.put("name", dashboardName);
    jobargs.put("eai:type", "views");
    jobargs.put("eai:data", dashboardXml);
    String endpoint = String.format("/servicesNS/rest_user/app_name/data/ui/views/%s", dashboardName);
    service.post(endpoint, jobargs);
0 Karma

ranjithjosephd
Explorer

I could crack this. Now using splunk sdk i could create dashboards as well!!

0 Karma

srinivasup
Explorer

any update on this, how can we create a dashboard

0 Karma

srinivasup
Explorer

I myself found the query.
Use below query to create a dashboard.

Service service = Service.connect(loginArgs);
System.out.println("Version "+service.version);
JobArgs jobargs = new JobArgs();
jobargs.put("name", "TestAutomation1");
jobargs.put("eai:data", "the_Automation_new_label");
jobargs.put("eai:type", "views");
service.post("/servicesNS/admin/search/data/ui/views/newSrini",jobargs);

0 Karma

TMazurek
New Member

What was the solution ?

0 Karma
Get Updates on the Splunk Community!

This Week's Community Digest - Splunk Community Happenings [9.26.22]

Get the latest news and updates from the Splunk Community here! Upcoming User Group Events! &#x1f44f; Check ...

BSides Splunk 2022 - The Call for Papers is now Open!

TLDR; Main Site: https://bsidessplunk.com CFP Site: https://bsidessplunk.com/cfp CFP Opens: December 15th, ...

Sending Metrics to Splunk Enterprise With the OpenTelemetry Collector

This blog post is part of an ongoing series on OpenTelemetry. The OpenTelemetry project is the second largest ...