@@ -4,10 +4,10 @@ import (
4
4
"context"
5
5
"time"
6
6
7
+ "github.com/Azure/azure-sdk-for-go/sdk/monitor/azquery"
7
8
armoperationalinsights "github.com/Azure/azure-sdk-for-go/sdk/resourcemanager/operationalinsights/armoperationalinsights/v2"
8
9
log "github.com/sirupsen/logrus"
9
10
azureCommon "github.com/webdevops/go-common/azuresdk/armclient"
10
- "github.com/webdevops/go-common/azuresdk/loganalytics"
11
11
prometheusCommon "github.com/webdevops/go-common/prometheus"
12
12
"github.com/webdevops/go-common/utils/to"
13
13
@@ -80,48 +80,53 @@ func (auditor *AzureAuditor) queryLogAnalytics(ctx context.Context, logger *log.
80
80
workspaceLogger .Panic (err )
81
81
}
82
82
83
- workspaces := []string {}
84
-
83
+ var workspaces []* string
85
84
if config .AdditionalWorkspaces != nil {
86
85
for _ , additionalWorkspaceResourceId := range * config .AdditionalWorkspaces {
87
86
additionalWorkspaceId , err := auditor .lookupWorkspaceResource (ctx , additionalWorkspaceResourceId )
88
87
if err != nil {
89
88
workspaceLogger .Panic (err )
90
89
}
91
90
92
- workspaces = append (workspaces , to . String ( additionalWorkspaceId ) )
91
+ workspaces = append (workspaces , additionalWorkspaceId )
93
92
}
94
93
}
95
94
96
95
workspaceLogger .WithField ("workspaces" , workspaces ).Debug ("sending query" )
97
96
startTime := time .Now ()
98
97
99
- queryResults , err := loganalytics .ExecuteQuery (
100
- ctx ,
101
- auditor .azure .client ,
102
- * mainWorkspaceId ,
103
- * config .Query ,
104
- config .Timespan ,
105
- & workspaces ,
106
- )
98
+ clientOpts := azquery.LogsClientOptions {* auditor .azure .client .NewAzCoreClientOptions ()}
99
+ logsClient , err := azquery .NewLogsClient (auditor .azure .client .GetCred (), & clientOpts )
100
+ if err != nil {
101
+ workspaceLogger .Error (err )
102
+ return
103
+ }
104
+
105
+ opts := azquery.LogsClientQueryWorkspaceOptions {}
106
+ queryBody := azquery.Body {
107
+ Query : config .Query ,
108
+ Timespan : config .Timespan ,
109
+ Workspaces : workspaces ,
110
+ }
111
+ queryResults , err := logsClient .QueryWorkspace (ctx , * mainWorkspaceId , queryBody , & opts )
107
112
if err != nil {
108
113
workspaceLogger .Error (err )
109
114
return
110
115
}
111
116
112
117
// parse and process result
113
- resultTables := * queryResults .Tables
118
+ resultTables := queryResults .Tables
114
119
for _ , table := range resultTables {
115
120
if table .Rows == nil || table .Columns == nil {
116
121
// no results found, skip table
117
122
continue
118
123
}
119
124
120
- for _ , v := range * table .Rows {
125
+ for _ , v := range table .Rows {
121
126
auditLine := map [string ]interface {}{}
122
127
auditLine ["resource.id" ] = mainWorkspaceResourceId
123
128
auditLine ["subscription.id" ] = mainWorkspaceInfo .Subscription
124
- for colNum , colName := range * resultTables [0 ].Columns {
129
+ for colNum , colName := range resultTables [0 ].Columns {
125
130
fieldName := to .String (colName .Name )
126
131
fieldValue := v [colNum ]
127
132
0 commit comments