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

Add support for cisco static nat #1

Closed
abhi1693 opened this issue May 2, 2022 · 11 comments
Closed

Add support for cisco static nat #1

abhi1693 opened this issue May 2, 2022 · 11 comments

Comments

@abhi1693
Copy link

abhi1693 commented May 2, 2022

Command

show run | include source static

Sample output

ip nat inside source static 10.10.10.10 3.3.3.3 extendable
ip nat inside source static tcp 192.168.1.10 443 3.3.4.4 443 vrf VRF1000 extendable
ip nat inside source static 192.168.2.10 3.3.4.5 vrf VRF1002 extendable
ip nat inside source static tcp 192.168.3.10 3389 3.3.5.6 13389 extendable
ip nat inside source static 20.20.20.20 6.6.6.6 extendable
ip nat inside source static tcp 30.30.30.30 443 interface TenGigabitEthernet0/0/0 1443
@dmulyalin
Copy link
Owner

Hi, sure, happy to add. Could you share a template to work on as a starting point.

@abhi1693
Copy link
Author

abhi1693 commented May 2, 2022

I don't have anything for a template yet. I found your repo about 3 hours ago and still trying to figure out how I can contribute to this. I have a few more commands that I'd like to parse via this.

@abhi1693
Copy link
Author

abhi1693 commented May 2, 2022

I have started with something but I'm at a loss at the moment of why the defaults are not being replaced when they are not found in the data. I'm using the sample input I have shared in the description. This template cannot detect the last line with the interface and I'm trying to go through the docs to find how to go about achieving the desired results.

template:

<vars>
default_values = {
    "protocol": "",
    "inside_port": 0,
    "global_port": 0,
    "vrf": "",
}
</vars>

<group default="default_values" to_int="inside_port, global_port">
ip nat {{ location }} source static {{ protocol }} {{ inside_ip }} {{ inside_port }} {{ global_ip }} {{ global_port }} {{ ignore }} {{ vrf }} extendable
</group>

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

output:

[
    [
        {
            "global_ip": "3.3.4.4",
            "global_port": 443,
            "inside_ip": "192.168.1.10",
            "inside_port": 443,
            "location": "inside",
            "protocol": "tcp",
            "vrf": "VRF1000"
        }
    ]
]

Any suggestions here?

@abhi1693
Copy link
Author

abhi1693 commented May 2, 2022

I have also tried writing a template like

<template>
<input name="static_nat" commands="show run | include source static ([0-9])+"/>
<input name="static_nat_intf" commands="show run | include source static.*interface"/>

<group name="result**" input="static_nat">
ip nat {{ location }} source static {{ inside_ip }} {{ global_ip }} extendable
</group>

<group name="result**" input="static_nat">
ip nat {{ location }} source static {{ protocol }} {{ inside_ip }} {{ inside_port | to_int }} {{ global_ip }} {{ global_port | to_int }} extendable
</group>

<group name="result**" input="static_nat">
ip nat {{ location }} source static {{ protocol }} {{ inside_ip }} {{ inside_port | to_int }} {{ global_ip }} {{ global_port | to_int }} vrf {{ vrf }} extendable
</group>

<group name="result**" input="static_nat_intf">
ip nat {{ location }} source static {{ inside_ip }} interface {{ interface }}
</group>

<group name="result**" input="static_nat_intf">
ip nat {{ location }} source static {{ protocol }} {{ inside_ip }} {{ inside_port | to_int }} interface {{ interface }} {{ global_port | to_int }}
</group>

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

And, this is resulting in an empty result. The groups work when I run them individually but ideally all the results should be returned in a combined result.

@abhi1693
Copy link
Author

abhi1693 commented May 2, 2022

3rd times a charm!!!

I got everything to work but as individual ttp commands. Ideally, if these can be run via a single template, that would be much easier to parse.

I have attached all the files that are working here along with the command which returns the result for them
static_nat_intf.txt: show run | include source static ([0-9]+).*interface
static_nat_simple.txt: show run | include source static ([0-9]+) This also has results with keyword vrf. I could not figure out to exclude those.
static_nat_vrf.txt: show run | include source static ([0-9]+).*vrf
static_pat_intf.txt: show run | include source static (tcp|udp).*interface
static_pat_simple.txt: show run | include source static (tcp|udp).* This also has results with keyword interface and vrf. I could not figure out to exclude those.
static_pat_vrf.txt: show run | include source static (tcp|udp).*vrf

I hope this is helpful for you to build the template.

dmulyalin added a commit that referenced this issue May 4, 2022
@dmulyalin
Copy link
Owner

Added template - https://dmulyalin.github.io/ttp_templates/ttp_templates/platform.cisco_ios_show_running_config_pipe_include_source_static/

Also created contribute guide - https://dmulyalin.github.io/ttp_templates/contribute/

Please check above template and let me know your thoughts.

@abhi1693
Copy link
Author

abhi1693 commented May 4, 2022

I'll try this today and let you know

@abhi1693
Copy link
Author

abhi1693 commented May 7, 2022

The template seems to be working. I'll integrate it into my app and recheck the results

@abhi1693
Copy link
Author

abhi1693 commented May 7, 2022

This is working as expected, closing

@abhi1693 abhi1693 closed this as completed May 7, 2022
@abhi1693
Copy link
Author

abhi1693 commented May 27, 2022

After updating the latest code from the master branch for both salt-nornir and nornir-salt, I have started to receive the following error

ttp_parser.check_matches: match variable function 'INT' failed, data '2813', error ''str' object has no attribute 'INT''

cc @dmulyalin

@dmulyalin
Copy link
Owner

Thank you for raising this problem, that was a typo in "cisco_ios_show_running_config_pipe_include_source_static" template, instead of INT it should be DIGIT, fix is in 0.1.4

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