<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do you define a custom log in Splunk? in Reporting</title>
    <link>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386902#M6583</link>
    <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I had a custom log from a monitoring tool and the output looks like:&lt;/P&gt;

&lt;P&gt;Disk_Space      Days        Path&lt;BR /&gt;
10G                   4days      /path/of/data/userA&lt;BR /&gt;
20G                   5days      /path/of/data/userA/folderA&lt;BR /&gt;
10G                   4days      /path/of/data/userB&lt;BR /&gt;
20G                   5days      /path/of/data/userB/folderA&lt;BR /&gt;
20G                   5days      /path/of/data/userB/folderB&lt;BR /&gt;
20G                   10days      /path/of/data/userA/folderB/subfolder_a&lt;BR /&gt;
.....&lt;/P&gt;

&lt;P&gt;Is it possible to sort the data, which is over 5days and over 10G for example, and send an email to userA, userB, and so on?&lt;/P&gt;

&lt;P&gt;Or do I have to rewrite this log to some other format like JSON?&lt;/P&gt;

&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 22:35:28 GMT</pubDate>
    <dc:creator>garumaru</dc:creator>
    <dc:date>2020-09-29T22:35:28Z</dc:date>
    <item>
      <title>How do you define a custom log in Splunk?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386902#M6583</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;

&lt;P&gt;I had a custom log from a monitoring tool and the output looks like:&lt;/P&gt;

&lt;P&gt;Disk_Space      Days        Path&lt;BR /&gt;
10G                   4days      /path/of/data/userA&lt;BR /&gt;
20G                   5days      /path/of/data/userA/folderA&lt;BR /&gt;
10G                   4days      /path/of/data/userB&lt;BR /&gt;
20G                   5days      /path/of/data/userB/folderA&lt;BR /&gt;
20G                   5days      /path/of/data/userB/folderB&lt;BR /&gt;
20G                   10days      /path/of/data/userA/folderB/subfolder_a&lt;BR /&gt;
.....&lt;/P&gt;

&lt;P&gt;Is it possible to sort the data, which is over 5days and over 10G for example, and send an email to userA, userB, and so on?&lt;/P&gt;

&lt;P&gt;Or do I have to rewrite this log to some other format like JSON?&lt;/P&gt;

&lt;P&gt;Thank you very much!&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:35:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386902#M6583</guid>
      <dc:creator>garumaru</dc:creator>
      <dc:date>2020-09-29T22:35:28Z</dc:date>
    </item>
    <item>
      <title>Re: How do you define a custom log in Splunk?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386903#M6584</link>
      <description>&lt;P&gt;&lt;a href="https://community.splunk.com/t5/user/viewprofilepage/user-id/156753"&gt;@garumaru&lt;/a&gt;,&lt;/P&gt;

&lt;P&gt;Its possible to work with this format but we need to consider few factors before going to the final solution.&lt;/P&gt;

&lt;P&gt;Assuming Disk_Space, Days and Path are already extracted fields in splunk, we still need to extract the information to do other numerical comparisons.&lt;/P&gt;

&lt;P&gt;For e.g. to sort the Disk_Space, the digits should be extracted and could be done with a regex &lt;CODE&gt;rex field=Disk_Space "(?&amp;lt;DU&amp;gt;\d+)"&lt;/CODE&gt;.&lt;/P&gt;

&lt;P&gt;But then, what if the disk space usage for some mounts are in TB/MB? In that case, it needs to be checked with a condition and convert to GB before doing any operation&lt;/P&gt;

&lt;P&gt;Similarly for Days - it can be extracted with &lt;CODE&gt;"(?&amp;lt;DAY&amp;gt;\d+)"&lt;/CODE&gt; . But what if it changes to 1month after 30/31 days?&lt;/P&gt;

&lt;P&gt;So with your sample data, the fields has to be extracted , compare and then an alert can be sent.&lt;/P&gt;

&lt;P&gt;Please find a sample solution done based on dummy data.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_* earliest=-5m|stats count by source| eval Days=1|accum Days|eval Days=Days."Days"|eval Disk_Space=if(count &amp;gt; 1000,round((count/1024))."TB",count."GB")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Result&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source                                                           count      Days    Disk_Space
C:\Program Files\Splunk\var\log\introspection\disk_objects.log      13      1Days   13GB
C:\Program Files\Splunk\var\log\introspection\kvstore.log           16      2Days   16GB
C:\Program Files\Splunk\var\log\introspection\resource_usage.log    191     3Days   191GB
C:\Program Files\Splunk\var\log\splunk\health.log                   80      4Days   80GB
C:\Program Files\Splunk\var\log\splunk\metrics.log                 853      5Days   853GB
C:\Program Files\Splunk\var\log\splunk\splunkd_access.log           9       6Days   9GB
C:\Program Files\Splunk\var\log\splunk\splunkd_ui_access.log        275     7Days   275GB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now extract fields and perform UNIT (TB-&amp;gt;GB) comparison and conversion (if needed)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;index=_* earliest=-5m|stats count by source| eval Days=1|accum Days|eval Days=Days."Days"
|eval Disk_Space=if(count &amp;gt; 1000,round((count/1024))."TB",count."GB")
|rex field=source "C:\\\\Program Files\\\\Splunk\\\\var\\\\log\\\\(?&amp;lt;USER&amp;gt;\w+)\\\\"
|rex field=Disk_Space "(?&amp;lt;DU&amp;gt;\d+)(?&amp;lt;UNIT&amp;gt;\w+)"|rex field=Days "(?&amp;lt;DAY&amp;gt;\d+)"
|eval DU=if(UNIT=="TB",DU*1024,DU)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Finally apply the filter and send mail to the users&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;    index=_* earliest=-5m|stats count by source| eval Days=1|accum Days|eval Days=Days."Days"
    |eval Disk_Space=if(count &amp;gt; 1000,round((count/1024))."TB",count."GB")
    |rex field=source "C:\\\\Program Files\\\\Splunk\\\\var\\\\log\\\\(?&amp;lt;USER&amp;gt;\w+)\\\\"
    |rex field=Disk_Space "(?&amp;lt;DU&amp;gt;\d+)(?&amp;lt;UNIT&amp;gt;\w+)"|rex field=Days "(?&amp;lt;DAY&amp;gt;\d+)"
    |eval DU=if(UNIT=="TB",DU*1024,DU)
    | where DAY &amp;gt; 5 AND DU &amp;gt; 10|sendmail to=USER@mydomain.com
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you have the control over the content of the log file, suggest you to handle the Unit conversion/Data format before pushing to splunk. The most commonly used and suggested format is &lt;CODE&gt;key=value&lt;/CODE&gt; format which splunk understands without any extra configuration.&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 22:39:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386903#M6584</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2020-09-29T22:39:48Z</dc:date>
    </item>
    <item>
      <title>Re: How do you define a custom log in Splunk?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386904#M6585</link>
      <description>&lt;P&gt;@renjith.nair, thanks for your reply, for the Disk_Space and Days, they will be using GB and days instead of TB and months.&lt;/P&gt;

&lt;P&gt;My sample log might be different from yours, which is my bad that I didn't explain it clearly at first.&lt;/P&gt;

&lt;P&gt;The amount of the monitor log file is only one, like /log/usage.log, and in this log file, it has the content like:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Disk_Space  Days   Path
10G        4days /path/of/data/userA
20G        5days /path/of/data/userA/folderA
10G        4days /path/of/data/userB
20G        5days /path/of/data/userB/folderA
20G        5days /path/of/data/userB/folderB
20G       10days /path/of/data/userA/folderB/subfolder_a
30G       40days /path/of/data/userA/folderB/subfolder_a
.....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;So using the way you provided, I will have below result:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;source         count    Days    Disk_Space
/log/usage.log    2  1Days    2GB
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;I think there must be something that still needs to be fixed in my log file, would you please share more ideas?&lt;BR /&gt;
Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 08 Jan 2019 02:24:25 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386904#M6585</guid>
      <dc:creator>garumaru</dc:creator>
      <dc:date>2019-01-08T02:24:25Z</dc:date>
    </item>
    <item>
      <title>Re: How do you define a custom log in Splunk?</title>
      <link>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386905#M6586</link>
      <description>&lt;P&gt;@garumaru,&lt;BR /&gt;
The first line of SPL is just to generate the dummy data similar to yourself. So you don't need to worry about it. Since you are always using GB and Days, you may start from&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;     "your existing search to get Disk_Space  Days   Path fields"
     |rex field=source "\/path\/of\/data\/(?&amp;lt;USER&amp;gt;\w+)\/"
     |rex field=Disk_Space "(?&amp;lt;DU&amp;gt;\d+)"|rex field=Days "(?&amp;lt;DAY&amp;gt;\d+)"
     | where DAY &amp;gt; 5 AND DU &amp;gt; 10
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Tue, 08 Jan 2019 02:31:07 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Reporting/How-do-you-define-a-custom-log-in-Splunk/m-p/386905#M6586</guid>
      <dc:creator>renjith_nair</dc:creator>
      <dc:date>2019-01-08T02:31:07Z</dc:date>
    </item>
  </channel>
</rss>

