2016-10-28 2 views
0

이 응용 프로그램은 기본 제공 Office 365 관리 API를 호출하여 SharePoint Online에 저장된 파일의 활동 및 이벤트를 검색합니다. 그러나 우리의 실험에 따르면, 응용 프로그램은 충분한 로그를 검색하지 못하는 것 같습니다.Office365의 관리 활동 API에서 누락 된 감사 로그 가져 오기

예제 : Sharepoint Online의 문서 라이브러리에 1000 개의 파일을 업로드합니다. 우리는 8 subscriptiona를받습니다. 구독 할 때마다 최대 100 개의 로그 만받습니다. 총 호출 API는 600 개의 로그를 가져 오기 위해 로그를 가져옵니다. 부족한!

여기 내 코드는

List<AuditLog> listAudit = new List<AuditLog>(); 
       foreach (var item in listSubscription) 
       { 
        var jsonAudit = ExecuteRequest(item.ContentUri.ToString(), HttpMethod.Get, authenticationResult); 

        if (string.IsNullOrEmpty(jsonAudit)) 
         continue; 
        var listAuditLog = Common.GetListAuditLog(jsonAudit); 
        } 

다음 각 구독 내 코드에서 감사 로그를 얻기 위해 요청을 여기에

public string ExecuteRequest(string url, HttpMethod method, AuthenticationResult token) 
    { 
     var responseStr = ""; 
     try 
     { 
      HttpClient client = new HttpClient(); 
      client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); 
      HttpRequestMessage request = new HttpRequestMessage(method, url); 
      request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", token.AccessToken); 
      HttpResponseMessage response = client.SendAsync(request).Result; 
      Log.Info("ExecuteRequest(string url, HttpMethod method, AuthenticationResult token): response.StatusCode: " + response.StatusCode + " ; response.ReasonPhrase: " + response.ReasonPhrase + " ; response.RequestMessage: " + response.RequestMessage); 


      if (response.IsSuccessStatusCode) 
      { 
       responseStr = response.Content.ReadAsStringAsync().Result; 
      } 
     } 
     catch (Exception ex) 
     { 
      Log.Error(ex); 
     } 

     return responseStr; 
    } 

내 코드를 실행하기 위해 가입 여기

List<SubscriptionsContent> GetSubscriptionsContents(AuthenticationResult authenticationResult, ManagementAPI m, DateTime startDate, DateTime endDate, bool proxyRequired = false) 
    { 
     try 
     { 
      string jsonSubscription = string.Empty; 
      string url = string.Empty; 
      string logType = "Audit.SharePoint"; 

      if (authenticationResult != null) 
      { 
       url = string.Format(UrlFormat, m.TenantId, string.Format("subscriptions/content?contentType={0}&startTime={1}&endTime={2}", logType, startDate.ToUniversalTime().ToString(DateFormat), endDate.ToUniversalTime().ToString(DateFormat))); 
       jsonSubscription = ExecuteRequest(url, HttpMethod.Get, authenticationResult); 
       //Log.Info("jsonSubscription:"); 
       //Log.Info(jsonSubscription); 
      } 
      var listContent = Common.GetListSubscriptionsContent(jsonSubscription); 
      Log.Info("Common.GetListSubscriptionsContent(jsonSubscription); Count: " + (listContent != null ? listContent.Count.ToString() : "IS NULL")); 
      return listContent; 
     } 
     catch (Exception ex) 
     { 
      Log.Error(ex); 
      return new List<SubscriptionsContent>(); 
     } 
    } 

내 코드를 얻을 수 파서 JsonString에

public static List<AuditLog> GetListAuditLog(string jsonString) 
    { 
     try 
     { 
      return JsonConvert.DeserializeObject<List<AuditLog>>(jsonString); 
     } 
     catch (Exception ex) 
     { 
      Log.Error("public static List<AuditLog> GetListAuditLog(string jsonString)", ex.InnerException); 
      return new List<AuditLog>(); 
     } 
    } 

답변

1

페이지 매김 헤더를 사용해야한다고 생각합니다.

데이터 양이 너무 큰 경우 API는 결과의 다음 페이지를 요청하는 데 사용할 주소가 포함 된 NextPageUrl이라는 헤더 항목을 반환합니다. 이 링크 (검색어를 나타내는)는 24 시간 동안 사용할 수 있습니다.

Ex.

HTTP/1.1 200 OK 
Content-Type: application/json; charset=utf-8 
NextPageUrl:https://manage.office.com/api/v1/{tenant_id}/activity/feed/subscriptions/content?contentType=Audit.SharePoint&amp;startTime=2015-10-01&amp;endTime=2015-10-02&amp;nextPage=2015101900R022885001761 

응답에이 헤더 항목이 포함되어 있으면 NextPageUrl 값을 사용하여 더 많은 데이터를 요청하십시오.

이 헤더 항목이 더 이상 존재하지 않을 때까지 프로세스를 반복하십시오.

자세한 내용은 Office 365 Management API reference

에서 찾을 수 있습니다.