def get_channel_info(channel_number=1): r""" Get the channel info and return as a dictionary. Example: channel_info: [channel_0x2_info]: [channel_medium_type]: 802.3 LAN [channel_protocol_type]: IPMB-1.0 [session_support]: multi-session [active_session_count]: 0 [protocol_vendor_id]: 7154 [volatile(active)_settings]: [alerting]: enabled [per-message_auth]: enabled [user_level_auth]: enabled [access_mode]: always available [non-volatile_settings]: [alerting]: enabled [per-message_auth]: enabled [user_level_auth]: enabled [access_mode]: always available """ status, ret_values = \ grk.run_key_u("Run IPMI Standard Command channel info " + str(channel_number)) key_var_list = list(filter(None, ret_values.split("\n"))) # To match the dict format, add a colon after 'Volatile(active) Settings' and 'Non-Volatile Settings' # respectively. key_var_list[6] = 'Volatile(active) Settings:' key_var_list[11] = 'Non-Volatile Settings:' result = vf.key_value_list_to_dict(key_var_list, process_indent=1) return result
def parse_nping_output(output): r""" Parse the output from the nping command and return as a dictionary. Example of output value: Starting Nping 0.6.47 ( http://nmap.org/nping ) at 2019-08-07 22:05 IST SENT (0.0181s) TCP Source IP:37577 > Destination IP:80 S ttl=64 id=39113 iplen=40 seq=629782493 win=1480 SENT (0.2189s) TCP Source IP:37577 > Destination IP:80 S ttl=64 id=39113 iplen=40 seq=629782493 win=1480 RCVD (0.4120s) TCP Destination IP:80 > Source IP:37577 SA ttl=49 id=0 iplen=44 seq=1078301364 win=5840 <mss 1380> Max rtt: 193.010ms | Min rtt: 193.010ms | Avg rtt: 193.010ms Raw packets sent: 2 (80B) | Rcvd: 1 (46B) | Lost: 1 (50.00%) Nping done: 1 IP address pinged in 0.43 seconds Example of data returned by this function: nping_result: [max_rtt]: 193.010ms [min_rtt]: 193.010ms [avg_rtt]: 193.010ms [raw_packets_sent]: 2 (80B) [rcvd]: 1 (46B) [lost]: 1 (50.00%) [percent_lost]: 50.00 Description of argument(s): output The output obtained by running an nping command. """ lines = output.split("\n") # Obtain only the lines of interest. lines = list(filter(lambda x: re.match(r"(Max rtt|Raw packets)", x), lines)) key_value_list = [] for line in lines: key_value_list += line.split("|") nping_result = vf.key_value_list_to_dict(key_value_list) # Extract percent_lost value from lost field. nping_result['percent_lost'] = \ float(nping_result['lost'].split(" ")[-1].strip("()%")) return nping_result