55 "fmt"
66 "net/http"
77 "net/url"
8+ "strings"
89
9- "github.com/threatwinds/logger"
1010 "github.com/utmstack/UTMStack/office365/configuration"
1111 "github.com/utmstack/UTMStack/office365/utils"
1212 "github.com/utmstack/config-client-go/types"
@@ -43,7 +43,7 @@ func GetOfficeProcessor(group types.ModuleGroup) OfficeProcessor {
4343 return offProc
4444}
4545
46- func (o * OfficeProcessor ) GetAuth () * logger. Error {
46+ func (o * OfficeProcessor ) GetAuth () error {
4747 requestUrl := configuration .GetMicrosoftLoginLink (o .TenantId )
4848
4949 data := url.Values {}
@@ -68,7 +68,7 @@ func (o *OfficeProcessor) GetAuth() *logger.Error {
6868 return nil
6969}
7070
71- func (o * OfficeProcessor ) StartSubscriptions () * logger. Error {
71+ func (o * OfficeProcessor ) StartSubscriptions () error {
7272 for _ , subscription := range o .Subscriptions {
7373 utils .Logger .Info ("starting subscription: %s..." , subscription )
7474 url := configuration .GetStartSubscriptionLink (o .TenantId ) + "?contentType=" + subscription
@@ -79,15 +79,16 @@ func (o *OfficeProcessor) StartSubscriptions() *logger.Error {
7979
8080 resp , status , e := utils .DoReq [StartSubscriptionResponse ](url , []byte ("{}" ), http .MethodPost , headers )
8181 if e != nil || status != http .StatusOK {
82- if e .Is ("subscription is already enabled" ) {
83- continue
82+ if strings .Contains (e .Error (), "subscription is already enabled" ) {
83+ // utils.Logger.Info("subscription is already enabled") // Debug
84+ return nil
8485 }
8586 return e
8687 }
8788
8889 respJson , err := json .Marshal (resp )
8990 if err != nil || status != http .StatusOK {
90- return utils . Logger . ErrorF ("failed to unmarshal response: %v" , err )
91+ return fmt . Errorf ("failed to unmarshal response: %v" , err )
9192 }
9293
9394 utils .Logger .Info ("starting subscription response: %v" , respJson )
@@ -96,7 +97,7 @@ func (o *OfficeProcessor) StartSubscriptions() *logger.Error {
9697 return nil
9798}
9899
99- func (o * OfficeProcessor ) GetContentList (subscription string , startTime string , endTime string , group types.ModuleGroup ) ([]ContentList , * logger. Error ) {
100+ func (o * OfficeProcessor ) GetContentList (subscription string , startTime string , endTime string , group types.ModuleGroup ) ([]ContentList , error ) {
100101 url := configuration .GetContentLink (o .TenantId ) + fmt .Sprintf ("?startTime=%s&endTime=%s&contentType=%s" , startTime , endTime , subscription )
101102
102103 headers := map [string ]string {
@@ -105,15 +106,15 @@ func (o *OfficeProcessor) GetContentList(subscription string, startTime string,
105106 }
106107
107108 respBody , status , err := utils .DoReq [[]ContentList ](url , nil , http .MethodGet , headers )
108- if err != nil && status != http .StatusOK {
109+ if err != nil || status != http .StatusOK {
109110 return []ContentList {}, err
110111 }
111112
112113 return respBody , nil
113114
114115}
115116
116- func (o * OfficeProcessor ) GetContentDetails (url string ) (ContentDetailsResponse , * logger. Error ) {
117+ func (o * OfficeProcessor ) GetContentDetails (url string ) (ContentDetailsResponse , error ) {
117118 headers := map [string ]string {
118119 "Content-Type" : "application/json" ,
119120 "Authorization" : fmt .Sprintf ("%s %s" , o .Credentials .TokenType , o .Credentials .AccessToken ),
@@ -131,20 +132,23 @@ func (o *OfficeProcessor) GetLogs(startTime string, endTime string, group types.
131132 for _ , subscription := range o .Subscriptions {
132133 contentList , err := o .GetContentList (subscription , startTime , endTime , group )
133134 if err != nil {
135+ utils .Logger .ErrorF ("error getting content list: %v" , err ) // Debug
134136 continue
135137 }
136138 logsCounter := 0
137139 if len (contentList ) > 0 {
138140 for _ , log := range contentList {
139141 details , err := o .GetContentDetails (log .ContentUri )
140142 if err != nil {
143+ utils .Logger .ErrorF ("error getting content details: %v" , err ) // Debug
141144 continue
142145 }
143146 if len (details ) > 0 {
144147 logsCounter += len (details )
145148 cleanLogs := ETLProcess (details , group )
146149 err = SendToCorrelation (cleanLogs )
147150 if err != nil {
151+ utils .Logger .ErrorF ("error sending logs to correlation: %v" , err ) // Debug
148152 continue
149153 }
150154 }
0 commit comments