Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

joinmatches doesn't work with embedded groups #69

Open
haowangapple opened this issue Jan 25, 2022 · 1 comment
Open

joinmatches doesn't work with embedded groups #69

haowangapple opened this issue Jan 25, 2022 · 1 comment

Comments

@haowangapple
Copy link

haowangapple commented Jan 25, 2022

joinmatches() doesn't work when the lines it matched appear after some other lines that are matched by an embedded group. This is similar to the following issue: #65

Example that is working:

<input load="text">
snmp-server chassis-id test
snmp-server enable traps bgp
snmp-server enable traps entity
snmp-server host 2.2.2.2 version 2c public
snmp-server host 1.1.1.1 version 2c public
</input>

<group name="snmp.config" expand="" >
snmp-server chassis-id {{ chassis_id }}
<group name="servers*" expand="" >
snmp-server host {{ server }} version {{ version }} {{ community }}
</group>
snmp-server enable traps {{ traps | joinmatches(',') | to_list }}
</group>

<output returner="terminal" format="json" />

It generates the following output, which is expected:

[
    {
        "snmp": {
            "config": {
                "chassis_id": "test",
                "servers": [
                    {
                        "community": "public",
                        "server": "2.2.2.2",
                        "version": "2c"
                    },
                    {
                        "community": "public",
                        "server": "1.1.1.1",
                        "version": "2c"
                    }
                ],
                "traps": [
                    "bgp",
                    "entity"
                ]
            }
        }
    }
]

However, if we move

snmp-server host 2.2.2.2 version 2c public
snmp-server host 1.1.1.1 version 2c public

above

snmp-server enable traps bgp
snmp-server enable traps entity

so that the embedded group "servers*" will match lines first, then the later joinmatches() does not work any more.
Here is the example code that show this:

<input load="text">
snmp-server chassis-id test
snmp-server host 2.2.2.2 version 2c public
snmp-server host 1.1.1.1 version 2c public
snmp-server enable traps bgp
snmp-server enable traps entity
</input>

<group name="snmp.config" expand="" >
snmp-server chassis-id {{ chassis_id }}
<group name="servers*" expand="" >
snmp-server host {{ server }} version {{ version }} {{ community }}
</group>
snmp-server enable traps {{ traps | joinmatches(',') | to_list }}
</group>

<output returner="terminal" format="json" />

And it generates following result, which doesn't include the joinmatches:

[
    {
        "snmp": {
            "config": {
                "chassis_id": "test",
                "servers": [
                    {
                        "community": "public",
                        "server": "2.2.2.2",
                        "version": "2c"
                    },
                    {
                        "community": "public",
                        "server": "1.1.1.1",
                        "version": "2c"
                    }
                ]
            }
        }
    }
]
@dmulyalin
Copy link
Owner

Added fix for this issue in latest commit 16c98a5, this is the test content -

def test_issue_69_fix():
- feel free to review or install from master and test for your environment, let me know how it goes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants