예제 #1
0
 def create(self, request):
     """
     Receives one or more notifications and saves them to the database.
     This method is a part of private API.
     
     Method: POST
     URL: /api/event/report/
     
     Case 1: Reporting single event (notification)
     ---------------------------------------------
     
     Request parameters:
         * description - message describing the event
         * short_description - shorter message, e.g. to use in list
         * timestamp - when the event occurred
         * event_type - type of the event which should also describe
           its importance
         * protocol - network protocol related to the event
         * hostname - name of the source host
         * source_host_ipv4, source_host_ipv6 - IPv4 and IPv6
           addresses of the source host
         * fields_class - monitoring module identifier
     
     Any additional data provided with the event will be serialized and
     saved together with fields described above.
           
     Response:
         * status - **ok** or **error**
         * message - details of the result
         
     Case 2: Reporting multiple events at once
     -----------------------------------------
     
     Request parameters:
         * events - list of events serialized with JSON
         
     Response:
         * status - **ok** or **error**
         * message - details of the result
     
     """
     if request.POST.get('events'):
         try:
             events = json.loads(request.POST.get('events', ''))
         except ValueError:
             return api_error(_('No events could be read'))
         
         for event_dict in events:
             try:
                 event_data = get_event_data(request, event_dict)
             except EventParseError, e:
                 message = str(e)
                 return api_error(_(message))
             event = Event(**event_data)
             event.save()
             
             if event.event_type.notify:
                 notifier.manager.add(event.short_message, event.message,
                                      event.user(), event)
         
         return api_ok(_('Events reported successfully'))
예제 #2
0
    def create(self, request):
        """
        Receives one or more notifications and saves them to the database.
        This method is a part of private API.
        
        Method: POST
        URL: /api/event/report/
        
        Case 1: Reporting single event (notification)
        ---------------------------------------------
        
        Request parameters:
            * description - message describing the event
            * short_description - shorter message, e.g. to use in list
            * timestamp - when the event occurred
            * event_type - type of the event which should also describe
              its importance
            * protocol - network protocol related to the event
            * hostname - name of the source host
            * source_host_ipv4, source_host_ipv6 - IPv4 and IPv6
              addresses of the source host
            * fields_class - monitoring module identifier
        
        Any additional data provided with the event will be serialized and
        saved together with fields described above.
              
        Response:
            * status - **ok** or **error**
            * message - details of the result
            
        Case 2: Reporting multiple events at once
        -----------------------------------------
        
        Request parameters:
            * events - list of events serialized with JSON
            
        Response:
            * status - **ok** or **error**
            * message - details of the result
        
        """
        if request.POST.get('events'):
            try:
                events = json.loads(request.POST.get('events', ''))
            except ValueError:
                return api_error(_('No events could be read'))

            for event_dict in events:
                try:
                    event_data = get_event_data(request, event_dict)
                except EventParseError, e:
                    message = str(e)
                    return api_error(_(message))
                event = Event(**event_data)
                event.save()

                if event.event_type.notify:
                    notifier.manager.add(event.short_message, event.message,
                                         event.user(), event)

            return api_ok(_('Events reported successfully'))
예제 #3
0
         
         return api_ok(_('Events reported successfully'))
     
     try:
         event_data = get_event_data(request, request.POST)
     except EventParseError, e:
         message = str(e)
         return api_error(_(message))
     event = Event(**event_data)
     event.save()
     
     if event.event_type.notify:
         notifier.manager.add(event.short_message, event.message,
                              event.user(), event)
     
     return api_ok(_('Event reported successfully'))
 
 def read(self, request, event_id=None):
     """
     The part of the public API. If the event_id parameter is specified,
     returns event details, otherwise returns events list ordered by timestamp.
     In the second case, events may be filtered by source host or
     timestamp and their number may be limited. 
     
     Method: GET
     
     Request parameters:
         * source_host - identifier of a source host
         * time_from - include only those events which timestamp is greater
           or equal than this value
         * time_to - include only those events which timestamp if less than
예제 #4
0
            return api_ok(_('Events reported successfully'))

        try:
            event_data = get_event_data(request, request.POST)
        except EventParseError, e:
            message = str(e)
            return api_error(_(message))
        event = Event(**event_data)
        event.save()

        if event.event_type.notify:
            notifier.manager.add(event.short_message, event.message,
                                 event.user(), event)

        return api_ok(_('Event reported successfully'))

    def read(self, request, event_id=None):
        """
        The part of the public API. If the event_id parameter is specified,
        returns event details, otherwise returns events list ordered by timestamp.
        In the second case, events may be filtered by source host or
        timestamp and their number may be limited. 
        
        Method: GET
        
        Request parameters:
            * source_host - identifier of a source host
            * time_from - include only those events which timestamp is greater
              or equal than this value
            * time_to - include only those events which timestamp if less than