<?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: SCADA bitwise registers time on and time off search in Splunk Search</title>
    <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77348#M181537</link>
    <description>&lt;P&gt;Ignore the answer below - I only read the 1st part of the question and got excited by binary conversions...&lt;/P&gt;</description>
    <pubDate>Thu, 28 Mar 2013 12:18:14 GMT</pubDate>
    <dc:creator>jonuwz</dc:creator>
    <dc:date>2013-03-28T12:18:14Z</dc:date>
    <item>
      <title>SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77345#M181534</link>
      <description>&lt;P&gt;Got posed a tricky question today for a search.&lt;/P&gt;

&lt;P&gt;We are monitoring a diesel generator which generates a number of alarms which are sent as a single integer with each bit of that integer meaning a particular alarm.&lt;/P&gt;

&lt;P&gt;ie&lt;BR /&gt;
bit 0 - high_rpm&lt;BR /&gt;
bit 1 - high_temp&lt;BR /&gt;
bit 2 - low_temp&lt;BR /&gt;
etc....&lt;/P&gt;

&lt;P&gt;Now this generator is being polled every 5 seconds and data results are begin fed back into Splunk.&lt;/P&gt;

&lt;P&gt;So an event would look like this (where sectionCode identifies the generator)&lt;BR /&gt;
    time_of_event, sectionCode=generator1, alarmCode, rpm, output_kw&lt;/P&gt;

&lt;P&gt;So I was asked to show a list of when alarms went on and off so I came up with this search.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;sourcetype="holdingRegisters" sectionCode=gen* | sort 0 sectionCode, _time asc | delta alarmCode AS alarmChange | search alarmChange!=0 | `gen_alarm_decode(alarmCode)` | sort 0 _time sectionCode desc | table _time, sectionCode, alarmCode, description
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and the macro gen_alarm_decode decodes the bitwise values into human readable terms. (this works fine)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;eval description=if(floor($bitVar$)%2&amp;gt;0,"High RPM, ","") | eval description=description + if(floor($bitVar$/2)%2&amp;gt;0,"High Temp, ","") | eval description=description + if(floor($bitVar$/4)%2&amp;gt;0,"Low Temp, ","")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now this search returns me a list of all entries where the alarmCode changed and what the remaining alarmCodes that were still set were.&lt;/P&gt;

&lt;P&gt;So results would look like this&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Sun 10:35pm, generator1, 0, 
Sun 10pm, generator1, 2, High Temp
Sun 8pm, generator1, 3, High RPM, High Temp
etc.....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;All well and good and I was pleased with my effort on that search. But I have been asked to change this to a more SCADA style output. Where the client sees a column for each alarm and its status.&lt;/P&gt;

&lt;P&gt;If the alarm is on it will list the time it turned on... when it goes off it will list the start and end times&lt;/P&gt;

&lt;P&gt;So it should be something like this (put in a pseudo csv/table format for display here)&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Time, sectionCode, alarmCode, high_rpm, high_temp, low_temp
Sun 10:35pm, generator1, 0, - , 8pm-10:35pm, -  
Sun 10pm, generator1, 2, 8pm-10pm, 8pm-?, -  
Sun 8pm, generator1, 3, 8pm-?, 8pm-?, -  
etc.....
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Note ? above are for where the alarm is still on. The - are for when alarm is off.&lt;/P&gt;

&lt;P&gt;If it helps matters I have also decoded the bitwise field on our custom modbus poller. So really events look like this&lt;BR /&gt;
    time_of_event, sectionCode=generator1, alarmCode, rpm, output_kw, bitAlarm0, bitAlarm1, bitAlarm2&lt;/P&gt;

&lt;P&gt;The only reason I didn't mention it until now was because I didn't need those bitfields yet.&lt;/P&gt;

&lt;P&gt;Anyone have any thoughts. It has me slightly stumped. If I find a solution will post here regardless.&lt;/P&gt;</description>
      <pubDate>Mon, 28 Sep 2020 13:37:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77345#M181534</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2020-09-28T13:37:56Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77346#M181535</link>
      <description>&lt;P&gt;It should be noted there are actually 32 bitwise alarmCodes so I am trying to keep the search as simple as possible &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 05:37:34 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77346#M181535</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-03-28T05:37:34Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77347#M181536</link>
      <description>&lt;P&gt;Nice question.&lt;/P&gt;

&lt;P&gt;It boils down to converting a decimal into a bitfield yes ?&lt;/P&gt;

&lt;P&gt;put this in etc/&lt;APP&gt;/bin/dec2bin.py&lt;/APP&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import re,sys,time, splunk.Intersplunk

def dogetbin(results, settings):

  try:
    fields, argvals = splunk.Intersplunk.getKeywordsAndOptions()

    for r in results:
      for f in fields:
        if f in r:

          try:
            r[f]=int(r[f])
            if r[f] &amp;gt;=0:
              r[f]=str(bin(r[f]))[2:]
            else:
              r[f]="-" + str(bin(r[f]))[3:]

          except:
            r[f]=""

          splunk.Intersplunk.outputResults(results)

  except:
    import traceback
    stack =  traceback.format_exc()
    results = splunk.Intersplunk.generateErrorResults("Error : Traceback: " + str(stack))

results, dummyresults, settings = splunk.Intersplunk.getOrganizedResults()
results = dogetbin(results, settings)
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Then put this in etc/&lt;APP&gt;/local/commands.conf&lt;/APP&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;[dec2bin]
retainsevents = true
streaming = true
filename = dec2bin.py
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Now you can do&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | dec2bin bitVar | ...
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and it'll turn it into something like "1001"&lt;/P&gt;

&lt;P&gt;Why is this useful ?&lt;/P&gt;

&lt;P&gt;well, you can define a multivalue field like this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | eval measures="high_rpm,low_rpm,low_temp" | makemv delim="," measures
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;and then split your bitfield like this :&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | bitVar=split(bitVar,"")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;If you do this you can see where this is heading ....&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;... | table bitVar measures
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;STRONG&gt;Example&lt;/STRONG&gt;&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;* | head 1 
  | eval bitVar="9" 
  | dec2bin bitVar 
  | eval bitVar=split(bitVar,"")
  | eval measure="temp_high,tem_low,ps_borked,no_cement"
  | makemv delim="," measure
  | table bitVar measure
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/cement_1.jpg" alt="alt text" /&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 12:10:18 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77347#M181536</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-03-28T12:10:18Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77348#M181537</link>
      <description>&lt;P&gt;Ignore the answer below - I only read the 1st part of the question and got excited by binary conversions...&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 12:18:14 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77348#M181537</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-03-28T12:18:14Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77349#M181538</link>
      <description>&lt;P&gt;Thanks for the response and the suggestion. But I have the decimal to bit sorted with that macro.&lt;/P&gt;

&lt;P&gt;eval bit0=if(floor($bitVar$)%2&amp;gt;0,"High RPM, ","")&lt;BR /&gt;
eval bit1=if(floor($bitVar$/2)%2&amp;gt;0,"High Temp, ","")&lt;BR /&gt;
etc....&lt;/P&gt;

&lt;P&gt;The bit decoding I can get sorted fine plus have access to them as their own variable if needed.&lt;/P&gt;

&lt;P&gt;The part I cant work out is the last part which will show the start and end times row as bits are turned on and off over time. With a column for each bit.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 12:55:38 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77349#M181538</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-03-28T12:55:38Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77350#M181539</link>
      <description>&lt;P&gt;Whoops didn't see this until I responded &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 12:56:36 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77350#M181539</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-03-28T12:56:36Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77351#M181540</link>
      <description>&lt;P&gt;You do bring up an interesting option though. I have thought about using a python script to perform the start-stop time detection with my existing search.&lt;/P&gt;

&lt;P&gt;I was just hoping to do it all in Splunk.&lt;/P&gt;

&lt;P&gt;It should be pretty straight forward with a python script so I may end up going down that route.&lt;/P&gt;

&lt;P&gt;There are also options for us to put that sort of detection in our data collection scripts however that then makes them stateful which we would prefer to avoid.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 12:58:02 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77351#M181540</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-03-28T12:58:02Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77352#M181541</link>
      <description>&lt;P&gt;Looking at your solution I like the use of 'makemv'. Never seen or used that before and its a good example of how it works.&lt;/P&gt;

&lt;P&gt;Thanks I will use makemv in the future for something I am sure.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 13:02:33 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77352#M181541</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-03-28T13:02:33Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77353#M181542</link>
      <description>&lt;P&gt;To sum up, you're trying to turn this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;time code1 code2 code3
  10     0     0     0
   9     1     1     0
   8     1     0     1
   7     0     0     1
   6     0     0     0
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;Into this:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;time code1 code2 code3
  10  8-10  9-10     -
   9   8-?   9-?   6-9
   8   8-?     -   6-?
   7     -     -   6-?
   6     -     -     -
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;?&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 13:51:28 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77353#M181542</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-03-28T13:51:28Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77354#M181543</link>
      <description>&lt;P&gt;You should probably re-word your problem - This has nothing to do with scada or bitwise operations - an google image search of SCADA doesn't show anything other than "whats happenening right now" - there's no historical data at all.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 14:22:55 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77354#M181543</guid>
      <dc:creator>jonuwz</dc:creator>
      <dc:date>2013-03-28T14:22:55Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77355#M181544</link>
      <description>&lt;P&gt;Thats exactly it Martin that it what I am trying to achieve. It was probably a long winded explanation but I wanted to give as much information as possible in order to assist with a solution.&lt;/P&gt;

&lt;P&gt;Jonuwz that is how this SCADA solution I am replicating in Splunk behaves. You will probably find a google image search doesnt really give you too much detail on how SCADA works. SCADA systems really shine when you use historical data to perform predictive failure analysis.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 19:42:48 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77355#M181544</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-03-28T19:42:48Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77356#M181545</link>
      <description>&lt;P&gt;This should do it:&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;| gentimes start=-1 increment=5m | eval code1 = if(starttime % 1800 &amp;gt; 600, 0, 1) | fields starthuman code1 | delta code1 as delta1 | eval output1 = case(delta1 == 1, starthuman." - ?", code1 == 0 AND delta1 == 0, "-") | filldown output1 | eval output1 = if(delta1 == -1, replace(output1, "\?", starthuman), output1) | reverse
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;&lt;IMG src="http://splunk-base.splunk.com//storage/scada.png" alt="results table" /&gt;&lt;/P&gt;

&lt;P&gt;Consider placing the bit from delta to the last eval (plus the fields - delta1 I omitted) into a macro with a variable for the field name/number to avoid your query growing hugely.&lt;/P&gt;</description>
      <pubDate>Thu, 28 Mar 2013 20:46:56 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77356#M181545</guid>
      <dc:creator>martin_mueller</dc:creator>
      <dc:date>2013-03-28T20:46:56Z</dc:date>
    </item>
    <item>
      <title>Re: SCADA bitwise registers time on and time off search</title>
      <link>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77357#M181546</link>
      <description>&lt;P&gt;That looks perfect thankyou. You sir are a genius!&lt;/P&gt;

&lt;P&gt;Good to see the 'gentimes' command too. Great way to similate results.&lt;/P&gt;

&lt;P&gt;Thanks again.&lt;/P&gt;

&lt;P&gt;Due to the frequency/volume of data coming from the engines I have discovered this search needs to actually run on a summary search which will only keep track of changes in the alarmCode which will be a much smaller data set.&lt;/P&gt;</description>
      <pubDate>Mon, 01 Apr 2013 23:49:59 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Search/SCADA-bitwise-registers-time-on-and-time-off-search/m-p/77357#M181546</guid>
      <dc:creator>phoenixdigital</dc:creator>
      <dc:date>2013-04-01T23:49:59Z</dc:date>
    </item>
  </channel>
</rss>

