Import Azure Monitor log data into Azure Data Factory - azure-data-factory

Is it possible to connect Azure Data Factory to the Azure Monitor logs to extract the data?
You can connect from Power BI as described here:
https://learn.microsoft.com/en-us/azure/azure-monitor/platform/powerbi
But I want to be able to connect from Data Factory to the log.

Per my knowledge,there is no direct way which is similar to the PB way in the link you mentioned in your question in the ADF. Based on this document and ADF portal UI, we could store the log in three residences:
Azure Storage Account.
Event Hub.
Log Analytics.
For storage account ,you could access them in copy activity.
For Event hub, maybe you could use Event Hub REST API in REST dataset and ADF Web Activity or you could get an idea of Azure Stream Analytics.
For Log Analytics, you could use Log Analytics REST API in REST dataset and ADF Web Activity:
POST https://api.loganalytics.io/v1/workspaces/DEMO_WORKSPACE/query
X-Api-Key: DEMO_KEY
Content-Type: application/json
{
"query": "AzureActivity | summarize count() by Category"
}

Got is all working. I have done the following:
Create a Pipeline which contains 2 Web Activities, 1 For Each Loop & Call to stored procedure to insert the data
First Web Activity gets the bearer token
Second Web Activity calls the REST API GET and has a Header name Authorization which brings in the access_token for the first web activity Bearer {access_token}
Then A For Each Loop which I pass the output for the second Web Activity
Stored procedure Activity which passes in all my fields into an insert stored procedure
Finally that all worked. I had a lot of trouble using the Copy Activity so resorted to the For Each Loop and stored procedure call to insert each record from the output of the REST API call in the web activity.
I will post more detailed info once I get some sleep!

Partial Answer:
I have been able to use 2 Web Activities in a pipeline. 1 which gets the bearer token and 2 which then uses the bearer token to carry out the GET command. BUT now the question is how can I use the Output from the Web Activity in a subsequent Copy Activity so I can load the data into SQL ????

There are two methods witch depend on the method of authentication to the API.
The first is with a service principle, High level steps described above. This Blog on the topic is also useful: https://datasavvy.me/2020/12/24/retrieving-log-analytics-data-with-data-factory/comment-page-1/#comment-28467
Second is with Managed Identity:
first give ADF access to Log Analytics using IAM How can I use this API in Azure Data Factory
Then connect to Log Analytic API with Web activity or a copy activity (these are the two i got working).
Web Activity
URL: https://api.loganalytics.io/v1/workspaces/[Workspace ID]/query
Body: {"query":"search '*'| where TimeGenerated >= datetime(#{pipeline().parameters.it_startDate}) and TimeGenerated < datetime(#{pipeline().parameters.it_endDate}) | distinct $table "}
Copy Activity
First the linked service.
ADF Datasets:
Base URL: URL: https://api.loganalytics.io/v1/workspaces/[Workspace ID]/
Copy Source:
Body: {
"query": "#{item()[0]} | where TimeGenerated >= datetime(#{pipeline().parameters.it_startDate}) and TimeGenerated < datetime(#{pipeline().parameters.it_endDate})"
}
Additional:
The body code above, gets a list of the table names in log analytics using the web activity. Which I then pass to the Copy Activity to exports copy of the data for each table.

Related

Logic Apps trigger Databricks notebook

I have an issue. Is that possible for Logic Apps to trigger Databricks notebook in its pipeline?
I want to automate processing of downloaded files from Sharepoint and trigger notebook of Databricks.
Starting to build the custom logicapp connector but struggling according to this guide: https://medium.com/#poojaanilshinde/create-azure-logic-apps-custom-connector-for-azure-databricks-e51f4524ab27
Unfortunately struggling to create json Openapi file (image below)
1.Created a Databricks resource in Azure.
Created a Logic Apps Custom Connector resource with name Databricksconnector.
Once created clicked on edit option as shown below,
Followed the document https://medium.com/#poojaanilshinde/create-azure-logic-apps-custom-connector-for-azure-databricks-e51f4524ab27
by # Pooja Shinde
and performed below steps.
Connector creation I have kept all with default values in this section.
In General Information, selected scheme as Https and in host give data bricks url as https://databricksinstancename.azuredatabricks.net
In Security, selected authentication as basic as shown below,
In Definition tab, added new action by clicking on New action
In General tab, provided Summary, Description, Operation ID and Visibility selected as none.
In Request tab, Clicked on Import from sample.
I am retrieving job details by passing job_id and details are,
Request Type: Get
Url: api/2.0/jobs/get?job_id=*******
Headers: Content-Type: application/ json
12.Click on import and request will be update as below,
Next click on Update connector and connector will be saved.
Connector saved successfully as shown below,
We can view all the provided details in json format by clicking on swagger editor,
Now created a logic app with recurrence trigger.
Able to see created custom connector as shown below,
Created connection for Azure data bricks as per the document https://medium.com/#poojaanilshinde/create-azure-logic-apps-custom-connector-for-azure-databricks-e51f4524ab27
Added parameter “job_id” and given value as shown below,
20. logic app ran successfully and able to get job details,
Reference: https://learn.microsoft.com/en-us/azure/databricks/dev-tools/api/2.0/jobs?source=recommendations#--runs-list

Fetch the data from Power BI related to username/emailId by whom Azure Pipeline was ran

"https://analytics.dev.azure.com/{organization}/{project}/_odata/v3.0-preview/PipelineRuns?"
Using this url I am able to fetch RunNumber, RunReason but unable to fetch RunBy which user.
You could get the user that requested the run using predefined variables.
$(Build.RequestedFor)
And additionally you can also use
echo $(Build.RequestedForEmail)
echo $(Build.RequestedForId)
https://learn.microsoft.com/en-us/azure/devops/pipelines/build/variables?view=azure-devops&tabs=yaml#identity_values
There are some predefined variable for RunReason and BuildID as well.
$(Build.Reason)
$(Build.BuildId)
According to your description, I tried to get the odata feed "https://analytics.dev.azure.com/{organization}/{project}/_odata/v3.0-preview/PipelineRuns" in Power BI, currently there is no option to fetch who trigger the pipeline. And check the REST API is also without this.
You could use "Request a feature" on the left side of Developer Community to open a new suggestion ticket.
For more information about who trigger the pipeline, you could refer to this.

Azure data factory pagination doesn't work

I am working on a pipeline which executes oAuth2 flow in order to access REST API json data. Once I have the bearer token I am executing a request which returns the following structure:
As you can see, since the response is quite large, there's paging enabled and as part of the response I get a link to the next page. In order to get to that resource I need to also present MS-ContinuationToken in the headers. So, this is how I basically do it in the config of the Copy activity that I use to get the data from the REST endpoint:
and the issue here is that I only get the first 2000 rows and the next page(s) don't seem to be visited at all. Pipeline executes successfully and only the first 2000 items are fetched.
NOTE: continuationToken and links.next.headers.value have the exact same values from the initial response.
Even if you fix the other issue you’ll have an issue with the “next” URL not including “v1”. This is a known issue in the partner center api team. I’ve escalated it pretty high. But they don’t want to break backwards compatibility by changing the “next” URI to include the v1 or to be relative. They are considering other options but I wouldn’t hold your breath.
I would ditch the idea of using data factory and instead write a .NET console app using the partner center SDK
(You might think to paginate manually with loops etc but the Copy activity doesn’t return eg the http headers, so you will need a complex set up to somehow store the data in a data store and be able to look up the last page in order to get the continuation token. I couldn’t figure it out)

How to use Web activity in Azure Data Factory to count the total number of pages in source data?

I am doing REST API call to get source data which is JSON and file size is around 1GB. I would like to use pagination concept. I see in this link https://learn.microsoft.com/en-us/answers/questions/59467/how-to-pass-pagination-rules-during-a-rest-api-cal.html?childToView=256118#answer-256118 where it uses Web activity to get the total page. But how? any advise!
My sink is COSMOS DB
According to your link, I think we only can make a web call to find out the total pages. In other words, the total pages is from your REST API. Then we can use an Array type variable to store the response.

Autocomplete testing on Azure Search explorer

I am trying to build and test the auto complete feature on a master item lookup tables using Azure Search (for a ASP MVC application). The search index was done with the suggesterName SG set to ItemDisplayName
I was looking to test it first on Azure portal- so that I could aim to replicate the results via code. This is because the results I am getting in code are quite unexpected
As I type the substring the itemDislayName, the expectation was that upto 5 selected names will be displayed
On the portal, I tried a query string of
search=str&suggesterName=SG
with the base request URL containing the index, api version and sugestorName-but I don't get results of items containing 'str' and with the fuzziness as below
Could you please guide around
[1] how I can get suggestor output in azure portal-search explorer
[2] can I control fuzziness using queryType and ~1,~2
I was referring to these 3 links
1) https://learn.microsoft.com/en-us/rest/api/searchservice/suggestions
and
2) https://channel9.msdn.com/Shows/Azure-Friday/Azure-Search-103-Azure-Search-Suggestions-with-Liam-Cavanagh
3) gunnarpeipman.com/2016/07/azure-search-suggesters/
Azure Search Portal doesn't support the Suggestion API yet. You will need to use an HTTP client like Fiddler or Postman.
Make sure you use the right URL for you Suggest requests:
https://[service name].search.windows.net/indexes/[index name]/docs/suggest
Please use our User Voice page to vote for adding the Suggest API to the Portal: https://feedback.azure.com/forums/263029-azure-search