def get_job_stat(self, jobargs): com_name = "checklastjob" if self.__exe_dict[com_name]: res_dict = {} try: cmd = "%s -client %s" % (self.__exe_dict[com_name], jobargs[0]) if len(jobargs) > 1: print "got 2nd arg" cmd += " -warningAge=%s" % (jobargs[1]) if len(jobargs) > 2: print "got 3rd arg" cmd += " -criticalAge=%s" % (jobargs[2]) # print "command= %s" % (cmd) cstat, result = commands.getstatusoutput(cmd) # print "result:", cstat, result j_dict = dict([("status", 0), ("message", result)]) if cstat == 256: # got warning message j_dict["status"] = cstat cstat = 0 if cstat == 512: # got critical message j_dict["status"] = cstat cstat = 0 if cstat: return "error %s gave (%d) %s" % (com_name, cstat, result) else: return "ok %s" % (hm_classes.sys_to_net(j_dict)) except: return "error calling %s: %s" % (self.__exe_dict[com_name], process_tools.get_except_info()) else: return "error %s command not found" % (com_name)
def get_user_info(self, user_name): com_name = "userinfo" if self.__exe_dict[com_name]: try: cstat, result = commands.getstatusoutput( "%s %s" % (self.__exe_dict[com_name], user_name)) if cstat: return "error %s gave (%d) %s" % (com_name, cstat, result) else: u_dict = dict([(key.lower().strip().replace(" ", "_"), value.strip()) for key, value in [ line.split(":", 1) for line in result.split("\n") if line.count(":") ]]) total_size = 0 u_dict["total_size"] = int(u_dict["total_size"]) if "max_size" in u_dict: u_dict["max_size"] = int(u_dict["max_size"]) return "ok %s" % (hm_classes.sys_to_net(u_dict)) except: return "error calling %s: %s" % ( com_name, process_tools.get_except_info()) else: return "error %s command not found" % (com_name)
def get_service_info(self, service_name): com_name = "omstat" if self.__exe_dict[com_name]: try: cstat, result = commands.getstatusoutput( "%s -s ; %s -a" % (self.__exe_dict[com_name], self.__exe_dict[com_name])) if cstat: return "error %s gave (%d) %s" % (com_name, cstat, result) else: act_dict = {} for l_p in [ line.strip().split() for line in result.split("\n") ]: if l_p[-1].isdigit(): num_subs = int(l_p.pop(-1)) else: num_subs = -1 start_date = l_p.pop(-1) act_state = l_p.pop(-1) act_name = " ".join(l_p) act_dict[act_name] = { "name": act_name, "num_sub": num_subs, "start_date": start_date, "act_state": act_state } if service_name: act_dict = act_dict.get(service_name, {}) return "ok %s" % (hm_classes.sys_to_net(act_dict)) except: return "error calling %s: %s" % ( self.__exe_dict[com_name], process_tools.get_except_info())
def get_user_info(self, user_name): com_name = "omshowu" if self.__exe_dict[com_name]: try: cstat, result = commands.getstatusoutput( "%s -n '%s' -f" % (self.__exe_dict[com_name], user_name)) if cstat: return "error %s gave (%d) %s" % (com_name, cstat, result) else: u_dict = dict([(key.lower().strip().replace(" ", "_"), value.strip()) for key, value in [ line.split(":", 1) for line in result.split("\n") if line.count(":") ]]) total_size = 0 if self.__exe_dict["sxdu"]: try: cstat, result = commands.getstatusoutput( "%s -a '%s'" % (self.__exe_dict["sxdu"], user_name)) except: pass else: total_size = int(result.split()[0]) * 1024 if self.__exe_dict["omlimit"]: try: cstat, result = commands.getstatusoutput( "%s -u '%s' -r" % (self.__exe_dict["omlimit"], user_name)) except: pass else: if not cstat: for key, value in [ line.strip().split(":", 1) for line in result.split("\n") if line.count(":") ]: key = key.strip() value = value.strip() if key.lower( ) == "message store size limit": if value.lower().endswith("kb"): u_dict["max_size"] = int( value[:-2]) * 1024 u_dict["total_size"] = total_size return "ok %s" % (hm_classes.sys_to_net(u_dict)) except: return "error calling %s: %s" % ( com_name, process_tools.get_except_info()) else: return "error %s command not found" % (com_name)
def server_call(self, cm): int_error = "IntError" if len(cm) != 1: return "invalid number of parameters (%d != 1)" % (len(cm)) s_dict = dict([(k.lower(), 0.) for k in self.module_info.sens_dict.keys()]) try: s_dict = sensor_int(self.module_info) except int_error: pass # print s_dict.keys(),cm what = cm[0].lower() if what in s_dict: return "ok %s" % (hm_classes.sys_to_net({"sensor": cm[0], "value": s_dict[what]})) else: return "invalid parameter %s not known (not one of %s)" % (str(what), ", ".join([str(x) for x in s_dict.keys()]) or "none set")
def server_call(self, cm): if len(cm) >= 1: lmstat_bin = cm[0] if len(cm) >= 2: lic_file_loc = " -c %s" % (cm[1]) else: lic_file_loc = "" if lmstat_bin.endswith("util"): lm_call = "%s lmstat -a%s" % (lmstat_bin, lic_file_loc) else: lm_call = "%s -a%s" % (lmstat_bin, lic_file_loc) stat, out = commands.getstatusoutput(lm_call) if stat: return "error calling %s (%d): %s" % (lmstat_bin, stat, out) else: s_dict = parse_lmstat_out(out) return "ok %s" % (hm_classes.sys_to_net(s_dict)) else: return "error no lmstat or lmutil binary given"
def get_user_list(self): com_name = "omshowu" if self.__exe_dict[com_name]: try: cstat, result = commands.getstatusoutput( "%s -m all" % (self.__exe_dict[com_name])) if cstat: return "error %s gave (%d) %s" % (com_name, cstat, result) else: u_list = [ line.split("/")[0].strip() for line in result.split("\n") ] return "ok %s" % (hm_classes.sys_to_net(u_list)) except: return "error calling %s: %s" % ( self.__exe_dict[com_name], process_tools.get_except_info()) else: return "error %s command not found" % (com_name)
def get_queue_stat(self, queue_names): com_name = "omstat" if self.__exe_dict[com_name]: res_dict = {} for queue_name in queue_names or SCALIX_QUEUES: try: cstat, result = commands.getstatusoutput( "%s -q %s" % (self.__exe_dict[com_name], queue_name)) if cstat: res_dict[queue_name] = "error %s gave (%d) %s" % ( com_name, cstat, result) else: res_dict[queue_name] = "ok %s" % (result) except: res_dict[queue_name] = "error calling %s: %s" % ( self.__exe_dict[com_name], process_tools.get_except_info()) return "ok %s" % (hm_classes.sys_to_net(res_dict)) else: return "error %s command not found" % (com_name)
def server_call(self, cm): self.module_info.init_ctrl_dict(self.logger) self.module_info.update_ctrl_dict(self.logger) return "ok %s" % (hm_classes.sys_to_net( self.module_info.get_ctrl_config()))
def server_call(self, cm): return "ok %s" % (hm_classes.sys_to_net( self.module_info.ext_num_mails(cm)))