dmulyalin / ttp

Template Text Parser
MIT License
351 stars 34 forks source link

Hostname - Nokia-SR-OS #43

Closed paramountk closed 3 years ago

paramountk commented 3 years ago

Hi,

Really enjoying working with TTP. I am parsing Nokia output, and trying to use the getter for hostname and it's not working. I see it;'s not in supported list.

Would you consider adding to this list? The Nokia is simply as per below. The : is the separator before the hostname.

*A:hostname#

I added a space to my nodal config to see if it would match like a Cisco one, but still didn't seem to work.

Thanks for any help

Kieran

dmulyalin commented 3 years ago

Hi Kieran,

Thanks for raising this issue. Used this as a reference: Page 30 of https://documentation.nokia.com/cgi-bin/dbaccessfilename.cgi/9300700701_V1_7750%20SR%20OS%20Basic%20System%20Configuration%20Guide%208.0r1.pdf

Starting with commit 597f614d9c8ec303ff7dca7592c846d334222ad9 gethostname should extract hostname properly from these SROS' prompts:

Feel free to install from master and test:

python -m pip uninstall ttp
python -m pip install git+https://github.com/dmulyalin/ttp
paramountk commented 3 years ago

Hi,

Thankyou so much for quick response. I uninstalled and re-installed as you suggested, but it still seems not to be pulling out the hostname.

I changed the hostname back to very simple: hostA, so that when connected it looks like this:

*A:hostA#

Which I believe matches one of your options above, but I still get not found when using:

hostname_var = "gethostname"

*A:hostA# ttp.functions.variable_gethostname: "text_data" file, Hostname not found

Many thanks Kieran

paramountk commented 3 years ago

Hi,

OK, so I replaced my dynamic output with pasted static output, and now the variable got picked up, so I think it's probably to do with my output - may be to do with \n or formatting etc. I will continue to try and get working - but looks like the TTP aspect is doing exactly what it should with the static output.

Thanks again for your support Kieran

Static output: "vars": { "hostname_var": "hostA" } } ]

Dynamic output: "vars": {} } ]

dmulyalin commented 3 years ago

Regarding not detecting hostname in dynamic output, got issue #44 sorted recently, could you try to reinstall from master and test it again to see if it fixes the problem?

paramountk commented 3 years ago

Hi,

Thanks for this. But, I am not sure if there will be a way for this to work.

I am using genie to connect to the node and run the commands, but, it seems that what gets passed to TTP does not include the hostname. It is just the command output only.

Thanks K

dmulyalin commented 3 years ago

You can match hostname from device configuration, for instance for Cisco IOS (not sure on command for SR OS) you can run something like show run | inc hostname, extract hostname from output and save it in template variables using record function.

E.g. data:

hostname lab-sw1

... additional data to parse

template:

<vars name="my_vars">
hostname_var=""
</vars>

<group void="">
hostname {{ hostname_var | record("hostname_var") }}
</group>

<!--
Other template goes here
-->

would produce:

[
    [
        {
            "my_vars": {
                "hostname_var": "lab-sw1"
            }
        }
    ]
]

void="" - tells TTP to not include group match results in overall results

paramountk commented 3 years ago

Got it!! many thanks, it works now exactly as you suggested.

    "my_vars": {
        "hostname_var": "hostA"
    }

Thanks for your support.

Command I used on SROS was:

show system info | match Name

K

dmulyalin commented 3 years ago

Great, let me know if anything else pop up.