示例#1
0
    def write_host_cpu_info(self,info={}):
        """function:"""
        try:
            if not db_ip or not db_user or not db_pwd or not db_name:
                log("DB Config info miss[host:%s,user:%s,pwd:%s,dbname:%s]"%(db_ip,db_user,db_pwd,db_name))
                return False
            
            sql = Sql(host=db_ip,port = db_port,user=db_user,passwd=db_pwd,dbname=db_name)
            sql_str = "replace into host_cpu_usage_info(`ip`,`cpuUsed`,`cpuTotal`)\
             values ('%s','%s','%s')"%(info.get("ip",""),info.get("cpuUsed"),info.get("cpuTotal"))
            log(sql_str)
            sql.execute(sql_str)
            sql.close()

        except Exception,e:
            log(str(e))
            return False
示例#2
0
    def write_host_mem_info(self,info={}):
        """function:"""
        try:
            if not db_ip or not db_user or not db_pwd or not db_name:
                log("DB Config info miss[host:%s,user:%s,pwd:%s,dbname:%s]"%(db_ip,db_user,db_pwd,db_name))
                return False
            
            sql = Sql(host=db_ip,port = db_port,user=db_user,passwd=db_pwd,dbname=db_name)
            sql_str = "replace into host_basic_info(`ip`,`memUsed`,`memTotal`,`memFree`,`memBuffers`,`memCached`)\
             values ('%s','%s','%s','%s','%s','%s')"%(info.get("ip",""),info.get("MemUsed"),info.get("MemTotal"),info.get("MemFree"),
                                                info.get("Buffers"),info.get("Cached"))
            log(sql_str)
            sql.execute(sql_str)
            sql.close()

        except Exception,e:
            log(str(e))
            return False
示例#3
0
    def write_info_into_db(self,ip_info="",file_svr="",info_list=[]):
        """"""
        try:
            if not db_ip or not db_user or not db_pwd or not db_name:
                log("DB Config info miss[host:%s,user:%s,pwd:%s,dbname:%s]"%(db_ip,db_user,db_pwd,db_name))
                return False
            
            tamp_2_time = stamp2time(time.time())
            sql = Sql(host=db_ip,port = db_port,user=db_user,passwd=db_pwd,dbname=db_name)
            for index,item in enumerate(info_list):
                sql_str = "replace into package_info(`fileServer`,`storePath`,`fileName`,`md5Info`,`updateTime`,`flag`)\
                 values ('%s','%s','%s','%s','%s','%s')"%(file_svr,item.get("storePath",""),item.get("fileName",""),
                                                    item.get("md5Info",""),tamp_2_time,0)
                log(sql_str)
                sql.execute(sql_str)
            sql.close()

        except Exception,e:
            log(str(e))
            return False
示例#4
0
 def sum_idc_host_info(self):
     """"""
     try:
         ret_info=[]
         sql = Sql(host=db_ip,port = db_port,user=db_user,passwd=db_pwd,dbname=db_name)
         sql_str="select count(1) as num,IdcId,ZoneId,BsiId from cmdb_host_info group by IdcId,ZoneId,BsiId;"
         info = sql.execute(sql_str)
         sql.close()
         for item in info:
             ret_info.append({"num":item[0],"idcId":item[1],"zoneId":item[2],"bsiId":item[3]})
         log(ret_info)
     except Exception,e:
         log(str(e))
示例#5
0
 def sum_idc_info(self):
     """function:"""
     try:
         log("start sum....")
         ret_info ={}
         sql = Sql(host=db_ip,port = db_port,user=db_user,passwd=db_pwd,dbname=db_name)
         sql_str="select count(1) as num,IdcId from cmdb_host_info group by IdcId;"
         info = sql.execute(sql_str)
         sql.close()
         
         for item in info:
             ret_info[item[1]]=item[0]
     except Exception,e:
         log(str(e))