示例#1
0
def process_cisco_kv(new_msg):
    """
    Processes a msg using gpb-kv
    """
    telemetry_msg = cisco_telemetry_pb2.Telemetry()
    telemetry_msg.ParseFromString(new_msg.data)
    #jsonStrTelemetry = MessageToJson(telemetry_msg)
    #grpc_message = json.loads(jsonStrTelemetry)
    grpc_message = MessageToDict(telemetry_msg)
    return grpc_message
示例#2
0
    def MdtDialout(self, message, context):
        grpcPeerStr = context.peer()

        grpcPeer = {}
        (grpcPeerProto, grpcPeer['telemetry_node'],
         grpcPeer['telemetry_node_port']) = grpcPeerStr.split(":")
        grpcPeer['telemetry_node_vendor'] = "Cisco"
        jsonTelemetryNode = json.dumps(grpcPeer)

        for new_msg in message:
            telemetry_msg = cisco_telemetry_pb2.Telemetry()
            telemetry_msg.ParseFromString(new_msg.data)
            jsonStrTelemetry = MessageToJson(telemetry_msg)
            dictTelemetry = json.loads(jsonStrTelemetry)

            (proto, path) = telemetry_msg.encoding_path.split(":")

            if (proto == "Cisco-IOS-XR-infra-statsd-oper"):
                for new_row in telemetry_msg.data_gpb.row:
                    dictIfStats = {}

                    ifStats_msg = cisco_ifstatsbag_generic_pb2.ifstatsbag_generic(
                    )
                    ifStats_msg.ParseFromString(new_row.content)
                    dictIfStatsContent = MessageToDict(
                        ifStats_msg,
                        including_default_value_fields=True,
                        preserving_proto_field_name=True,
                        use_integers_for_enums=True)

                    dictIfStats['row'] = {}
                    dictIfStats['row']['content'] = dictIfStatsContent
                    dictIfStats['row']['timestamp'] = new_row.timestamp

                    dictTelemetry['dataGpb'] = dictIfStats
                    sendJsonTelemetryData(jsonTelemetryNode, dictTelemetry)
            else:
                sendJsonTelemetryData(jsonTelemetryNode, dictTelemetry)