Pushing log from mongoDB Atlas to Azure Log Analytics workspace

Hi,

We have one M10 Atlas cluster hosted in Azure(Netherlands). I want to send any kind of log(query, database, expectation, CPU usage warning etc) to Azure Log Analytics workspace. How can I do that?

Hi @Souvik_Sardar ,

You will need to orchestrate it via the API

Etc.

Thanks
Pavel

Hi @Pavel_Duchovny,

Thank you for your response. I was trying to consume one API from C# console code, it is showing Unauthorized error.
Steps I followed:

  1. Turned on ’ Require IP Access List for Public API’ from cluster settings.
  2. Configured public & private key.
  3. Whitelisted my IP from where I am consuming the API.

C# Console code is as below, tried with Basic / Bearer / Digest authentications. Please let me know where I am doing the mistake.

    private static string APIUrl = "https://cloud.mongodb.com/api/atlas/v1.0/";
    
    public static async Task GetDataWithAuthentication()
    {
        var authCredential = Encoding.UTF8.GetBytes("myPublicKeyVal : myPrivateKeyVal");
        using (var client = new HttpClient())
        {
            client.DefaultRequestHeaders.Authorization =
                new AuthenticationHeaderValue("Digest", Convert.ToBase64String(authCredential));
				
            client.BaseAddress = new Uri(APIUrl);
            HttpResponseMessage response = await client.GetAsync(APIUrl + "groups/Project Name 1/processes");

            if (response.IsSuccessStatusCode)
            {
                var readTask = response.Content.ReadAsStringAsync().ConfigureAwait(false);
                var rawResponse = readTask.GetAwaiter().GetResult();
                Console.WriteLine(rawResponse);
            }
            Console.WriteLine("Complete");
        }
    }
	static void Main(string[] args)
    {
       var res =  GetDataWithAuthentication();
        Console.ReadKey();
    }

Hi @Souvik_Sardar ,

Can you provide full error.

Make sure you whitelisted API access and not cluster access as those differ.

Additionally please verify that the keys ard correctly provided and user has sufficient privs for the requested task.

Perhaps first try with project owner.

Also try curl first to see if its c# specific.

Thanks
Pavel

HI @Pavel_Duchovny ,

I am sure that keys are correct and IP is also whitelisted because once I run the below command by replacing PUBLIC-KEY, PRIVATE-KEY & GROUP-ID, I am getting data from the cluster as expected.
curl -i -u “{PUBLIC-KEY}:{PRIVATE-KEY}” --digest “https://cloud.mongodb.com/api/atlas/v1.0/groups/{GROUP-ID}/processes?pretty=true

I am trying with project owner only. Find the details of the error in Visual Studio below. In my code I have replaced all the keys & GROUP-ID properly.

I am sharing the RequestMessage body as well below.

I will be waiting for your response.

Hi @Souvik_Sardar ,

Well this means that the issue is specifically with your c# code.

I am honestly never tried this web method but are you sure the following line places the variable inside the string and not this exact string when encoding:

        var authCredential = Encoding.UTF8.GetBytes("myPublicKeyVal : myPrivateKeyVal");

I am afraid it uses those words as your credentials rather than the parameters.

When googling rest api digest in c# I hot different examples:

Perhaps try this?

Thanks
Pavel

Hi @Pavel_Duchovny ,

Yes issue in code only because I am not sure how I can pass the keys while invoking the API.

While posting the code content in public I changed my keys to “myPublicKeyVal : myPrivateKeyVal” but THESE ARE NOT THE ACTUAL VALUES, in my code I am using the actual public & private keys which was created in Atlas. For you I am sharing the actual keys. The link what you have given I tried that one as well yesterday but that fails with same 401(Unauthorized) error. Find the screenshot below.

Not only this, I have tried with CredentialCache as well but result is same(401). Find the methods below.

private static string DigestAuthentication1(string url, string username, string password)
    {


        Uri myUri = new Uri(url);
        WebRequest myWebRequest = HttpWebRequest.Create(myUri);

        HttpWebRequest myHttpWebRequest = (HttpWebRequest)myWebRequest;

        NetworkCredential myNetworkCredential = new NetworkCredential(username, password);

        CredentialCache myCredentialCache = new CredentialCache();
        myCredentialCache.Add(myUri, "Digest", myNetworkCredential);

        myHttpWebRequest.PreAuthenticate = true;
        myHttpWebRequest.Credentials = myCredentialCache;

        WebResponse myWebResponse = myWebRequest.GetResponse();

        Stream responseStream = myWebResponse.GetResponseStream();

        StreamReader myStreamReader = new StreamReader(responseStream, Encoding.Default);

        string pageContent = myStreamReader.ReadToEnd();

        responseStream.Close();

        myWebResponse.Close();

        return pageContent;
    }

static void Main(string args)
{

DigestAuthentication1(“https://cloud.mongodb.com/api/atlas/v1.0/groups/60812b6fb449622900b9b7b8/processes”, “pulickey”, “privateKey”);

}

Oh sure @Souvik_Sardar ,

Don’t ever share the actual values on the forum!

I suggest you change the keys immediately and post only placeholders.

Sorry if I let you think I need the private keys.

I will try to look what cause it but suggest to open a support case with atlas to followup.

Thanks
Pavel

@Pavel_Duchovny , Thank you for your suggestion. I understand not to post something with actual secret value in public forum this is why every time I was posting with placeholder but in my code I have the actual value instead of the placeholders. Anyway I have changed the actual value with placeholder now in the above replies of mine.

Raised one support request as well but if you have anything please do share with me.