Telegraf input plugin to execute CLI commands on network devices and TextFSM based parsing

telegraf
#1

Hi all,

I was thinking if Telegraf could have an input plugin to execute CLI commands on network devices and a processor plugin to parse that output using TextFSM. This is because many metrics are pulled using CLI command outputs (with custom parsing) directly instead of SNMP, as finding vendor specific MIBs is not always easy and quick.

Currently, I use netmiko and textfsm to do this in Python.

The reason why I suggest this for Telegraf is that, I’m planning to use Telegraf for polling the devices using SNMP (input plugin) and InfluxDB as the time-series database, and I think it’ll be beneficial to have CLI based parsing in the same stack, wherever SNMP is not feasible.

What do you guys think?

Regards,
Rahul Swaminathan

#2

To run the command remotely you could use the exec plugin along with ssh, I think this would be a reasonable method although it would require reconnecting on every interval. I could imagine the exec plugin adding the ability to keep a remote shell open across intervals to address this.

Textfsm would probably best be added as a parser, so that it can be use with the data_format option on many plugins.

If you like you could open a feature request on the Telegraf issue tracker.

#3

It looks like we need textfsm ported to Go if we wanted to make it a parser, so that probably would not be a trivial task.

#4

Thanks Daniel!

To use SSH within the exec plugin and login to the device is possible and as you mention the SSH session will have to be kept open, but I’ve observed significant delays getting introduced while using shell commands within other programming languages (Perl and Python), especially when you want to execute multiple commands in a single login to the devices and also multiple large number of simultaneous sessions. Please feel free to correct me if you’ve observed otherwise. I’ve mainly seen this due to the relay of execution between the Perl/Python interpreter and Shell. So, I think it’ll be better to have a pure Go implementation for handling the login. Let me know your thoughts.

Using textfsm as a data_format is a good idea.

I can open a feature request for this if you’re okay with this design.

Regards,
Rahul Swaminathan

#5

I would expect most interpreted languages to be a little on the slow side starting up, this is a general issue that applies to the exec plugin even locally. Compiled languages help with this significantly, but are still expensive, the required solution would be to implement this issue. To reduce the connection time you might also want to use connection sharing which will make the ssh case almost as fast as a local script over a fast network.

Yeah, please open a pair of issues for textfsm and for a ssh_exec plugin.