pythonregexcsvtext-parsingpython-textfsm

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


I need to parse out 'show env all' from switch/router, but there's have different text 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 different is 'System'. I need to create one TextFSM template that can be used switch 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 I add like [System] Temperature Value or anything?

Thanks :)


Solution

  • You can add system as optional

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

    See DEMO with explanation