Skip to content

Commit a9657f5

Browse files
author
kkumara3
committed
Added function and example for telemetry streaming of a IOS-XR 6.1.1 box
1 parent 9f20ee7 commit a9657f5

File tree

6 files changed

+896
-106
lines changed

6 files changed

+896
-106
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
ems.pem
1+
*.pem
22
.DS_STORE
33
*.pyc

examples/telemetry_collector.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
""" Basic collector for telemetry.
2+
Initiate a gRPC dial-in telemetry channel, subscribe to a stream,
3+
and output to display. Converts from protobuf to JSON for display.
4+
"""
5+
6+
import sys
7+
sys.path.insert(0, '../')
8+
from lib.cisco_grpc_client import CiscoGRPCClient
9+
import json
10+
11+
client = CiscoGRPCClient('10.200.96.16', 57400, 100, 'mdt', 'f33dm3d4t4')
12+
subscription_id = 'sub1'
13+
recv_count = 0
14+
for segment in client.get_subscription(subscription_id):
15+
recv_count += 1
16+
print json.dumps(segment, indent=4, separators=(',', ': '))
17+
print 'End Telemetry Segment'
18+
print str(recv_count) + ' Segments Received'
19+

lib/cisco_grpc_client.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import grpc
22
from grpc.beta import implementations
33
import ems_grpc_pb2
4+
import protobuf_json
5+
import ems_grpc_pb2
6+
import telemetry_message_pb2
47

58
class CiscoGRPCClient(object):
69
def __init__(self, host, port, timeout, user, password, creds=None, options=None):
@@ -59,6 +62,26 @@ def getconfig(self, path):
5962
objects += response.yangjson
6063
return objects
6164

65+
def get_subscription(self, sub_id):
66+
"""Telemetry subscription function
67+
:param sub_id: Subscription ID
68+
:type: string
69+
:return: Returns discrete values emitted by telemetry stream
70+
:rtype: JSON formatted string
71+
"""
72+
sub_args = ems_grpc_pb2.CreateSubsArgs(ReqId=1, encode=3, subidstr=sub_id)
73+
stream = self._stub.CreateSubs(sub_args, timeout=self._timeout, metadata=self._metadata)
74+
self._channel.subscribe(self.connectivity_handler, True)
75+
for segment in stream:
76+
# Go straight for telemetry data
77+
telemetry_pb = telemetry_message_pb2.Telemetry()
78+
telemetry_pb.ParseFromString(segment.data)
79+
# Return in JSON format instead of protobuf.
80+
yield protobuf_json.pb2json(telemetry_pb)
81+
82+
def connectivity_handler(self, result):
83+
print result
84+
6285
def mergeconfig (self, yangjson):
6386
"""Merge grpc call equivalent of PATCH RESTconf call
6487
:param data: JSON

0 commit comments

Comments
 (0)