0

we are not getting list shown under diagnostics settings in azure portal, with using azure rest API

i tried using azure rest API for diagnostics setting list

i want list of resources under diagnostics settings from azure portal using azure rest API.

so the attached snapshot is what we want to get

Community
  • 1
  • 1
  • Any update now? If it helps you, please accept it as answer.(click on the check mark beside the answer to toggle it from greyed out to filled in.) – Joey Cai Oct 28 '19 at 02:05

1 Answers1

0

It seems that there is no single API call to retrieve all the diagnostic settings, you could gets the active diagnostic settings list for the specified resource.

Refer to the link https://learn.microsoft.com/en-us/rest/api/monitor/diagnosticsettings/list

Update:

1.First, go to your sql server>Access control(IAM)>Add>Add Role Assignment and assign a role to your service principal.

enter image description here

2.Use the following rest api C# code to get sql database diagnostics settings info.

public static void getDiaSettings()
{
    var appId = "xxxxxxxx";
    var secretKey = "xxxxxxxx";
    var tenantId = "xxxxxxxx";
    var context = new AuthenticationContext("https://login.windows.net/" + tenantId);
    ClientCredential clientCredential = new ClientCredential(appId, secretKey);
    var tokenResponse = context.AcquireTokenAsync("https://management.azure.com/", clientCredential).Result;
    var accessToken = tokenResponse.AccessToken;
    using (var client = new HttpClient())
    {
        client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken);
        var baseUrl = new Uri($"https://management.azure.com/");
        var request2=  baseUrl +
                     @"/subscriptions/xxxxxxxx/resourceGroups/yourResourceGroup/providers/Microsoft.Sql/servers/yourSqlServer/databases/yourSqlDatabase/providers/microsoft.insights/diagnosticSettings?api-version=2017-05-01-preview";
        var response = client.GetAsync(request2).Result.Content.ReadAsStringAsync().Result;
    }
}
Joey Cai
  • 18,968
  • 1
  • 20
  • 30
  • Thanks for your reply joey, already we have gone through above Mention API. but the parameters that are needed for this API are workflow name, we have passed subscriptionId, ResourceGroupname but we dont have any workflows created... how can we pass the specified resource (not resourceGroup) as parameter to this API. is there any way you can suggest.. any help will be appreciated. – prashant k Oct 21 '19 at 07:10
  • Go to the resource, here for example logic app: logic app>Properties>Resource ID. Get the resource ID and use as resourceUri then you could get logic app diagnostic settings. – Joey Cai Oct 21 '19 at 07:13
  • If it helps you, please accept it as answer.(click on the check mark beside the answer to toggle it from greyed out to filled in.) – Joey Cai Oct 21 '19 at 07:14
  • there are currently two resources shown under diagnostics settings.which are sql server and sql database, but there are no resourceId for both of them. can you please explain how can i get list of resources under diagnostics settings ? – prashant k Oct 21 '19 at 08:55
  • As I have mentioned, it seems that there is no signal Api to get list of resources under it, you could only get the list for specified resource. – Joey Cai Oct 21 '19 at 08:57
  • And the sql server do not have diagnostics settings. – Joey Cai Oct 21 '19 at 08:59
  • alright, can you please provide me the example API which i can use for getting list for specified resource. i need this to get working .. i m stuck at this – prashant k Oct 21 '19 at 09:59