Forum Discussion

David_Bond's avatar
11 months ago

Incident 2023-06-20 - Duplicate Azure devices

Yesterday’s Azure device duplication issue (see https://status.logicmonitor.com/) is still active (details below).

This has had far-reaching implications for a few of our (Panoramic Data Limited)’s customers, including an alert storm.

At the current time, LogicMonitor have not posted a solution for de-duplicating the Azure VMs or silencing the alerts.

We have developed a script to do so, and we are happy to help you to (carefully!) bulk delete your duplicate Azure devices.

If you would like to hold a call to remedy this on your LM portal, please contact me direct via Linked In (https://www.linkedin.com/in/davidbond/).

However…  IF you have a tame .NET dev, feed them some caffeine and instruct them as follows…


At a PowerShell prompt:

dotnet new install LogicMonitor.Cli 

dotnet new logicmonitor --name "My.AzureDeduplicator" 

code .

Edit and update appsettings.json

  • Provide account, tokenId and tokenKey
  • Set “Setting1” to the string version of the ResourceGroup ID that you want to deduplicate from
  • Modify Application.cs as follows:

    protected override async Task ExecuteAsync(CancellationToken cancellationToken)

    {

        try

        {

            // Use _logger for logging

            _logger.LogInformation("Application start.  DeviceGroupId is set to {setting1}", _config.Setting1);

            using var logicMonitorClient = new LogicMonitorClient(_config.LogicMonitorClientOptions);

            var allDevices = await logicMonitorClient

                .GetAllAsync<Device>(

                    cancellationToken

                )

                .ConfigureAwait(false);

            var deviceGroupIdString = _config.Setting1;

            var devices = allDevices

                .Where(d => d.DeviceGroupIdsString.Split(',').Any(dgs => dgs == deviceGroupIdString))

                .ToList();

            _logger.LogInformation("Found {deviceCount} devices", devices.Count);

            // Find a list of those with a similar name, but ending in #1

            var devicesToDedupe = devices

                .Where(d => d.DisplayName.EndsWith("#1") && devices.Any(d2 => d2.DisplayName == d.DisplayName.Replace("#1", "")))

                .ToList();

            foreach(var device in devicesToDedupe)

            {

                if(cancellationToken.IsCancellationRequested)

                {

                    return;

                }

                _logger.LogInformation("Deduplicate {deviceName}?", device.DisplayName);

                // Read a keypress from the user and check that it's a Y

                if(Console.ReadKey().KeyChar == 'Y')

                {

                    // Delete the duplicate

                    _logger.LogInformation("Deleting {deviceName}", device.DisplayName);

                    await logicMonitorClient

                        .DeleteAsync(device, cancellationToken)

                        .ConfigureAwait(false);

                }

                else

                {

                    _logger.LogInformation("Skipping {deviceName}", device.DisplayName);

                }

            }

        }

        finally

        {

            _lifetime.StopApplication();

        }

    }

  • READ AND UNDERSTAND THE CODE - BE SURE THAT THIS IS WHAT YOU WANT TO DO

dotnet run

This will prompt you for each device.

Usual caveats:

THE OWNER MAKES NO WARRANTIES, EXPRESS OR IMPLIED, WITH RESPECT TO THE CONFIDENTIAL INFORMATION AND HEREBY EXPRESSLY DISCLAIMS ANY AND ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.


LogicMonitor’s Status page text:

LogicMonitor is currently investigating impacts to our LM Cloud Component(s) for MS AzureSubscribe

Update - We have rolled back the component responsible for adding duplicate Azure devices. We are continuing to investigate the best approach for removing the incorrectly added duplicate devices. The next update will be around 10am PT on Wednesday June 21st.
Jun 20, 2023 - 19:37 CDT

Identified - LogicMonitor has identified an issue with our LM Cloud application that may be creating duplicate Azure devices for some customer's accounts. We are currently working towards remediating the issue with our Engineering backend team. We will provide further updates in approximately 2 hours, or if more information is uncovered.
Jun 20, 2023 - 17:32 CDT

Investigating - LogicMonitor is currently investigating technical abnormalities, which may be impacting customer accounts. We will update once we have further information on the full scope of impact.
Jun 20, 2023 - 17:27 CDT

3 Replies

  • @Mike Moniz,

    The script will:

    1. Find Resources in the ResourceGroup with the Id set in the appsettings.json.
    2. Note those with a display name ending with #1 (e.g “xxx#1”) that have a “twin” (e.g. “xxx”)
    3. Prompt the user to delete the duplicate (the one ending in “#1”)
    4. ONLY IF the user types Capital Y” on the keyboard (deliberate safety feature for people that didn’t read the code properly!) will the device be deleted.
    5. Repeat for all such devices
    6. You can stop the code with Ctrl+C.
  • Yeah, we didn’t have that problem, but we did have an issue where our idempotent device adding script incorrectly attempted to add devices that were already present. I conclude that this is related. At the beginning of the script, it pulls the current list of all devices. For all devices in our SoR, it checks if the device already exists in LM. If it not in LM yet, the script attempts to add the device to LM.

    During the timeframe in question, the script tried to add devices that were already present in LM. This means that the script thought the device was not in LM already, meaning that the device was not in the original GET request fetching all devices (which uses pagination so that’s not the issue). Without me doing anything, it started working a few hours later.

    If the Azure discovery had the same problem, it would have thought the device was not already in LM, tried to add it and failed because it already existed, so it appended #1 and added it anyway.

  • Looks like we so happen to not be affected by this issue but want to confirm. Reviewing your code I assume the duplicate devices show up in LM with “#1” appended to the name? And they would be located in the same group/folder as the original device?

    Thanks!