Splunk Search

Concatenate date in label

vikas_gopal
Builder

Hi Everyone,
Is it possible to concatenate current date and time with dashboard label e.g. my dashboard label is "Monthly status report" and I want to show it as "Monthly status report" + "Current date and time".Please suggest me how to do it and if it is not possible with concatenate then how I can achieve this ?

Thanks in advance

Tags (1)
0 Karma
1 Solution

vikas_gopal
Builder

by using the simple xml code and combination of javascript and read only text box I achieved this...thanks everyone for your valuable inputs..

View solution in original post

0 Karma

vikas_gopal
Builder

by using the simple xml code and combination of javascript and read only text box I achieved this...thanks everyone for your valuable inputs..

0 Karma

jhowkins
Path Finder

If you want implement the date as a text label in your dashboard using Javascript, you can also do the following (again, I'm assuming you're using advanced XML and SideView Utils' HTML module);

<module name="HTML">
    <param name="html">
    <![CDATA[

    <script>
        var theDate = new Date();
        $$(function() {
        $$( "#ReportTitle" ).text(theDate);
        });
    </script>

    <h3>Monthly status report <Label id="ReportTitle" ></h3>

    ]]>
    </param>
</module>

I hope this helps!

vikas_gopal
Builder

@jhowkins thanks for quick response..I am not using SideView Utils, I am working on simple XML .Is it possible with simple XML..?

0 Karma

jhowkins
Path Finder

Assuming you are using advanced XML for your dashboard and you're willing to use SideView Utils' HTML module, the following will work;

<module name="HiddenSearch" autoRun="True">
    <param name="search">index=_internal | stats count | eval ReportLabel = "Monthly status report ".strftime( time(), "%B %e, %Y %k:%M:%S %p") | table ReportLabel</param>
    <module name="HTML">
        <param name="html">
            <![CDATA[
            <p>$results[0].ReportLabel$</p>
            ]]>
        </param>
    </module>  
</module>

You don't necessarily need to concatenate with an eval either. You could change the code above as follows:

eval = strftime( time(), "%B %e, %Y %k:%M:%S %p")

and

<![CDATA[
<p>Monthly status report $results[0].ReportLabel$</p>
]]>

Note: index=_internal can be swapped for whatever index you feel comfortable using

You can format the date/time using Splunk's date and time format variables: http://docs.splunk.com/Documentation/Splunk/latest/SearchReference/Commontimeformatvariables

yannK
Splunk Employee
Splunk Employee

You can concatenate fields values in an eval command using the dot as separator.

examples :
<mywonderfulsearch> | eval newfield=fieldA.fieldB | table newfield

<mywonderfulsearch> | eval newfield=fieldA." and my other information is ".fieldB | table newfield

If you have fields names already in a string with spaces, you will have to use double quotes, so it may mess up the eval.
I recommend to use simple fields names, and rename then at the end at display time.

yannK
Splunk Employee
Splunk Employee

understood, the eval works for the results, not the panels names.
the javascript is the way to go.

0 Karma

vikas_gopal
Builder

@yannK Thanks for the reply but how I can use eval command with label .I can use it in search bar only....

0 Karma

vikas_gopal
Builder

I have prepared a javascript which shows me a date in an alert now how I can link this to label ...

0 Karma

aelliott
Motivator

do you have javascript available to you?

0 Karma
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...