一、Official Development Guide URL: H3C Switch Telemetry Secondary Development Guide (Comware V7) - 6W100 - H3C
二、Development Breakdown:
2.1 Switch Configuration:
#
telemetry
sensor-group SG_10
sensor path device/fans selection-nodes currentspeed index slot status
sensor path device/powersupplys selection-nodes index slot status
sensor path lldp/lldpneighbors
sensor-group SG_15
sensor path ifmgr/interfaces
sensor path ifmgr/statistics selection-nodes indiscards inerrors inoctets name outdiscards outerrors outoctets
sensor-group SG_2
sensor path device/cpus selection-nodes chassis cpuusage slot
sensor path ospf/neighbours
sensor-group SG_50
sensor path device/base selection-nodes hostname
sensor path mlag/base
sensor path ospf/instances
sensor path route/ipv4routes selection-nodes age ifindex ifname neighbor nexthop vrf
sensor-group SG_5
sensor path buffermonitor/egressdrops
sensor path diagnostic/memories selection-nodes buffers cached commitlimit committed_as free freeratio slot
sensor path ospf/interfaces
destination-group out_srv
ipv4-address 192.168.1.100 port 54108 vpn-instance Mgt
destination-group zts_srv
ipv4-address 192.168.1.100 port 55556 vpn-instance Mgt
subscription SubA
sensor-group SG_10 sample-interval 10
sensor-group SG_15 sample-interval 15
sensor-group SG_2 sample-interval 5
sensor-group SG_50 sample-interval 50
sensor-group SG_5 sample-interval 5
destination-group out_srv
#
2.2 Create grpc_dialout.proto File
Copy the content from the official guide directly into the grpc_dialout.proto file.
2.4 CentOS Server Configuration:
pip3 install grpcio grpcio-tools # Install required gRPC tools
python3 -m grpc_tools.protoc -I . --python_out=. --grpc_python_out=. grpc_dialout.proto
2.5 Entry Code (Adjusted for Clarity):
import grpc
from concurrent import futures
import threading
import grpc_dialout_pb2_grpc
import grpc_dialout_pb2
import json
# Custom servicer class inheriting from generated gRPC servicer
class TelemetryDialoutServicer(grpc_dialout_pb2_grpc.GRPCDialoutServicer):
def Dialout(self, request_iterator, context):
for idx, req in enumerate(request_iterator):
print(f"Thread ID: {threading.get_ident()}, Message Index: {idx}")
print(f"Request Data: {req}")
print("--- Data Stream Completed ---")
return grpc_dialout_pb2.DialoutResponse(response="Processing Done")
def start_server():
server_address = "[::]:55556" # Updated port
server = grpc.server(futures.ThreadPoolExecutor(max_workers=5)) # Adjusted worker count
grpc_dialout_pb2_grpc.add_GRPCDialoutServicer_to_server(TelemetryDialoutServicer(), server)
server.add_insecure_port(server_address)
server.start()
print(f"gRPC Dial-Out Server Running on {server_address}")
try:
server.wait_for_termination()
except KeyboardInterrupt:
print("Server Terminated by Interrupt")
if __name__ == "__main__":
start_server()