Output transfer rate in humand readable warning message
This commit is contained in:
		
							parent
							
								
									c3699bcbe9
								
							
						
					
					
						commit
						a0377961c4
					
				
					 1 changed files with 43 additions and 4 deletions
				
			
		| 
						 | 
					@ -154,6 +154,44 @@ def run_iperf3(options) -> Union[dict, NoReturn]:
 | 
				
			||||||
    nagexit(3, "what happended?")
 | 
					    nagexit(3, "what happended?")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def sizeof_fmt(num, suffix="B", units=None, power=None, sep="", precision=2, sign=False):
 | 
				
			||||||
 | 
					    sign = "+" if sign and num > 0 else ""
 | 
				
			||||||
 | 
					    fmt = "{0:{1}.{2}f}{3}{4}{5}"
 | 
				
			||||||
 | 
					    prec = 0
 | 
				
			||||||
 | 
					    for unit in units[:-1]:
 | 
				
			||||||
 | 
					        if abs(round(num, precision)) < power:
 | 
				
			||||||
 | 
					            break
 | 
				
			||||||
 | 
					        num /= float(power)
 | 
				
			||||||
 | 
					        prec = precision
 | 
				
			||||||
 | 
					    else:
 | 
				
			||||||
 | 
					        unit = units[-1]
 | 
				
			||||||
 | 
					    return fmt.format(num, sign, prec, sep, unit, suffix)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def sizeof_fmt_iec(num, suffix="B", sep="", precision=2, sign=False):
 | 
				
			||||||
 | 
					    return sizeof_fmt(
 | 
				
			||||||
 | 
					        num,
 | 
				
			||||||
 | 
					        suffix=suffix,
 | 
				
			||||||
 | 
					        sep=sep,
 | 
				
			||||||
 | 
					        precision=precision,
 | 
				
			||||||
 | 
					        sign=sign,
 | 
				
			||||||
 | 
					        units=["", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi"],
 | 
				
			||||||
 | 
					        power=1024,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def sizeof_fmt_decimal(num, suffix="B", sep="", precision=2, sign=False):
 | 
				
			||||||
 | 
					    return sizeof_fmt(
 | 
				
			||||||
 | 
					        num,
 | 
				
			||||||
 | 
					        suffix=suffix,
 | 
				
			||||||
 | 
					        sep=sep,
 | 
				
			||||||
 | 
					        precision=precision,
 | 
				
			||||||
 | 
					        sign=sign,
 | 
				
			||||||
 | 
					        units=["", "k", "M", "G", "T", "P", "E", "Z", "Y"],
 | 
				
			||||||
 | 
					        power=1000,
 | 
				
			||||||
 | 
					    )
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
def determine_result(options, json_data) -> Tuple[int, Optional[List[str]]]:
 | 
					def determine_result(options, json_data) -> Tuple[int, Optional[List[str]]]:
 | 
				
			||||||
    """
 | 
					    """
 | 
				
			||||||
    Evaluates iperf3 test results against performance thresholds and determines the Nagios status.
 | 
					    Evaluates iperf3 test results against performance thresholds and determines the Nagios status.
 | 
				
			||||||
| 
						 | 
					@ -196,21 +234,22 @@ def determine_result(options, json_data) -> Tuple[int, Optional[List[str]]]:
 | 
				
			||||||
    bps_avg_down = json_end['sum_sent_bidir_reverse']['bits_per_second'] if options.bidir else \
 | 
					    bps_avg_down = json_end['sum_sent_bidir_reverse']['bits_per_second'] if options.bidir else \
 | 
				
			||||||
        json_data['end']['sum_sent']['bits_per_second'] if options.downstream else None
 | 
					        json_data['end']['sum_sent']['bits_per_second'] if options.downstream else None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    fmt = lambda s: sizeof_fmt_iec(s, suffix="B/s", sep=" ", precision=0)
 | 
				
			||||||
    if bps_avg_up is not None:
 | 
					    if bps_avg_up is not None:
 | 
				
			||||||
        if options.rate_up_crit and bps_avg_up <= options.rate_up_crit:
 | 
					        if options.rate_up_crit and bps_avg_up <= options.rate_up_crit:
 | 
				
			||||||
            rc = max(rc, 2)
 | 
					            rc = max(rc, 2)
 | 
				
			||||||
            statuslines.append("upstream rate below critical threshold")
 | 
					            statuslines.append(f"upstream rate below critical threshold: {fmt(bps_avg_up)} < {fmt(options.rate_up_crit)}")
 | 
				
			||||||
        elif options.rate_up_warn and bps_avg_up <= options.rate_up_warn:
 | 
					        elif options.rate_up_warn and bps_avg_up <= options.rate_up_warn:
 | 
				
			||||||
            rc = max(rc, 1)
 | 
					            rc = max(rc, 1)
 | 
				
			||||||
            statuslines.append("upstream rate below warning threshold")
 | 
					            statuslines.append(f"upstream rate below warning threshold: {fmt(bps_avg_up)} < {fmt(options.rate_up_warn)}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if bps_avg_down is not None:
 | 
					    if bps_avg_down is not None:
 | 
				
			||||||
        if options.rate_down_crit and bps_avg_down <= options.rate_down_crit:
 | 
					        if options.rate_down_crit and bps_avg_down <= options.rate_down_crit:
 | 
				
			||||||
            rc = max(rc, 2)
 | 
					            rc = max(rc, 2)
 | 
				
			||||||
            statuslines.append("downpstream rate below critical threshold")
 | 
					            statuslines.append(f"downpstream rate below critical threshold: {fmt(bps_avg_down)} < {fmt(options.rate_down_crit)}")
 | 
				
			||||||
        elif options.rate_down_warn and bps_avg_down <= options.rate_down_warn:
 | 
					        elif options.rate_down_warn and bps_avg_down <= options.rate_down_warn:
 | 
				
			||||||
            rc = max(rc, 1)
 | 
					            rc = max(rc, 1)
 | 
				
			||||||
            statuslines.append("downstream rate below warning threshold")
 | 
					            statuslines.append(f"downstream rate below warning threshold: {fmt(bps_avg_down)} < {fmt(options.rate_down_warn)}")
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if not options.udp and options.retrans_crit and options.retrans_warn:
 | 
					    if not options.udp and options.retrans_crit and options.retrans_warn:
 | 
				
			||||||
        retransmits = json_data["end"]["sum_sent"]["retransmits"]
 | 
					        retransmits = json_data["end"]["sum_sent"]["retransmits"]
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue