Пример #1
0
    def get_queryset(self):
        queryset = Alarm.objects.all().order_by('-create_time')
        start_time = self.request.GET.get('start_time', '')
        end_time = self.request.GET.get('end_time', '')
        pool_id = self.request.GET.get('pool_id', '')
        exclude_source_id = self.request.GET.get('exclude_source_id', 0)
        level__in = self.request.GET.get('level__in', '')
        source__in = self.request.GET.get('source__in', '')
        type__in = self.request.GET.get('type__in', '')
        source_id = self.request.GET.get('source_id', '')

        self_defined_exclude = {}
        self_defined_filters = {}
        if start_time:
            try:
                self_defined_filters['create_time__gte'] = str2stamp(
                    start_time, '%Y-%m-%d %H:%M')
            except ValueError:
                raise MyException(u'time format error')

        if end_time:
            try:
                self_defined_filters['create_time__lt'] = str2stamp(
                    end_time, '%Y-%m-%d %H:%M')
            except ValueError:
                raise MyException(u'time format error')

        if pool_id:
            pools = EventDetail.objects.filter(pool__id=pool_id)
            self_defined_filters['event__id__in'] = [
                pool.event_id for pool in pools
            ]

        if exclude_source_id:
            self_defined_exclude['event__source_id'] = exclude_source_id

        if level__in:
            self_defined_filters['event__level__in'] = level__in.split(',')

        if source__in:
            self_defined_filters['event__source__in'] = source__in.split(',')

        if type__in:
            self_defined_filters['event__type__in'] = type__in.split(',')

        if source_id:
            self_defined_filters['event__source_id'] = source_id

        queryset = queryset.filter(**self_defined_filters).exclude(
            **self_defined_exclude)
        return queryset
Пример #2
0
    def get_queryset(self):
        queryset = EventLevelAdjustment.objects.all().order_by('-create_time')
        start_time = self.request.GET.get('start_time', '')
        end_time = self.request.GET.get('end_time', '')

        self_defined_filters = {}
        if start_time:
            self_defined_filters['start_time__gte'] = str2stamp(
                start_time, '%Y-%m-%d %H:%M:%S')

        if end_time:
            self_defined_filters['start_time__lte'] = str2stamp(
                end_time, '%Y-%m-%d %H:%M:%S')

        queryset = queryset.filter(**self_defined_filters)
        return queryset
Пример #3
0
 def save_data(self, server_id, ori_str):
     data = ori_str['values']
     processorinfo = self.format_process(data)
     nicinfo = self.format_nic_info(data)
     try:
         fact_date = stamp2str(
             str2stamp(data.get('last_run'), '%a %b %d %H:%M:%S %Z %Y'))
     except ValueError, e:
         print('data format error(server_id=%s):%s' %
               (str(server_id), data.get('last_run')))
         return
Пример #4
0
    def get_queryset(self):
        queryset = Event.objects.all().order_by('-get_time')
        status_q = self.request.GET.get('status', '')
        level_id = self.request.GET.get('level_id', '')
        level__in = self.request.GET.get('level__in', '')
        source__in = self.request.GET.get('source__in', '')
        type__in = self.request.GET.get('type__in', '')
        site_id = self.request.GET.get('site_id', '')
        pool_id = self.request.GET.get('pool_id', '')
        start_time = self.request.GET.get('start_time', '')
        end_time = self.request.GET.get('end_time', '')
        source_id = self.request.GET.get('source_id', '')

        # for undone event
        if status_q:
            queryset = Event.objects.all().order_by('level__id', '-get_time')

        self_defined_filters = {}
        if level_id:
            self_defined_filters['level_id__lt'] = level_id

        if level__in:
            self_defined_filters['level__in'] = level__in.split(',')

        if source__in:
            self_defined_filters['source__in'] = source__in.split(',')

        if type__in:
            self_defined_filters['type__in'] = type__in.split(',')

        if site_id:
            sites = EventDetail.objects.filter(site__id=site_id)
            self_defined_filters['id__in'] = [site.event_id for site in sites]

        if pool_id:
            pools = EventDetail.objects.filter(pool__id=pool_id)
            self_defined_filters['id__in'] = [pool.event_id for pool in pools]

        if start_time:
            try:
                if start_time.count(':') == 1:
                    start_time += ':00'
                self_defined_filters['get_time__gte'] = str2stamp(
                    start_time, '%Y-%m-%d %H:%M:%S')
            except ValueError:
                raise MyException(u'time format error')

        if end_time:
            try:
                if end_time.count(':') == 1:
                    end_time += ':00'
                self_defined_filters['get_time__lt'] = str2stamp(
                    end_time, '%Y-%m-%d %H:%M:%S')
            except ValueError:
                raise MyException(u'time format error')

        if source_id:
            self_defined_filters['source__id'] = source_id

        queryset = queryset.select_related("source", "type", "level")
        queryset = queryset.filter(**self_defined_filters)
        return queryset
Пример #5
0
def get_alarmlistv2(request):
    # event parameter
    pool_id = request.GET.get('pool_id', '')
    exclude_source_id = request.GET.get('exclude_source_id', 0)

    source__in = request.GET.get('source__in', '')
    type__in = request.GET.get('type__in', '')
    level__in = request.GET.get('level__in', '')

    # compatible
    source_id = request.GET.get('event__source__id', '')
    type_id = request.GET.get('event__type__id', '')
    level_id = request.GET.get('event__level__id', '')

    search = request.GET.get('search', '')

    event_defined_filters = {}
    event_defined_exclude = {}

    if pool_id:
        event_detail = EventDetail.objects.filter(
            pool_id=pool_id).values('event_id')
        event_ids = [one['event_id'] for one in event_detail]
        event_defined_filters['id__in'] = event_ids

    if exclude_source_id:
        event_defined_exclude['source_id'] = exclude_source_id

    if source__in:
        event_defined_filters['source_id__in'] = source__in.split(',')

    if type__in:
        event_defined_filters['type_id__in'] = type__in.split(',')

    if level__in:
        event_defined_filters['level_id__in'] = level__in.split(',')

    if source_id:
        event_defined_filters['source_id'] = source_id

    if type_id:
        event_defined_filters['type_id'] = type_id

    if level_id:
        event_defined_filters['level_id'] = level_id

    if search:
        event_defined_filters['message__contains'] = search

    # alarm parameter
    id_q = request.GET.get('id', '')
    status_id = request.GET.get('status_id', '')
    method_id = request.GET.get('method_id', '')

    start_time = request.GET.get('start_time', '')
    end_time = request.GET.get('end_time', '')

    order_by_list = ['-create_time']
    alarm_defined_filters = {}

    if id_q:
        alarm_defined_filters['id'] = id_q

    if status_id:
        alarm_defined_filters['status_id'] = status_id

    if method_id:
        alarm_defined_filters['method_id'] = method_id

    if start_time:
        try:
            alarm_defined_filters['create_time__gte'] = str2stamp(
                start_time, '%Y-%m-%d %H:%M')
        except ValueError:
            raise MyException('time format error')
    else:
        # 如果没有指定id,则设置默认时间
        if not id_q:
            # start_time 默认为过去的24h
            start_time_default = int(time.time()) - 24 * 3600
            alarm_defined_filters['create_time__gte'] = start_time_default

    if end_time:
        try:
            alarm_defined_filters['create_time__lt'] = str2stamp(
                end_time, '%Y-%m-%d %H:%M')
        except ValueError:
            raise MyException('time format error')
    else:
        # 如果没有指定id,则设置默认时间
        if not id_q:
            # end_time 默认为现在
            end_time_default = int(time.time()) + 60
            alarm_defined_filters['create_time__lt'] = end_time_default

    event_id_list = []
    # 是否要过滤
    if event_defined_filters or event_defined_exclude:
        # 过滤1:alarm
        alarm_count = Alarm.objects.filter(**alarm_defined_filters).count()
        if alarm_count == 0:
            return HttpResponse(json.dumps({
                'count': 0,
                'results': []
            }),
                                content_type="application/json")

        alarm_columns = ['event_id']
        alarm_result_set = Alarm.objects.filter(
            **alarm_defined_filters).values(*alarm_columns)

        event_id_list = []
        for one in alarm_result_set:
            event_id_list.append(one['event_id'])

        old_event_ids = event_defined_filters.get('id__in', [])
        if old_event_ids:
            # 交集
            event_id_merge = list(
                set(event_id_list).intersection(set(old_event_ids)))
            event_defined_filters['id__in'] = event_id_merge
        else:
            event_defined_filters['id__in'] = event_id_list

        # 过滤2: event
        event_count = Event.objects.filter(**event_defined_filters).exclude(
            **event_defined_exclude).count()
        if event_count == 0:
            return HttpResponse(json.dumps({
                'count': 0,
                'results': []
            }),
                                content_type="application/json")

        event_columns = ['id']
        event_result_set = Event.objects.filter(
            **event_defined_filters).exclude(**event_defined_exclude).values(
                *event_columns)
        event_id_list = []
        for one in event_result_set:
            event_id_list.append(one['id'])

    # page information
    limit = int(request.GET.get('page_size', 30))
    offset = (int(request.GET.get('page', 1)) - 1) * limit

    # query alarm info
    if event_id_list:
        alarm_defined_filters['event_id__in'] = event_id_list
    alarm_count = Alarm.objects.filter(**alarm_defined_filters).count()
    if alarm_count == 0:
        return HttpResponse(json.dumps({
            'count': 0,
            'results': []
        }),
                            content_type="application/json")

    count = alarm_count
    if offset + limit > count:
        limit = count - offset + 1

    columns_list = [
        'id', 'event_id', 'method_id', 'result', 'create_time', 'receiver',
        'error'
    ]
    alarm_result_set = Alarm.objects.filter(**alarm_defined_filters).order_by(
        *order_by_list)[offset:offset + limit].values(*columns_list)

    event_id_list = []
    for one in alarm_result_set:
        event_id_list.append(one['event_id'])

    # query event info
    event_defined_filters = {'id__in': event_id_list}
    event_columns = [
        'id', 'source_id', 'type_id', 'level_id', 'title', 'message',
        'level_adjustment_id'
    ]
    event_result_set = Event.objects.filter(**event_defined_filters).values(
        *event_columns)

    event_map = {}
    for one in event_result_set:
        event_map.setdefault(one['id'], one)

    # event detail.eg.ip and pool
    ed_columns = ['event_id', 'ip', 'pool_id']
    event_detail_res = EventDetail.objects.filter(
        event_id__in=event_id_list).values(*ed_columns)
    event_detail_map = {}
    pool_id_list = []
    for ed in event_detail_res:
        pool_id_list.append(ed['pool_id'])
        if ed['event_id'] not in event_detail_map:
            event_detail_map[ed['event_id']] = {
                'ip': [ed['ip']],
                'pool_id': ed['pool_id']
            }
        else:
            event_detail_map[ed['event_id']]['ip'].append(ed['ip'])

    # preload app info
    event_global_var.update_app_info(pool_id_list)

    # add extra info
    # method_name, receiver_name, source_name, type_name, level_name
    for row in alarm_result_set:
        # alarm
        row['method_name'] = event_global_var.get_alarm_method_name(
            row['method_id'])
        row['create_time'] = stamp2str(row['create_time'])

        # event
        event_id = row['event_id']
        one_event = event_map.get(event_id, {})
        for event_field in one_event:
            if event_field != 'id':
                row[event_field] = one_event[event_field]

        row['source_name'] = event_global_var.get_source_info(
            one_event.get('source_id', 0))
        row['type_name'] = event_global_var.get_type_info(
            one_event.get('type_id', 0))
        row['level_name'] = event_global_var.get_level_info(
            one_event.get('level_id', 0))

        # event_detail
        one_event_detail = event_detail_map.get(event_id, {})
        row['ip'] = one_event_detail.get('ip', [])
        pack_pool_id = one_event_detail.get('pool_id', 0)
        row['pool_id'] = pack_pool_id

        # pool name
        app_info = event_global_var.get_app_info(pack_pool_id)
        if app_info:
            site_pool_name = app_info[0] + "/" + app_info[1]
        else:
            site_pool_name = ''
        row.setdefault('pool_name', site_pool_name)

        # receiver_name
        row['receiver'] = event_global_var.get_alarm_receiver_name(
            row['method_id'], row['receiver'])

    alarm_result_set = alarm_result_set[:]
    return HttpResponse(json.dumps({
        'count': count,
        'results': alarm_result_set
    }),
                        content_type="application/json")
Пример #6
0
def get_eventlistv2(request):
    id_q = request.GET.get('id', '')
    source__id = request.GET.get('source__id', '')
    type__id = request.GET.get('type__id', '')
    level__id = request.GET.get('level__id', '')
    status_q = request.GET.get('status', '')
    converge_id = request.GET.get('converge_id', '')
    # 小于level_id
    level_id = request.GET.get('level_id', '')
    level__in = request.GET.get('level__in', '')
    source__in = request.GET.get('source__in', '')
    type__in = request.GET.get('type__in', '')
    site_id = request.GET.get('site_id', '')
    pool_id = request.GET.get('pool_id', '')

    start_time = request.GET.get('start_time', '')
    end_time = request.GET.get('end_time', '')
    search = request.GET.get('search')

    order_by_list = ['-get_time']
    self_defined_filters = {}
    undone_event_flag = False

    if id_q:
        self_defined_filters['id'] = id_q

    if source__id:
        self_defined_filters['source__id'] = source__id

    if type__id:
        self_defined_filters['type__id'] = type__id

    if level__id:
        self_defined_filters['level__id'] = level__id

    if status_q:
        try:
            status_q = int(status_q)
        except ValueError:
            raise MyException(u'the parameter \'status\' incorrect')

        self_defined_filters['status'] = status_q
        # for undone event
        if status_q == 0:
            order_by_list.insert(0, 'level__id')
            undone_event_flag = True

    if converge_id:
        self_defined_filters['converge_id'] = converge_id

    # 小于level_id
    if level_id:
        self_defined_filters['level_id__lt'] = level_id

    if level__in:
        self_defined_filters['level__in'] = level__in.split(',')

    if source__in:
        self_defined_filters['source__in'] = source__in.split(',')

    if type__in:
        self_defined_filters['type__in'] = type__in.split(',')

    if site_id:
        event_detail = EventDetail.objects.filter(site__id=site_id)
        self_defined_filters['id__in'] = [one.event_id for one in event_detail]

    if pool_id:
        event_detail = EventDetail.objects.filter(
            pool_id=pool_id).values('event_id')
        event_ids = [one['event_id'] for one in event_detail]
        self_defined_filters['id__in'] = event_ids

    if start_time:
        try:
            if start_time.count(':') == 1:
                start_time += ':00'
            self_defined_filters['get_time__gte'] = str2stamp(
                start_time, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            raise MyException(u'time format error')
    else:
        # 如果没有指定id,则设置默认时间
        if not id_q:
            # start_time 默认为过去的24h
            start_time_default = int(time.time()) - 24 * 3600
            self_defined_filters['get_time__gte'] = start_time_default

    if end_time:
        try:
            if end_time.count(':') == 1:
                end_time += ':00'
            self_defined_filters['get_time__lt'] = str2stamp(
                end_time, '%Y-%m-%d %H:%M:%S')
        except ValueError:
            raise MyException(u'time format error')
    else:
        # 如果没有指定id,则设置默认时间
        if not id_q:
            # end_time 默认为现在
            end_time_default = int(time.time()) + 60
            self_defined_filters['get_time__lt'] = end_time_default

    if search:
        self_defined_filters['message__contains'] = search

    # page information
    limit = int(request.GET.get('page_size', 30))
    offset = (int(request.GET.get('page', 1)) - 1) * limit

    # the count of the result
    # the count use about 600ms(local test)
    count = Event.objects.filter(**self_defined_filters).count()

    # if 0, return directly
    if count == 0:
        return HttpResponse(json.dumps({
            'count': 0,
            'results': []
        }),
                            content_type="application/json")

    if offset + limit > count:
        limit = count - offset + 1

    # the result set
    columns_list = [
        'id', 'level_id', 'level_adjustment_id', 'type_id', 'source_id',
        'title', 'message', 'get_time', 'create_time', 'cancel_time',
        'cancel_user', 'comment', 'status', 'cancel_type'
    ]

    # use about 600ms(local test)
    result_set = Event.objects.filter(**self_defined_filters).order_by(
        *order_by_list)[offset:offset + limit].values(*columns_list)

    # event id in result
    eventid_list = []
    for event in result_set:
        eventid_list.append(event['id'])

    # event detail.eg.ip and pool
    ed_columns = ['event_id', 'ip', 'pool_id']
    event_detail_res = EventDetail.objects.filter(
        event_id__in=eventid_list).values(*ed_columns)
    event_detail_map = {}
    pool_id_list = []
    for ed in event_detail_res:
        pool_id_list.append(ed['pool_id'])
        if ed['event_id'] not in event_detail_map:
            event_detail_map[ed['event_id']] = {
                'ip': [ed['ip']],
                'pool_id': ed['pool_id']
            }
        else:
            event_detail_map[ed['event_id']]['ip'].append(ed['ip'])

    # preload app info
    event_global_var.update_app_info(pool_id_list)

    # add extra info
    for row in result_set:
        # 未处理事件持续时间
        if undone_event_flag:
            row['during_time'] = timelength_format(row['get_time'],
                                                   int(time.time()))

        # time format
        row['get_time'] = stamp2str(row['get_time'])
        row['create_time'] = stamp2str(row['create_time'])
        if row['cancel_time'] == 0:
            row['cancel_time'] = ""
        else:
            row['cancel_time'] = stamp2str(row['cancel_time'])

        detail = event_detail_map.get(row['id'], {})
        row.setdefault('ip', detail.get('ip', []))

        pack_pool_id = detail.get('pool_id', 0)
        row.setdefault('pool_id', pack_pool_id)
        app_info = event_global_var.get_app_info(pack_pool_id)
        if app_info:
            site_pool_name = app_info[0] + "/" + app_info[1]
        else:
            site_pool_name = ''
        row.setdefault('pool_name', site_pool_name)

        row.setdefault('source_name',
                       event_global_var.get_source_info(row['source_id']))
        row.setdefault('level_name',
                       event_global_var.get_level_info(row['level_id']))
        row.setdefault('type_name',
                       event_global_var.get_type_info(row['type_id']))

        # status name
        row['status'] = event_global_var.get_event_status_name(row['status'])

    # queryset转为list
    result_set = result_set[:]
    return HttpResponse(json.dumps({
        'count': count,
        'results': result_set
    }),
                        content_type="application/json")
    def handle(self, *args, **options):
        error = False
        message = []
        try:
            action_list = AccidentAction.objects.using('accident').filter(
                status=1)  #进行中的action
            today = str2stamp(date.today().strftime("%Y-%m-%d"),
                              formt='%Y-%m-%d')

            for action in action_list:
                if action.expect_time < today:
                    action.status = 2
                    action.save()

            accident_list = Accident.objects.using('accident').filter(
                is_accident=0, status_id=5)  #改进措施进行中的事故列表
            for accident in accident_list:
                cur_actions = AccidentAction.objects.using('accident').filter(
                    accident_id=accident.accidentid)
                action_status = [c_act.status for c_act in cur_actions]
                if 2 in action_status:
                    accident.status_id = 6
                    accident.save()

            #发送值班日报邮件
            lastday_str = stamp2str(today - 86400)
            try:
                cur_rota = Rota.objects.using('default').get(
                    promotion=0,
                    duty_domain=DOMAIN_HEAD_ID,
                    duty_date_start__lt=lastday_str,
                    duty_date_end__gte=lastday_str)
                duty_manager = RotaMan.objects.using('default').get(
                    rota_id=cur_rota.id).man
                back_duty_manager = RotaBackup.objects.using('default').get(
                    rota_id=cur_rota.id).backup

                cur_duty_manager = duty_manager.username
                cur_back_duty_manager = back_duty_manager.username

                if duty_manager.display_name != '':
                    cur_duty_manager_ch = str(duty_manager.display_name[(
                        duty_manager.display_name.rfind('_') + 1):-1])
                else:
                    cur_duty_manager_ch = '无'
                if back_duty_manager.display_name != '':
                    cur_back_duty_manager_ch = str(
                        back_duty_manager.display_name[(
                            back_duty_manager.display_name.rfind('_') + 1):-1])
                else:
                    cur_back_duty_manager_ch = '无'

                if cur_rota is not None:
                    duty_date_start = cur_rota.duty_date_start.strftime(
                        '%Y-%m-%d %H:%M:%S')
                    duty_date_end = cur_rota.duty_date_end.strftime(
                        '%Y-%m-%d %H:%M:%S')

            except Exception, e:
                cur_duty_manager = ''
                cur_back_duty_manager = ''
                cur_duty_manager_ch = ''
                cur_back_duty_manager_ch = ''

            acc = Accident.objects.using('accident').exclude(status=1).filter(
                is_accident=0,
                happened_time__lt=today - 14400,
                happened_time__gte=today - 100800)
            accidents = []
            for accident in acc:
                accidents.append({
                    'level':
                    accident.get_level_display,
                    'title':
                    accident.title,
                    'happened_time':
                    stamp2str(accident.happened_time, formt='%Y-%m-%d %H:%M'),
                    'finish_time':
                    stamp2str(accident.finish_time, formt='%Y-%m-%d %H:%M'),
                    'affect':
                    accident.affect,
                    'reason':
                    accident.reason,
                    'duty_dept_names':
                    accident.duty_dept_names,
                    'process':
                    accident.process,
                    'action':
                    accident.action
                })
            delay_actions = AccidentAction.objects.using('accident').filter(
                accident_id__gte=2016010101,
                expect_time__gte=1451577600,
                status=2)
            delay_action = []
            delay_action_users = []
            for da in delay_actions:
                try:
                    act = Accident.objects.using('accident').get(
                        accidentid=da.accident_id, is_accident=0)
                except Accident.DoesNotExist:
                    act = None
                if act:
                    delay_action.append({
                        'level': act.get_level_display,
                        'duty_manager_ch': act.duty_manager_name_ch,
                        'accidentid': act.accidentid,
                        'title': act.title,
                        'action': da.action,
                        'duty_dept': da.dutydept_name,
                        'duty_users': da.duty_users,
                        'expect_time': da.expect_time_format
                    })
                    for user in da.duty_users.split(','):
                        try:
                            delay_action_users.append(
                                DdUsers.objects.using('default').get(
                                    username=user, enable=0).email)
                        except DdUsers.DoesNotExist, DdUsers.MultipleObjectsReturned:
                            error = True
                            message.append(
                                '### duty user mail does not exist: username=%s'
                                % user)
Пример #8
0
def syn_appcontact():
    message = []

    get_response = urllib.urlopen(settings.CRON_APP_AND_CONTACT_API).read()
    res = json.loads(get_response)
    data = res['response']
    response = {'success': True, 'msg': u'CMIS系统同步完成!'}
    for item in data:
        cmis_site_id = item['siteId']
        try:
            site = Site.objects.get(cmis_id=cmis_site_id)
            site_id = site.id

            cmis_sync_app, created = App.objects.get_or_create(
                cmis_id=item['id'],
                cmis_site_id=cmis_site_id,
                defaults={
                    'name':
                    item['poolName'].strip(),
                    'site_id':
                    site_id,
                    'type':
                    0,
                    'level':
                    item['poolLevel'],
                    'ctime':
                    str2stamp(item['createTime'], formt='%Y-%m-%d %H:%M:%S'),
                    'comment':
                    item['businessDesc'],
                    'status':
                    item['enable'],
                    'is_cmis_sync':
                    1,
                    'domainid':
                    item['domainId'],
                    'service_name':
                    item['serviceTypeName'],
                    'test_status':
                    item['testEnvEnable']
                })

            if not created:
                if cmis_sync_app.type == 0:
                    #以后应添加新增App记录至变更系统
                    cmis_sync_app.name = item['poolName'].strip()
                    cmis_sync_app.site_id = site_id
                    cmis_sync_app.type = 0
                    cmis_sync_app.level = item['poolLevel']
                    cmis_sync_app.ctime = str2stamp(item['createTime'],
                                                    formt='%Y-%m-%d %H:%M:%S')
                    cmis_sync_app.comment = item['businessDesc']
                    cmis_sync_app.status = item['enable']
                    cmis_sync_app.is_cmis_sync = 1
                    cmis_sync_app.domainid = item['domainId']
                    cmis_sync_app.service_name = item['serviceTypeName']
                    cmis_sync_app.test_status = item['testEnvEnable']
                    cmis_sync_app.save()
                else:
                    content = u'CMIS系统调用非业务POOL的更新,cmis ID为%s,POOL名为 %s' % (
                        cmis_sync_app.cmis_id, cmis_sync_app.name)
                    response = {'success': False, 'msg': content}
                    message.append(
                        'error: CMIS系统调用非业务POOL的更新,cmis ID为%s,POOL名为 %s' %
                        (cmis_sync_app.cmis_id, cmis_sync_app.name))
                    continue
            #以后应添加删除App记录至变更系统
            cmis_sync_appcontact, created = AppContact.objects.get_or_create(
                site_id=site.id,
                pool_id=cmis_sync_app.id,
                defaults={
                    'site_name':
                    item['siteName'].strip(),
                    'pool_name':
                    item['poolName'].strip(),
                    'pool_status':
                    item['enable'],
                    'department_id':
                    item['deptId'],
                    'p_user':
                    item['domainLeaderVo']['adAccount'],
                    'p_email':
                    item['domainLeaderVo']['email'],
                    'p_no':
                    item['domainLeaderVo']['mobilePhoneNo'],
                    'domain_email':
                    item['domainEmailGroup'],
                    'sa_user':
                    item['saVo']['adAccount'],
                    'sa_email':
                    item['saVo']['email'],
                    'sa_no':
                    item['saVo']['mobilePhoneNo'],
                    'b_user':
                    item['backupDomainLeaderVo']['adAccount']
                    if item.has_key('backupDomainLeaderVo') else '',
                    'b_email':
                    item['backupDomainLeaderVo']['email']
                    if item.has_key('backupDomainLeaderVo') else '',
                    'b_no':
                    item['backupDomainLeaderVo']['mobilePhoneNo']
                    if item.has_key('backupDomainLeaderVo') else '',
                    'department':
                    item['deptName'].strip(),
                    'domain_id':
                    item['domainId'],
                    'domain_code':
                    item['domainCode'].strip(),
                    'domain_name':
                    item['domainName'].strip(),
                    'domain_leader':
                    item['domainLeaderVo']['displayName']
                    if item.has_key('domainLeaderVo') else '',
                    'domain_account':
                    item['domainLeaderVo']['adAccount']
                    if item.has_key('domainLeaderVo') else '',
                    'sa_backup_user':
                    item['backupSaVo']['adAccount']
                    if item.has_key('backupSaVo') else '',
                    'sa_backup_email':
                    item['backupSaVo']['email']
                    if item.has_key('backupSaVo') else '',
                    'sa_backup_no':
                    item['backupSaVo']['mobilePhoneNo']
                    if item.has_key('backupSaVo') else '',
                    'head_user':
                    item['departmentLeaderVo']['adAccount']
                    if item.has_key('departmentLeaderVo') else '',
                    'head_email':
                    item['departmentLeaderVo']['email']
                    if item.has_key('departmentLeaderVo') else '',
                    'head_no':
                    item['departmentLeaderVo']['mobilePhoneNo']
                    if item.has_key('departmentLeaderVo') else ''
                })
            if not created:
                cmis_sync_appcontact.site_name = item['siteName'].strip()
                cmis_sync_appcontact.pool_name = item['poolName'].strip()
                cmis_sync_appcontact.pool_status = item['enable']
                cmis_sync_appcontact.department_id = item['deptId']
                cmis_sync_appcontact.p_user = item['domainLeaderVo'][
                    'adAccount']
                cmis_sync_appcontact.p_email = item['domainLeaderVo']['email']
                cmis_sync_appcontact.p_no = item['domainLeaderVo'][
                    'mobilePhoneNo']
                cmis_sync_appcontact.domain_email = item['domainEmailGroup']
                cmis_sync_appcontact.sa_user = item['saVo']['adAccount']
                cmis_sync_appcontact.sa_email = item['saVo']['email']
                cmis_sync_appcontact.sa_no = item['saVo']['mobilePhoneNo']
                cmis_sync_appcontact.b_user = item['backupDomainLeaderVo'][
                    'adAccount'] if item.has_key(
                        'backupDomainLeaderVo') else ''
                cmis_sync_appcontact.b_email = item['backupDomainLeaderVo'][
                    'email'] if item.has_key('backupDomainLeaderVo') else ''
                cmis_sync_appcontact.b_no = item['backupDomainLeaderVo'][
                    'mobilePhoneNo'] if item.has_key(
                        'backupDomainLeaderVo') else ''
                cmis_sync_appcontact.department = item['deptName'].strip()
                cmis_sync_appcontact.domain_id = item['domainId']
                cmis_sync_appcontact.domain_code = item['domainCode'].strip()
                cmis_sync_appcontact.domain_name = item['domainName'].strip()
                cmis_sync_appcontact.domain_leader = item['domainLeaderVo'][
                    'displayName'] if item.has_key('domainLeaderVo') else ''
                cmis_sync_appcontact.domain_account = item['domainLeaderVo'][
                    'adAccount'] if item.has_key('domainLeaderVo') else ''
                cmis_sync_appcontact.sa_backup_user = item['backupSaVo'][
                    'adAccount'] if item.has_key('backupSaVo') else ''
                cmis_sync_appcontact.sa_backup_email = item['backupSaVo'][
                    'email'] if item.has_key('backupSaVo') else ''
                cmis_sync_appcontact.sa_backup_no = item['backupSaVo'][
                    'mobilePhoneNo'] if item.has_key('backupSaVo') else ''
                cmis_sync_appcontact.head_user = item['departmentLeaderVo'][
                    'adAccount'] if item.has_key('departmentLeaderVo') else ''
                cmis_sync_appcontact.head_email = item['departmentLeaderVo'][
                    'email'] if item.has_key('departmentLeaderVo') else ''
                cmis_sync_appcontact.head_no = item['departmentLeaderVo'][
                    'mobilePhoneNo'] if item.has_key(
                        'departmentLeaderVo') else ''
                cmis_sync_appcontact.save()
        except Site.DoesNotExist:
            response = {
                'success': False,
                'msg': u'站点%s不存在,同步错误!' % cmis_site_id
            }
            message.append('error: 站点%s不存在,同步错误!' % cmis_site_id)
            break
        except Exception, e:
            response = {'success': False, 'msg': str(e)}
            message.append('error: 站点ID:%s pool名:%s detail: %s' %
                           (cmis_site_id, cmis_sync_app.name, str(e)))
            break