@@ -281,47 +281,50 @@ def zhongji_check():
281281 cmd , ip = x [0 ], sm = x [1 ], interface = x [2 ]), ports ))
282282
283283#############################################traffic####################
284- zte_traffic = partial (Zte .traffic ,
284+ zte_traffic = partial (Zte .get_traffics ,
285285 username = zte_olt_username ,
286286 password = zte_olt_password )
287- hw_traffic = partial (Huawei .traffic ,
287+ hw_traffic = partial (Huawei .get_traffics ,
288288 username = hw_olt_username ,
289289 password = hw_olt_password )
290290
291291
292292def get_traffic (olt ):
293293 functions = dict (hw = hw_traffic , zte = zte_traffic )
294- no_company = lambda x , y : ['fail' , None , x , y ]
295- ip , company , port = olt
296- return functions .get (company , no_company )(ip = ip , port = port )
294+ no_company = lambda x , y : ['fail' , None , x ]
295+ ip , company , ports = olt
296+ return functions .get (company , no_company )(ip = ip , ports = ports )
297297
298298
299299def traffic_output (lock , info ):
300- mark , result , ip , port = info
300+ mark , result , ip = info
301301 with lock :
302302 with open (log_file , 'a' ) as logging :
303- logging .write ("{ip}:{port}:{mark}\n " .format (
304- ip = ip , port = port , mark = mark ))
303+ logging .write ("{ip}:{mark}\n " .format (ip = ip , mark = mark ))
305304 if result and mark == 'success' :
306305 with lock :
307- with open (result_file , 'a' ) as frslt :
308- frslt .write ("{ip},{port},{down}M,{up}M\n " .format (
309- ip = ip , port = port , down = result [0 ], up = result [1 ]))
306+ for r in result :
307+ with open (result_file , 'a' ) as frslt :
308+ frslt .write ("{ip},{port},{down},{up}\n " .format (
309+ ip = ip , port = r ['name' ].strip (), down = r ['in_traffic' ], up = r ['out_traffic' ]))
310310
311311
312312def traffic_check ():
313- clear_log ()
314- cmd = 'match(n:Olt)-[*]-(p:Port) return n.ip,n.company,p.name'
315- nodes = graph .cypher .execute (cmd )
316- # nodes = graph.find('Olt')
317- # nodes = graph.find('Olt', property_key='ip', property_value='172.18.0.46')
318- olts = [(x [0 ], x [1 ], x [2 ].strip ()) for x in nodes ]
319- pool = Pool (16 )
320- lock = Manager ().Lock ()
321- func = partial (traffic_output , lock )
322- list (pool .map (compose (func , get_traffic ), olts ))
323- pool .close ()
324- pool .join ()
313+ # clear_log()
314+ # cmd = 'match(n:Olt)-[*]-(p:Port) where n.company="hw" return n.ip,n.company,collect(p.name)'
315+ # nodes = graph.cypher.execute(cmd)
316+ # olts = [(x[0], x[1], x[2]) for x in nodes]
317+ # pool = Pool(16)
318+ # lock = Manager().Lock()
319+ # func = partial(traffic_output, lock)
320+ # list(pool.map(compose(func, get_traffic), olts))
321+ # pool.close()
322+ # pool.join()
323+
324+ records = (x .split (',' ) for x in open (result_file ))
325+ cmd = "match (n:Olt)-[*]-(p:Port) where n.ip={ip} and p.name={name} set p.in_traffic={i},p.out_traffic={o}"
326+ list (map (lambda x : graph .cypher .execute (
327+ cmd , ip = x [0 ], name = x [1 ], i = x [2 ], o = x [3 ]), records ))
325328
326329
327330def hw_gpon ():
0 commit comments