def check_mode(args): Units required = [ "command", "forecast_interval", "forecast_range", "host", "lookback_range", "method", "performanceLabel", "service", "value" ] for r in required: if eval("args." + r) is None: plugin_exit(Returncodes.Unknown, r + " can not be empty in CheckMode") method = args.method.lower() if method not in MethodCollector.classes.keys(): plugin_exit(Returncodes.Unknown, "Method " + method + "is unknown") forecast_interval = string_to_ms(args.forecast_interval) forecast_range = string_to_ms(args.forecast_range) lookback_range = string_to_ms(args.lookback_range) lookback_data = InfluxDBReader.request_past( host=args.host, service=args.service, performance_label=args.performanceLabel, lookback=lookback_range) if not lookback_data: plugin_exit(Returncodes.Unknown, "Could not fetch data from InfluxDB") result = MethodCollector.classes[method]. \ calc_intersection( # TODO: if needed add args options={}, forecast_start=Job.calc_start_date( lookback_data[len(lookback_data) - 1][0], forecast_interval), forecast_range=forecast_range, forecast_interval=forecast_interval, lookback_range=lookback_range, lookback_data=lookback_data, y=args.value) casted_result = None try: casted_result = result / eval("Units." + args.unit) except AttributeError: plugin_exit(Returncodes.Unknown, "Unit: " + args.unit + " is unknown") if args.warn and args.warn < casted_result: plugin_exit(Returncodes.Warning, "Reached in: " + str(casted_result) + args.unit, casted_result, args.unit, args.warn, args.crit) elif args.crit and args.crit < casted_result: plugin_exit(Returncodes.Critical, "Reached in: " + str(casted_result) + args.unit, casted_result, args.unit, args.warn, args.crit) else: plugin_exit( Returncodes.OK, "Reached in: " + str(casted_result) + " " + args.unit + " ", casted_result, args.unit, args.warn, args.crit)
def check_mode(args): Units required = ["command", "forecast_interval", "forecast_range", "host", "lookback_range", "method", "performanceLabel", "service", "value"] for r in required: if eval("args." + r) is None: plugin_exit(Returncodes.Unknown, r + " can not be empty in CheckMode") method = args.method.lower() if method not in MethodCollector.classes.keys(): plugin_exit(Returncodes.Unknown, "Method " + method + "is unknown") forecast_interval = string_to_ms(args.forecast_interval) forecast_range = string_to_ms(args.forecast_range) lookback_range = string_to_ms(args.lookback_range) lookback_data = InfluxDBReader.request_past(host=args.host, service=args.service, performance_label=args.performanceLabel, lookback=lookback_range) if not lookback_data: plugin_exit(Returncodes.Unknown, "Could not fetch data from InfluxDB") result = MethodCollector.classes[method]. \ calc_intersection( # TODO: if needed add args options={}, forecast_start=Job.calc_start_date( lookback_data[len(lookback_data) - 1][0], forecast_interval), forecast_range=forecast_range, forecast_interval=forecast_interval, lookback_range=lookback_range, lookback_data=lookback_data, y=args.value) casted_result = None try: casted_result = result / eval("Units." + args.unit) except AttributeError: plugin_exit(Returncodes.Unknown, "Unit: " + args.unit + " is unknown") if args.warn and args.warn < casted_result: plugin_exit(Returncodes.Warning, "Reached in: " + str(casted_result) + args.unit, casted_result, args.unit, args.warn, args.crit) elif args.crit and args.crit < casted_result: plugin_exit(Returncodes.Critical, "Reached in: " + str(casted_result) + args.unit, casted_result, args.unit, args.warn, args.crit) else: plugin_exit(Returncodes.OK, "Reached in: " + str(casted_result) + " " + args.unit + " ", casted_result, args.unit, args.warn, args.crit)
def __init__(self, config): threading.Thread.__init__(self) self.setDaemon(True) self.__stop_event = threading.Event() self.__host = config[0] self.__service = config[1] self.__command = config[2]['command'] self.__config = config[2] self.__update_rates = [] for p in self.__config['perf_labels']: for c in self.__config['config']: if p == c[LABEL]: if self.get_method(c) in MethodCollector.classes.keys(): self.__update_rates.append((string_to_ms(c[UPDATE_RATE]), c)) else: logging.warning("for " + c[METHOD] + " does no class exist") for u in self.__update_rates: for k, v in u[1].items(): if k in TIME_KEYS: u[1][k] = string_to_ms(v) self.__update_rates = sorted(self.__update_rates, key=lambda x: x[0])