コード例 #1
0
 def parse_object_as_json_fortmat(self, event):
     date_time = DateTime()
     args = {
              'id'               : event.id,
              'name'             : event.name,
              'location'         : event.location,
              'region'           : event.region,
              'start_date'       : str(date_time.convert_unix_timestamp_2_human_creadeble(event.start_date)),
              'end_date'         : str(date_time.convert_unix_timestamp_2_human_creadeble(event.end_date)),
              'create_date'      : str(date_time.convert_unix_timestamp_2_human_creadeble(event.create_date)),
              'active'           : True if event.active else False
             }
     return args
コード例 #2
0
 def standby(self, request):
     args = {}
     date_time = DateTime()
     now = date_time.get_now()
     standby_list = ServiceCheck.objects.filter(active=1)
     if standby_list:
         args_standby_list = []
         for service in standby_list:
             args_standby_list.append(
                 ServiceCheck().parse_object_as_json_fortmat(service))
         args["detail"] = "OK"
         args["service_check_standby_list"] = args_standby_list
     else:
         args["detail"] = "Service is empty"
     data = json.dumps(args)
     return HttpResponse(data,
                         content_type='application/json',
                         status=status.HTTP_200_OK)
コード例 #3
0
 def standby(self, request):
     args = {}
     date_time = DateTime()
     now = date_time.get_now()
     standby_list = Event.objects.filter(active=1, end_date__gt=now)
     if standby_list:
         args_standby_list = []
         for event in standby_list:
             args_standby_list.append(
                 Event().parse_object_as_json_fortmat(event))
         args["detail"] = "OK"
         args["event_standby_list"] = args_standby_list
     else:
         args["detail"] = "Event is empty"
     data = json.dumps(args)
     return HttpResponse(data,
                         content_type='application/json',
                         status=status.HTTP_200_OK)
コード例 #4
0
 def put(self, request, pk):
     try:
         data = json.loads(request.body)
     except Exception as e:
         agrs["detail"] = "No data input found!"
         messages = json.dumps(agrs)
     if data:
         event_monitor = self.get_object(pk)
         flag = False
         #status
         if ('status' in data):
             event_monitor.status = data['status']
             flag = True
         #pid
         if ('pid' in data):
             event_monitor.pid = data['pid']
             flag = True
         if ('active' in data):
             active = 1 if data['active'] else 0
             event_monitor.active = data['active']
             flag = True
         if ('service_check_id' in data):
             event_monitor.service_check_id = data['service_check_id']
             flag = True
         if ('descr' in data):
             event_monitor.descr = data['descr']
             flag = True
         if ('event_id' in data):
             event_monitor.event_id = data['event_id']
             flag = True
         if ('encoder_id' in data):
             event_monitor.encoder_id = data['encoder_id']
             flag = True
         if ('last_update' in data):
             event_monitor.last_update = data['last_update']
             flag = True
         else:
             date_time = DateTime()
             now = date_time.get_now()
             event_monitor.last_update = now
         if flag:
             event_monitor.save()
             return HttpResponse(status=202)
     return HttpResponse(status=400)
コード例 #5
0
    def post(self, request):
        data = json.loads(request.body)
        flag = False
        #status
        if ('status' in data):
            status = data['status']
            flag = True
        else:
            status = None
        #pid
        if ('pid' in data):
            pid = data['pid']
            flag = True
        else:
            pid = None
        if ('active' in data):
            active = data['active']
            if active:
                active = 1
            else:
                active = 0
            flag = True
        else:
            active = 1

        if ('service_check_id' in data):
            service_check_id = data['service_check_id']
            flag = True
        else:
            service_check_id = None
        if ('descr' in data):
            descr = data['descr']
            flag = True
        else:
            descr = ""
        if ('event_id' in data):
            event_id = data['event_id']
            flag = True
        else:
            event_id = None
        if ('encoder_id' in data):
            encoder_id = data['encoder_id']
            flag = True
        else:
            encoder_id = None
        if ('last_update' in data):
            last_update = data['last_update']
            flag = True
        else:
            date_time = DateTime()
            now = date_time.get_now()
            last_update = now
        if flag:
            event_monitor = EventMonitor(pid=pid,
                                         event_id=event_id,
                                         encoder_id=encoder_id,
                                         service_check_id=service_check_id,
                                         status=status,
                                         last_update=last_update,
                                         active=active,
                                         descr=descr)
            event_monitor.save()
            return HttpResponse(status=202)
        return HttpResponse(status=400)
コード例 #6
0
    def post(self, request):
        agrs = {}
        try:
            data = json.loads(request.body)
        except Exception as e:
            agrs["detail"] = "No data input found!"
            messages = json.dumps(agrs)
            return HttpResponse(messages,
                                content_type='application/json',
                                status=203)
        flag = False
        if ('end_date' in data):
            flag = True
            end_date = data['end_date']
            date_time = DateTime()
            end_date = date_time.conver_human_creadeble_2_unix_timetamp(
                end_date)
        else:
            end_date = 0
        if ('name' in data):
            flag = True
            name = data['name'].encode("utf-8")
        else:
            agrs["detail"] = "Name not empty!"
            messages = json.dumps(agrs)
            return HttpResponse(messages,
                                content_type='application/json',
                                status=203)
        if ('start_date' in data):
            flag = True
            start_date = data['start_date']
            date_time = DateTime()
            start_date = date_time.conver_human_creadeble_2_unix_timetamp(
                start_date)
        else:
            start_date = 0
        if ('active' in data):
            flag = True
            active = data['active']
            if active:
                active = 1
            else:
                active = 0
        else:
            active = 1
        if ('create_date' in data):
            flag = True
            create_date = data['create_date']
        else:
            date_time = DateTime()
            create_date = date_time.get_now()
        if ('region' in data):
            flag = True
            region = data['region'].encode("utf-8")
        else:
            region = "HCM"
        if ('location' in data):
            flag = True
            location = data['location']
        else:
            location = ""

        if flag:
            new_obj_event = Event(name=name,
                                  location=location,
                                  region=region,
                                  start_date=start_date,
                                  end_date=end_date,
                                  create_date=create_date,
                                  active=active)
            new_obj_event.save()
            agrs["detail"] = "Successfully added event: %s" % (name)
            messages = json.dumps(agrs)
            return HttpResponse(messages,
                                content_type='application/json',
                                status=202)
        else:
            agrs["detail"] = "Invalid data input!"
            messages = json.dumps(agrs)
            return HttpResponse(messages,
                                content_type='application/json',
                                status=203)
        return HttpResponse(status=400)
コード例 #7
0
 def put(self, request, pk):
     agrs = {}
     event = self.get_object(pk)
     if not event:
         args["detail"] = 'Event ID not found.'
         data = json.dumps(args)
         return HttpResponse(data,
                             content_type='application/json',
                             status=203)
     try:
         data = json.loads(request.body)
     except Exception as e:
         agrs["detail"] = "No data input found!"
         messages = json.dumps(agrs)
         return HttpResponse(messages,
                             content_type='application/json',
                             status=203)
     flag = False
     if ('end_date' in data):
         flag = True
         end_date = data['end_date']
         date_time = DateTime()
         end_date = date_time.conver_human_creadeble_2_unix_timetamp(
             end_date)
         event.end_date = end_date
     if ('name' in data):
         flag = True
         name = data['name'].encode("utf-8")
         event.name = name
     else:
         agrs["detail"] = "Name not empty!"
         messages = json.dumps(agrs)
         return HttpResponse(messages,
                             content_type='application/json',
                             status=203)
     if ('start_date' in data):
         flag = True
         start_date = data['start_date']
         date_time = DateTime()
         start_date = date_time.conver_human_creadeble_2_unix_timetamp(
             start_date)
         event.start_date = start_date
     if ('active' in data):
         flag = True
         active = data['active']
         if active:
             active = 1
         else:
             active = 0
         event.active = active
     if ('region' in data):
         flag = True
         region = data['region'].encode("utf-8")
         event.region = region
     if ('location' in data):
         flag = True
         location = data['location']
         event.location = location
     if flag:
         event.save()
         agrs["detail"] = "Successfully edited event: %s" % (name)
         messages = json.dumps(agrs)
         return HttpResponse(messages,
                             content_type='application/json',
                             status=202)
     else:
         agrs["detail"] = "Invalid data input!"
         messages = json.dumps(agrs)
         return HttpResponse(messages,
                             content_type='application/json',
                             status=203)
     return HttpResponse(status=400)