<?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 Re: best practices vs my code in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450116#M168203</link>
    <description>&lt;P&gt;it works until here but after i dont succeed............&lt;/P&gt;

&lt;P&gt;( index="perfmon" sourcetype="perfmon:logicaldisk" instance=c: counter="Free Megabytes" OR counter="% Free Space" ) OR &lt;BR /&gt;
( index="windows-wmi" sourcetype="WMI:LastLogon" LastLogon ) OR ( index="windows-wmi" sourcetype="WMI:LastReboot" LastBootUpTime ) OR &lt;BR /&gt;
( index="windows-wmi" sourcetype="wmi:MemorySize" ) OR &lt;BR /&gt;
( earliest=-120d index=windows sourcetype=winregistry ) OR &lt;BR /&gt;
( index="windows-wmi" sourcetype="wmi:videosignal" )&lt;BR /&gt;&lt;BR /&gt;
| inputlookup append=t NZDL-Out.csv &lt;BR /&gt;
| rename ComputerName as host, Online as Ping_Status &lt;BR /&gt;
| eval Ping_Status =if(Ping_Status=="True","OK","KO") &lt;BR /&gt;
| table host Ping_Status  | dedup host&lt;/P&gt;</description>
    <pubDate>Tue, 29 Sep 2020 20:34:32 GMT</pubDate>
    <dc:creator>jip31</dc:creator>
    <dc:date>2020-09-29T20:34:32Z</dc:date>
    <item>
      <title>best practices vs my code</title>
      <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450111#M168198</link>
      <description>&lt;P&gt;hello all&lt;/P&gt;

&lt;P&gt;i use this code but he has not good performances&lt;BR /&gt;
following splunk best practices, is it possible to give me ideas of the way to optimize it?? many thanks&lt;/P&gt;

&lt;P&gt;`| inputlookup append=t NZDL-Out.csv &lt;/P&gt;

&lt;P&gt;| search ComputerName=$tok_filterhost$ &lt;/P&gt;

&lt;P&gt;| rename ComputerName as host, Online as Ping_Status&lt;/P&gt;

&lt;P&gt;| eval Ping_Status =if(Ping_Status=="True","OK","KO") &lt;/P&gt;

&lt;P&gt;| join type=outer host [search index="perfmon" sourcetype="perfmon:logicaldisk" instance=c:  counter="Free Megabytes" OR counter="% Free Space"&lt;/P&gt;

&lt;P&gt;| eval perc_free = if(counter="% Free Space",Value,null)&lt;/P&gt;

&lt;P&gt;| eval mb_free = if(counter="Free Megabytes",Value,null)&lt;/P&gt;

&lt;P&gt;| stats latest(mb_free) as mb_free latest(perc_free) as perc_free by instance,host&lt;/P&gt;

&lt;P&gt;| eval total_space = mb_free / (perc_free) * 100  | eval Disk_(Space_vs_Capacity) = round(mb_free,0)."MB / ".round(total_space,0)."MB"]&lt;/P&gt;

&lt;P&gt;| join type=outer host [search index="windows-wmi" sourcetype="WMI:LastLogon" LastLogon | rex field=LastLogon mode=sed "s/..*$//" | eval LastLogon = strftime(strptime(LastLogon,"%Y%m%d%H%M%S"),"%d/%m/%Y %H:%M")] &lt;/P&gt;

&lt;P&gt;| join type=outer host [search index="windows-wmi" sourcetype="WMI:LastReboot" LastRebootUpTime | rex field=LastRebootUpTime mode=sed "s/..*$//" | eval LastRebootUpTime = strftime(strptime(LastRebootUpTime,"%Y%m%d%H%M%S"),"%d/%m/%Y %H:%M")] &lt;/P&gt;

&lt;P&gt;| join type=outer host [search index="windows-wmi" sourcetype="wmi:MemorySize" | eval Physical_Memory =round(TotalPhysicalMemory, 0). " Bytes"]&lt;/P&gt;

&lt;P&gt;| join type=outer host [search earliest=-120d index=windows sourcetype=winregistry key_path="\registry\machine\software\wow6432node\airbus\master\PatchLevel" &lt;/P&gt;

&lt;P&gt;| stats first(data) as PatchLevel by host&lt;/P&gt;

&lt;P&gt;]&lt;/P&gt;

&lt;P&gt;| join type=outer host [search index="windows-wmi" sourcetype="wmi:videosignal" &lt;/P&gt;

&lt;P&gt;| rename SystemName as host&lt;/P&gt;

&lt;P&gt;| lookup  Availability.csv Availability&lt;/P&gt;

&lt;P&gt;]&lt;/P&gt;

&lt;P&gt;| table host, TimeStamp, Ping_Status, Status, Disk_(Space_vs_Capacity), Physical_Memory, PatchLevel, LastLogon, LastRebootUpTime | rename Status as Video_Signal_Status&lt;/P&gt;

&lt;P&gt;| sort  -TimeStamp, +host&lt;/P&gt;

&lt;P&gt;| dedup host&lt;BR /&gt;
`&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:32:21 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450111#M168198</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2020-09-29T20:32:21Z</dc:date>
    </item>
    <item>
      <title>Re: best practices vs my code</title>
      <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450112#M168199</link>
      <description>&lt;P&gt;Hi jip31,&lt;/P&gt;

&lt;P&gt;to start with: &lt;BR /&gt;
you are using 6 times &lt;CODE&gt;join&lt;/CODE&gt; which is causing the performance issues and a lot other problems you probably not even notice you have them &lt;span class="lia-unicode-emoji" title=":winking_face:"&gt;😉&lt;/span&gt; &lt;/P&gt;

&lt;P&gt;As a start combine all you searches into one single base search:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ( index="perfmon" sourcetype="perfmon:logicaldisk" instance=c: counter="Free Megabytes" OR counter="% Free Space" ) OR 
 ( index="windows-wmi" sourcetype="WMI:LastLogon" LastLogon ) OR ( index="windows-wmi" sourcetype="WMI:LastReboot" LastRebootUpTime ) OR 
 ( index="windows-wmi" sourcetype="wmi:MemorySize" ) OR 
 ( earliest=-120d index=windows sourcetype=winregistry ) OR 
 ( index="windows-wmi" sourcetype="wmi:videosignal" )
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and do what ever needs to be done in the next SPL steps. I you want to use the first lookup file as filter for the base searches you can actually just do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt; ( index="perfmon" sourcetype="perfmon:logicaldisk" instance=c: counter="Free Megabytes" OR counter="% Free Space" ) OR 
( index="windows-wmi" sourcetype="WMI:LastLogon" LastLogon ) OR ( index="windows-wmi" sourcetype="WMI:LastReboot" LastRebootUpTime ) OR 
( index="windows-wmi" sourcetype="wmi:MemorySize" ) OR 
( earliest=-120d index=windows sourcetype=winregistry ) OR 
( index="windows-wmi" sourcetype="wmi:videosignal" ) 
[| inputlookup append=t NZDL-Out.csv 
| search ComputerName=$tok_filterhost$ 
| rename ComputerName as host, Online as Ping_Status 
| eval Ping_Status =if(Ping_Status=="True","OK","KO") 
| table host Ping_Status 
| format ]
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;The sub search here is okay, because it uses a lookup file and will return a &lt;CODE&gt;OR&lt;/CODE&gt; search pattern like &lt;CODE&gt;((host=foo1 AND Ping_Status="KO") OR (host=foo2 AND Ping_Status="OK"))&lt;/CODE&gt;&lt;/P&gt;

&lt;P&gt;Once you get the base search sorted, you can do all the &lt;CODE&gt;rename&lt;/CODE&gt;, &lt;CODE&gt;eval&lt;/CODE&gt; and/or &lt;CODE&gt;stats&lt;/CODE&gt; to get the result you need.&lt;/P&gt;

&lt;P&gt;Hope this helps ...&lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jul 2018 20:15:19 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450112#M168199</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2018-07-22T20:15:19Z</dc:date>
    </item>
    <item>
      <title>Re: best practices vs my code</title>
      <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450113#M168200</link>
      <description>&lt;P&gt;HI Mus and thanks&lt;/P&gt;

&lt;P&gt;when you say "As a start combine all you searches into one single base search" does i have to create 2 search (one for search and one for next steps)? Or just one serarch?&lt;BR /&gt;
when i execute your code i have no results pearhaps because inputlookup append=t NZDL-Out.csv has to be put at the beginning???&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 09:31:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450113#M168200</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2018-07-23T09:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: best practices vs my code</title>
      <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450114#M168201</link>
      <description>&lt;P&gt;HI Mus and thanks&lt;/P&gt;

&lt;P&gt;when you say "As a start combine all you searches into one single base search" does i have to create 2 search (one for search and one for next steps)? Or just one serarch?&lt;BR /&gt;
when i execute your code i have no results pearhaps because inputlookup append=t NZDL-Out.csv has to be put at the beginning???&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 09:35:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450114#M168201</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2018-07-23T09:35:32Z</dc:date>
    </item>
    <item>
      <title>Re: best practices vs my code</title>
      <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450115#M168202</link>
      <description>&lt;P&gt;The examples just show you possible ways to to do it, they are not bullet proof. No you don't need to create two searches. And no, the second example will work if you adjust it to your real world events. &lt;/P&gt;

&lt;P&gt;cheers, MuS&lt;/P&gt;</description>
      <pubDate>Mon, 23 Jul 2018 09:38:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450115#M168202</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2018-07-23T09:38:28Z</dc:date>
    </item>
    <item>
      <title>Re: best practices vs my code</title>
      <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450116#M168203</link>
      <description>&lt;P&gt;it works until here but after i dont succeed............&lt;/P&gt;

&lt;P&gt;( index="perfmon" sourcetype="perfmon:logicaldisk" instance=c: counter="Free Megabytes" OR counter="% Free Space" ) OR &lt;BR /&gt;
( index="windows-wmi" sourcetype="WMI:LastLogon" LastLogon ) OR ( index="windows-wmi" sourcetype="WMI:LastReboot" LastBootUpTime ) OR &lt;BR /&gt;
( index="windows-wmi" sourcetype="wmi:MemorySize" ) OR &lt;BR /&gt;
( earliest=-120d index=windows sourcetype=winregistry ) OR &lt;BR /&gt;
( index="windows-wmi" sourcetype="wmi:videosignal" )&lt;BR /&gt;&lt;BR /&gt;
| inputlookup append=t NZDL-Out.csv &lt;BR /&gt;
| rename ComputerName as host, Online as Ping_Status &lt;BR /&gt;
| eval Ping_Status =if(Ping_Status=="True","OK","KO") &lt;BR /&gt;
| table host Ping_Status  | dedup host&lt;/P&gt;</description>
      <pubDate>Tue, 29 Sep 2020 20:34:32 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450116#M168203</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2020-09-29T20:34:32Z</dc:date>
    </item>
    <item>
      <title>Re: best practices vs my code</title>
      <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450117#M168204</link>
      <description>&lt;P&gt;okay, what are you trying to achieve with the &lt;CODE&gt;inputlookup&lt;/CODE&gt;? I f you just want to get the &lt;CODE&gt;Ping_Status&lt;/CODE&gt; added as column based on &lt;CODE&gt;host&lt;/CODE&gt; do something like this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;( index="perfmon" sourcetype="perfmon:logicaldisk" instance=c: counter="Free Megabytes" OR counter="% Free Space" ) OR 
( index="windows-wmi" sourcetype="WMI:LastLogon" LastLogon ) OR ( index="windows-wmi" sourcetype="WMI:LastReboot" LastBootUpTime ) OR 
( index="windows-wmi" sourcetype="wmi:MemorySize" ) OR 
( earliest=-120d index=windows sourcetype=winregistry ) OR 
( index="windows-wmi" sourcetype="wmi:videosignal" ) 
| inputlookup append=t NZDL-Out.csv 
| eval Ping_Status = if(Online=="True","OK","KO"), host = case(isnotnull(ComputerName), ComputerName, isnotnull(host), host, 1=1, "unknown")
| stats values(*) AS * by host | do more SPL-fu here 
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Mon, 23 Jul 2018 19:54:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450117#M168204</guid>
      <dc:creator>MuS</dc:creator>
      <dc:date>2018-07-23T19:54:48Z</dc:date>
    </item>
    <item>
      <title>Re: best practices vs my code</title>
      <link>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450118#M168205</link>
      <description>&lt;P&gt;yes mus, but i have difficulty to adapt it.....&lt;/P&gt;</description>
      <pubDate>Tue, 24 Jul 2018 06:03:31 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/best-practices-vs-my-code/m-p/450118#M168205</guid>
      <dc:creator>jip31</dc:creator>
      <dc:date>2018-07-24T06:03:31Z</dc:date>
    </item>
  </channel>
</rss>

