Beispiel #1
0
 private void CallInternalCommon()
 {
     try
     {
         if (GlobalInfo.NodeId == Guid.Empty)
         {
             GlobalInfo.NodeId = new Guid(SALsA.GetInstance(Id).ICM.GetCustomField(Constants.AnalyzerNodeIdField));
         }
         var startTime = SALsA.GetInstance(Id).ICM.ICMImpactStartTime().AddHours(-12);
         var endTime   = new DateTime(Math.Min(startTime.AddHours(+24).Ticks, DateTime.UtcNow.Ticks));
         GetAllNodeDiagnosticsFiles(GlobalInfo.Fabric, GlobalInfo.NodeId.ToString(), startTime.ToString("s"), endTime.ToString("s"));
     }
     catch (Exception ex)
     {
         Log.Critical("Failed to use GetAllNodeDiagnosticsFiles with exception : {0}", ex);
         Log.Exception(ex);
     }
     if (GlobalInfo.ContainerID != Guid.Empty)
     {
         ExecuteKustoContainerEnrichment(Id, GlobalInfo.ContainerID.ToString());
     }
     if (GlobalInfo.ContainerID == GlobalInfo.NodeId) // If they are equal, it means Guid.Empty
     {
         SALsA.GetInstance(Id).State = SALsAState.MissingInfo;
     }
     SALsA.GetInstance(Id)?.ICM.QueueICMDiscussion(GlobalInfo.ToString());
 }
Beispiel #2
0
            private async Task RunOperationManualPollAsync(int icm)
            {
                try
                {
                    ExecuteOperationResponse operationRunning = await client.Operations.RunOperationAsync(operationRequest);

                    while (true)
                    {
                        OperationResult status = await client.Operations.GetOperationStatusAsync(operationRunning.Id);

                        if (status.Status.IsStateComplete())
                        {
                            // Operation reached a final state, get the result.
                            operationResult = await client.Operations.GetOperationResultsAsync(operationRunning.Id);

                            Log.Verbose("Operation has completed execution for {0}: {1}. Operation Result is:{2}{3}", extensionName, operationName, System.Environment.NewLine, operationResult.ResultMessage);
                            // We upload all results of all operations
                            SALsA.GetInstance(icm)?.TaskManager.AddTask(
                                BlobStorage.UploadText(icm, String.Format("action/{1}-{0}_{2}.txt", extensionName, operationName, Log.UID),
                                                       operationResult.ResultMessage));
                            return;
                        }
                        // Warning: Setting too short a delay could result in requests being throttled
                        Log.Verbose("Operation <{0}: {1}> is still in process, polling status again in 5 seconds", extensionName, operationName);
                        await Task.Delay(5000);
                    }
                }

                catch (Exception ex)
                {
                    Log.Error("Operation <{0}: {1}> execution failed.", extensionName, operationName);
                    Log.Exception(ex);
                }
            }
Beispiel #3
0
        private Nullable <Guid> GetSubscriptionId(ICM icm)
        {
            try
            {
                // Look for the custom field "subscription"
                String subscriptionId = SALsA.GetInstance(Id).ICM.GetCustomField(Constants.AnalyzerSubscriptionIdField);

                // Look in the ICM field for the subscriptionId
                if (!CheckIfSubscriptionIdIsValid(subscriptionId))
                {
                    Log.Verbose("Failed to get SubscriptionId from CustomField");
                    subscriptionId = icm.CurrentICM.SubscriptionId;
                    // Look in the ICM description for the subscriptionId
                    if (!CheckIfSubscriptionIdIsValid(subscriptionId))
                    {
                        Log.Verbose("Failed to get SubscriptionId from SubscriptionId ICM Field");
                        // If we coudnt find it, fail it.
                        if (!CheckIfSubscriptionIdIsValid(subscriptionId))
                        {
                            Log.Error("Failed to find any SubscriptionId in the ICM");
                            throw new Exception("Failed to find valid SubscriptionId");
                        }
                    }
                }
                return(Guid.Parse(Utility.DecodeHtml(subscriptionId)));
            }
            catch (Exception ex)
            {
                Log.Error("Failed to find a valid subscription id for ICM : {0}", icm.CurrentICM.Id);
                Log.Exception(ex);
                return(null);
            }
        }
Beispiel #4
0
        private void ExecuteAllActionsForVMSS(ARMDeployment dep)
        {
            int instanceId = TryConvertInstanceNameToInstanceId(this.VMName);

            // TODO instead of using 0, take 5 random and use them
            instanceId = instanceId == -1 ? 0 : instanceId;

            Task <string> modelTask = null;

            SALsA.GetInstance(Id).ICM.QueueICMDiscussion(dep.ToString());
            SALsA.GetInstance(Id).TaskManager.AddTask(
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerConsoleSerialOutputFilename, GenevaActions.GetVMConsoleSerialLogs(Id, dep, instanceId), Id),
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerVMScreenshotOutputFilename, GenevaActions.GetVMConsoleScreenshot(Id, dep, instanceId), Id),
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerVMModelAndViewOutputFilename, modelTask = GenevaActions.GetVMModelAndInstanceView(Id, dep, instanceId), Id),
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerInspectIaaSDiskOutputFilename, GenevaActions.InspectIaaSDiskForARMVM(Id, dep, instanceId), Id)
                );
            var rawInfo = LogContainerId(modelTask, Id);

            if (rawInfo != null)
            {
                GlobalInfo.Update(
                    new Guid(rawInfo.ContainerId),
                    new Guid(rawInfo.NodeId),
                    rawInfo.Cluster
                    );
                SALsA.GetInstance(Id).TaskManager.AddTask(
                    BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerNodeDiagnosticsFilename, GenevaActions.GetNodeDiagnosticsFilesByContainerId(Id, GlobalInfo), Id)
                    );
            }
        }
Beispiel #5
0
        /*
         * private bool AnalyzeHost()
         * {
         *  var currentICM = SALsA.GetInstance(Id).ICM;
         *  var title = currentICM.CurrentICM.Title;
         *  var isHostIssue = Regex.Match(title, @"HostGAPlugin.*Cluster.*Node.*(\{){0,1}[0-9a-fA-F]{8}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{4}\-[0-9a-fA-F]{12}(\}){0,1}", RegexOptions.IgnoreCase).Success;
         *  if (isHostIssue)
         *  {
         *      var splitTitle = title.ToLowerInvariant().Replace(" :", ":").Replace(": ", ":").Replace(",", " ").Replace(".", " ").Replace("nodeid", "node").Split(' ');
         *      splitTitle = Array.FindAll(splitTitle, s => s.Contains(":"));
         *      var dict = splitTitle.ToDictionary(
         *          k => k.Split(':')[0],
         *          e => e.Split(':')[1]
         *      );
         *      var cluster = dict["cluster"];
         *      var nodeid = dict["node"];
         *      var creationTime = currentICM.CurrentICM.CreateDate;
         *      var startTime = creationTime.AddHours(-12);
         *      var endTime = new DateTime(Math.Min(creationTime.AddHours(+12).Ticks, DateTime.UtcNow.Ticks));
         *      SALsA.GetInstance(Id).TaskManager.AddTask(
         *      Utility.SaveAndSendBlobTask(Constants.AnalyzerHostGAPluginFilename,
         *          GenevaActions.GetNodeDiagnosticsFiles(Id, cluster, nodeid, startTime.ToString("s"), endTime.ToString("s")), Id)
         *      );
         *  }
         *  return isHostIssue;
         * }
         */
        private void ExecuteAllActionsForIaaS(ARMDeployment dep)
        {
            Task <string> modelTask = null;

            SALsA.GetInstance(Id).ICM.QueueICMDiscussion(dep.ToString());
            SALsA.GetInstance(Id).TaskManager.AddTask(
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerConsoleSerialOutputFilename, GenevaActions.GetVMConsoleSerialLogs(Id, dep), Id),
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerVMScreenshotOutputFilename, GenevaActions.GetVMConsoleScreenshot(Id, dep), Id),
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerVMModelAndViewOutputFilename, modelTask = GenevaActions.GetVMModelAndInstanceView(Id, dep), Id),
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerInspectIaaSDiskOutputFilename, GenevaActions.InspectIaaSDiskForARMVM(Id, dep), Id)
                );

            var rawInfo = LogContainerId(modelTask, Id);

            if (rawInfo != null)
            {
                GlobalInfo.Update(
                    new Guid(rawInfo.ContainerId),
                    new Guid(rawInfo.NodeId),
                    rawInfo.Cluster
                    );
                var startTime = SALsA.GetInstance(Id).ICM.ICMImpactStartTime().AddHours(-12);
                var endTime   = new DateTime(Math.Min(startTime.AddHours(+24).Ticks, DateTime.UtcNow.Ticks));
                SALsA.GetInstance(Id).TaskManager.AddTask(
                    BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerNodeDiagnosticsFilename, GenevaActions.GetNodeDiagnosticsFilesByContainerId(Id, GlobalInfo), Id)
                    );
            }
        }
Beispiel #6
0
 private void GetAllNodeDiagnosticsFiles(string cluster, string nodeid, string startTime, string endTime)
 {
     SALsA.GetInstance(Id).TaskManager.AddTask(
         BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerHostMultiFilename,
                                                GenevaActions.GetNodeDiagnosticsFiles(Id, cluster, nodeid, String.Join(",", Constants.GetNodeDiagnosticsFilesTagsParamMultiHost), startTime, endTime), Id)
         );
 }
Beispiel #7
0
        private void AnalyzerInternal(bool checkARM = true, bool checkRDFE = true)
        {
            (var arm, var rdfe) = CallARMAndRDFE(checkARM, checkRDFE);
            (var type, var dep) = DetectVMType(arm, rdfe);

            if (dep == null && IsCustomRun == false)
            {
                try
                {
                    var instance = AnalyzeARMResourceURI(SubscriptionId.ToString(), ResourceGroupName, VMName);
                    GlobalInfo.Update(
                        new Guid(instance.Last().ContainerId),
                        new Guid(instance.Last().NodeId),
                        instance.Last().Cluster
                        );

                    if (!string.IsNullOrWhiteSpace(instance.FirstOrDefault().Usage_ResourceGroupName))
                    {
                        this.ResourceGroupName = instance.FirstOrDefault().Usage_ResourceGroupName;
                    }
                    this.VMName = instance.FirstOrDefault().RoleInstanceName;
                }
                catch
                {
                    try
                    {
                        var instance = AnalyzeRDFEResourceURI(SubscriptionId.ToString(), ResourceGroupName, VMName);
                        GlobalInfo.Update(
                            new Guid(instance.Last().ContainerId),
                            new Guid(instance.Last().NodeId),
                            instance.Last().Cluster
                            );
                        this.ResourceGroupName = instance.FirstOrDefault().TenantId;
                        this.VMName            = instance.FirstOrDefault().RoleInstanceName;
                    }
                    catch
                    {
                        SALsA.GetInstance(Id).State = SALsAState.NotFound;
                        throw new Exception("VM not found");
                    }
                }

                (type, dep) = DetectVMType(arm, rdfe);

                if (dep == null && IsCustomRun == false)
                {
                    SALsA.GetInstance(Id).ICM.QueueICMDiscussion(String.Format("Could not find VM: {0} in RG: {1}. This VM might have been already deleted or moved",
                                                                               this.VMName, this.ResourceGroupName));

                    // Lets try to check kusto data
                    SALsA.GetInstance(Id).TaskManager.AddTask(
                        BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerNodeDiagnosticsFilename, GenevaActions.GetNodeDiagnosticsFilesByContainerId(Id, GlobalInfo), Id));
                }
            }
            CallInternalComputeTypes(type, dep);
        }
        private static void SendSASToICM(string name, int Id)
        {
            var sasToken = BlobStorage.GetSASToken(Id, name);

            // Since we build our own HTML, we directly call the AddICMDiscussion instead of callign Log.Online
            if (!SALsA.GetInstance(Id).ICM.QueueICMDiscussion(Utility.UrlToHml(name, sasToken), false))
            {
                Log.Information("Did not add ICM discussion : {0} with sasToken {1}. Probably already exists", name, sasToken);
            }
        }
Beispiel #9
0
 private void RefreshTempPage(bool isTemp = false)
 {
     if (SALsA.GetInstance(Id).State == SALsAState.Ignore)
     {
         return;                                                   // Ignore the ICM
     }
     lock (__lockObj)
     {
         var message = Utility.GenerateICMHTMLPage(Id, MessageQueue.ToArray(), Log.StartTime, isTemp);
         SAS = BlobStorageUtility.UploadICMRun(Id, message);
         SALsA.GetInstance(Id)?.RefreshTable();
     }
 }
Beispiel #10
0
        public VMA2ContainerId.MessageLine[] AnalyzeARMResourceURI(string subscriptions, string resourceGroups, string virtualMachines)
        {
            var vminfo = new VMA2ContainerId(Id, virtualMachines, subscriptions, resourceGroups);

            if (vminfo.Results.Length == 0)
            {
                throw new Exception(String.Format(
                                        "Kusto query for Deployment {0}//{1}//{2} returned empty results", subscriptions, resourceGroups, virtualMachines));
            }

            SALsA.GetInstance(Id)?.ICM.QueueICMDiscussion(vminfo.HTMLResults, htmlfy: false);
            Log.Information(vminfo.Results);
            return(vminfo.Results);
        }
Beispiel #11
0
        public CAD.MessageLine[] AnalyzeRDFEResourceURI(string subscriptions, string tenantName, string virtualMachines)
        {
            var vminfo = new CAD(Id, subscriptions, tenantName, virtualMachines);

            if (vminfo.Results.Length == 0)
            {
                throw new Exception(String.Format(
                                        "Kusto query for Deployment {0}//{1}//{2} returned empty results", subscriptions, tenantName, virtualMachines));
            }

            SALsA.GetInstance(Id)?.ICM.QueueICMDiscussion(vminfo.HTMLResults, htmlfy: false);
            Log.Information(vminfo.Results);
            return(vminfo.Results);
        }
Beispiel #12
0
        public static void Run(int icm, object manualRun = null)
        {
            try
            {
                SALsA.AddInstance(icm);
                SALsA.GetInstance(icm).ICM.PostICMHeader();
                // We do not need to keep the analyzer in memory, for now.
                _ = manualRun == null ? new Analyzer(icm) : new Analyzer(icm, manualRun);

                SALsA.GetInstance(icm)?.TaskManager.WaitAllTasks();
            }
            catch (Exception ex)
            {
                Log.Critical("Main failed !");
                Log.Exception(ex);

                SALsA.GetInstance(icm)?.TaskManager.WaitAllTasks();

                try
                {
                    Log.Information("ICM State : {0}", Utility.ObjectToJson(SALsA.GetInstance(icm).ICM));
                }
                catch { }
                try
                {
                    Log.Information("ICM SALsA : {0}", Utility.ObjectToJson(SALsA.GetInstance(icm)));
                }
                catch { }
                //throw ex;
            }
            finally
            {
                SALsA.GetInstance(icm)?.ICM.EmptyMessageQueue();
                if (SALsA.GetInstance(icm)?.State == SALsAState.Running)
                {
                    if (SALsA.GetInstance(icm)?.ICM?.SAS != null)
                    {
                        SALsA.GetInstance(icm).State = SALsAState.Done;
                    }
                    else
                    {
                        SALsA.GetInstance(icm).State = SALsAState.UnknownException;
                    }
                }
                BlobStorageUtility.UploadLog(icm);
                SALsA.GetInstance(icm)?.RefreshTable();
            }
        }
Beispiel #13
0
        private void ExecuteAllActionsForPaaS(RDFEDeployment dep)
        {
            var instance = dep.RoleInstances.Where(x => String.Equals(x.RoleInstanceName, VMName, StringComparison.OrdinalIgnoreCase)).FirstOrDefault();

            if (instance?.RoleInstanceName == null)
            {
                instance = dep.RoleInstances.Where(x => String.Equals(x.RoleInstanceName, TryConvertInstanceNameToVMName(this.VMName), StringComparison.OrdinalIgnoreCase)).FirstOrDefault();
            }
            if (instance?.RoleInstanceName == null)
            {
                instance = dep.RoleInstances.Where(x => String.Equals(x.ID.ToString(), VMName)).FirstOrDefault();
            }

            GlobalInfo = new ShortRDFERoleInstance
            {
                Icm            = Id,
                Fabric         = dep.FabricGeoId,
                DeploymentId   = dep.Id,
                DeploymentName = dep.Name,
                ContainerID    = instance.ID,
                InstanceName   = instance.RoleInstanceName
            };

            Task <string> modelTask = null;

            SALsA.GetInstance(Id).TaskManager.AddTask(
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerVMScreenshotOutputFilename, GenevaActions.GetClassicVMConsoleScreenshot(Id, GlobalInfo), Id),
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerNodeDiagnosticsFilename, GenevaActions.GetNodeDiagnosticsFilesByDeploymentIdorVMName(Id, GlobalInfo), Id),
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerContainerSettings, modelTask = GenevaActions.GetContainerSettings(Id, GlobalInfo), Id)
                );

            try
            {
                var model = Utility.JsonToObject <Json2Class.ContainerSettings>(modelTask.Result);
                GlobalInfo.NodeId = new Guid(model.NodeId);
            }
            catch (Exception ex)
            {
                Log.Critical("Failed to populate NodeId");
                Log.Exception(ex);
            }
            finally
            {
                SALsA.GetInstance(Id)?.ICM.QueueICMDiscussion(GlobalInfo.ToString());
            }
        }
Beispiel #14
0
        private (Nullable <Guid> subscriptionId, string resourceGroupName, string VMName, DateTime startTime) AnalyzeICM()
        {
            var currentICM        = SALsA.GetInstance(Id).ICM;
            var subscriptionId    = GetSubscriptionId(currentICM);
            var resourceGroupName = currentICM.GetCustomField(Constants.AnalyzerResourceGroupField);
            var VMName            = currentICM.GetCustomField(Constants.AnalyzerVMNameField);

            // If the VMName is a ContainerId, we should ignore any other data, and check with Kusto instead
            Guid containerId;
            bool isValid = Guid.TryParse(currentICM.GetCustomField(Constants.AnalyzerVMNameField), out containerId);

            if (isValid)
            {
                try
                {
                    var vma = new Kusto.VMA2ContainerId(currentICM.Id, containerId.ToString(),
                                                        null, null).Results.First();

                    if (!string.IsNullOrEmpty(vma.ContainerId))
                    {
                        VMName = vma.ContainerId;
                    }
                    if (!string.IsNullOrWhiteSpace(vma.Usage_ResourceGroupName) || !string.IsNullOrWhiteSpace(vma.TenantName))
                    {
                        resourceGroupName = vma.Usage_ResourceGroupName;
                        if (string.IsNullOrWhiteSpace(resourceGroupName))
                        {
                            resourceGroupName = vma.TenantName;
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(vma.LastKnownSubscriptionId))
                    {
                        subscriptionId = Guid.Parse(vma.LastKnownSubscriptionId);
                    }
                    GlobalInfo.Update(containerId, Guid.Parse(vma.NodeId), vma.Cluster);
                }
                catch
                { } // This is a best case, just ignore.
            }
            DateTime startTime = currentICM.ICMImpactStartTime();

            return(subscriptionId, resourceGroupName, VMName, startTime);
        }
Beispiel #15
0
        private LogContainerSnapshot2ContainerId.MessageLine LogContainerId(Task <string> modelTask, int Id)
        {
            if (modelTask != null)
            {
                try
                {
                    var model  = Utility.JsonToObject <Dictionary <string, dynamic> >(modelTask.Result);
                    var vmid   = (string)(model["VM Model"].properties.vmId);
                    var vmInfo = new LogContainerSnapshot2ContainerId(Id, vmid);
                    SALsA.GetInstance(Id).ICM.QueueICMDiscussion(vmInfo.HTMLResults, htmlfy: false);

                    return(vmInfo.Results.Last());
                }
                catch (Exception ex)
                {
                    Log.Critical("Failed to populate ContainerId");
                    Log.Exception(ex);
                }
            }
            return(null);
        }
Beispiel #16
0
        public void EmptyMessageQueue()
        {
            Log.Verbose("Empty Message Queue with {0} elements", MessageQueue.Count);
            if (MessageQueue.IsEmpty || SALsA.GetInstance(Id).State == SALsAState.Ignore)
            {
                return;                                                                           // Ignore the ICM
            }
            string reason = null;

            try
            {
                RefreshTempPage();
                if (Constants.ShouldPostToICM)
                {
                    var message = Utility.UrlToHml(String.Format("SALsA Logs {0}",
                                                                 DateTime.ParseExact(Log.StartTime, "yyMMddTHHmmss", null)
                                                                 .ToString("yyyy-MM-ddTHH:mm:ssZ")), SAS);
                    if (message == null)
                    {
                        throw new ArgumentNullException("Message is null, please verify run log");
                    }
                    var body = new StringContent(Utility.ObjectToJson(new Incident.DescriptionPost(message)));
                    body.Headers.ContentType = new MediaTypeHeaderValue("application/json");
                    var response = Client.PatchAsync(BuildUri(this.Id), body).Result;
                    reason = response.Content.ReadAsStringAsync().Result;
                    response.EnsureSuccessStatusCode();
                    Log.Verbose("Got response for ICM {0}", this.Id);
                }
            }
            catch (Exception ex)
            {
                SALsA.GetInstance(Id).State = SALsAState.UnknownException;
                Log.Error("Failed to add message element to ICM {0}. Reason : {1}", this.Id, reason);
                Log.Exception(ex);
            }
            finally
            {
                MessageQueue = new ConcurrentBag <string>(); // Dispose of our current one
            }
        }
Beispiel #17
0
        public Analyzer(int Id)
        {
            if (SALsA.GetInstance(Id).ICM.CurrentICM.Keywords?.Contains("AutomatedHGAP") == true)
            {
                SALsA.GetInstance(Id).State = SALsAState.Ignore;
                return;
            }
            this.Id             = Id;
            this.GlobalInfo.Icm = Id;
            Nullable <Guid> sub;

            (sub, ResourceGroupName, VMName, StartTime) = AnalyzeICM();

            /*
             * var isHostIssue = AnalyzeHost();
             * if (isHostIssue == true)
             * {
             *  return;
             * }
             */
            if (!sub.HasValue || VMName == null)
            {
                if (String.IsNullOrWhiteSpace(SALsA.GetInstance(Id).ICM.GetCustomField(Constants.AnalyzerNodeIdField)) == false)
                {
                    CallInternalCommon();
                    return;
                }
                else
                {
                    SALsA.GetInstance(Id).State = SALsAState.MissingInfo;
                    SALsA.GetInstance(Id).ICM.QueueICMDiscussion("Could not detect any valid SubscriptionId (must be a valid GUID). or VMName (!= null) Aborting analysis.");
                    throw new ArgumentNullException("SubscriptionId and VMName must not be null");
                }
            }
            SubscriptionId = (Guid)sub;
            SALsA.GetInstance(Id)?.ICM.QueueICMDiscussion(String.Format("{0}", Utility.ObjectToJson(this, true)));
            AnalyzerInternal();

            CallInternalCommon();
        }
Beispiel #18
0
        public bool PostICMHeader(string head = Constants.ICMInfoHeaderHtml)
        {
            string entry = head + "<br>" + Utility.UrlToHml(Constants.ICMInfoReportName, Constants.ICMInfoReportEndpoint + this.Id.ToString(), 24);

            Log.Verbose("Adding to ICM String {0}", entry);
            var discussion = ICM.GetICMDiscussion(this.Id);
            var cur        = SALsA.GetInstance(this.Id).ICM.CurrentICM;

            if (Constants.ICMTeamsDoNotRepostHeaderIfPreviouslyAlreadyPosted.Contains(
                    SALsA.GetInstance(this.Id).ICM.CurrentICM.OwningTeamId.Split('\\').First(),
                    StringComparer.InvariantCultureIgnoreCase) == true)
            {
                foreach (var de in discussion)
                {
                    if (de.SubmittedBy == Constants.ICMIdentityName || de.Text.Contains(Constants.ICMInfoHeaderHtml))
                    {
                        Log.Verbose("Did not add entry to ICM since already sent", this.Id);
                        return(false);
                    }
                }
            }
            else
            {
                var currentTime = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ssZ", CultureInfo.InvariantCulture);
                entry = String.Format("[{0}] {1}", currentTime, entry);
            }
            try
            {
                return(ICM.PostDiscussion(this.Id, entry));
            }
            catch (Exception ex)
            {
                Log.Error("Failed to add discussion element to ICM {0}", Id);
                Log.Exception(ex);
                return(false);
            }
        }
Beispiel #19
0
        public Analyzer(int Id, object manualRun)
        {
            this.IsCustomRun = true;
            this.Id          = Id;
            StartTime        = SALsA.GetInstance(Id).ICM.CurrentICM.CreateDate;
            Log.Information("Received ManualRun order type {0} with param {1} : ",
                            manualRun.GetType(), Utility.ObjectToJson(manualRun));
            if (manualRun.GetType() == typeof(ManualRun_ICM))
            {
                ManualRun_ICM manualArm = (ManualRun_ICM)manualRun;

                SubscriptionId    = manualArm.SubscriptionID;
                ResourceGroupName = manualArm.ResourceGroupName;
                VMName            = manualArm.VMName;

                AnalyzerInternal();
            }
            else if (manualRun.GetType() == typeof(ManualRun_IID))
            {
                ManualRun_IID manualIID = (ManualRun_IID)manualRun;

                SubscriptionId    = manualIID.SubscriptionID;
                ResourceGroupName = manualIID.ResourceGroupName;
                VMName            = manualIID.VMName;

                ARMDeployment dep        = null;
                int           instanceId = -1;
                if (String.IsNullOrEmpty(manualIID.Region))
                {
                    Log.Information("Calling automatic ARM VMdetection. No Region parameter provided.");
                    ARMSubscription arm = AnalyzeARMSubscription(SubscriptionId, this.ResourceGroupName);
                    dep        = AnalyzeARMDeployment(arm);
                    instanceId = TryConvertInstanceNameToInstanceId(this.VMName);
                }
                else
                {
                    dep                = new ARMDeployment();
                    dep.Name           = manualIID.VMName;
                    dep.Subscriptions  = manualIID.SubscriptionID.ToString();
                    dep.ResourceGroups = manualIID.ResourceGroupName;
                    dep.Location       = manualIID.Region;
                    instanceId         = manualIID.Instance;
                }
                if (instanceId < 0)
                {
                    Log.Information("No Instance ID detected. Assuming this is a normal single IaaS VM");
                    SALsA.GetInstance(Id).TaskManager.AddTask(
                        BlobStorageUtility.SaveAndSendBlobTask(
                            Constants.AnalyzerInspectIaaSDiskOutputFilename,
                            GenevaActions.InspectIaaSDiskForARMVM(Id, dep), Id));
                }
                else
                {
                    Log.Information("No Instance ID detected. Assuming this is a normal single IaaS VM");
                    SALsA.GetInstance(Id).TaskManager.AddTask(
                        BlobStorageUtility.SaveAndSendBlobTask(
                            Constants.AnalyzerInspectIaaSDiskOutputFilename,
                            GenevaActions.InspectIaaSDiskForARMVM(Id, dep, instanceId), Id));
                }
            }
            else if (manualRun.GetType() == typeof(ManualRun_RDFE_Fabric))
            {
                var rdfe   = (ManualRun_RDFE_Fabric)manualRun;
                var vmInfo = new ShortRDFERoleInstance
                {
                    ContainerID = new Guid(rdfe.ContainerID),
                    Fabric      = rdfe.FabricCluster,
                    NodeId      = new Guid(rdfe.NodeId)
                };
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerNodeDiagnosticsFilename, GenevaActions.GetNodeDiagnosticsFilesByContainerId(Id, vmInfo), Id).Wait();
            }
            else if (manualRun.GetType() == typeof(ManualRun_RDFE_Tenant))
            {
                var rdfe   = (ManualRun_RDFE_Tenant)manualRun;
                var vmInfo = new ShortRDFERoleInstance
                {
                    Fabric       = rdfe.FabricCluster,
                    DeploymentId = rdfe.DeploymentID,
                    InstanceName = rdfe.RoleInstanceName
                };
                BlobStorageUtility.SaveAndSendBlobTask(Constants.AnalyzerNodeDiagnosticsFilename, GenevaActions.GetNodeDiagnosticsFilesByDeploymentIdorVMName(Id, vmInfo), Id).Wait();
            }
        }
Beispiel #20
0
            internal GenevaAction(int icm, string extensionName, string operationName, Dictionary <string, string> actionParam)
            {
                try
                {
                    this.extensionName = extensionName;
                    this.operationName = operationName;
                    this.actionParam   = actionParam;
                    Uri dstsUri = null;
                    switch (SALsA.GetInstance(icm)?.ICM.CurrentICM.SiloId)
                    {
                    case 1:
                        this.actionsEnvironments = ActionsEnvironments.Public;
                        //dstsUri = new Uri("https://ch1-dsts.dsts.core.windows.net");
                        break;

                    case 5:
                        this.actionsEnvironments = ActionsEnvironments.Fairfax;
                        //dstsUri = new Uri("https://usgoveast-dsts.dsts.core.usgovcloudapi.net");
                        break;

                    case 3:
                        this.actionsEnvironments = ActionsEnvironments.Mooncake;
                        //dstsUri = new Uri("https://chinanorth-dsts.dsts.core.chinacloudapi.cn");
                        break;

                    case 8:
                        this.actionsEnvironments = ActionsEnvironments.Blackforest;
                        //dstsUri = new Uri("https://germanycentral-dsts.dsts.core.cloudapi.de");
                        break;

                    case -1:
                        this.actionsEnvironments = ActionsEnvironments.USNat;
                        dstsUri = new Uri("https://usnatw-dsts.dsts.core.eaglex.ic.gov");
                        break;

                    case -2:
                        this.actionsEnvironments = ActionsEnvironments.USSec;
                        dstsUri = new Uri("https://ussecw-dsts.dsts.core.microsoft.scloud");
                        break;

                    default:
                        Log.Warning("Unkown Environment. SilotId : {0}. Will default to public Environment! ", SALsA.GetInstance(icm)?.ICM.CurrentICM.SiloId);
                        goto case 1;
                    }

                    Log.Verbose("Creating GenevaAction for {0}: {1}, with parameters : {2}", extensionName, operationName,
                                Utility.ObjectToJson(actionParam));

                    //sts = new ClientHomeSts(dstsUri);
                    cp     = ConnectionParameters.Create(actionsEnvironments, Authentication.Instance.Cert, null, X509CertCredentialType.SubjectNameCredential);
                    client = new GenevaActionsRestAPIClient(cp);
                    Log.Verbose("Client created for {0}: {1}", extensionName, operationName);

                    var operationDetails = client.Extension.GetOperationDetails(extensionName, operationName);
                    Log.Verbose("operationDetails id : ", operationDetails.Id);

                    operationRequest = new OperationRequest
                    {
                        // TODO : a smarter way than takign first endpoint by default
                        Endpoint   = operationDetails.AllowedEndpoints[0],
                        Extension  = extensionName,
                        Id         = operationDetails.Id,
                        Parameters = actionParam
                    };
                    Log.Verbose("operationRequest populated. Extension : {0}", operationRequest.Extension);
                }
                catch (Exception ex)
                {
                    Log.Error("Failed GenevaAction {0}: {1}", extensionName, operationName);
                    Log.Exception(ex);
                }
            }