tobieiss / go-textfsm Goto Github PK
View Code? Open in Web Editor NEWgolang textfsm
License: MIT License
golang textfsm
License: MIT License
like this
parseVal
should accept value options
like Required
, List
, Filldown
and Fillup
template example:
Value Required INTF (\S+)
Value IPADDR (\S+)
Value STATUS (down|up)
Value PROTO (up|down)
Start
^${INTF}\s+${IPADDR}\s+\w+\s+\w+\s+${STATUS}\s+${PROTO} -> Record
add support for Filldown
value option
related to this
in textFSM
you can have multiple records
in same state
, and when ever you reach to a cmd
/line
with a record
you should add a new record and move to the next line in data.
in go-textFSM
it continue on same line and add new record,
for example :
Value Slot (\d)
Value State (\w+)
Value Temperature (\d+)
Value DRAM (\d+)
Value Buffer (\d+)
Start
# We can't use .* for unused placeholders, as greedy matching will break it.
^\s+${Slot}\s+${State}\s+${Temperature}\s+\d+\s+\d+\s+${DRAM}\s+\d+\s+${Buffer} -> Record
^\s+${Slot}\s+${State} -> Record
data:
Slot State (C) Total Interrupt DRAM (MB) Heap Buffer
0 Online 24 7 0 256 38 51
1 Online 25 7 0 256 38 51
2 Online 24 3 0 256 37 49
3 Online 23 3 0 256 37 49
4 Empty
5 Empty
6 Empty
7 Empty
in go-textfsm
the results will be
[0 Online 24 256 51]
[0 Online ] <- duplicate record on same line
[1 Online 25 256 51]
[1 Online ] <- duplicate record on same line
[2 Online 24 256 49]
[2 Online ] <- duplicate record on same line
[3 Online 23 256 49]
[3 Online ] <- duplicate record on same line
[4 Empty ]
[5 Empty ]
[6 Empty ]
[7 Empty ]
it should be
[0 Online 24 256 51]
[1 Online 25 256 51]
[2 Online 24 256 49]
[3 Online 23 256 49]
[4 Empty ]
[5 Empty ]
[6 Empty ]
[7 Empty ]
I am unsure if this is currently supported or not but I am trying to figure out the best way to create a template that can leverage A Record of the value as the item to search for. I guess the best example I can give is something like the following:
router bgp
local-asn 1299
neighbor 1.1.1.1 remote-asn 1987
address-family ipv4 unicast
neighbor 1.1.1.1 route-policy allow-all in
neighbor 1.1.1.1 route-policy allow-all out
exit-context
What I am trying to do is basically have the following template:
Value Filldown ProcessASN (\d+)
Value Neighbor (\S+)
Value Filldown AddressFamily (ipv\d)
Value RPInbound (\S+)
Value RPEgress (\S+)
Start
^.*router bgp
^.*local-asn ${ProcessASN} -> AddressFamily
AddressFamily
^.*address-family ${AddressFamily} unicast -> BGP
BGP
^.*neighbor ${Neighbor} -> Continue
^.*neighbor ${Neighbor} route-policy ${RoutePolicyIn} in -> Continue
^.*neighbor ${Neighbor} route-policy ${RoutePolicyOut} out -> Continue Record
^.*exit-context -> AFI
The above would produce:
["1299","ipv4","1.1.1.1","allow-all","allow-all"]
I am wondering if it is possible to lookup the actual BGP neighbor when transitioning the state to BGP, so the output would look more like:
["1299","1.1.1.1","1897","ipv4","allow-all","allow-all"]
Hi,
I have a interest in helping out on this library, What is the current status?
I have started looking into this but it appears that the Required is not working as expected.
Test Config Source:
testConfig.txt
Test Template:
lsp.txt
When running this in python's textfsm I receive what I expect:
[['5455', 'RTRA->RTRB->LAB', 'Loopback65', '8.8.8.8']]
But when running with go I get the following:
[ 15.21.66.154]
[5455 RTRA->RTRB->LAB Loopback65 8.8.8.8]
I would assume that since it is required that it shouldn't add the first Row at all.
in textfsm
should accept |
as a token for or
,
if my tamplate has |
i get illegal token
I think we need an CLI like textfsm. With that it's easier to explain some examples #2 .
like this
can we have an example of how to run it
end of line in textFSM
should be optional and defined by user using $$
,
go-textfsm
append each matchingLine
with $
which making it not optional.$$
and raises illegal token
if exist in template.go-textfsm
does not accept ?
char.Python TextFSM parser returns the names of the variables as the first row. It is useful to match the data and the corresponding variables in the presence of optional variables.
It is crucial to have the same behavior in go-textfsm as well.
go-textfsm
is recording a Columns
instead of Raws
.
for example,
template :
Value IFACE (\S+)
Value Required NAME (\S+)
Value STATUS (down|up)
Value ERROR (.*)
Start
^Interface:\s+${IFACE}
^\s+name\s+"${NAME}"
^\s+status\s+${STATUS}
^\s+errors:\s+${ERROR} -> Record
input file
:
Interface: Gi0/1
name "wan1"
status up
errors: output Queue errors
Interface: Gi0/2
name "wan2"
status down
errors: input Queue errors
in go-textfsm
the records will be like :
[Gi0/1 Gi0/2]
[wan1 wan2 ]
[up down]
[output Queue errors input Queue errors]
while in google/textfsm
it will be :
['Gi0/1', 'wan1', 'up', 'output Queue errors']
['Gi0/2', 'wan2', 'down', 'input Queue errors']
Please look at the attached template and text file.
The value of bar should be 300 but it is 200 - probably because the string to match is Bar and it is a suffix of FooBar.
Expected output:
"100" "300"
Actual output:
"100" "200"
"" 300
I am testing the following template and config.
Template:
https://gist.github.com/metajar/9965f7ed135a24acd1fc455f88d319bc
Test Config:
https://gist.github.com/metajar/63362dd0273fa0388d784edd2c56e2ab
In python I receive:
['192.168.74.22', '', 'INERNALCPE', 'INTERNAL:CPE:ROUTEREFLECTOR', '', '']
['192.168.74.23', '', 'INERNALCPE', 'INTERNAL:CPE:ROUTEREFLECTOR', '', '']
['192.168.74.24', '', 'INERNALCPE', 'INTERNAL:CPE:ROUTEREFLECTOR', '', '']
['192.168.74.25', '', 'INERNALCPE', 'INTERNAL:CPE:ROUTEREFLECTOR', '', '']
['172.31.255.11', '', 'EXTERNALBLUE', 'EXTERNAL:CPE:ROUTEREFLECTOR', 'reject', 'reject']
['1.1.1.1', '808', '808HAWAII', 'EXTERNAL:CUSTOMER:808', '', '']
['2.2.2.2', '', '1299TT', 'FULLROUTES:TT', '', 'TT']
['19.12.12.1', '', '19NG', 'INTERNAL:ROUTES:VPN', 'reject-some', 'reject-them']
['32.12.12.12', '9999', 'BLACKHOLE', 'EXTERNAL:SERVICEVPN:100', '', '']
['23.23.23.23', '9082', '23S-policy', 'EXTERNAL:SERVICEVPN:200', '', '']
But unfortunately with the Go-TextFSM I see the following:
["192.168.74.23" "" "INERNALCPE" "INTERNAL:CPE:ROUTEREFLECTOR" "" ""]
["192.168.74.23" "" "INERNALCPE" "INTERNAL:CPE:ROUTEREFLECTOR" "" ""]
["192.168.74.24" "" "INERNALCPE" "INTERNAL:CPE:ROUTEREFLECTOR" "" ""]
["192.168.74.25" "" "INERNALCPE" "INTERNAL:CPE:ROUTEREFLECTOR" "" ""]
["172.31.255.11" "" "EXTERNALBLUE" "EXTERNAL:CPE:ROUTEREFLECTOR" "reject" "reject"]
["172.31.255.11" "" "EXTERNALBLUE" "EXTERNAL:CPE:ROUTEREFLECTOR" "reject" "reject"]
["2.2.2.2" "808" "808HAWAII" "EXTERNAL:CUSTOMER:808" "reject" "reject"]
["2.2.2.2" "808" "1299TT" "FULLROUTES:TT" "reject" "TT"]
["2.2.2.2" "808" "1299TT" "FULLROUTES:TT" "reject" "TT"]
["19.12.12.1" "808" "19NG" "INTERNAL:ROUTES:VPN" "reject-some" "reject-them"]
["19.12.12.1" "808" "19NG" "INTERNAL:ROUTES:VPN" "reject-some" "reject-them"]
["32.12.12.12" "9999" "BLACKHOLE" "EXTERNAL:SERVICEVPN:100" "reject-some" "reject-them"]
["23.23.23.23" "9082" "23S-policy" "EXTERNAL:SERVICEVPN:200" "reject-some" "reject-them"]
["23.23.23.23" "9082" "23S-policy" "EXTERNAL:SERVICEVPN:200" "reject-some" "reject-them"]
Is there something within the templating that I need to change to work with Go-TextFSM?
like this
PFA the template and text files.
Expected output:
foo bar xyz
"100" "200" ""
(This is the output from Python TextFSM library.)
Actual output:
(Empty)
The value xyz is treated as mandatory probably because it appears along with the Record action in the template.
Actually the Record action itself is not mandatory. This is another deviation from the original Python library.
add Filldown
Value option support.
related to this
Fails to parse Value Regex with brackets
eg: (\d+|(n/a))
expected matches: 1234
, 9
, n/a
A cliTable like here
add support for Required
option,
related to #5
implement support for multiple "states"
add support for List
value option.
related to this this
like this
Hi
Please try parsing the attached file source.txt with the template template.txt. go-textfsm does not output any record whereas the Python implementation of textfsm outputs [['100', '2']] which is the expected output.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.