Tag: dashboard

  • Recovering Deleted or Overwritten Dashboards in Splunk 

    Recovering Deleted or Overwritten Dashboards in Splunk 

    By Aaron Dobrzeniecki, Senior Splunk Consultant

    Have you ever been in a situation where you are heads down, grinding on your work, when you accidentally delete or overwrite a very crucial dashboard? If so, no need to panic! We have a resolution to recover your important dashboard.

    Accidentally deleting dashboards in Splunk can be a nerve-wracking experience, especially for those who rely on these powerful tools for monitoring and analyzing critical data. In this blog post, we’ll explore one very powerful way for you to recover your Splunk dashboard (the XML code) inside of Splunk’s internal logs.

    This use case came about when I was working with a customer on his high-level management dashboards. My customer had been working on these dashboards for higher ups for about 2 weeks, inputting critical information and designing his dashboards to show only the points of interest. Once he realized he had overwritten his dashboard, panic set it. He immediately reached out to me for a solution to recover his dashboard. As I had seen this issue before, I immediately dipped into my bag of searches and tricks, digging for a solution to his problem. 

    Find Old XML Coding

    The search below will provide insight and OLD xml coding to your previously saved dashboard. 

    index=_internal dashboard_shortname sourcetype=splunkd_conf data.payload_extra=* 

    Let me breakdown the search to give a little bit more insight. 

    Obviously we are searching the internal index of Splunk, so make sure someone has access to this index as this is where the code is stored for dashboards. The dashboard_shortname is the name of your dashboard when you see it in the Splunk URL. Please see the example below: 

    Example URL: https://organization.splunkcloud.com/en-US/app/search/data_quality?form.time_picker.earliest=-24h%40h

    data_quality is the dashboard shortname for this example

    Including the sourcetype of splunkd_conf will assist with making the search results return quicker. Finally, data.payload_extra, this field is crucial when recovering previously overwritten dashboard code. This is the field where the XML code is kept in the internal event.

    I took one of my dashboards and purposely overwrote it for this post. Please see the overwritten code of my dashboard in the screenshot below: 

    A screenshot of a Splunk configuration or API output view, displaying complex search queries, data parsing settings, and repository synchronization details with a "status: applied" message.

    I was able to use the search I created above to find the newly overwritten xml code. I will use the same exact search to find the original xml code for my dashboard. Any time before 10:55AM ET on June 17 and after 10:53AM ET, I will be able to find my original code.

    NOTE: For your xml code to show up in the internal logs, you need to save your dashboard. I saved my original code at exactly 10:54 AM ET, and then overwrote it. Please see the original code for my dashboard below: 

    A screenshot of Splunk configuration code displaying complex search definitions, payload_extra settings, and data source configurations.

    Not only does this save you time, effort, and stress, but it is a great way to recover any mistakes made onto your dashboard.

    In conclusion, recovering dashboards is essential for keeping data monitoring and analysis smooth and reliable. By having good backup and recovery plans, companies can reduce downtime and prevent data loss, making sure their important information stays accurate. Regularly updating and testing these plans, and using the right recovery tools, will help handle unexpected problems better. In the end, being prepared for dashboard recovery helps create a stable and secure data system, allowing businesses to make smart decisions and stay productive.

    Read more about TekStream Splunk Services here.

  • Not Enough Space? Rotate Through Your Dashboard Panels Automatically

    Not Enough Space? Rotate Through Your Dashboard Panels Automatically

    By Marvin Martinez, Team Lead, Security Operations

    Splunk dashboards allow for great flexibility and can provide many ways to visualize your data. Sometimes, however, you may need to ensure you can fit everything on one non-scrollable screen. Perhaps you’re in a SOC with a main screen and need some different panes to display at specific intervals? What if you need to cycle through a set of data between different time ranges like the last 24 hrs, 7 days, and 30 days? In these situations, it would be very helpful to be able to have a dashboard that automatically rotates the desired panels on specific time intervals, not unlike a fast food menu screen or those digital billboards you frequently see on the interstate!

    In the example we’ll use for this article, I’ll demonstrate how to configure a dashboard to display an Attack Map in two separate ways. The first view will contain a full screen attack map with all of the different sources in one single map to provide a comprehensive view. The second view is a broken out set of panels that shows each individual source/group in its own panel with a dedicated attack map for added detail. The Missile Map app that contains this attack map visualization used below can be found on Splunkbase.

    View 1

    Cybersecurity attack map showing global data flows and threat origins in a single interactive panel.

    View 2

    Rotated Splunk dashboard displaying four grouped attack maps with segmented threat visualization panels.

    These two views will cycle automatically based on a specified time interval defined within a global search in your dashboard. There are a few tokens to ensure you set up correctly but, once set up as needed, your dashboard will cycle through the two configured views (sets of panels) on its own for use in any monitor on a wall or other constantly monitored screen.

    The snippet of dashboard XML code responsible for the setup is below, with a full detailed explanation below:

       <search> 
    
        <query>| makeresults count=1 
    
    | eval test = IF("global" = "global","individual","global") 
    
        </query> 
    
        <done> 
    
          <eval token="panelView">IF($panelView$ = 
    
    &quot;global&quot;,&quot;individual&quot;,&quot;global&quot;)</eval> 
    
          <set token="form.panelView">$panelView$</set> 
    
          <eval token="refreshCount">$refreshCount$ + 1</eval> 
    
        </done> 
    
        <refresh>15s</refresh> 
    
        <refreshType>interval</refreshType> 
    
      </search> 
    
      <fieldset submitButton="false"> 
    
        <input type="text" token="panelView" depends="$tok_hide$"> 
    
          <label>field1</label> 
    
          <initialValue>global</initialValue> 
    
        <change> 
    
          <condition value="global"> 
    
              <set token="globalView">true</set> 
    
              <unset token="individualView"></unset> 
    
          </condition> 
    
          <condition> 
    
            <unset token="globalView"></unset> 
    
            <set token="individualView">true</set> 
    
          </condition> 
    
        </change> 
    
        </input> 
    
      </fieldset> 

    Components

    The components of this setup are as follows:

    – Search to detect what view is currently being displayed and what the next one will be, as well as to define what the refresh interval will be

    – A hidden input to allow for catching the resulting value and setting the appropriate tokens for view hiding/showing.

    – Setup your rows (or panels) with the appropriate depends settings to leverage the appropriate tokens to ensure they are shown only when desired.

    First, the initial search. Set this search up at the top of your dashboard.

    <search> 
    
        <query>| makeresults count=1 
    
    | eval test = IF("global" = "global","individual","global") 
    
        </query> 
    
        <done> 
    
          <eval token="panelView">IF($panelView$ = &quot;global&quot;,&quot;individual&quot;,&quot;global&quot;)</eval> 
    
          <set token="form.panelView">$panelView$</set> 
    
          <eval token="refreshCount">$refreshCount$ + 1</eval> 
    
        </done> 
    
        <refresh>15s</refresh> 
    
        <refreshType>interval</refreshType> 
    
      </search> 

    The query is just a generic makeresults command to return some output value but it’s being leveraged to set the token value of the hidden input. This is to ensure that you don’t end up with an infinite loop by trying to set the token of an input within itself. Use the done event handler to set the token of the hidden input (“panelView” in my example) (details below) within it. Use an eval to set the token appropriately based on the value of the “panelView” input currently (i.e. if “global” currently, set it to “individual” and vice versa). The refresh property is what defines how often the panels/views will rotate between displaying. You can statically set it here or even define it using a token from an input, if desired, to make that refresh interval easily customizable.

    As far as the input is concerned, create a text box input and set the “depends” property on it to a token you don’t intend on setting so that it is always hidden (i.e. “$tok_hide$”). Add a change condition so you can set, and unset, appropriate tokens based on the value of the input. This is where the magic happens! When the value of the token is “global”, in this case, it sets the globalView token and unsets the individualView token. This will hide the individual panels and display the global one. The default condition after that is executed when the value is anything other than “global”, which is sufficient in our scenario but you may need additional explicit conditions if you have more than two views in your dashboard. Note how the set/unset is just reversed from the first one to ensure only one is set at any given time.

    <fieldset submitButton="false"> 
    
        <input type="text" token="panelView" depends="$tok_hide$"> 
    
          <label>field1</label> 
    
          <initialValue>global</initialValue> 
    
        <change> 
    
          <condition value="global"> 
    
              <set token="globalView">true</set> 
    
              <unset token="individualView"></unset> 
    
          </condition> 
    
          <condition> 
    
            <unset token="globalView"></unset> 
    
            <set token="individualView">true</set> 
    
          </condition> 
    
        </change> 
    
        </input> 
    
      </fieldset> 
    
     

    Finally, it’s time to configure your rows/panels with the appropriate depends property to hide/show panels when necessary, as shown below. Set the value of each to be the token that will show the panel/row.

      <row depends="$globalView$"> 

    Save your dashboard and enjoy the automatic cycling between your panels with no engagement from a human!

  • Creating Chart Overlays and Annotations (Flags) in a TimeChart

    Creating Chart Overlays and Annotations (Flags) in a TimeChart

    The TimeChart function is one of most used visualizations of Splunk Dashboards, easily showing the volume of specific events, broken down by category over time. In certain situations, you may want to overlay additional data on top of your time chart to highlight certain events that correlate with the time chart. Luckily the masterminds at Splunk have already thought of a clever way on how we can flag certain search results and overlay it: Annotations!

    It’s not as simple as clicking a few buttons on your dashboard. Don’t be worried though, it’s not difficult either! As long as looking at the XML source doesn’t scare you, you’ll be fine. Let’s continue.

    Create a Chart Overlay

    In this example we’ll be using the Simple XML Dashboard. The below data will show a count of events over the span of 2 months. They’re placed into 1-day buckets using the span argument.

    Additionally, we’ll group these events by their action so we can distinguish the two different actions.

    SPL code example using timechart to count actions (search and list_health) over daily intervals in the audit index.

    This gives us a TimeChart that will look like this:

    Splunk bar chart displaying daily counts of 'search' and 'list_health' actions with separate bars for each category.

    Now, let’s stack our chart to reduce clutter across the TimeChart.

    Splunk chart editing panel set to stacked mode with multi-series enabled, allowing for layered visualization of time series data.
    Stacked bar chart showing combined daily totals for 'search' and 'list_health' actions for visual comparison over time.

    To give us more clarity in our data, we can also add an overlay to show the total of both groupings. We can do this with the addtotals command.

     SPL query showing the addition of a TOTAL field using addtotals to sum all daily action counts across columns.
    Bar chart showing TOTAL count as a third category, alongside search and list_health, visualized in distinct colors.

    Now we can use the new field created by the addtotals command, to overlay in the Dashboard settings.

    Splunk chart overlay settings with TOTAL selected as the overlay metric and axis view toggled on.

    This gives us a Dashboard that looks like this. You’ll see the orange TOTAL line is now added to the TimeChart.

    Combined bar and line chart showing 'search' and 'list_health' as bars, with a TOTAL overlay as a line for trend analysis.

    Now for the fun part. Let’s add in the Annotations, or flags, to highlight certain events.

    In this example, I’ll just be using a unique timestamp value from 3 of the events, but in real world situations you could use a dynamic search to flag server reboots or critical errors on an application.

    To add the Annotations:

    1) Go into ‘Edit’ on your Dashboard and modify the XML source.

    Splunk dashboard editor showing UI and Source buttons for switching between visual and XML editing views.

    2) Find the <chart> for your TimeChart in the XML

    XML snippet of a Splunk dashboard panel showing a timechart query, addtotals, and display options like chart height and refresh settings.

    3) Insert this annotation XML directly below the opening <chart> tag:

    <search type="annotation">
    <query>YOUR SPL QUERY HERE
    | eval annotation_label = “ANNOTATION LABEL – FREE TEXT HERE (optional)”
    | eval annotation_category = “SPECIFY A SPLUNK FIELD HERE (optional)”
    </query></search>
    XML code snippet showing how to define an annotation search within a Splunk dashboard. The query uses eval to define annotation_label as “- - - URGENT EVENT! - - -” and assigns the annotation_category based on the action field.

    After saving the XML, you’ll see your annotations display on your TimeChart if it found matching events. It may look something like this:

    A Splunk timechart displaying stacked bar and line data with three vertical dashed lines and flags at the top—representing annotated timestamps for urgent events layered onto the TOTAL line overlay.

    If you hover over the annotation label, you’ll see what we defined under the eval annotation commands.

    Close-up of a tooltip on a Splunk timechart annotation flag. It reads “- - - URGENT EVENT! - - -” and provides the action category (search) and the exact timestamp of the event (Oct 31, 2022, 11:36:12.220 PM).

    Voila! You’ve got yourself a powerful visualization, able to show multiple data sources and correlate them together through the TimeChart command. Happy Splunking!

  • Slice And Dice: Comparing Values Over Specific Times With Splunk Dashboards — Part Three

    Slice And Dice: Comparing Values Over Specific Times With Splunk Dashboards — Part Three

    By Marvin Martinez, Team Lead – Security Operations

    Part Three: Specific Hour Over Day Visualization

    Welcome back to our series discussing some unique ways to visualize data across specific points in time with Splunk SPL! Previously, we created a dashboard chart to isolate and compare a specific day from a prior week, and then we isolated and compared it to the same day from the current week to see the percentage change between the two values across the day in a new area chart visualization. In this installment, we will pick a specific hour from one day and chart out those specific values across a prior set of weeks in a straightforward visualization.

    Referring back to our first installment (Figure 1 below), we showed a full day across four weeks, overlayed in one line chart visualization. Then, in our second installment, we isolated one of these specific days to compare to the current week (Figure 2).

    Splunk dashboard line chart comparing total events across four Thursdays, showing consistent trends and a sharp dip after 4 a.m. on December 16.
    Part One: Day Over Week (Figure 1)
    Line graph with shaded green delta area visualizing percent change between current week and three weeks prior by the hour, highlighting early-morning fluctuations.
    Part Two: Isolate and Compare (Figure 2)

    Now, for example, let’s say we noticed that spike at 10 am where the Compared Week is much higher than the Current Week and we want to see if that’s just an anomaly or a consistent trend at that same hour. One thing that would make it easy to visualize this would be a line chart that charts that specific hour for that day of the week across the past 4 weeks.

    Let’s build that very search! Once we’re done, our visualization will look as shown below. In the image below, two dropdown inputs are populated with the specified day of the week and hour to isolate for the past 4 weeks, including the current week. This is just a line chart but it is isolated to just that specific day/hour across the past 4 weeks, which makes it much easier to visualize without any other data points to distract the view.

    Splunk dashboard line chart comparing total sales at 10 a.m. over four weeks, with tooltip showing a drop to 1.99 sales on December 9.
    Visualizing a specific day/hour (Figure 3)

    The complete search consists of various parts and transformation so let’s break it up into the few major steps that comprise it and analyze it to ensure we understand how this cake is baked. The final search is below:

    Index=test…
    | eval Date = strftime(_time,"%m/%d %I %p"), Day = strftime(_time,"%A"), Hour=strftime(_time,"%H"), TotalSales = round(TotalSales,2)
    | fields _time, "TotalSales", Hour, Day, Date 
    | where Day="Thursday" AND Hour = 10
    | sort 0 - _time
    | streamstats dc(Date) as WeekNum current=true
    | eval WeekNum = WeekNum -1, WeeksBefore = WeekNum . CASE(WeekNum = 0, " Current Week",WeekNum = 1, " Wk Prior",1=1," Wks Prior") . " (" . Date . ")"
    | chart values(TotalSales) as "Week Value" by WeeksBefore 
    | sort 0 - WeeksBefore
    | eval WeeksBefore = IF(match(WeeksBefore,"^0s"),substr(WeeksBefore,3),WeeksBefore)
    

    Now let’s break this search down and explain what is going on here. The first four lines are setting up our data. We create fields to store the specific Date, Day and Hour for our values as well as filter out only the information for the specific days and hour we are looking to compare. In this case, Thursday is the selected day and 10 am is the selected hour but this could easily be replaced with a token here to allow dynamic selection of any day of the week (it actually is in our specific dashboard).

    | sort 0 - _time
    | streamstats dc(Date) as WeekNum current=true
    | eval WeekNum = WeekNum -1, WeeksBefore = WeekNum . CASE(WeekNum = 0, " Current Week",WeekNum = 1, " Wk Prior",1=1," Wks Prior") . " (" . Date . ")"
    

    The next three lines of the search allow us to format and prepare the data so that the chart will be easy to understand with descriptive labels on the x-axis. The sort command just sorts our data by descending time order so that the subsequent streamstats command can appropriately categorize the date in terms of how many weeks before the event is in relation to the current week. The eval command after this takes the WeekNum value, adjusts it so it reflects the appropriate relation to current week and then creates a WeeksBefore field that contains text values to better articulate how many weeks before the value presented is from, as well as identifying the current week and labeling it appropriately. We’ll discuss what needs to be further finalized on this field for optimal readability a bit later but we can continue for now.

    | chart values(TotalSales) as "Week Value" by WeeksBefore
    | sort 0 - WeeksBefore
    | eval WeeksBefore = IF(match(WeeksBefore,"^0s"),substr(WeeksBefore,3),WeeksBefore)
    

    Now that we’ve isolated and appropriately categorized and formatted our data, all that is needed is a chart command to group the values by the WeeksBefore field. Then, sort the results in descending order by WeeksBefore to ensure that the values are displayed in chronological order once placed in the visualization/line chart. If you were to run the search at this point, you’d notice that the WeeksBefore field has values like this:

    Splunk table column listing timestamps labeled as “3 Wks Prior,” “2 Wks Prior,” “1 Wk Prior,” and “0 Current Week,” all referencing 7 a.m.
    WeeksBefore field after running search (Figure 4)

    In order to get the field to display the right value for the current week (without the 0), the eval command at the end cleans up the data so that the “Current Week” value for WeeksBefore is labeled appropriately using the match function with some simple regex. Once applied, the values look as follows:

    Similar Splunk table as above, confirming week-based timestamps labeled by relative time and date for 7 a.m.
    WeeksBefore field after eval command removes the “0” on the Current Week label (Figure 5)

    The visualization is now ready! It will display much like a timechart but over a certain time period for only that day/hour data point across multiple weeks and with helpful, dynamic, and descriptive labeling on your x-axis!

    Stay tuned for our fourth and final installment in this series on unique Splunk Dashboard panels, when we will discuss how to pick one single time value from a day (i.e. a specific hour value) and plot that data point back across various weeks, comparing each prior data point to the current week (same hour/day) and showing percentage deltas along the way. A sample image is shown below.

    Area chart comparing hourly percent change for December 9 at 10 a.m., showing a highlighted pink delta area between current and prior week’s values.

    Part Four Sneak Peek: Hour Over Week Percentage Change Timechart (Figure 6)

    Until next time, please contact us for more information on this specific Splunk dashboard tutorial, or any Splunk questions you may have!