Skip to content

RFC: pattern template support #76

@ihrwein

Description

@ihrwein

In my very first proposal I mentioned the pattern reuse problem: there are similar patterns and we want to gather the common parts into one pattern which can be used by the others:

{                                                                                                                                                
    "patterns": [                                                                                                                                
        {                                                                                                                                        
            "pattern": "loading configuration from '%{GREEDY:file}'",                                                                            
            "name": "bind9",                                                                                                                     
            "uuid": "db36c4bf-0310-41d4-b59a-1dfe1929c4da"                                                                                       
        },                                                                                                                                       
        {                                                                                                                                        
            "pattern": "general: loading configuration from '%{GREEDY:file}'",                                                                   
            "name": "bind9",                                                                                                                     
            "uuid": "db36c4bf-0310-41d4-b59a-1dfe1929c4da"                                                                                       
        }                                                                                                                                        
    ]                                                                                                                                            
} 

The loading configuration from '%{GREEDY:file}' part is common in both pattern definitions.

The proposed syntax is the following:

{                                                                                                                                                
    "patterns": [                                                                                                                                
        {                                                                                                                                        
            "pattern": "%{BIND9_LOADING_CONFIG}",                                                                                                
            "name": "bind9",                                                                                                                     
            "uuid": "db36c4bf-0310-41d4-b59a-1dfe1929c4da"                                                                                       
        },                                                                                                                                       
        {                                                                                                                                        
            "pattern": "general: %{BIND9_LOADING_CONFIG}",                                                                                       
            "name": "bind9",                                                                                                                     
            "uuid": "db36c4bf-0310-41d4-b59a-1dfe1929c4da"                                                                                       
        }                                                                                                                                        
    ],                                                                                                                                           
    "templates": [                                                                                                                               
        {                                                                                                                                        
            "pattern": "loading configuration from '%{GREEDY:appacct.conf_file}'",                                                               
            "name": "BIND9_LOADING_CONFIG",                                                                                                      
            "test_messages": [                                                                                                                   
                {                                                                                                                                
                    "message": "loading configuration from '/etc/bind/unctions.overreact.tld'",                                                  
                    "values": {                                                                                                                  
                        "appacct.conf_file": "/etc/bind/unctions.overreact.tld"                                                                  
                    }                                                                                                                            
                }                                                                                                                                
            ]                                                                                                                                    
        }                                                                                                                                        
    ]                                                                                                                                            
}

At first I'd support only the SET, INT, GREEDY parsers in templates. If that's not enough we may enable cross references between templates, but we have to care about cycles in the graph.

I'd support the following attributes in pattern templates:

  • name: it's mandatory
  • pattern: it's mandatory
  • tags: optional tags (copied into the referencing pattern)
  • values: optional values (copied into the referencing pattern)
  • test_messages: optional test messages. They aren't copied into the pattern, because the message wouldn't match every time.

Pattern templates doesn't have uuid:

  • user would expect that a pattern can inherit it: but what if they forgot to include the uuid in the template?
  • pattern templates are referenced by their names

I'm not sure about the "pattern template" expression. Maybe the user defined parser or user defined template would be a better option.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions