Ejemplo n.º 1
0
 def log_execute(self, log_files):
     sql = 'DELETE FROM accesslog;'
     MySQLConnection.execute_sql(sql, fetch=False)
     sql = 'insert into accesslog(ip,url,status,count) values(%s, %s, %s, %s)'
     rt_dict = {}
     try:
         log_files = open(log_files, 'r')
         while True:
             line = log_files.readline()
             if not line:
                 break
             logs = line.split()
             (ip, url, status) = logs[0], logs[6], logs[8]
             if (ip, url, status) not in rt_dict:
                 rt_dict[(ip, url, status)] = 1
             else:
                 rt_dict[(ip, url, status)] += 1
         log_files.close()
         # args_list = sorted(rt_dict.items(), key=lambda x:x[1], reverse=True)
         _count = MySQLConnection.bulker_commit_sql(sql,
                                                    args=rt_dict.items())
         return _count != 0
     except BaseException as e:
         print traceback.format_exc()
         print e
         return False
Ejemplo n.º 2
0
 def add(cls, req):
     _ip = req.get('ip')
     _cpu = req.get('cpu')
     _ram = req.get('ram')
     _time = req.get('time')
     _sql = 'insert into performs(ip, cpu, ram, time) values(%s,%s,%s,%s)'
     MySQLConnection.execute_sql(_sql, (_ip, _cpu, _ram, _time),
                                 fetch=False)
Ejemplo n.º 3
0
 def get_list(cls):
     _column = 'id,sn,ip,hostname,idc_id,purchase_date,warranty,vendor,model,admin,business,cpu,ram,disk,os,status'
     _columns = _column.split(',')
     _sql = 'select {column} from assets where status=0'.format(
         column=_column)
     _count, _rt_list = MySQLConnection.execute_sql(_sql, fetch=True)
     return [dict(zip(_columns, _list)) for _list in _rt_list]
Ejemplo n.º 4
0
 def get_list(cls):
     _columns = ('id', 'domain_name', 'username', 'password', 'function')
     _sql = 'select * from service_manage'
     _count, _rt_list = MySQLConnection.execute_sql(_sql, fetch=True)
     _rt = []
     for _list in _rt_list:
         _rt.append(dict(zip(_columns, _list)))
     return _rt
Ejemplo n.º 5
0
 def get_list(cls):
     _columns = ('id', 'username', 'password', 'age')
     _sql = 'select * from user'
     _count, _rt_list = MySQLConnection.execute_sql(_sql, fetch=True)
     # return [User(**dict(zip(_columns, _list))) for _list in _rt_list]
     _rt = []
     for _list in _rt_list:
         _rt.append(dict(zip(_columns, _list)))
     return _rt
Ejemplo n.º 6
0
 def log_fetch(self, topn):
     _rt = []
     _columns = ('id', 'ip', 'url', 'status', 'count')
     sql = 'select * from accesslog order by count desc limit %s'
     _count, _rt_list = MySQLConnection.execute_sql(sql,
                                                    args=(topn, ),
                                                    fetch=True)
     for _list in _rt_list:
         _rt.append(dict(zip(_columns, _list)))
     return _rt
Ejemplo n.º 7
0
 def create(cls, asset_dict):
     sql = 'insert into assets(sn,ip,hostname,idc_id,purchase_date,warranty,vendor,model,admin,business,cpu,ram,disk,os) values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)'
     args_list = []
     lists = [
         'sn', 'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty',
         'vendor', 'model', 'admin', 'business', 'cpu', 'ram', 'disk', 'os'
     ]
     for i in lists:
         args_list.append(asset_dict.get('_' + i))
     _count, _rt_list = MySQLConnection.execute_sql(sql,
                                                    args_list,
                                                    fetch=False)
     return _count != 0
Ejemplo n.º 8
0
 def get_list(cls, ip):
     _sql = 'select cpu,ram,time from performs where ip=%s and time>=%s order by time asc'
     _args = (ip,
              time.strftime('%Y-%m-%d %H:%M:%S',
                            time.localtime(time.time() - 60 * 60)))
     _count, _rt_list = MySQLConnection.execute_sql(_sql, _args, fetch=True)
     datetime_list = []
     cpu_list = []
     ram_list = []
     for _cpu, _ram, _time in _rt_list:
         cpu_list.append(_cpu)
         ram_list.append(_ram)
         datetime_list.append(_time.strftime('%H:%M:%S'))
     return datetime_list, cpu_list, ram_list
Ejemplo n.º 9
0
 def update(cls, asset_dict, _id):
     sql = 'update assets set sn=%s,ip=%s,hostname=%s,idc_id=%s,purchase_date=%s,warranty=%s,vendor=%s,model=%s,admin=%s,business=%s,cpu=%s,ram=%s,disk=%s,os=%s where id=%s'
     args_list = []
     lists = [
         'sn', 'ip', 'hostname', 'idc_id', 'purchase_date', 'warranty',
         'vendor', 'model', 'admin', 'business', 'cpu', 'ram', 'disk', 'os'
     ]
     for i in lists:
         args_list.append(asset_dict.get('_' + i))
     args_list.append(_id)
     _count, _rt_list = MySQLConnection.execute_sql(sql,
                                                    args_list,
                                                    fetch=False)
     return _count != 0
Ejemplo n.º 10
0
 def get_idcs_by_id(cls, uid):
     sql = 'select * from idcs where id=%s and status=0'
     _count, _rt_list = MySQLConnection.execute_sql(sql,
                                                    args=(uid, ),
                                                    fetch=True)
     return _rt_list
Ejemplo n.º 11
0
 def add_service(cls, _url, _username, _password, _func):
     sql = 'insert into service_manage(domain_name,username,password,function) values(%s,%s,%s,%s)'
     args = (_url, _username, _password, _func)
     _count, _rt_list = MySQLConnection.execute_sql(sql, args, fetch=False)
     return _count != 0
Ejemplo n.º 12
0
 def update_service(cls, _url, _username, _password, _func, _id):
     sql = 'update service_manage set domain_name=%s, username=%s, password=%s, function=%s where id=%s'
     args = (_url, _username, _password, _func, _id)
     _count, _rt_list = MySQLConnection.execute_sql(sql, args, fetch=False)
     return _count != 0
Ejemplo n.º 13
0
 def get_idc_list(cls):
     _sql = 'select id,name from idcs where status=0'
     _count, _rt_list = MySQLConnection.execute_sql(_sql, fetch=True)
     return _rt_list
Ejemplo n.º 14
0
 def del_service(cls, uid):
     sql = 'delete from service_manage where id=%s'
     _count, _rt_list = MySQLConnection.execute_sql(sql, uid, fetch=False)
     return _count != 0
Ejemplo n.º 15
0
 def delete(self):
     sql = 'delete from user where id=%s'
     _count, _rt_list = MySQLConnection.execute_sql(sql, self.id)
     return _count != 0
Ejemplo n.º 16
0
 def save(self):
     sql = 'insert into user(username, password, age) values(%s,%s,%s)'
     args = (self.username, Md5Str.md5(self.password), self.age)
     _count, _rt_list = MySQLConnection.execute_sql(sql, args, fetch=False)
     return _count != 0
Ejemplo n.º 17
0
 def delete(cls, uid):
     sql = 'update assets set status=1 where id=%s'
     _count, _rt_list = MySQLConnection.execute_sql(sql, uid)
     return _count != 0
Ejemplo n.º 18
0
 def validate_login(self):
     _columns = ('id', 'username')
     sql = 'select * from user where username=%s and password=%s'
     _count, _rt_list = MySQLConnection.execute_sql(
         sql, (self.username, Md5Str.md5(self.password)), fetch=True)
     return dict(zip(_columns, _rt_list[0])) if _count != 0 else None
Ejemplo n.º 19
0
 def update(self):
     sql = 'update user set age=%s where id=%s'
     _count, _rt_list = MySQLConnection.execute_sql(sql,
                                                    (self.age, self.id))
     return _count != 0
Ejemplo n.º 20
0
 def update_user_pass(self, newpassword):
     sql = 'update user set password=%s where id=%s'
     _count, _rt_list = MySQLConnection.execute_sql(
         sql, (Md5Str.md5(newpassword), self.id))
     return _count != 0