예제 #1
0
 def get(self, request, region=None):
     args = {}
     monitor_list = self.event.get_event_monitor_list(region=region)
     args['monitor_list'] = monitor_list
     date_time = DateTime()
     args['now'] = date_time.get_now()
     data = json.dumps(args)
     return HttpResponse(data,
                         content_type='application/json',
                         status=status.HTTP_200_OK)
예제 #2
0
 def get(self, request, event_monitor_id):
     args = {}
     monitor = self.event.get_event_monitor(event_monitor_id)
     #update last update
     self.event.update_last_update(event_monitor_id)
     args["monitor"] = monitor
     date_time = DateTime()
     args['now'] = date_time.get_now()
     data = json.dumps(args)
     return HttpResponse(data,
                         content_type='application/json',
                         status=status.HTTP_200_OK)
예제 #3
0
 def service_check(self):
     pid = os.getpid()
     event_monitor = EventMonitorDAL()
     self.my_event["pid"] = int(pid)
     data = {"pid": int(pid)}
     rsp = event_monitor.put(self.my_event["id"], data)
     date_time = DateTime()
     now = date_time.get_now()
     #print str(now) + " >= " + str(self.my_event["start_date"]) + " and " + str(now) + " <= " + str(self.my_event["end_date"])
     while (now >= int(self.my_event["start_date"])
            and now <= int(self.my_event["end_date"])
            and self.my_event['active']):
         change = None
         data_expire_time = now + DATA_EXPIRE_TIME * 60
         service_check = Service(self.my_event)
         if self.my_event['service_check_id'] == 1:
             while data_expire_time > now:
                 change = service_check.check_ping()
                 time.sleep(1)
                 now = date_time.get_now()
                 """Waiting update data to server and reload data"""
                 if change:
                     time.sleep(1)
                     break
         elif self.my_event['service_check_id'] == 2:
             while data_expire_time > now:
                 change = service_check.check_source()
                 time.sleep(1)
                 now = date_time.get_now()
                 """Waiting update data to server and reload data"""
                 if change:
                     time.sleep(1)
                     break
         now = date_time.get_now()
         self.update_data()
     #Up date PID affter expire time
     json_data = {"pid": 0}
     rsp = event_monitor.put(self.my_event["id"], json_data)
     return 0
예제 #4
0
 def get(self, request, pk):
     args = {}
     event_monitor = self.get_object(pk)
     if event_monitor:
         args_event_monitor = []
         args_event_monitor.append(
             EventMonitor().parse_object_as_json_fortmat(event_monitor))
         args["detail"] = 'OK'
         args['event_monitor'] = args_event_monitor
     else:
         args["detail"] = 'Not found.'
     date_time = DateTime()
     args['now'] = date_time.get_now()
     data = json.dumps(args)
     return HttpResponse(data,
                         content_type='application/json',
                         status=status.HTTP_200_OK)
예제 #5
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)
예제 #6
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)
예제 #7
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)
예제 #8
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)
예제 #9
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)
예제 #10
0
 def update_status(self, status):
     event_monitor = EventMonitorBLL()
     date_time = DateTime()
     now = date_time.get_now()
     data = {"status": int(status), "last_update": now}
     rsp = event_monitor.put(self.my_event["id"], data)