55# Licensed under the MIT License. See License.txt in the project root for license information.
66# --------------------------------------------------------------------------------------------
77
8- from azure .kusto .data import KustoConnectionStringBuilder
9- from azure .kusto .data .data_format import DataFormat
10- from azure .kusto .ingest import (
11- IngestionProperties ,
12- QueuedIngestClient ,
13- ReportLevel ,
14- )
15- import csv
168import datetime
179import json
1810import logging
1911import os
20- import subprocess
21- import sys
2212
2313logger = logging .getLogger (__name__ )
2414logger .setLevel (logging .DEBUG )
2818
2919BUILD_ID = os .environ .get ('BUILD_ID' , None )
3020BUILD_BRANCH = os .environ .get ('BUILD_BRANCH' , None )
31- # authenticate with AAD application.
32- KUSTO_CLIENT_ID = os .environ .get ('KUSTO_CLIENT_ID' )
33- KUSTO_CLIENT_SECRET = os .environ .get ('KUSTO_CLIENT_SECRET' )
34- KUSTO_CLUSTER = os .environ .get ('KUSTO_CLUSTER' )
35- KUSTO_DATABASE = os .environ .get ('KUSTO_DATABASE' )
36- KUSTO_TABLE = os .environ .get ('KUSTO_TABLE' )
37- # get tenant id from https://docs.microsoft.com/en-us/onedrive/find-your-office-365-tenant-id
38- KUSTO_TENANT_ID = os .environ .get ('KUSTO_TENANT_ID' )
3921
4022
4123def generate_csv ():
@@ -53,31 +35,5 @@ def generate_csv():
5335 return data
5436
5537
56- def send_to_kusto (data ):
57- logger .info ('Start send codegen report csv data to kusto db' )
58-
59- with open (f'/tmp/codegen_report.csv' , mode = 'w' , newline = '' ) as file :
60- writer = csv .writer (file )
61- writer .writerows (data )
62-
63- kcsb = KustoConnectionStringBuilder .with_aad_application_key_authentication (KUSTO_CLUSTER , KUSTO_CLIENT_ID , KUSTO_CLIENT_SECRET , KUSTO_TENANT_ID )
64- # The authentication method will be taken from the chosen KustoConnectionStringBuilder.
65- client = QueuedIngestClient (kcsb )
66-
67- # there are a lot of useful properties, make sure to go over docs and check them out
68- ingestion_props = IngestionProperties (
69- database = KUSTO_DATABASE ,
70- table = KUSTO_TABLE ,
71- data_format = DataFormat .CSV ,
72- report_level = ReportLevel .FailuresAndSuccesses
73- )
74-
75- # ingest from file
76- result = client .ingest_from_file (f"/tmp/codegen_report.csv" , ingestion_properties = ingestion_props )
77- # Inspect the result for useful information, such as source_id and blob_url
78- print (repr (result ))
79- logger .info ('Finsh send codegen report csv data to kusto db.' )
80-
81-
8238if __name__ == '__main__' :
83- send_to_kusto ( generate_csv () )
39+ generate_csv ()
0 commit comments