from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from dashboard.models import *
from returner.models import *
import logging
from shaker.tasks import dashboard_task,grains_task


logger = logging.getLogger('django')

@login_required(login_url="/account/login/")
def index(request):
    dashboard_task.delay()
    grains_task.delay()
    try:
        dashboard_status = Dashboard_status.objects.get(id=1)
    except:
        status_list = [0, 0, 0, 0, 0]
    else:
        status_list = [int(dashboard_status.up),
                   int(dashboard_status.down),
                   int(dashboard_status.accepted),
                   int(dashboard_status.unaccepted),
                   int(dashboard_status.rejected),
                   ]
        logger.info(status_list)

    salt_grains = Salt_grains.objects.all()
    release_list = []
    os_all = []
    os_release = []
    for release in salt_grains:
        release_dic = eval(release.grains)
        release_info = release_dic.get('osfullname').decode('string-escape') + release_dic.get('osrelease').decode('string-escape')
        release_list.append(release_info)
        os_release = list(set(release_list))
        logger.info(os_release)

    for release_name in os_release:
        os_dic = {'name': release_name, 'value': release_list.count(release_name)}
        os_all.append(os_dic)
        logger.info(os_all)

    return render(request, 'dashboard/index.html', {'status': status_list,
                                                    'os_release': os_release,
                                                    'os_all': os_all,
                                                    })

@@ -203,16 +203,17 @@
 rd_task,
+ 
 grains_t
@@ -216,16 +216,73 @@
 ns_task%0A
+from shaker.check_service import CheckPort, CheckProgress
 %0A%0Alogger
@@ -378,16 +378,29 @@
 quest):%0A
+    try:%0A    
     dash
@@ -414,24 +414,28 @@
 ask.delay()%0A
+    
     grains_t
@@ -442,24 +442,111 @@
 ask.delay()%0A
+    except:%0A        logger.error(%22Connection refused, don't connect rabbitmq service%22)%0A
     try:%0A   
@@ -1577,16 +1577,459 @@
 s_all)%0A%0A
+    salt_master_stauts = CheckPort('Salt Master', '127.0.0.1', 4505)%0A    salt_api_status = CheckPort('Salt Api', '127.0.0.1', 8000)%0A    rabbitmy_status = CheckPort('RabbixMQ', '127.0.0.1', 5672)%0A    rabbitmy_m_status = CheckPort('RabbixMQ Management', '127.0.0.1', 15672)%0A    celery_statu = CheckProgress('Celery', 'celery worker')%0A    check_service = %5Bsalt_master_stauts, salt_api_status, rabbitmy_status, rabbitmy_m_status, celery_statu%5D%0A%0A%0A%0A
     retu
@@ -2173,16 +2173,16 @@
 elease,%0A
-
         
@@ -2243,16 +2243,100 @@
 os_all,%0A
+                                                    'check_service': check_service,%0A
         

添加连接不上rabbitmq后的异常处理，添加dashboard页面服务组件状态监控