How to parse text using TextFSM with option (like or condiiton)

I need to parse "show env all" from switch / router, but there is a different textual structure.

Switch A:

FAN is OK
SYSTEM TEMPERATURE is OK
System Temperature Value: 38 Degree Celsius
System Temperature State: GREEN
Yellow Threshold : 58 Degree Celsius
Red Threshold    : 68 Degree Celsius

      

Switch B:

FAN is OK
TEMPERATURE is OK
Temperature Value: 42 Degree Celsius
Temperature State: GREEN
Yellow Threshold : 54 Degree Celsius
Red Threshold    : 64 Degree Celsius

      

the "System" is different. I need to create one TextFSM template that can be used with switches A and B. So I don't need to create 2 TextFSM templates for each switch.

my current template:

Value FAN (\S*) 
Value TEMPERATURE (\S*) 
Value TEMPERATURE_VALUE (\S*) 
Value TEMPERATURE_STATE (\S*)
Value YELLOW_THRESHOLD (\S*)
Value RED_THRESHOLD (\S*) 
Value POWER (\S*)
Value RPS (\S*)

Start 
  ^FAN is ${FAN}
  ^TEMPERATURE is ${TEMPERATURE}
  ^Temperature Value: ${TEMPERATURE_VALUE}
  ^Temperature State: ${TEMPERATURE_STATE}
  ^Yellow Threshold : ${YELLOW_THRESHOLD}
  ^Red Threshold    : ${RED_THRESHOLD}

      

* only for switch B

should be added like [System] Temperature Value

or something else?

Thank:)

+3


source to share


1 answer


You can add system

as optional

^(?:SYSTEM )?TEMPERATURE is (.*)$

      



See DEMO for explanation

0


source







All Articles