Git Product home page Git Product logo

textfsm's Introduction

TextFSM

Python module which implements a template based state machine for parsing semi-formatted text. Originally developed to allow programmatic access to information returned from the command line interface (CLI) of networking devices.

The engine takes two inputs - a template file, and text input (such as command responses from the CLI of a device) and returns a list of records that contains the data parsed from the text.

A template file is needed for each uniquely structured text input. Some examples are provided with the code and users are encouraged to develop their own.

By developing a pool of template files, scripts can call TextFSM to parse useful information from a variety of sources. It is also possible to use different templates on the same data in order to create different tables (or views).

TextFSM was developed internally at Google and released under the Apache 2.0 licence for the benefit of the wider community.

See documentation for more details.

Before contributing

If you are not a Google employee, our lawyers insist that you sign a Contributor Licence Agreement (CLA).

If you are an individual writing original source code and you're sure you own the intellectual property, then you'll need to sign an individual CLA. Individual CLAs can be signed electronically. If you work for a company that wants to allow you to contribute your work, then you'll need to sign a corporate CLA. The Google CLA is based on Apache's. Note that unlike some projects (notably GNU projects), we do not require a transfer of copyright. You still own the patch.

Sadly, even the smallest patch needs a CLA.

textfsm's People

Contributors

aplanas avatar buxtronix avatar harro avatar jmcgill298 avatar ktbyers avatar legnbass avatar nicolascanceill-optiver avatar shamrin avatar sumkincpp avatar tirkarthi avatar xavierhardy avatar ytti avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

textfsm's Issues

Loading fcntl in terminal breaks windows load on Netmiko

I wanted to added textfsm parsing into the output of network device show commands in the Netmiko library, but the terminal.py module imports fcntl (which breaks Windows support):

https://github.com/google/textfsm/blob/master/terminal.py#L28

For use in TerminalSize() function. My use case doesn't use this TerminalSize() function.

Would you be willing to make that import conditional?

For example, something like the following:

try:
    import fcntl
    USE_FCNTL = True
except ImportError:
    USE_FCNTL = False

Then on TerminalSize() something like:

def TerminalSize():
  """Returns terminal length and width as a tuple."""
  try:
    with open(os.ctermid(), 'r') as tty_instance:
      if USE_FCNTL:
          length_width = struct.unpack(
              'hh', fcntl.ioctl(tty_instance.fileno(), termios.TIOCGWINSZ, '1234'))
      else:
          # Basically raise an error so it falls to your other try/except handler
          raise OSError()
  except (IOError, OSError):
    try:
      length_width = (int(os.environ['LINES']),
                      int(os.environ['COLUMNS']))
    except (ValueError, KeyError):
      length_width = (24, 80)
  return length_width

If you are willing to accept a PR similar to this, I will write it and submit it.

Parentheses in variable definition

I had an issue where i put an opening parenthesis in my variable definition as such:
Value interface ([^ (]+)

Textfsm instance raised a TextFSMTemplateError exception
Value '([^ (]+)' must be contained within a '()' pair.

Is this a bug?

textfsm.py is missing

Hi

I am not able to locate the file textfsm.py in the repository. Has it been removed by mistake? Please check.

Thanks,
Mani

How to match string from end

How to match a string from end:

String:
Github is good

Want to match good from right to left

Value string ((\S+)$)

Start
    ${string} -> Record

Expected Answer:
good

Result:
[ ]

Include test files in tarball and pypi releases

Both the GitHub release and pypi tarballs are missing the tests/ directory, which prevents packagers from running unit tests during a package build.

Would it be possible to include this directory in releases? Thanks in advance.

How to loop over multiple newlines in a match.

I'm running into an issue where I'd love to select and loop over each line after a specific match:
For example.

Text I'm parsing

Order:120983
Status: Error

ORDER LEVEL ERROR(S):
      ERRORCODE1: BAD THINGS HAPPENED
Heres a new line with more details about this bad error and things.
Heres another new line about the error.
      ERRORCODE2: MORE BAD THINGS HAPPENED
Heres a new line with more details about this bad error and things.
Heres another new line about the error.

-------------------

Template

Value ERROR_CODE (\w+)
Value ERROR_MESSAGE (.*)

Start
  ^ORDER LEVEL ERROR\(S\): -> ErrorList

ErrorList
  ^\s{6}${ERROR_CODE}:${ERROR_MESSAGE} -> Record

Results

ERROR_CODE | ERROR_MESSAGE
ERRORCODE1 | BAD THINGS HAPPENED
ERRORCODE2 | MORE BAD THINGS HAPPENED

As you can see I can get the first line just fine, but I'm struggling to figure out how to snag the next lines referring to that error. Anything I've tried seams to grab too much, and will start grabbing things in the next error code.

Essentially how would i get all new lines before the next error code?
Thanks for any insight or thoughts!

Cannot install due to textfsm issue

Hi All
I have a critical issue with textfsm and gtextfsm:
When I try an installation of a module called pycsco, I encountered this error message:
: =============================
sudo -H pip install pycsco --proxy="http://proxy.rd.francetelecom.fr:8080"
Collecting pycsco
Downloading https://files.pythonhosted.org/packages/55/6d/47e3fc0ae13d34a87f6328cb724f65e0484ce76b21de23e5767ecdfeddef/pycsco-0.3.5.tar.gz (54kB)
100% |████████████████████████████████| 61kB 1.7MB/s
Collecting gtextfsm==0.2.1 (from pycsco)
Downloading https://files.pythonhosted.org/packages/98/12/edfdccf3d968ffbb94ac8e48b3172395b6902eb4265bded0b0d07a1652f3/gtextfsm-0.2.1.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-403qlws9/gtextfsm/setup.py", line 19, in
import textfsm
File "/tmp/pip-install-403qlws9/gtextfsm/textfsm/init.py", line 2, in
version = textfsm.version
NameError: name 'textfsm' is not defined

Thanks for help this is extremely annoying.
Regards

Proposals

Trying to get a feel for what the appetite for a few updates into textfsm are. Using it a fair amount I have identified a few short comings (that you can work around, but are difficult.)

Missed captures
Example: I recently had a case in which on a "show interface status" I hit a condition in about %2 of interfaces. My data size what over 60K of interfaces so it was not easy to find.

Proposal: Set a flag that indicates all lines must match. Not that there must be a capture group in a given match, but that simply you have seen every line, and have profiled it already. Meaning that if it completes the rule set without a match, fail. This would be helpful when trying to match large routing tables, or large amounts of data to identify an issue early.

Repeated Data
Example: As noted in #11 when data is repeated, there is not an elegant solution to capture the multiple items

Proposal: A new key (RepeatedItem) that will reprocess a line with the assumption that there is repeated data, and to add to the list.

Trim()
Example: Often it is tough (reverse or forward lookbacks is the only way I have found) to get rid of pre/post white space.

Proposal: A new key (Trim) that will do minor post processing on the data after the match

Column Count
Example: Some output is merely based on column count (routing tables especially) and difficult to match when data may or may not be there.

Proposal: This is clearly the flimsiest of the proposals, however I would like a mechanism to identify the regex in one space, and just define space counts in the next.

Documentation about 'forward match' style

Hello,

I have read the WIKI page and I noticed in the Using 'List' section this section:

This example was somewhat more complex than the average List usage. If there is a clear delimiter between rows, then that can be used for the Record rather than having to do the 'forward match' style here.

Can you explain that 'forward match' style in this WIKI documentation, please?

Regards,
Ludovic

textfsm for cisco_ios show mac address-table not pulling entries for VLAN #s greater than 999

When i run 'show mac address-table with TextFSM on a Cisco_IOS device, i've noticed that it only grabs lines for entries where the VLAN is 3 characters or less. When the VLAN # is 4 digits in length, there is no whitespace to start the line.

Within the cisco_ios_show_mac-address-table.template file i've removed the '/s+' from the beginning of TYPE4 and it will then grab only the MAC entries where there is no whitespace to start (VLANs 1000 and greater) but it will not pick up the entries where the VLAN leads with whitespace.

I tried adding a TYPE5 where there is no '\s+' to begin but it had no impact.

I'm still learning regular expressions so please forgive me if this is an easy fix.

Can you tell me what changes i need to make to the template to get results for entries with VLANs that lead with whitespace and those without?

Thanks,
Chris

Template file handed to the TextFSM should have their file pointer put to the top of the file.

What steps will reproduce the problem?
Take any pointer to a template file and reuse it with subsequent TextFSM() 
calls.

What is the expected output? What do you see instead?
Expected output would be nothing, instead get:
Missing state 'Start'.

Basically, you want to have one reference to a template as a module level 
constant:

# Read in textfsm template and have it parse the output.
TMP = open(os.path.join(PATH, 'some_template'))

If you were to do:
 re_table = textfsm.TextFSM(TMP)
 parse_results = re_table.ParseText(output_text)
 re_table = textfsm.TextFSM(TMP)
 parse_results = re_table.ParseText(output_text)

The second one would fail.  The reason being is that textfsm is not putting the 
file pointer back to the top of the file.  This means I need to move the file 
pointer back to the top each time.  This should be done inside textfsm.

Original issue reported on code.google.com by [email protected] on 8 Apr 2011 at 9:21

Issue with Textfsm and StringsIO

I am seeing an issue where I have a template defined as a string object like this:

`interface = StringIO('''Value Key,Required interface (\w+1\d{1,2})
Value Required avlan ([0-9]+)
Value tvlan (([0-9]+,)+)

Start
^\sinterface ${interface} -> Continue
^\s
switchport access vlan ${avlan} -> Continue
^\s*switchport trunk allowed vlan ${tvlan} -> Record''')

template = textfsm.TextFSM(interface)
return template.ParseText(config), template`

In an older version, using this as the template for parsing data would work just find, however now I am seeing this issue when I attempt to use a template defined in this way:

File "/usr/local/lib/python3.7/site-packages/jtextfsm.py", line 852, in ParseText lines = text.splitlines() AttributeError: '_io.TextIOWrapper' object has no attribute 'splitlines'

Import Functionality [Feature Request]

Breakout from #18 to better discuss and judge interest.

Often it is useful to have two states that are very similar, with a few different expressions. Since Continue and state transitions are disallowed due to possible infinite loop issues, a way of reducing development time and redundant SLOC would be to allow a state to import another state which would be evaluated as a setup time macro.

E.g:

Start
  \<some expressions\>
  $$IMPORT ToImportState
  \<some expressions\>

ToImportState
  \<some expressions\>
  ^\S -> Start

Questions:

  1. is there interest in this feature?
  2. is there interest in a separate import feature that does not allow the imported statements to initiate a state transition?
  3. What might the syntax look like? Currently the $$IMPORT is a placeholder.

Potential issues:

  1. Cyclical dependencies. This would be solved by not importing anything which has already been imported into a state. Another option would be only to allow immediate imports.
  2. Debug output statements would become slightly more complex. A current suggestion is to provide a back trace like: line: 10.102.50 where line 50 is the error, but was imported by line 102, which was in turn imported from line 10, which is your current state.
  3. This would likely add complexity to the visual debugger #48 .
  4. Unless using only immediate imports as a simple copy-paste macro, or forgoing a reasonable debug output, this feature would add a decent amount of complexity to multiple parts of the code.

Personally, when I was writing/editing/maintaining templates this feature probably would have saved me a few hours a month in development time. Which is to say it would have been nice but clearly wasn't a deal-breaker.

juniper_bgp_summary_template assumes record ends on IPv6 RIB

https://github.com/google/textfsm/blob/master/examples/juniper_bgp_summary_template

seems to assume every neighbour has IPV6 RIB which terminates record. Obviously this is not true, neighbours can have arbitrary set of RIBs and record is terminated when we introduce new neighbour or at double new line.

How can this be expressed in textfsm? Example should reflect this, having neighbor with just inet4, just inet6 and both (There could be many others too, so we can't create exhaustive list).

Possible to change name of clitable to cli_table?

There's another read to clitable which may offend some.

I'm happy to submit a PR if this is something the maintainers would be open to. Although, I realize that leads to a backwards incompatible change to the module.

Create source dist for textFSM 1.1.0

The build system I'm using relies on building PIP libraries from source. We would like to upgrade to textFSM 1.1.0 but there is currently no source package for this version in PyPi. Would it be possible to create one?

Named Records??

hi, Sir

I have some text files store data like machine, software part# and hardware part#. the format is as something like:
Model: Y300
SN: 1111111111
Ship Date: 2018/4/25
State: Cancel
...
SW 1111 Windows 10
SW 1112 Office 2013
SW 1113 Eclipse 3.0
...
HW 2012 Intel CPU I6 ---
HW 2013 4GB DIMM
.....
It is a clear there are 2 one-to-many associated tables.. (machine -->hardware , machine-->software)
However when using textfsm to parser the text , all parts will be store into a single record, that is bad for further processing.(I can not recognized it is SW or HW just from part#)

My current solution is spilt my template into SW.fsm and HW.fsm, it can work, but no elegant. My I know if TextFSM can provide a feature like naming records , which allow me to create tables to store value by logic, the template can work like this

Record("Order") PK ${SN} # Claim a record with a Primary Key
Record ("Order") one-many Record ("SW") # associate other record
Record ("Order") one-many Record("HW") # associate other record

Model: ${modle} -> Record("Order")
SW ${SW} ... ->Record("SW")
HW ${SW} ... ->Record("HW")

After parse , there will be 3 tables in memory present with 2 1-to-many relationship.

BR
RAy

PyPi update version

Can we please get v1.0.0 published to PyPi? Currently it is still showing v0.4.1.

no timeout error or functionality

Proposal to add a detailed timeout error allowing the template developer to quickly identify the offending regular expression.

I have found that some poorly written templates may have a line or lines that are syntactically correct but often result in a timeout when searching for a match. When this happens it may be hard to diagnose which line in the template is causing an issue.

Is this an issue worth addressing?

Can not work using python37-32 install by pip install textfsm

Description:
Can not work using python37-32 install by pip install textfsm

Steps To Reproduce:
1. install python37-32 in win10
2.pip install textfsm
3. import textfsm
will get:
import textfsm
ImportError: bad magic number in 'textfsm': b'\x03\xf3\r\n'

terminal.py is not copied during setup

terminal.py is not copied when running setup.py install
can't import clitable after installing the module because terminal can't be found

should it be added to :
py_modules=['clitable', 'textfsm', 'copyable_regex_object', 'texttable', 'terminal']) ?

Transition to "End" state does not terminate processing of input lines

What steps will reproduce the problem?
Using the attached example files:
 textfsm.py exampletemplate exampleinput

What is the expected output?
FSM Table:
['IsOK', 'LineNo']
['OK', '1']
['OK', '2']

What do you see instead?
FSM Table:
['IsOK', 'LineNo']
['OK', '1']
['OK', '2']
['OK', '4']
['OK', '5']

What version of the product are you using? On what operating system?
textfsm 0.2.0, Ubuntu 10.04.4 LTS, x86_64, Python 2.6.5


TextFSMHowto mentions that "The End state is reserved and terminates processing
of input lines and does not execute the EOF state."
This doesn't seem to work. The exampletemplate file also contains my current
workaround, i.e. transition to a state "Foo" which has no rules, but while
faster it's not a real solution.

Original issue reported on code.google.com by [email protected] on 25 Apr 2012 at 1:20

Attachments:

How to record a Value only if it has changed?

Summary

I'm parsing a CISCO BGP router address-family using TextFSM. How can I record BGP neighbor only when a new one is match ?

WARNING all below data is fake.


Some sample configuration

 address-family ipv4 vrf EASY-GOING
  no synchronization
  neighbor 10.42.80.2 remote-as 64442
  neighbor 10.42.80.2 inherit peer-session LTE-ASR
  neighbor 10.42.80.2 description *** some EASY-GOING router ***
  neighbor 10.42.80.2 activate
  neighbor 10.42.80.2 inherit peer-policy LTE-ASR
  neighbor 10.42.80.2 default-originate
 exit-address-family
 !
 address-family ipv4 vrf THE-MONTAIN
  import path selection all
  import path limit 8
  no synchronization
  redistribute static route-map advertise-primary
  redistribute connected route-map advertise-primary
  neighbor 10.144.139.165 remote-as 65021
  neighbor 10.144.139.165 description *** peering CASE DMZ MONTAINVPDMZ01 ***
  neighbor 10.144.139.165 route-map RESILIENCE_VIPS_EXT
  neighbor 10.144.139.166 remote-as 65021
  neighbor 10.144.139.166 ebgp-multihop 5
  neighbor 10.144.139.166 update-source Vlan508
  neighbor 10.144.139.166 route-map DENY_ALL out
 exit-address-family

What I want

+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+
|     VRF     |    NEIGHBOR    | REMOTE-AS |               DESCRIPTION               |      ROUTE-MAP      | UPDATE-SRC | MULTIHOP_NB |
+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+
| EASY-GOING  | 10.42.80.2     |     64442 | *** some EASY-GOING router ***          |                     |            |             |
| THE-MONTAIN | 10.144.139.165 |     65021 | *** peering CASE DMZ MONTAINVPDMZ01 *** | RESILIENCE_VIPS_EXT |            |             |
| THE-MONTAIN | 10.144.139.166 |           |                                         | DENY_ALL out        | Vlan508    |           5 |
+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+

Warning There are far more possible configuration options for each neighbor, above output and table are just samples. Beside, there is not any pattern, a neighbor can have only one configuratoin (e.g a timer) or a very large number. The consequence is that I can't use them as separator between two different neighbors.


What I tried

Use end of block to record

$ cat templates/cisco_show_run_part_address-family_ipv4_vrf_00.template    
Value Filldown VRF (\S+)
Value NEIGHBOR (\S+)
Value REMOTE_AS (\d+)
Value DESCRIPTION (\S+)
Value ROUTE_MAP (\S+)
Value UPDATE-SRC (\S+)
Value MULTIHOP_NB (\d+)

Start
  ^ address-family ipv4 vrf ${VRF} -> NEIGHBOR

NEIGHBOR
  ^  neighbor ${NEIGHBOR} remote-as ${REMOTE_AS}
  ^  neighbor ${NEIGHBOR} route-map ${ROUTE_MAP}
  ^  neighbor ${NEIGHBOR} description ${DESCRIPTION}
  ^  neighbor ${NEIGHBOR} update-source ${UPDATE-SRC}
  ^  neighbor ${NEIGHBOR} ebgp-multihop ${MULTIHOP_NB}
  ^ exit-address-family -> Record Start
$ 

What I get

+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+
|     VRF     |    NEIGHBOR    | REMOTE-AS |               DESCRIPTION               |      ROUTE-MAP      | UPDATE-SRC | MULTIHOP_NB |
+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+
| EASY-GOING  | 10.42.80.2     |     64442 | *** some EASY-GOING router ***          |                     |            |             |
| THE-MONTAIN | 10.144.139.166 |    65021  |  *** peering CASE DMZ MONTAINVPDMZ01 ***| DENY_ALL out        | Vlan508    |           5 |
+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+

Unfortunately, doing this records only the last neighbor matched and "erase" the previous one matched between two records.

Record after each neighbor line

$ cat templates/cisco_show_run_part_address-family_ipv4_vrf_01.template
Value Filldown VRF (\S+)
Value NEIGHBOR (\S+)
Value REMOTE_AS (\d+)
Value DESCRIPTION (\S+)
Value ROUTE_MAP (\S+)
Value UPDATE-SRC (\S+)
Value MULTIHOP_NB (\d+)

Start
  ^ address-family ipv4 vrf ${VRF} -> NEIGHBOR

NEIGHBOR
  ^  neighbor ${NEIGHBOR} remote-as ${REMOTE_AS} -> Record
  ^  neighbor ${NEIGHBOR} route-map ${ROUTE_MAP} -> Record
  ^  neighbor ${NEIGHBOR} description ${DESCRIPTION} -> Record
  ^  neighbor ${NEIGHBOR} update-source ${UPDATE-SRC} -> Record
  ^  neighbor ${NEIGHBOR} ebgp-multihop ${MULTIHOP_NB} -> Record
  ^ exit-address-family -> Start
$ 

What I get

+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+
|     VRF     |    NEIGHBOR    | REMOTE-AS |               DESCRIPTION               |      ROUTE-MAP      | UPDATE-SRC | MULTIHOP_NB |
+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+
| EASY-GOING  | 10.42.80.2     |     64442 |                                         |                     |            |             |
| EASY-GOING  | 10.42.80.2     |           | *** some EASY-GOING router ***          |                     |            |             |
| THE-MONTAIN | 10.144.139.165 |     65021 |                                         |                     |            |             |
| THE-MONTAIN | 10.144.139.165 |           | *** peering CASE DMZ MONTAINVPDMZ01 *** |                     |            |             |
| THE-MONTAIN | 10.144.139.165 |           |                                         | RESILIENCE_VIPS_EXT |            |             |
| THE-MONTAIN | 10.144.139.166 |           |                                         | DENY_ALL out        |            |             |
| THE-MONTAIN | 10.144.139.166 |           |                                         |                     | Vlan508    |             |
| THE-MONTAIN | 10.144.139.166 |           |                                         |                     |            |           5 |
+-------------+----------------+-----------+-----------------------------------------+---------------------+------------+-------------+

This one create a new line for each configuration on a specific neighbor. At least I can see the different neighbors for an address-family but since I'm gonna perform a lot of request (using SQL) on each of those tables, I want them to avoid unecessary duplicates. Conceptually, there shouldn't have several lines for one neighbor.

Both solutions aren't satisfying at all.

Wiki Documentation Error

Under State Definitions in TextFSM on the wiki, it states that a white space followed by a carat is necessary for rules, but I believe it's actually 2 spaces. 1 space gave me the error of "missing white space or carat before rule". Should clarify that it's 2.

Usage on Windows

Module clitables can not be imported on Windows machines due to fcntl.

>>> import textfsm
>>> from textfsm import clitable
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Wyko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textfsm\clitable.py", line 41, in <module>
    from textfsm import texttable
  File "C:\Users\Wyko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textfsm\texttable.py", line 42, in <module>
    from textfsm import terminal
  File "C:\Users\Wyko\AppData\Local\Programs\Python\Python36-32\lib\site-packages\textfsm\terminal.py", line 25, in <module>
    import fcntl
ModuleNotFoundError: No module named 'fcntl'

No pypi entry; easy_install textfsm fails

What steps will reproduce the problem?
1.  Ensure you have the setuptools module installed
2.  On linux (either with sudo, or as root) type the following (remove 
quotes)... 'easy_install -U textfsm'
3.

Q: What is the expected output? What do you see instead?

A: Expected output should look something like this...

[mpenning@Bucksnort ~]$ sudo easy_install -U textfsm
Searching for textfsm
Reading http://pypi.python.org/simple/textfsm/
Reading http://code.google.com/p/textfsm/
Best match: textfsm 0.1.0
Downloading http://textfsm.googlecode.com/files/textfsm-0.1.0.tar.gz
Processing textfsm-0.1.0.tar.gz
Running textfsm-0.1.0/setup.py -q bdist_egg --dist-dir 
/tmp/easy_install-tfrQ7o/textfsm-0.1.0/egg-dist-tmp-cYw9dH
zip_safe flag not set; analyzing archive contents...
Adding textfsm 0.1.0 to easy-install.pth file

Installed /usr/lib/python2.5/site-packages/textfsm-0.1.0-2.5.egg
Processing dependencies for textfsm
Finished processing dependencies for textfsm
[mpenning@Bucksnort ~]$

However, the install will fail, because easy_install does not know where to 
find the tarball for the installer

Q: What version of the product are you using? On what operating system?

A: I hope to use 0.1.0 on linux... proceeding with a manual installation next.

Q: Please provide any additional information below.
A: Feel free to contact me via gmail if you would like more information.  User: 
penningtonthing

Original issue reported on code.google.com by [email protected] on 21 Mar 2011 at 10:40

Support returning list of dicts

Many uses cases end up doing something like this

for row in rows:
  column1, column2, column3, columnN = row
  submit(
    column1: column1,
    column2: Metric(column2),
    column3: column3,
    columnN: columnM,

Sometimes it leads to unnecessary wet (is that opposite of dry) code, as you may not actually CARE about most of the column name.
In my use case, I only care if column name is metric or label, so I'd rather do something like this.

for row in rows:
  row["column2"] = Metric(row["column2"])
  submit(row)

The rest I can rely on be labels, and thus don't need to do anything to them.

Python 3 compatibility (NameError: name 'textfsm' is not defined during installation)

I can install gtextfsm using Python 2.7 but not using Python 3.5.

Python 2:

user@debian:/tmp$ virtualenv py27
New python executable in /tmp/py27/bin/python
Installing setuptools, pip, wheel...done.
user@debian:/tmp$ . ./py27/bin/activate
(py27) user@debian:/tmp$ python
Python 2.7.3 (default, Jun 21 2016, 18:38:19) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> 
(py27) user@debian:/tmp$ pip install gtextfsm
Collecting gtextfsm
Installing collected packages: gtextfsm
Successfully installed gtextfsm-0.2.1

Python 3:

user@debian:/tmp$ virtualenv-3.5 -p python3.5 py35
Already using interpreter /home/user/bin/python3.5
Using base prefix '/home/user'
New python executable in /tmp/py35/bin/python3.5
Also creating executable in /tmp/py35/bin/python
Installing setuptools, pip, wheel...done.
user@debian:/tmp$ . py35/bin/activate
(py35) user@debian:/tmp$ pip install gtextfsm
Collecting gtextfsm
  Using cached gtextfsm-0.2.1.tar.gz
    Complete output from command python setup.py egg_info:
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "/tmp/pip-build-wpyy1qn6/gtextfsm/setup.py", line 19, in <module>
        import textfsm
      File "/tmp/pip-build-wpyy1qn6/gtextfsm/textfsm/__init__.py", line 2, in <module>
        __version__ = textfsm.__version__
    NameError: name 'textfsm' is not defined
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-wpyy1qn6/gtextfsm/

namespace conflict with texttable

There is python package texttable which provides texttable.py file same like this project.

Collision report from the rpm:

found conflict of python2-textfsm-0.4.1-3.1.noarch with python2-texttable-1.1.1-1.2.noarch:

  • /usr/lib/python2.7/site-packages/texttable.py

found conflict of python3-textfsm-0.4.1-3.1.noarch with python3-texttable-1.1.1-1.2.noarch:

  • /usr/lib/python3.6/site-packages/texttable.py

Command line argument for output_file doesn't seem to work

When running textfsm.py with the output_file argument I always get an error "Directory or File cannot be found" when specifying the output_file. The script runs and the error is seen at the end when it tries to write the file.

My command line is below...is my syntax wrong or is there an issue with the script?

python C:\Python27\Lib\site-packages\textfsm.py cisco_asa_show_access-list.template putty.txt output.txt

need a help on escaping the paranthesis

Hi All ,

can anybody help me how do i escape the paranthesis

my requirement is to pull the X86_64_LINUX_IOSD-UNIVERSALK9-M

from the build from the cisco show version output

Cisco IOS Software, CSR1000V Software (X86_64_LINUX_IOSD-UNIVERSALK9-M),

since textfsm has the definition where most of the pattern we want to fetch it needs to be grouped

if i try like

pattern = ((.*)) to extract the (X86_64_LINUX_IOSD-UNIVERSALK9-M)

the textFSM throws the error .

any help on this will be appreciated .

no timeout error or functionality

Proposal to add a detailed timeout error allowing the template developer to quickly identify the offending regular expression.

I have found that some poorly written templates may have a line or lines that are syntactically correct but often result in a timeout when searching for a match. When this happens it may be hard to diagnose which line in the template is causing an issue.

Is this an issue worth addressing?

How to record instances of a variable which can occur upto 512 times

I am using textfsm to modify few old configurations to newly supported format.
So for that i need the client id's and its interface specifications from below configs
So here is my old configs.

cluster xyz
client c1
interface port-channel 40
client c2
interface port-channel 42
client c3
interface port-channel 55
client c4
interface port-channel 66

This may go upto 512 clients under cluster

The Table should be like this

xyz | c1 | port-channel 40
| c2 | port-channel 42
| c3 | port-channel 55
...
...

Can somebody please help me on this ?

recursive application of field pattern for list type values

There are cases where a field of List type should capture space/comma separated words in a single line. Currently in these cases last value replaces the previous values and only one item ends up in the list. Is it fairly easy to implement that feature or major refactoring required? Creating the issue for collecting input before start working on it. Thanks. Attaching the following example, Member Ports should be a Value field in List type.

TextFSM and german "umlaute" re.unicode option

Hello,

I use TextFSM and want to use German umlauts like ä,ö and ü in the regular expressions. When I test the regular expression in an editor this works. If I use the expression in a TextFSM template, the values with umlauts are not read. Can TextFSM handle such characters (öäü)? If so, how?

I use that expression:

Value Required posten ([\w üöä.-]{28})

Many thanks and greetings
Hendrik

Gauging interest for visual debug feature

Hi, I really like this project (I use it at work parsing responses from routers/switches). I was wondering if anyone would be happy for me to add a visual debug feature? It would work by taking the typical two input arguments (template and cli text) plus a flag like '--visual-debug' and spit out the cli text with coloured highlighting, indicating matches and state transitions. I think it would be useful as a debug feature to show any errors in the template implementation. It would either produce an html doc of the cli text using css for the highlighting or just push the coloured cli text to stdout, whichever you prefer. Thanks!

pip install textfsm fails for python3.4

I am unable to install textfsm with puython3.4

Collecting textfsm (from netmiko)
Downloading https://files.pythonhosted.org/packages/a1/0d/a1b490503545b3b4600b965eae5d44cc2b6ce27cfb44f4debc563dbb56d3/textfsm-0.4.1.tar.gz
ERROR: Complete output from command python setup.py egg_info:
ERROR: running egg_info
creating pip-egg-info/textfsm.egg-info
writing pip-egg-info/textfsm.egg-info/PKG-INFO
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-install-a2cvg8zh/textfsm/setup.py", line 50, in
'texttable', 'terminal'])
File "/usr/lib/python3.4/site-packages/setuptools/init.py", line 145, in setup
return distutils.core.setup(**attrs)
File "/usr/lib64/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/usr/lib64/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/usr/lib64/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/usr/lib/python3.4/site-packages/setuptools/command/egg_info.py", line 289, in run
writer(self, ep.name, os.path.join(self.egg_info, ep.name))
File "/usr/lib/python3.4/site-packages/setuptools/command/egg_info.py", line 621, in write_pkg_info
metadata.write_pkg_info(cmd.egg_info)
File "/usr/lib64/python3.4/distutils/dist.py", line 1108, in write_pkg_info
self.write_pkg_file(pkg_info)
File "/usr/lib/python3.4/site-packages/setuptools/dist.py", line 165, in write_pkg_file
long_desc = rfc822_escape(self.get_long_description())
File "/usr/lib64/python3.4/distutils/util.py", line 470, in rfc822_escape
lines = header.split('\n')
TypeError: Type str doesn't support the buffer API
----------------------------------------
ERROR: Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-install-a2cvg8zh/textfsm/

pip install textfsm fails for python3.4

switch_management]$pip install textfsm

Collecting textfsm
Downloading https://files.pythonhosted.org/packages/a1/0d/a1b490503545b3b4600b965eae5d44cc2b6ce27cfb44f4debc563dbb56d3/textfsm-0.4.1.tar.gz
Complete output from command python setup.py egg_info:
running egg_info
creating pip-egg-info/textfsm.egg-info
writing top-level names to pip-egg-info/textfsm.egg-info/top_level.txt
writing dependency_links to pip-egg-info/textfsm.egg-info/dependency_links.txt
writing pip-egg-info/textfsm.egg-info/PKG-INFO
/auto/pysw/cel63/python/3.4.1/lib/python3.4/distutils/dist.py:260: UserWarning: Unknown distribution option: 'long_description_content_type'
warnings.warn(msg)
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-ln4qucwi/textfsm/setup.py", line 50, in
'texttable', 'terminal'])
File "/auto/pysw/cel63/python/3.4.1/lib/python3.4/distutils/core.py", line 148, in setup
dist.run_commands()
File "/auto/pysw/cel63/python/3.4.1/lib/python3.4/distutils/dist.py", line 955, in run_commands
self.run_command(cmd)
File "/auto/pysw/cel63/python/3.4.1/lib/python3.4/distutils/dist.py", line 974, in run_command
cmd_obj.run()
File "/nobackup/rmullang/pyats-raj/lib/python3.4/site-packages/setuptools/command/egg_info.py", line 188, in run
writer(self, ep.name, os.path.join(self.egg_info, ep.name))
File "/nobackup/rmullang/pyats-raj/lib/python3.4/site-packages/setuptools/command/egg_info.py", line 403, in write_pkg_info
metadata.write_pkg_info(cmd.egg_info)
File "/auto/pysw/cel63/python/3.4.1/lib/python3.4/distutils/dist.py", line 1108, in write_pkg_info
self.write_pkg_file(pkg_info)
File "/nobackup/rmullang/pyats-raj/lib/python3.4/site-packages/setuptools/dist.py", line 70, in write_pkg_file
long_desc = rfc822_escape(self.get_long_description())
File "/auto/pysw/cel63/python/3.4.1/lib/python3.4/distutils/util.py", line 470, in rfc822_escape
lines = header.split('\n')
TypeError: Type str doesn't support the buffer API

----------------------------------------

Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ln4qucwi/textfsm/

Python version in the linux server.

Python 3.4.1 (default, Nov 12 2014, 13:34:48)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux
Type "help", "copyright", "credits" or "license" for more information.

import sys
print(sys.version)
3.4.1 (default, Nov 12 2014, 13:34:48)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)]

Cannot clone repository

When attempting to clone this repo, I get the following error:

git clone [email protected]:google/textfsm.git
Cloning into 'textfsm'...
Warning: Permanently added the RSA host key for IP address '192.30.252.131' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

Request: add Boolean flag?

Hello team,

I was hoping you could add a flag for values that would allow Boolean matches. Something like so:

Value Required INTERFACE (\S+)
Value INTERFACE_ZONE (.+?)
Value Boolean LINK_UP (up)
Value Boolean PROTOCOL_UP (up)

Start
  ^.*Interface ${INTERFACE} "${INTERFACE_ZONE}", is ${LINK_UP}.*protocol is ${PROTOCOL_UP}

(Just a quick example for reference. This wouldn't match on administratively down for example)

Instead of inserting the word "up" into the dictionary it would be true if the link is up and false if not. On each new Record it would reset back to false as the default value.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.