5 Replies Latest reply on Nov 3, 2011 2:47 PM by Yanick Girouard

    Need help with custom grammar file

    Yanick Girouard

      I'm trying to understand the Extended Object grammar file documentation for BladeLogic 7.6, and I'm having trouble figuring out what I need to do to get what I want. Attached is the PDF documentation I found, and per our Premier Support contact, it's the latest for 7.6.

       

      My goal is to write a grammar file that will parse simple tab-delimited output (that's easy), but use the first 2 fields as the record key when storing the record in the database.

       

      Take the following example record (\t is a tab character):

       

      FIELD1\tFIELD2\tFIELD3

       

      I want the data to be stored in the BSARA reporting database as such (in the V_EXTENDED_OBJ_INFO_SNAPSHOT table) as such:

       

      asset_full_name=EXTENDED_OBJECT_NAME//FIELD1-FIELD2

      NAME=FIELD1

      COLUMN1=FIELD2

      COLUMN2=FIELD3

       

      Here's a basic tab-delimiter grammar file I am using at the moment. I would need to modify it to change the way it generate the key, if it's even possible (how can I concatenate fields in the argument passed to $save_record?):

       

      VAR_TAB \t

       

      %%

       

      COMMENT #.*

      VAL [^\t]*

      TAB \t

       

      %%

       

      comment COMMENT $save_as_comment $0

       

      sub_rule TAB VAL $new_field $1 %sub_rule

       

      record VAL $new_field $0 %sub_rule $save_record $0

       

      %%

       

      add $write_record $VAR_TAB

       

      An alternative to produce the desired results would be to generate the key in the first field of my output which would be parsed by my current grammar file, but that would generate a lot more work and tweaks with all of our EO's that produce tab-delimited output.

       

      The reason I want this, is to be able to properly store snapshots of something like this:

       

      Network Adapter 1\tIP Address\t192.168.1.20

      Network Adapter 1\tDefault Gateway\t192.168.1.1

      Network Adapter 1\tDNS Servers\t192.168.1.100 192.168.1.101

      Network Adapter 2\tIP Address\t192.168.1.21

      Network Adapter 2\tDefault Gateway\t192.168.1.1

      Network Adapter 2\tDNS Servers\t192.168.1.100 192.168.1.101

      Network Adapter 3\tIP Address\t192.168.1.22

      Network Adapter 3\tDefault Gateway\t192.168.1.1

      Network Adapter 3\tDNS Servers\t192.168.1.100 192.168.1.101

       

      And then be able to produce a BSARA Inventory Report, which would list the configuration of each adapter line by line, grouped by the name of the adapter.

       

      Example:

       

      ------------------+-----------------+----------------------------                 

      Network Adapter 1 | IP Address      | 192.168.1.20

                        | Default Gateway | 192.168.1.1

                        | DNS Servers     | 192.168.1.100 192.168.1.101

      ------------------+-----------------+----------------------------                 

      Network Adapter 2 | IP Address      | 192.168.1.21

                        | Default Gateway | 192.168.1.1

                        | DNS Servers     | 192.168.1.100 192.168.1.101

      ------------------+-----------------+----------------------------

      Network Adapter 3 | IP Address      | 192.168.1.22

                        | Default Gateway | 192.168.1.1

                        | DNS Servers     | 192.168.1.100 192.168.1.101

       

      The problem with the current grammar, is that since the ETL process looks at the key (or asset_full_name) of a record to define if a value was added, removed or modified since the last snapshot, it wouldn't be able to properly detect changes if the key is always the same thing for each row. I know I could use a horizontal layout (putting all values side by sides in columns), but then I wouldn't be able to list them vertically in a report to make them properly readable (some values are just too long to fit on a page horizontally).


        • 1. Re: Need help with custom grammar file
          Bill Robinson

          Why don’t you just change your output? that might be a lot easier.  How are you getting this output ?

          • 2. Re: Need help with custom grammar file
            Yanick Girouard

            I have litterally dozens of different extended object that parse unix and windows commands output to convert them into tab-delimited output, and more are coming on the way. The use of a control-character as a delimiter saves a lot of post-parsing since it's very unlikely to be in a value string. If I need to modify every single extended object to change their output format in order to do what I want, it's a lot more work. It would be much more helpful to have a generic grammar file that does the work for us when we need this type of output (double-field key) depending on what we want to do with it in BSARA Reporting.

             

            Is it that the grammar file language does not allow for what I want or that it's too complicated?

            • 3. Re: Need help with custom grammar file
              Bill Robinson

              If you know regex well, it should not be too complicated.  have you reviewed the grammar writing guide?

              https://communities.bmc.com/communities/docs/DOC-8603

              • 4. Re: Need help with custom grammar file
                Yanick Girouard

                That is the same document that I have attached to this thread if you take a look. So yes, I have. I would need more examples of what it's possible to do with it in order to understand how I can make it work. The syntax is not that intuitive for someone new to it.

                 

                I think I understand the most part of it, but I still don't know how to do what I want. For example, it says the $save_record command takes one argument, which is the key of the record. This seems to be what I need, but what it doesn't say, is how can you concatenate two fields together to make that key? All of the examples only show $0 as the parameter, which matches to the first field in the rule from what I get. Does it accept syntax such as $save_record $0-$1 ?

                • 5. Re: Need help with custom grammar file
                  Yanick Girouard

                  I found the solution!

                   

                  Here's the grammar file I wrote (the record line is wrapped, so unwrap it first):

                   

                  #

                  # Grammar: tab-delimited

                  # Uses first two fields as primary key

                  #

                   

                  VAR_TAB \t

                  VAR_KEY

                   

                  %%

                   

                  COMMENT #.*

                  VAL [^\t]*

                  TAB \t

                   

                  %%

                   

                  comment COMMENT $save_as_comment $0

                   

                  sub_rule TAB VAL $new_field $1 %sub_rule

                   

                  record VAL TAB VAL $new_field $0 $new_field $2 $save_var $VAR_KEY $0 $append_field_to_var $VAR_KEY $2 %sub_rule $save_record $VAR_KEY

                   

                  %%

                   

                  add $write_record $VAR_TAB

                   

                  Here is the Extended Object code I used to test it. I named the object CGI_Test:

                   

                  echo "Item1\tField1\tValue1"

                  echo "Item1\tField2\tValue2"

                  echo "Item1\tField3\tValue3"

                  echo "Item1\tField4\tValue4"

                  echo "Item2\tField1\tValue1"

                  echo "Item2\tField2\tValue2"

                  echo "Item2\tField3\tValue3"

                  echo "Item2\tField4\tValue4"

                  echo "Item3\tField1\tValue1"

                  echo "Item3\tField2\tValue2"

                  echo "Item3\tField3\tValue3"

                  echo "Item3\tField4\tValue4"

                  echo "Item4\tField1\tValue1"

                  echo "Item4\tField2\tValue2"

                  echo "Item4\tField3\tValue3"

                  echo "Item4\tField4\tValue4"

                   

                   

                  Here is the exported snapshot result showing how the data will be stored in the database:

                   

                  CGI_Test//Item1-Field1          Item1          Field1          Value1

                  CGI_Test//Item1-Field2          Item1          Field2          Value2

                  CGI_Test//Item1-Field3          Item1          Field3          Value3

                  CGI_Test//Item1-Field4          Item1          Field4          Value4

                  CGI_Test//Item2-Field1          Item2          Field1          Value1

                  CGI_Test//Item2-Field2          Item2          Field2          Value2

                  CGI_Test//Item2-Field3          Item2          Field3          Value3

                  CGI_Test//Item2-Field4          Item2          Field4          Value4

                  CGI_Test//Item3-Field1          Item3          Field1          Value1

                  CGI_Test//Item3-Field2          Item3          Field2          Value2

                  CGI_Test//Item3-Field3          Item3          Field3          Value3

                  CGI_Test//Item3-Field4          Item3          Field4          Value4

                  CGI_Test//Item4-Field1          Item4          Field1          Value1

                  CGI_Test//Item4-Field2          Item4          Field2          Value2

                  CGI_Test//Item4-Field3          Item4          Field3          Value3

                  CGI_Test//Item4-Field4          Item4          Field4          Value4