Help with multi-line regex data capture

94 views
Skip to first unread message

Shane Cauley

unread,
May 8, 2024, 12:42:07 PM5/8/24
to rundeck-discuss
I have a key value data match with the following output:

output.png
Here is the current log filter for the last step, step 3.

logfilter.png
I would like to modify the multi-line regex to only capture the first occurrence of "Disk.Bay.0" and nothing else.  The extract string match should like like this:

disk.png
Note, using Key Value log filter works but will only match the last line of output from a multi-line input. Thus trying the multi-line method.

I'm sure I am making this too difficult but first time working with Rundeck and multi-line regex.  Any guidance is greatly appreciated.

Shane Cauley

unread,
May 8, 2024, 1:02:47 PM5/8/24
to rundeck-discuss
Here is the unaltered output I wish to use as the input. 

- Drives detected for controller "RAID.SL.3-1" and RaidStatus
 - Disk: Disk.Bay.0:Enclosure.Internal.0-1:RAID.SL.3-1, Raidstatus: Ready
 - Disk: Disk.Bay.1:Enclosure.Internal.0-1:RAID.SL.3-1, Raidstatus: Ready

The input could vary from system to system but I always want the first occurrence of "Disk.Bay" (it may not be 0) up to the first comma in the line.  "Disk.Bay.0:Enclosure.Internal.0-1:RAID.SL.3-1"

Hope this is clear.

Shane Cauley

unread,
May 8, 2024, 2:35:11 PM5/8/24
to rundeck-discuss
I was able to accomplish what I needed with an inline Python script but still would be nice to know how to do this natively within Rundeck :-)

rac...@rundeck.com

unread,
May 8, 2024, 7:34:29 PM5/8/24
to rundeck-discuss

Hello,

I faced the same issue: the regex always gets the last match. So, another “tricky” way is to get the desired substring and post-process it natively in bash. I made an example, take a look at the regex string:

- defaultTab: nodes description: '' executionEnabled: true id: c2c7a769-5a8f-4f06-9a35-1137e718b02c loglevel: INFO name: REGEX nodeFilterEditable: false options: - enforced: true label: choose the disk name: disk value: '1' values: - '1' - '2' - '3' - '4' - '5' valuesListDelimiter: ',' plugins: ExecutionLifecycle: {} scheduleEnabled: true sequence: commands: - plugins: LogFilter: - config: captureMultipleKeysValues: 'true' hideOutput: 'false' logData: 'true' name: disks regex: '^.*(Disk.Bay.*)(?=,).*$' type: key-value-data-multilines script: |- echo " Drives detected for controller \"RAID.SL.3-1\" and RaidStatus" echo " - Disk: Disk.Bay.0: Enclosure.Internal.0-1:RAID.SL.3-1, Raidstatus: Ready" echo " - Disk: Disk.Bay.1: Enclosure.Internal.0-1:RAID.SL.3-1, Raidstatus: Ready" - exec: echo ${data.disks} | head -${option.disk} | tail -1 plugins: LogFilter: [] keepgoing: false strategy: node-first uuid: c2c7a769-5a8f-4f06-9a35-1137e718b02c

You can select the disk from the options and then see the desired string (probably you need only the first entry). Feel free to modify/improve the example.

Regards!

Reply all
Reply to author
Forward
0 new messages