Package: cisco-mdt
cisco-mdt-pythonThis library provides a basic Model-Driven Telemetry (MDT) server implementation to ease development, as well as a sample CLI potentially useful for debugging.Usagepipinstallcisco-mdt
python-c"import cisco_mdt; print(cisco_mdt)"cisco-mdt--helpThis library only implements the MDT gRPC server at this time.cisco-mdt CLIA CLI callable ascisco-mdtis provided which may be useful for simply interacting with an MDT capable Cisco device, and also serves as a reference for how to use thiscisco_mdtlibrary. CLI usage is documented at the bottom of this README inCLI Usage.MDTgRPCServerA simple implementation of a Cisco MDT server/receiver is provided which allows the library user to specify callback functions on a per-message basis. This allows flexibility in implementation. This class may also be subclassed and theMdtDialoutmethod overridden for completely custom control of the incoming requests and context.ExamplesMDTgRPCServeris used like any gRPC servicer implementation, but with the notion of callbacks."""Effectively ripped from cli.py"""fromconcurrentimportfuturesimportgrpcfromgoogle.protobufimportjson_format,text_formatfromcisco_mdtimportproto,MDTgRPCServerdefcallback(request):telemetry_pb=proto.telemetry_bis_pb2.Telemetry()telemetry_pb.ParseFromString(request.data)logging.debug(text_format.MessageToString(request))logging.info(text_format.MessageToString(telemetry_pb))mdt_grpc_server=MDTgRPCServer()mdt_grpc_server.add_mdt_callback(callback)grpc_server=grpc.server(futures.ThreadPoolExecutor(max_workers=10))proto.mdt_dialout_pb2_grpc.add_gRPCMdtDialoutServicer_to_server(mdt_grpc_server,grpc_server)grpc_server.add_insecure_port("[::]:50051")grpc_server.start()try:grpc_server.wait_for_termination()exceptKeyboardInterrupt:logging.warning("Stopping on interrupt.")grpc_server.stop(None)exceptException:logging.exception("Stopping due to exception!")Model-Driven TelemetryModel-Driven Telemetry (MDT) is a feature across IOS XE, IOS XR, and NX-OS which may be used to export various operational data sources with general greater efficiency than other similar protocols such as SNMP. MDT has options which vary across operating systems (such as transport, encoding, etc.), but at minimum all platforms provide a "dial-out", "push" model of operation, gRPC client implementation with self-describing protocol buffers which may connect to an implementing gRPC server and export desired data. Generally this data is described via YANG modules, and desired data specified by YANG XPaths.DevelopmentRequires Python and utilizespipenvfor environment management. Manual usage ofpip/virtualenvis not covered. Usesblackfor code formatting andpylintfor code linting.blackis not explicitly installed as it requires Python 3.6+.Get Sourcegitclonehttps://github.com/cisco-ie/cisco-mdt-python.gitcdcisco-mdt-python# If pipenv not installed, install!pipinstall--userpipenv# Now use Makefile...makesetup# Or pipenv manually if make not presentpipenv--threeinstall--dev# Enter virtual environmentpipenvshell# Work workexitCode HygieneWe useblackfor code formatting andpylintfor code linting.hygiene.shwill runblackagainst all of the code undersrc/cisco_mdt/except forprotoccompiled protobufs, and runpylintagainst Python files directly undergnmi/. They don't totally agree, so we're not looking for perfection here.blackis not automatically installed due to requiring Python 3.6+.hygiene.shwill check for regular path availability and viapipenv, and otherwise falls directly topylint. Ifblackusage is desired, please install it intopipenvif using Python 3.6+ or separate methods e.g.brew install black.# If using Python 3.6+pipenvinstall--devblack# Otherwise..../hygiene.shRecompile ProtobufsIf new protocol buffer definitions (proto/) are released, useupdate_protos.shto recompile. If breaking changes are introduced the library must be updated../update_protos.shCLI UsageThe below details the currentcisco-mdtusage options.cisco-mdt --help
usage:
cisco-mdt <protocol> [<args>]

Version 0.0.1

Supported Protocols:
grpc

cisco-mdt grpc

See <protocol> --help for RPC options.


MDT CLI demonstrating cisco_mdt library usage.

positional arguments:
  protocol    MDT protocol to utilize.

optional arguments:
  -h, --help  show this help message and exitgRPCThis protocol will handle MDT via gRPC transport and dump the telemetry data in JSON or textual protocol buffer format tostdout.cisco-gnmi grpc -netloc 0.0.0.0:50051 -debugUsagecisco-mdt grpc --help
usage: cisco-mdt [-h] [-dump_json] [-netloc NETLOC] [-debug]

Start gRPC protocol server.

optional arguments:
  -h, --help      show this help message and exit
  -dump_json      Dump as JSON instead of textual protos.
  -netloc NETLOC  <host>:<port>
  -debug          Print debug messages.Output[cisco-mdt-python] cisco-mdt grpc -debug
DEBUG:root:Starting gRPC server on [::]:50051.
DEBUG:root:ReqId: 10
data: "\n\003ios\032\006testme29openconfig-interfaces:interfaces/..."

INFO:root:node_id_str: "ios"
subscription_id_str: "testme"
encoding_path: "openconfig-interfaces:interfaces/interface/state/counters"
collection_id: 914301
...Licensingcisco-mdt-pythonis licensed asApache License, Version 2.0.IssuesOpen an issue :)Related ProjectsYangModels/yangcisco-ie/cisco-protoCiscoDevNet/nx-telemetry-protoios-xr/model-driven-telemetryTelegraf Cisco MDT PluginPipeline