private bool CreateWorkspace(LogAnalyticsWorkspaceModel workspaceModel = null)
        {
            Log.Info("enter");
            bool response = false;

            // create workspaceModel
            Log.Info($"creating workspaceModel {_config.LogAnalyticsWorkspaceName}");

            if (_config.LogAnalyticsCreate)
            {
                _arm.CreateResourceGroup($"/subscriptions/{_config.AzureSubscriptionId}/resourcegroups/{_config.AzureResourceGroup}", _config.AzureResourceGroupLocation);
            }

            string resourceId = $"/subscriptions/{_config.AzureSubscriptionId}/resourcegroups/{_config.AzureResourceGroup}/providers/Microsoft.OperationalInsights/workspaces/{_config.LogAnalyticsWorkspaceName}";

            if (workspaceModel == null)
            {
                Log.Info("creating default workspaceModel");
                workspaceModel = new LogAnalyticsWorkspaceModel()
                {
                    location   = _config.AzureResourceGroupLocation,
                    properties = new LogAnalyticsWorkspaceModel.Properties()
                    {
                        retentionInDays = _config.LogAnalyticsWorkspaceSku.ToLower() == "free" ? 7 : 30,
                        source          = "Azure",
                        sku             = new LogAnalyticsWorkspaceModel.Properties.Sku()
                        {
                            name = _config.LogAnalyticsWorkspaceSku
                        }
                    }
                };
            }

            Http http = _arm.ProvisionResource(resourceId, JsonConvert.SerializeObject(workspaceModel), _logAnalyticsApiVer);

            if (!http.Success)
            {
                return(false);
            }

            response = GetCurrentWorkspace(JsonConvert.DeserializeObject <LogAnalyticsWorkspaceRecordResult>(http.ResponseStreamString).properties.customerId);

            // set new key
            _config.LogAnalyticsKey = GetWorkspacePrimaryKey();
            return(response);
        }
        private bool GetCurrentWorkspace(string workspaceId = null)
        {
            Log.Info("enter");
            string url  = $"{Constants.ManagementAzureCom}/subscriptions/{_config.AzureSubscriptionId}/providers/Microsoft.OperationalInsights/workspaces?{_logAnalyticsApiVer}";
            Http   http = _arm.SendRequest(url);

            workspaceId = workspaceId ?? _config.LogAnalyticsId;

            LogAnalyticsWorkspaceRecordResult[] workspaces = (JsonConvert.DeserializeObject <LogAnalyticsWorkspaceRecordResults>(http.ResponseStreamString)).value.ToArray();
            CurrentWorkspace = workspaces.FirstOrDefault(x => x.properties.customerId == workspaceId);

            Log.Info("current workspaceModel:", ConsoleColor.Green, null, CurrentWorkspace);
            if (CurrentWorkspace != null)
            {
                _config.AzureResourceGroupLocation = _config.AzureResourceGroupLocation ?? CurrentWorkspace.location;
                _config.LogAnalyticsWorkspaceName  = _config.LogAnalyticsWorkspaceName ?? CurrentWorkspace.name;
                _config.LogAnalyticsId             = CurrentWorkspace.properties.customerId;
                _currentWorkspaceModelModel        = GetCurrentWorkspaceModel();
            }

            return(http.Success & CurrentWorkspace != null);
        }
        private LogAnalyticsWorkspaceModel GetCurrentWorkspaceModel()
        {
            LogAnalyticsWorkspaceModel currentWorkspaceModel = new LogAnalyticsWorkspaceModel();

            if (ParseWorkspaceResourceId(CurrentWorkspace.id))
            {
                currentWorkspaceModel.location   = CurrentWorkspace.location;
                currentWorkspaceModel.properties = new LogAnalyticsWorkspaceModel.Properties()
                {
                    retentionInDays = CurrentWorkspace.properties.retentionInDays,
                    sku             = new LogAnalyticsWorkspaceModel.Properties.Sku()
                    {
                        name = CurrentWorkspace.properties.sku.name
                    }
                };
            }
            else
            {
                Log.Error("unable to get current workspaceModel model");
            }

            return(currentWorkspaceModel);
        }