def process_client_args(self, opts, hmb): ok, why = (1, "") my_lim = limits.limits() for opt, arg in opts: if hmb.name in ["jobinfo"]: if opt == "-w": if my_lim.set_warn_val(arg) == 0: ok, why = (0, "Can't parse warning value !") if opt == "-c": if my_lim.set_crit_val(arg) == 0: ok, why = (0, "Can't parse critical value !") return ok, why, [my_lim]
def process_client_args(self, opts, hmb): ok, why = (1, "") my_lim = limits.limits() for opt, arg in opts: # print opt, arg if opt == "-w": if my_lim.set_warn_val(arg) == 0: ok = 0 why = "Can't parse warning value !" if opt == "-c": if my_lim.set_crit_val(arg) == 0: ok = 0 why = "Can't parse critical value !" return ok, why, [my_lim]
def process_return(self): _dict = self._reorder_dict(self.snmp_dict.values()[0]) # keys: # 1 ... pid # 2 ... name # 3 ... oid (always (0, 0)) # 4 ... path # 5 ... options # 6 ... type (4 ... application 2 ... operatingSystem) # 7 ... status (1 ... running, 2 ... runnable) if self.opts.name: _name_re = re.compile(self.opts.name) # import pprint # pprint.pprint(_dict) _dict = { key: value for key, value in _dict.iteritems() if 2 in value and _name_re.match(value[2]) } _lim = limits.limits(warn_val=self.opts.w, crit_val=self.opts.c) ret_state, _state_str = _lim.check_floor(len(_dict)) info_f = [ "found {} of {}".format( logging_tools.get_plural("instance", len(_dict)), self.opts.name) ] if self.opts.detail: if _dict: for _key in sorted(_dict): _value = _dict[_key] print _value info_f.append("{}@{:d}: {} {}".format( _value[2], _value[1], _value[4], _value[5], )) else: info_f.append("nothing found") ret_str = ", ".join(info_f) # use range_parameter in limits for comparision elif self.opts.overview: _type_dict = {} for _entry in _dict.itervalues(): _type_dict.setdefault(_entry[6], []).append(_entry) _info_str = ", ".join([ "{}: {}".format({ 4: "application", 2: "operatingSystem", }.get(_key, "type {:d}".format(_key)), logging_tools.get_plural( "entry", len(_type_dict[_key]))) for _key in sorted(_type_dict.keys()) ]) ret_state, ret_str = (limits.mon_STATE_OK, "{:d} Processes, {}".format( len(_dict), _info_str, )) else: ret_state, ret_str = (limits.mon_STATE_OK, "Process tree has {}".format( logging_tools.get_plural( "entry", len(_dict)))) return ret_state, ret_str