Netmiko: parse cli output to csv file from network device using TextFSM

Created on 12 May 2017  路  3Comments  路  Source: ktbyers/netmiko

  • Template Creation Help

hi guys, sorry for the inconvenience, i want to ask how to create new template TextFSM for '_show memory statistics_', i already looked at https://github.com/networktocode/ntc-templates/tree/master/templates but there's no '_show memory statistics template_'.

thanks :)

Most helpful comment

Hi @NedySuprianto,

Try something like this:
I have two options for MEMTYPE, one for explicit matching and one for more general (commented out) but it may pick up more than you wanted.

I've attached the sample text I used and the CSV (saved as XLSX for upload here) file of the results.
I tend to process lots of files at once so I always start with the hostname but you can do that other ways and simplify this a bit more.
MEM_cisco_ios_show_memory_stat-results.xlsx

This may not be exactly what you want but hopefully will serve as an example that you can edit for your own needs.

I'm fairly new at this myself so this may not be the best approach (so If anyone has any suggestions I'd love to hear them!) but at least in my small sample set it seems to be working.

I hope this helps!

cisco_ios_show_memory_stat.template
<>
Value Filldown HOSTNAME (S+)

Value MEMTYPE ([^0-9]+)

Value MEMTYPE ((Processor|s+I/O|Driver te))
Value HEAD ([0-9A-f]+)
Value TOTAL (d+)
Value USED (d+)
Value FREE (d+)
Value LOW (d+)
Value LARGE (d+)

Start
^s+Heads+
^(hostname|switchname) ${HOSTNAME}
^${MEMTYPE}s+${HEAD}s+${TOTAL}s+${USED}s+${FREE}s+${LOW}s+${LARGE} -> Record
^${MEMTYPE}s+${HEAD}s+${TOTAL}s+${USED}s+${FREE}s+${LOW}s+${LARGE} -> Record
^${MEMTYPE}s+${HEAD}s+${TOTAL}s+${USED}s+${FREE}s+${LOW}s+${LARGE} -> Record

<>

Sample Config
cisco_ios_show_mem_stat_example.txt

All 3 comments

Hi @NedySuprianto,

Try something like this:
I have two options for MEMTYPE, one for explicit matching and one for more general (commented out) but it may pick up more than you wanted.

I've attached the sample text I used and the CSV (saved as XLSX for upload here) file of the results.
I tend to process lots of files at once so I always start with the hostname but you can do that other ways and simplify this a bit more.
MEM_cisco_ios_show_memory_stat-results.xlsx

This may not be exactly what you want but hopefully will serve as an example that you can edit for your own needs.

I'm fairly new at this myself so this may not be the best approach (so If anyone has any suggestions I'd love to hear them!) but at least in my small sample set it seems to be working.

I hope this helps!

cisco_ios_show_memory_stat.template
<>
Value Filldown HOSTNAME (S+)

Value MEMTYPE ([^0-9]+)

Value MEMTYPE ((Processor|s+I/O|Driver te))
Value HEAD ([0-9A-f]+)
Value TOTAL (d+)
Value USED (d+)
Value FREE (d+)
Value LOW (d+)
Value LARGE (d+)

Start
^s+Heads+
^(hostname|switchname) ${HOSTNAME}
^${MEMTYPE}s+${HEAD}s+${TOTAL}s+${USED}s+${FREE}s+${LOW}s+${LARGE} -> Record
^${MEMTYPE}s+${HEAD}s+${TOTAL}s+${USED}s+${FREE}s+${LOW}s+${LARGE} -> Record
^${MEMTYPE}s+${HEAD}s+${TOTAL}s+${USED}s+${FREE}s+${LOW}s+${LARGE} -> Record

<>

Sample Config
cisco_ios_show_mem_stat_example.txt

hi @cldeluna

this is like what i want,i tried it and its worked.
thanks for your help @cldeluna this is so helpful :)

hmm how about show flash? i trying to get same output from flash memory ( free and total)

config :
57931776 bytes total (42589184 bytes free)

i cant get the output because there's have '(' and ')', if i delete this part (42589184 bytes free) i still get the total memory, if not i cant get the total and free memory.
what should i add on the template?

simple Template :

Value Total (d+)

Start
^${Total} bytes total

i solved this problem, should we close this issue?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Murali24872019 picture Murali24872019  路  6Comments

yixiuGit picture yixiuGit  路  4Comments

aegiacometti picture aegiacometti  路  6Comments

rajaramanlala picture rajaramanlala  路  7Comments

MichalTaratuta picture MichalTaratuta  路  7Comments