Forum Discussion

jsgibbs1's avatar
jsgibbs1
Icon for Nimbostratus rankNimbostratus
Aug 15, 2015

Parse data w/white spaces

I need to split data received from a sideband connection on white space. However, the data packet includes a PKI Subj DN with spaces that I don't want to split.

 

Data Format: Some_More_Data1: cn=last first middle initials, ou=xxx,ou=yyy,ou=zzz,o=aaa,c=bb Some_More_Data2: xxx Some_More_Data3: yyy Some_More_Data4: zzz

 

Ideally, I'd like to be able: 1) Parse the receive packet for each occurrence of Some_

 

2) Trim Some_ and keep the remaining header More_Data

 

3) Grab the associated variable after the colon: xxx then insert the pair HTTP::header insert More_Data $value

 

Appreciate any suggestions

 

1 Reply

  • While still searching for a way to make this dynamic, I was permitted to hard-code it temporarily. I wanted to post what I have with questions.

     

    The findstr command includes a blank space after each data field I needed to insert and caused the header inserts to fail. So, I added a trim command to remove the space. Is there a way to make this a one-line command?

     

    Also, I need to insert the headers on a Permit or Deny status. How do I do that w/out duplicating the code as I'm currently doing?

     

    ($recv_data excerpt:)

     

    Some_More_Data1: cn=last first middle initials, ou=xxx,ou=yyy,ou=zzz,o=aaa,c=bb Some_More_Data2: xxx Some_More_Data3: yyy Some_More_Data4: zzz status=Permit

     

    set Some_More_Data1 [findstr $recv_data "Some_More_Data1:" 15 "Some"

     

    set Some_More_Data1_trim [string trim $Some_More_Data1]

     

    set Some_More_Data2 [findstr $recv_data "Some_More_Data2:" 15 "Some"

     

    set Some_More_Data2_trim [string trim $Some_More_Data2]

     

    set Some_More_Data3 [findstr $recv_data "Some_More_Data3:" 15 "Some"

     

    set Some_More_Data3_trim [string trim $Some_More_Data3]

     

    if {$recv_data contains "permit" } {

     

    HTTP::header insert insert Some_More_Data1 $Some_More_Data1_trim

     

    HTTP::header insert insert Some_More_Data1 $Some_More_Data2_trim

     

    HTTP::header insert insert Some_More_Data1 $Some_More_Data3_trim

     

    log local0. "Inserted Some_More_Data1 $Some_More_Data1_trim

     

    log local0. "Inserted Some_More_Data2 $Some_More_Data1_trim

     

    log local0. "Inserted Some_More_Data3 $Some_More_Data1_trim

     

    }

     

    else {

     

    HTTP::header insert insert Some_More_Data1 $Some_More_Data1_trim

     

    HTTP::header insert insert Some_More_Data1 $Some_More_Data2_trim

     

    HTTP::header insert insert Some_More_Data1 $Some_More_Data3_trim

     

    log local0. "Inserted Some_More_Data1 $Some_More_Data1_trim

     

    log local0. "Inserted Some_More_Data2 $Some_More_Data1_trim

     

    log local0. "Inserted Some_More_Data3 $Some_More_Data1_trim

     

    }