1import { DataSourceInstanceSettings, DataSourceJsonData, DataSourceSettings, TableData } from '@grafana/data';
2import Datasource from '../datasource';
3
4import { AzureMonitorQuery } from './query';
5
6export type AzureDataSourceSettings = DataSourceSettings<AzureDataSourceJsonData, AzureDataSourceSecureJsonData>;
7export type AzureDataSourceInstanceSettings = DataSourceInstanceSettings<AzureDataSourceJsonData>;
8
9export interface DatasourceValidationResult {
10  status: 'success' | 'error';
11  message: string;
12  title?: string;
13}
14
15/**
16 * Azure clouds known to Azure Monitor.
17 */
18export enum AzureCloud {
19  Public = 'AzureCloud',
20  China = 'AzureChinaCloud',
21  USGovernment = 'AzureUSGovernment',
22  Germany = 'AzureGermanCloud',
23  None = '',
24}
25
26export type AzureAuthType = 'msi' | 'clientsecret';
27
28export type ConcealedSecret = symbol;
29
30interface AzureCredentialsBase {
31  authType: AzureAuthType;
32  defaultSubscriptionId?: string;
33}
34
35export interface AzureManagedIdentityCredentials extends AzureCredentialsBase {
36  authType: 'msi';
37}
38
39export interface AzureClientSecretCredentials extends AzureCredentialsBase {
40  authType: 'clientsecret';
41  azureCloud?: string;
42  tenantId?: string;
43  clientId?: string;
44  clientSecret?: string | ConcealedSecret;
45}
46
47export type AzureCredentials = AzureManagedIdentityCredentials | AzureClientSecretCredentials;
48
49export interface AzureDataSourceJsonData extends DataSourceJsonData {
50  cloudName: string;
51  azureAuthType?: AzureAuthType;
52
53  // monitor
54  tenantId?: string;
55  clientId?: string;
56  subscriptionId?: string;
57
58  // logs
59  /** @deprecated Azure Logs credentials */
60  azureLogAnalyticsSameAs?: boolean;
61  /** @deprecated Azure Logs credentials */
62  logAnalyticsTenantId?: string;
63  /** @deprecated Azure Logs credentials */
64  logAnalyticsClientId?: string;
65  /** @deprecated Azure Logs credentials */
66  logAnalyticsSubscriptionId?: string;
67  /** @deprecated Azure Logs credentials */
68  logAnalyticsDefaultWorkspace?: string;
69
70  // App Insights
71  appInsightsAppId?: string;
72}
73
74export interface AzureDataSourceSecureJsonData {
75  clientSecret?: string;
76  appInsightsApiKey?: string;
77}
78
79// Represents an errors that come back from frontend requests.
80// Not totally sure how accurate this type is.
81export type AzureMonitorErrorish = Error;
82
83// Azure Monitor API Types
84export interface AzureMonitorMetricsMetadataResponse {
85  value: AzureMonitorMetricMetadataItem[];
86}
87
88export interface AzureMonitorMetricMetadataItem {
89  id: string;
90  resourceId: string;
91  primaryAggregationType: string;
92  supportedAggregationTypes: string[];
93  name: AzureMonitorLocalizedValue;
94  dimensions?: AzureMonitorLocalizedValue[];
95  metricAvailabilities?: AzureMonitorMetricAvailabilityMetadata[];
96}
97
98export interface AzureMonitorMetricAvailabilityMetadata {
99  timeGrain: string;
100  retention: string;
101}
102
103export interface AzureMonitorLocalizedValue {
104  value: string;
105  localizedValue: string;
106}
107
108export interface AzureMonitorMetricDefinitionsResponse {
109  data: {
110    value: Array<{ name: string; type: string; location?: string }>;
111  };
112  status: number;
113  statusText: string;
114}
115
116export interface AzureMonitorResourceGroupsResponse {
117  data: {
118    value: Array<{ name: string }>;
119  };
120  status: number;
121  statusText: string;
122}
123
124export interface AzureLogsVariable {
125  text: string;
126  value: string;
127}
128
129export interface AzureLogsTableData extends TableData {
130  columns: AzureLogsTableColumn[];
131  rows: any[];
132  type: string;
133}
134
135export interface AzureLogsTableColumn {
136  text: string;
137  type: string;
138}
139
140export interface AzureMonitorOption<T = string> {
141  label: string;
142  value: T;
143  options?: AzureMonitorOption[];
144}
145
146export interface AzureQueryEditorFieldProps {
147  query: AzureMonitorQuery;
148  datasource: Datasource;
149  subscriptionId?: string;
150  variableOptionGroup: { label: string; options: AzureMonitorOption[] };
151
152  onQueryChange: (newQuery: AzureMonitorQuery) => void;
153  setError: (source: string, error: AzureMonitorErrorish | undefined) => void;
154}
155
156export interface AzureResourceSummaryItem {
157  subscriptionName: string;
158  resourceGroupName: string | undefined;
159  resourceName: string | undefined;
160}
161
162export interface RawAzureResourceGroupItem {
163  subscriptionURI: string;
164  subscriptionName: string;
165
166  resourceGroupURI: string;
167  resourceGroupName: string;
168}
169
170export interface RawAzureResourceItem {
171  id: string;
172  name: string;
173  subscriptionId: string;
174  resourceGroup: string;
175  type: string;
176  location: string;
177}
178
179export interface AzureGraphResponse<T = unknown> {
180  data: T;
181  // skipToken is used for pagination, to get the next page
182  $skipToken?: string;
183}
184
185// https://docs.microsoft.com/en-us/rest/api/azureresourcegraph/resourcegraph(2021-03-01)/resources/resources#queryrequestoptions
186export interface AzureResourceGraphOptions {
187  $skip: number;
188  $skipToken: string;
189  $top: number;
190  allowPartialScopes: boolean;
191  resultFormat: 'objectArray' | 'table';
192}
193