Response: CLI Is an API
Andrew Yourtchenko and Dr. Tony Przygienda left wonderful comments to my Screen Scraping in 2025 blog post, but unfortunately they prefer commenting on a closed platform with ephemeral content; the only way to make their thoughts available to a wider audience is by reposting them. Andrew first:
I keep saying CLI is an API. However, it is much simpler and an easier way to adapt to the changes, if these three conditions are met:
- regexes are written in a defensive, yet permissive fashion (generously ignore the spaces and lines that do not match, but make sure you ignore both spaces and tabs)
- for the data that you do capture, be very conservative, such that your likely outcome if something goes awry is no data rather than garbage data.
- handle all the parsed data as Option enum in a language which allows for that and always check whether it is Some(value) or None before using it.
The (3) you will have to do anyway even with structured API, when handling the changes. For the (1) and (2), if (in some mythical universe), vendors were to publish the regexes, it will be indistinguishable from the other transports. (I am of course leaving aside the question of data conversions, because they are equally a problem when using the “structured” APIs as well, just of a different shape.
It looks like Cisco (having to deal with ancient codebase with printf statements sprinkled all over it) did something like what Andrew suggested at least once (pyATS/Genie) if not twice (ConfD on Cisco IOS/XE).
Not surprisingly, Tony disagreed (probably based on his battle scars):
Sorry, it’s largely putting lipstick on you know what. It’s impossible to know as a vendor what kind of “smart regexes” some customer put in that can deal with “any change” until they can’t. Because whatever the “smart regex” is it is still something that does fundamentally not understand the semantic structure of the underlying output. And having dealt with some of it it’s about the third circle of hell to maintain such “super smart regexes” with backtracking and whatever else not …
I have to agree with Tony: regexes suck, and I always prefer to work with structured data… if only the vendors wouldn’t make it so cumbersome that it’s easier to deal with the pain of screen-scraping.