Got posed a tricky question today for a search.
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.
ie
bit 0 - high_rpm
bit 1 - high_temp
bit 2 - low_temp
etc....
Now this generator is being polled every 5 seconds and data results are begin fed back into Splunk.
So an event would look like this (where sectionCode identifies the generator)
time_of_event, sectionCode=generator1, alarmCode, rpm, output_kw
So I was asked to show a list of when alarms went on and off so I came up with this search.
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
and the macro gen_alarm_decode decodes the bitwise values into human readable terms. (this works fine)
eval description=if(floor($bitVar$)%2>0,"High RPM, ","") | eval description=description + if(floor($bitVar$/2)%2>0,"High Temp, ","") | eval description=description + if(floor($bitVar$/4)%2>0,"Low Temp, ","")
Now this search returns me a list of all entries where the alarmCode changed and what the remaining alarmCodes that were still set were.
So results would look like this
Sun 10:35pm, generator1, 0,
Sun 10pm, generator1, 2, High Temp
Sun 8pm, generator1, 3, High RPM, High Temp
etc.....
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.
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
So it should be something like this (put in a pseudo csv/table format for display here)
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.....
Note ? above are for where the alarm is still on. The - are for when alarm is off.
If it helps matters I have also decoded the bitwise field on our custom modbus poller. So really events look like this
time_of_event, sectionCode=generator1, alarmCode, rpm, output_kw, bitAlarm0, bitAlarm1, bitAlarm2
The only reason I didn't mention it until now was because I didn't need those bitfields yet.
Anyone have any thoughts. It has me slightly stumped. If I find a solution will post here regardless.
... View more