示例#1
0
文件: views.py 项目: 957177498/b
def article_archive(request):
    # 告警
    messageinfo_list = models_frame.TabAlarmInfo.objects.all()

    type = request.GET.get('type')
    author_id = request.GET.get('author_id')

    blog_tags = models_blog.BlogTag.objects.all()

    blog_views = models_blog.BlogArticle.objects.order_by('-views')[:10]

    sql = """
    select a.id,
       date_format(a.created_time,'%%Y-%%m-%%d') created_time,
       date_format(a.created_time,'%%Y') created_year,
       date_format(a.created_time,'%%m') created_month,
       a.title,
       a.body,
       a.pub_time,
       a.type,
       a.subtype,
       a.views,
       a.author_id,
       b.username
  from blog_article a
  left join accounts_bloguser b
    on a.author_id = b. id where if ('%s'='None',1=1,a.type='%s') and if ('%s'='None',1=1,a.author_id='%s') order by a.id desc
""" % (type, type, author_id, author_id)

    blog_articles = tools.mysql_django_query(sql)

    now = tools.now()
    if request.method == 'POST':
        if request.POST.has_key('search'):
            search = request.POST.get('search', None)
            return HttpResponseRedirect('/blog_index?search=%s' % search)
        else:
            logout(request)
            return HttpResponseRedirect('/login/')
    if messageinfo_list:
        msg_num = len(messageinfo_list)
        msg_last = models_frame.TabAlarmInfo.objects.latest('id')
        msg_last_content = msg_last.alarm_content
        tim_last = (datetime.datetime.now() - msg_last.alarm_time).seconds / 60
    else:
        msg_num = 0
        msg_last_content = ''
        tim_last = ''
    return render_to_response(
        'my_blog/article_archive.html', {
            'messageinfo_list': messageinfo_list,
            'msg_num': msg_num,
            'now': now,
            'msg_last_content': msg_last_content,
            'tim_last': tim_last,
            'blog_articles': blog_articles,
            'blog_tags': blog_tags,
            'blog_views': blog_views
        })
示例#2
0
文件: views.py 项目: 957177498/b
def article_detail(request):
    # 告警
    article_id = request.GET.get('id')
    messageinfo_list = models_frame.TabAlarmInfo.objects.all()
    blog_tags = models_blog.BlogTag.objects.all()
    blog_views = models_blog.BlogArticle.objects.order_by('-views')[:10]

    sql = """
    select a.id,
       date_format(a.created_time,'%%Y-%%m-%%d') created_time,
       a.title,
       a.body,
       a.pub_time,
       a.type,
       a.subtype,
       a.views,
       a.author_id,
       b.username
  from blog_article a
  left join accounts_bloguser b
    on a.author_id = b. id
  where a.id= %s """ % article_id

    article_detail = tools.mysql_django_query(sql)

    sql = "update blog_article a set a.views = a.views+1 where id = %s " % article_id

    tools.mysql_exec(sql, '')

    now = tools.now()
    if request.method == 'POST':
        if request.POST.has_key('search'):
            search = request.POST.get('search', None)
            return HttpResponseRedirect('/blog_index?search=%s' % search)
        else:
            logout(request)
            return HttpResponseRedirect('/login/')

    if messageinfo_list:
        msg_num = len(messageinfo_list)
        msg_last = models_frame.TabAlarmInfo.objects.latest('id')
        msg_last_content = msg_last.alarm_content
        tim_last = (datetime.datetime.now() - msg_last.alarm_time).seconds / 60
    else:
        msg_num = 0
        msg_last_content = ''
        tim_last = ''
    return render_to_response(
        'my_blog/article_detail.html', {
            'messageinfo_list': messageinfo_list,
            'msg_num': msg_num,
            'now': now,
            'msg_last_content': msg_last_content,
            'tim_last': tim_last,
            'article_detail': article_detail,
            'blog_tags': blog_tags,
            'blog_views': blog_views
        })
示例#3
0
文件: views.py 项目: 957177498/b
def mysql_slowquery(request):
    messageinfo_list = models_frame.TabAlarmInfo.objects.all()
    tagsinfo = models_mysql.MysqlDb.objects.filter(mon_status='connected')

    tagsdefault = request.GET.get('tagsdefault')
    if not tagsdefault:
        tagsdefault = models_mysql.MysqlDb.objects.filter(mon_status='connected').order_by('tags')[0].tags

    sql = "select host,port,user,password,user_os,password_os from tab_mysql_servers where tags= '%s' " % tagsdefault
    mysql_conf = tools.mysql_query(sql)
    host = mysql_conf[0][0]
    port = mysql_conf[0][1]
    user = mysql_conf[0][2]
    password = mysql_conf[0][3]
    password = base64.decodestring(password)
    user_os = mysql_conf[0][4]
    password_os = mysql_conf[0][5]
    password_os = base64.decodestring(password_os)

    conn = MySQLdb.connect(host=host, user=user, passwd=password, port=int(port), connect_timeout=5, charset='utf8')
    # 获取慢查询日志文件
    slow_log_file = check_msql.get_mysql_para(conn,'slow_query_log_file')
    # 清空历史解析结果
    sql = "delete from mysql_slowquery where tags='%s' " %tagsdefault
    tools.mysql_exec(sql,'')
    # 解析慢查询日志
    logparser.mysql_slow_query(tagsdefault,host,port,user_os,password_os,slow_log_file)


    # 查询解析结果
    sql = """
      select id,
         host,port,start_time,client_host,db_name,substr(sql_text,1,30) sql_text,sql_text sql_text_full,query_time,lock_time,rows_examined,rows_sent
    from mysql_slowquery where tags='%s' order by start_time desc """ %tagsdefault
    slow_query_list = tools.mysql_django_query(sql)


    if request.method == 'POST':
        if request.POST.has_key('select_tags'):
            tagsdefault = request.POST.get('select_tags', None).encode("utf-8")
            return HttpResponseRedirect('/mysql_slowquery?tagsdefault=%s' % (
            tagsdefault))
        else:
            logout(request)
            return HttpResponseRedirect('/login/')


    if messageinfo_list:
        msg_num = len(messageinfo_list)
        msg_last = models_frame.TabAlarmInfo.objects.latest('id')
        msg_last_content = msg_last.alarm_content
        tim_last = (datetime.datetime.now() - msg_last.alarm_time).seconds / 60
    else:
        msg_num = 0
        msg_last_content = ''
        tim_last = ''
    return render(request, 'mysql_mon/mysql_slowquery.html', {'tagsdefault': tagsdefault, 'tagsinfo':tagsinfo, 'msg_num':msg_num, 'msg_last_content':msg_last_content, 'tim_last':tim_last, 'slow_query_list':slow_query_list})
示例#4
0
文件: views.py 项目: 957177498/b
def mysql_ctl(request):
    # 告警
    messageinfo_list = models_frame.TabAlarmInfo.objects.all()
    oper_type = request.GET.get('oper_type')
    host = request.GET.get('host')

    if oper_type:
        log_type = 'Mysql启停'
        sql = '''select user,password from tab_linux_servers where host='%s' ''' % host
        mysql = tools.mysql_query(sql)
        user = mysql[0][0]
        password = mysql[0][1]
        password = base64.decodestring(password)
        if oper_type == 'startup':
            # ora_do.oracle_startup(host, user, password)
            return HttpResponseRedirect('/mysql_ctl/')
        elif oper_type == 'shutdown':
            # ora_do.oracle_shutdown(host, user, password)
            return HttpResponseRedirect('/mysql_ctl/')
        else:
            # ora_do.oracle_shutdown(host, user, password)
            # ora_do.oracle_startup(host, user, password)
            return HttpResponseRedirect('/mysql_ctl/')
    else:
        # 数据库操作面板
        mysql_ctl_sql = '''select t1.tags,
             t1.host,
             t1.port,
             (case t2.mon_status
             when 'connected' then 'running' else 'suspend' end) run_status,
             (case t2.mon_status
             when 'connected' then 'success' else 'danger' end) is_run,
               (case t2.mon_status
             when 'connected' then 'red' else 'green' end) run_color,
             (case t2.mon_status
             when 'connected' then 'shutdown' else 'startup' end) oper_type
        from tab_mysql_servers t1
        left join mysql_db t2
          on t1.tags = t2.tags'''

        mysql_ctl_list = tools.mysql_django_query(mysql_ctl_sql)

        paginator_mysql_ctl = Paginator(mysql_ctl_list, 5)
        page_mysql_ctl = request.GET.get('page_mysql_ctl')
        try:
            mysql_ctls = paginator_mysql_ctl.page(page_mysql_ctl)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            mysql_ctls = paginator_mysql_ctl.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            mysql_ctls = paginator_mysql_ctl.page(page_mysql_ctl.num_pages)

        now = tools.now()
        if request.method == 'POST':
            logout(request)
            return HttpResponseRedirect('/login/')

        if messageinfo_list:
            msg_num = len(messageinfo_list)
            msg_last = models_frame.TabAlarmInfo.objects.latest('id')
            msg_last_content = msg_last.alarm_content
            tim_last = (datetime.datetime.now() - msg_last.alarm_time).seconds / 60
            return render_to_response('mysql_mon/mysql_ctl.html',
                                      {'messageinfo_list': messageinfo_list, 'mysql_ctls': mysql_ctls,
                                       'msg_num': msg_num, 'now': now,
                                       'msg_last_content': msg_last_content, 'tim_last': tim_last})
        else:
            msg_num = 0
            msg_last_content = ''
            tim_last = ''
            return render_to_response('mysql_mon/mysql_ctl.html',
                                      {'messageinfo_list': messageinfo_list, 'mysql_ctls': mysql_ctls, 'now': now,
                                       'msg_last_content': msg_last_content, 'tim_last': tim_last})
示例#5
0
文件: views.py 项目: 957177498/b
def blog_index(request):
    # 告警
    messageinfo_list = models_frame.TabAlarmInfo.objects.all()

    type = request.GET.get('type')
    subtype = request.GET.get('subtype')
    search = request.GET.get('search')

    author_id = request.GET.get('author_id')
    blog_tags = models_blog.BlogTag.objects.all()
    blog_views = models_blog.BlogArticle.objects.order_by('-views')[:10]

    sql = """
    select a.id,
       date_format(a.created_time,'%%Y-%%m-%%d') created_time,
       a.title,
       a.body,
       a.pub_time,
       a.type,
       a.subtype,
       a.views,
       a.author_id,
       b.username
  from blog_article a
  left join accounts_bloguser b
    on a.author_id = b. id where if ('%s'='None',1=1,a.type='%s') and if ('%s'='None',1=1,a.author_id='%s')
     and if ('%s'='None',1=1,a.subtype='%s') and if ('%s'='None',1=1,a.title like '%%%s%%' )  order by a.id desc
""" % (type, type, author_id, author_id, subtype, subtype, search, search)

    blog_article_list = tools.mysql_django_query(sql)

    if blog_article_list:
        paginator = Paginator(blog_article_list, 10)

        page = request.GET.get('page')
        try:
            blog_articles = paginator.page(page)
        except PageNotAnInteger:
            # If page is not an integer, deliver first page.
            blog_articles = paginator.page(1)
        except EmptyPage:
            # If page is out of range (e.g. 9999), deliver last page of results.
            blog_articles = paginator.page(paginator.num_pages)
    else:
        blog_articles = {}

    now = tools.now()
    if request.method == 'POST':
        if request.POST.has_key('search'):
            search = request.POST.get('search', None)
            return HttpResponseRedirect('/blog_index?search=%s' % search)
        else:
            logout(request)
            return HttpResponseRedirect('/login/')

    if messageinfo_list:
        msg_num = len(messageinfo_list)
        msg_last = models_frame.TabAlarmInfo.objects.latest('id')
        msg_last_content = msg_last.alarm_content
        tim_last = (datetime.datetime.now() - msg_last.alarm_time).seconds / 60
    else:
        msg_num = 0
        msg_last_content = ''
        tim_last = ''
    return render_to_response(
        'my_blog/blog_index.html', {
            'messageinfo_list': messageinfo_list,
            'msg_num': msg_num,
            'now': now,
            'msg_last_content': msg_last_content,
            'tim_last': tim_last,
            'blog_articles': blog_articles,
            'blog_tags': blog_tags,
            'blog_views': blog_views,
            'type': type,
            'subtype': subtype,
            'search': search
        })