def gen_request(xpath):
    mysubs = []
    for path in xpath:
        mypath = path_from_string(path)
        #mysub = gnmi_pb2.Subscription(path=mypath, mode=opt.submode, suppress_redundant=opt.suppress, sample_interval=opt.interval*1000000000, heartbeat_interval=opt.heartbeat)
        mysub = gnmi_pb2.Subscription(path=mypath,
                                      mode=0,
                                      suppress_redundant=False,
                                      sample_interval=10 * 1000000000)
        mysubs.append(mysub)

    myprefix = path_from_string(None)
    mysblist = gnmi_pb2.SubscriptionList(prefix=myprefix,
                                         mode=0,
                                         allow_aggregation=True,
                                         encoding=4,
                                         subscription=mysubs)
    mysubreq = gnmi_pb2.SubscribeRequest(subscribe=mysblist)

    #log.info('Sending SubscribeRequest\n'+str(mysubreq))
    #yield mysubreq
    #return mysblist,mysubreq
    #return mysubreq
    #return mysubreq
    return mypath
Exemple #2
0
def gen_request(paths, opt, prefix):
    """Create subscribe request for passed xpath.
    Args:
        paths: (str) gNMI path.
        opt: (dict) Command line argument passed for subscribe reqeust.
    Returns:
      gNMI SubscribeRequest object.
    """
    mysubs = []
    mysub = gnmi_pb2.Subscription(path=paths, mode=opt["submode"],
      sample_interval=opt["interval"]*1000000,
        heartbeat_interval=opt['heartbeat']*1000000,
          suppress_redundant=opt['suppress'])
    mysubs.append(mysub)

    if prefix:
      myprefix = prefix
    elif opt["prefix"]:
        myprefix = _parse_path(_path_names(opt["prefix"]))
    else:
        myprefix = None

    if opt["qos"]:
        myqos = gnmi_pb2.QOSMarking(marking=opt["qos"])
    else:
        myqos = None
    mysblist = gnmi_pb2.SubscriptionList(prefix=myprefix, mode=opt['subscribe_mode'],
      allow_aggregation=opt['aggregate'], encoding=opt['encoding'],
      subscription=mysubs, use_aliases=opt['use_alias'], qos=myqos)
    mysubreq = gnmi_pb2.SubscribeRequest(subscribe=mysblist)

    print('Sending SubscribeRequest\n'+str(mysubreq))
    yield mysubreq
Exemple #3
0
    def __init__(self, channel):
        self.channel = channel
        self.stub = gnmi_pb2_grpc.gNMIStub(self.channel)
        # ask for the capabilites
        #cap_req = gnmi_pb2.CapabilityRequest()
        #cap_res = self.stub.Capabilities(cap_req)
        self.encapsulation = gnmi_pb2.PROTO
        encoding_path = "/interfaces"
        path = gnmi_utils.simple_gnmi_string_parser(encoding_path)
        mysub = gnmi_pb2.Subscription(path=path, sample_interval=60*1000000000)
        mysubs = [mysub]
        mysblist = gnmi_pb2.SubscriptionList(prefix=None, encoding=self.encapsulation, subscription=mysubs)
        mysubreq = gnmi_pb2.SubscribeRequest( subscribe=mysblist )
        def x():
            yield mysubreq
        y = x()
        base_grpc = {"grpcPeer": self.channel._channel.target().decode(), "ne_vendor": "gnmi"}

        msgs  = self.stub.Subscribe(y, None)
        for msg in msgs:
            if msg.HasField('update'):
                grpc = dict(base_grpc)
                data = {"node_id_str": "r33.labxtx01.us.bb"}
                notification = msg.update
                timestamp = notification.timestamp # in nanoseconds since epoch
                prefix = notification.prefix
                sensor_path, keys  = gnmi_utils.gnmi_to_string_and_keys(prefix)
                data["encoding_path"] = sensor_path
                data["collection_timestamp"] = timestamp / 1000
                data["keys"] = keys
                gnmi = []
                header_info = None
                for upd in notification.update:
                    upd_name, extra_keys  = gnmi_utils.gnmi_to_string_and_keys(upd.path)
                    try:
                        value = getattr(upd.val, upd.val.WhichOneof("value"))
                    except:
                        breakpoint()
                    if upd.val.WhichOneof("value") in ("leaflist_val", "any_val", "decimal_val"):
                        value = str(value)
                    if upd_name == "__juniper_telemetry_header__":
                        header_bytes = value
                        continue

                    if extra_keys:
                        breakpoint()
                    gnmi.append({"keys": extra_keys, "name": upd_name, "value": value})
                data["gnmi"] = gnmi
                message_dict = {"collector": {"grpc": grpc, "data": data}}

                try:
                    returned = FinalizeTelemetryData(message_dict)
                except Exception as e:
                    PMGRPCDLOG.error("Error finalazing  message: %s", e)
Exemple #4
0
def gen_request( opt, log ):
    import gnmi_pb2
    mysubs = []
    for path in opt.xpaths:
        mypath = grpc_support.path_from_string(path)
        mysub = gnmi_pb2.Subscription(path=mypath, mode=opt.submode, suppress_redundant=opt.suppress, sample_interval=opt.interval*1000000000, heartbeat_interval=opt.heartbeat)
        mysubs.append(mysub)

    if opt.prefix:
        myprefix = path_from_string(opt.prefix)
    else:
        myprefix = None

    if opt.qos:
        myqos = gnmi_pb2.QOSMarking(marking=opt.qos)
    else:
        myqos = None

    mysblist = gnmi_pb2.SubscriptionList(prefix=myprefix, mode=opt.mode, allow_aggregation=opt.aggregate, encoding=opt.encoding, subscription=mysubs, use_aliases=opt.use_alias, qos=myqos)
    mysubreq = gnmi_pb2.SubscribeRequest( subscribe=mysblist )

    log.info('Sending SubscribeRequest\n'+str(mysubreq))
    yield mysubreq