private void AddResult(string strError) { if (strError == "") { oOnDemand.UpdateStepDoneServer(intServer, intStep, oOnDemand.GetStep(intStep, "done"), 0, false, false); oServer.NextStep(intServer); intStep++; } else { oEventLog.AddEvent(strName, strSerial, strError, LoggingType.Error); //Functions oFunction = new Functions(0, dsn, intEnvironment); //Variables oVariable = new Variables(intEnvironment); oOnDemand.UpdateStepDoneServer(intServer, intStep, strError, 1, false, false); // Generic Error Request Services oService = new Services(0, dsn); ResourceRequest oResourceRequest = new ResourceRequest(0, dsn); ServiceRequests oServiceRequest = new ServiceRequests(0, dsn); int intProvisioningErrorService = intService; int intProvisioningErrorItem = oService.GetItemId(intProvisioningErrorService); int intProvisioningErrorNumber = oResourceRequest.GetNumber(intRequest, intProvisioningErrorItem); int intError = oServer.AddError(intRequest, intProvisioningErrorItem, intProvisioningErrorNumber, intServer, intStep, strError); int intProvisioningError = oResourceRequest.Add(intRequest, intProvisioningErrorItem, intProvisioningErrorService, intProvisioningErrorNumber, "Provisioning Error (" + strName + ")", 1, 0.00, 2, 1, 1, 1); if (oServiceRequest.NotifyApproval(intProvisioningError, intResourceRequestApprove, intEnvironment, "", dsnServiceEditor) == false) { oServiceRequest.NotifyTeamLead(intProvisioningErrorItem, intProvisioningError, intAssignPage, intViewPage, intEnvironment, "", dsnServiceEditor, dsnAsset, dsnIP, 0); } if (boolEmailError == true) { oFunction.SendEmail("Auto-Provisioning ERROR: " + strName, strTo, strCC, "", "Auto-Provisioning ERROR: " + strName, "<p><b>This message is to inform you that the server " + strName + " has encountered an error and has been stopped!</b><p><p>Serial Number: " + strSerial.ToUpper() + "<br/>Asset Tag: " + strAsset.ToUpper() + "<br/>Model: " + strModel.ToUpper() + "<br/>Step #: " + intStep.ToString() + "<br/>Error: " + strError + "<br/>ILO: <a href=\"https://" + strILO + "\" target=\"_blank\">" + strILO + "</a></p><p>When this issue has been resolved, <a href=\"" + oVariable.URL() + "/admin/errors_server.aspx?id=" + intServer.ToString() + "\" target=\"_blank\">click here</a> to clear this error and continue with the build.</p>", true, false); } } }
private void AddResult(string strResult, string strError, int intAuditIDError) { if (strError == "") { if (boolMIS == false) { //oServer.NextStep(intServer); //oOnDemand.UpdateStepDoneServer(intServer, intStep, strResult, 0, false, false); // Update to prevent it being kicked off again oServer.UpdateStep(intServer, intStep + 1); // Set the done status oOnDemand.UpdateStepDoneServer(intServer, intStep, strResult, 0, false, false); // Go back to current step oServer.UpdateStep(intServer, intStep); // Push through to next step oServer.NextStep(intServer); intStep++; } else { oServer.UpdateMISAudits(intServer, DateTime.Now.ToString()); } } else { oLog.AddEvent(strName, strSerial, strError, LoggingType.Error); if (boolMIS == false) { oOnDemand.UpdateStepDoneServer(intServer, intStep, strError, 1, false, false); } else { oServer.UpdateMISAudits(intServer, DateTime.Now.ToString()); } // Generic Error Request Services oService = new Services(0, dsn); ResourceRequest oResourceRequest = new ResourceRequest(0, dsn); ServiceRequests oServiceRequest = new ServiceRequests(0, dsn); int intServerAuditErrorService = intService; int intServerAuditErrorItem = oService.GetItemId(intServerAuditErrorService); int intServerAuditErrorNumber = oResourceRequest.GetNumber(intRequest, intServerAuditErrorItem); oAudit.AddError(intRequest, intServerAuditErrorService, intServerAuditErrorNumber, intAuditIDError, intStep, boolMIS); int intError = oServer.AddError(intRequest, intServerAuditErrorItem, intServerAuditErrorNumber, intServer, intStep, strError); int intServerAuditError = oResourceRequest.Add(intRequest, intServerAuditErrorItem, intServerAuditErrorService, intServerAuditErrorNumber, "Server Audit Exception (" + strName + ")", 1, 0.00, 2, 1, 1, 1); if (oServiceRequest.NotifyApproval(intServerAuditError, intResourceRequestApprove, intEnvironment, "", dsnServiceEditor) == false) { oServiceRequest.NotifyTeamLead(intServerAuditErrorItem, intServerAuditError, intAssignPage, intViewPage, intEnvironment, "", dsnServiceEditor, dsnAsset, dsnIP, 0); } } }
public void Backups(int EnvironmentID) { // Setup Classes Servers oServer = new Servers(0, dsn); AvamarRegistration oAvamarRegistration = new AvamarRegistration(0, dsn); Log oLog = new Log(0, dsn); Variables oVariable = new Variables(EnvironmentID); // Setup Webservice for querying via SSH System.Net.NetworkCredential oCredentialsDNS = new System.Net.NetworkCredential(oVariable.ADUser(), oVariable.ADPassword(), oVariable.Domain()); ClearViewWebServices oWebService = new ClearViewWebServices(); oWebService.Url = oVariable.WebServiceURL(); DataSet dsBackups = oServer.GetAvamarBackups(); if (dsBackups.Tables[0].Rows.Count > 0) { oLog.AddEvent("", "", "Get avamar backups (" + dsBackups.Tables[0].Rows.Count.ToString() + ")", LoggingType.Debug); foreach (DataRow drBackup in dsBackups.Tables[0].Rows) { ClearResults(); int intServer = Int32.Parse(drBackup["id"].ToString()); DateTime datCreated = DateTime.Parse(drBackup["created"].ToString()); int intAnswer = Int32.Parse(drBackup["answerid"].ToString()); string strName = drBackup["servername"].ToString(); string strGrid = drBackup["grid"].ToString(); string strDomain = drBackup["domain"].ToString(); string strGroup = drBackup["group"].ToString(); oLog.AddEvent(intAnswer, strName, "", "Starting automated Avamar backup validation", LoggingType.Debug); string strError = ""; // Initiate backup for client AvamarReturnType backup = oAvamarRegistration.API(oWebService.GetAvamarBackup(strGrid, strDomain, strName)); if (backup.Error == false) { oLog.AddEvent(intAnswer, strName, "", "There are " + backup.Nodes.Count.ToString() + " backup(s).", LoggingType.Information); if (backup.Nodes.Count > 0) { oLog.AddEvent(intAnswer, strName, "", "Backup has been validated", LoggingType.Information); oServer.UpdateAvamarBackupCompleted(intServer, backup.Nodes[0].InnerXml, DateTime.Now.ToString(), 0); } else { // Check to see if a certain amount of time has passed and if so, throw error. TimeSpan span = DateTime.Now.Subtract(datCreated); if (span.TotalMinutes > 90) { // It's been an hour and a half. Throw error. strError = "The backup has still not completed after 90 minutes on grid " + strGrid; } } } else { strError = backup.Message + " (" + backup.Code + ")"; } if (strError != "") { oLog.AddEvent(intAnswer, strName, "", strError, LoggingType.Error); oServer.UpdateAvamarBackupCompleted(intServer, strError, DateTime.Now.ToString(), 1); oServer.AddError(0, 0, 0, intServer, 906, strError); } } } }
public void SystemError(int _serverid, int _workstationid, int _stepid, string _error, int _assetid, int _modelid, bool _is_vmware, VMWare _vmware, int _environment, string _dsn_asset) { int intError = 0; if (_stepid > 0) { string strName = ""; string strType = ""; int intID = 0; OnDemand oOnDemand = new OnDemand(0, dsn); if (_serverid > 0) { oOnDemand.UpdateStepDoneServer(_serverid, _stepid, _error, 1, false, false); Servers oServer = new Servers(0, dsn); intError = oServer.AddError(0, 0, 0, _serverid, _stepid, _error); strName = oServer.GetName(_serverid, true); strType = "server"; intID = _serverid; } if (_workstationid > 0) { oOnDemand.UpdateStepDoneWorkstation(_workstationid, _stepid, _error, 1, false, false); Workstations oWorkstation = new Workstations(0, dsn); intError = oWorkstation.AddVirtualError(0, 0, 0, _workstationid, _stepid, _error); int intName = 0; if (Int32.TryParse(oWorkstation.GetVirtual(_workstationid, "nameid"), out intName) == true) { strName = oWorkstation.GetName(intName); } strType = "workstation"; intID = _workstationid; } if (_serverid > 0 || _workstationid > 0) { ModelsProperties oModelsProperties = new ModelsProperties(0, dsn); Functions oFunction = new Functions(0, dsn, _environment); Variables oVariable = new Variables(_environment); Asset oAsset = new Asset(0, _dsn_asset); int intType = oModelsProperties.GetType(_modelid); DataSet dsSteps = oOnDemand.GetSteps(intType, 1); string strStep = "N / A"; if (dsSteps.Tables[0].Rows.Count > 0) { strStep = dsSteps.Tables[0].Rows[_stepid - 1]["name"].ToString(); } string strEMailIdsBCC = oFunction.GetGetEmailAlertsEmailIds("EMAILGRP_PROVISIONING_SUPPORT"); try { if (_is_vmware == true) { oFunction.SendEmail("Auto-Provisioning FATAL ERROR: " + strName, strEMailIdsBCC, "", "", "Auto-Provisioning FATAL ERROR: " + strName, "<p><b>This message is to inform you that the " + strType + " " + strName + " has encountered a FATAL error and has been stopped!</b><p><p>Serial Number: " + oAsset.Get(_assetid, "serial").ToUpper() + "<br/>Asset Tag: " + oAsset.Get(_assetid, "asset").ToUpper() + "<br/>Model: " + oModelsProperties.Get(_modelid, "name").ToUpper() + "<br/>Step #: " + _stepid.ToString() + "<br/>Step: " + strStep + "<br/>Error: " + _error + "<br/>DataCenter: " + _vmware.DataCenter() + "<br/>Virtual Center: " + _vmware.VirtualCenter() + "</p><p>When this issue has been resolved, <a href=\"" + oVariable.URL() + "/admin/errors_" + strType + ".aspx?id=" + intID.ToString() + "\" target=\"_blank\">click here</a> to clear this error and continue with the build.</p>", true, false); } else { oFunction.SendEmail("Auto-Provisioning FATAL ERROR: " + strName, strEMailIdsBCC, "", "", "Auto-Provisioning FATAL ERROR: " + strName, "<p><b>This message is to inform you that the " + strType + " " + strName + " has encountered a FATAL error and has been stopped!</b><p><p>Serial Number: " + oAsset.Get(_assetid, "serial").ToUpper() + "<br/>Asset Tag: " + oAsset.Get(_assetid, "asset").ToUpper() + "<br/>Model: " + oModelsProperties.Get(_modelid, "name").ToUpper() + "<br/>Step #: " + _stepid.ToString() + "<br/>Step: " + strStep + "<br/>Error: " + _error + "<br/>ILO: <a href=\"https://" + oAsset.GetServerOrBlade(_assetid, "ilo") + "\" target=\"_blank\">" + oAsset.GetServerOrBlade(_assetid, "ilo") + "</a></p><p>When this issue has been resolved, <a href=\"" + oVariable.URL() + "/admin/errors_" + strType + ".aspx?id=" + intID.ToString() + "\" target=\"_blank\">click here</a> to clear this error and continue with the build.</p>", true, false); } } catch (Exception ex) { oFunction.SendEmail("Auto-Provisioning FATAL ERROR: " + strName, strEMailIdsBCC, "", "", "Auto-Provisioning FATAL ERROR: " + strName, "<p><b>This message is to inform you that the " + strType + " " + strName + " has encountered a FATAL error and has been stopped!</b><p><p>Serial Number: " + oAsset.Get(_assetid, "serial").ToUpper() + "<br/>Asset Tag: " + oAsset.Get(_assetid, "asset").ToUpper() + "<br/>Model: " + oModelsProperties.Get(_modelid, "name").ToUpper() + "<br/>Step #: " + _stepid.ToString() + "<br/>Step: " + strStep + "<br/>Error: " + _error + "<br/>Notification Error: (Error Message: " + ex.Message + ") (Source: " + ex.Source + ") (Stack Trace: " + ex.StackTrace + ")</p><p>When this issue has been resolved, <a href=\"" + oVariable.URL() + "/admin/errors_" + strType + ".aspx?id=" + intID.ToString() + "\" target=\"_blank\">click here</a> to clear this error and continue with the build.</p>", true, false); } } } UpdateError(_error); }
public void Activations(int EnvironmentID) { // Setup Classes Servers oServer = new Servers(0, dsn); AvamarRegistration oAvamarRegistration = new AvamarRegistration(0, dsn); Log oLog = new Log(0, dsn); Variables oVariable = new Variables(EnvironmentID); // Setup Webservice for querying via SSH System.Net.NetworkCredential oCredentialsDNS = new System.Net.NetworkCredential(oVariable.ADUser(), oVariable.ADPassword(), oVariable.Domain()); ClearViewWebServices oWebService = new ClearViewWebServices(); oWebService.Url = oVariable.WebServiceURL(); DataSet dsActivations = oServer.GetAvamarActivations(); if (dsActivations.Tables[0].Rows.Count > 0) { oLog.AddEvent("", "", "Get avamar activations (" + dsActivations.Tables[0].Rows.Count.ToString() + ")", LoggingType.Debug); foreach (DataRow drActivation in dsActivations.Tables[0].Rows) { ClearResults(); int intServer = Int32.Parse(drActivation["id"].ToString()); oServer.UpdateAvamarActivationStarted(intServer, DateTime.Now.ToString()); int intAnswer = Int32.Parse(drActivation["answerid"].ToString()); string strName = drActivation["servername"].ToString(); string strGrid = drActivation["grid"].ToString(); string strDomain = drActivation["domain"].ToString(); string strGroup1 = drActivation["group1"].ToString(); string strGroup2 = drActivation["group2"].ToString(); string strGroup3 = drActivation["group3"].ToString(); oLog.AddEvent(intAnswer, strName, "", "Starting automated Avamar activation", LoggingType.Information); string strError = ""; string strSuccess = ""; try { // Activate client AvamarReturnType activate = oAvamarRegistration.API(oWebService.ActivateAvamarClient(strGrid, strDomain, strName)); if (activate.Error == false) { strSuccess = activate.Message; // Wait 1/2 minute for synchronization oLog.AddEvent(intAnswer, strName, "", "Activation script complete = " + activate.Message + ".", LoggingType.Information); bool HasActivated = false; for (int ii = 0; ii < 10 && HasActivated == false; ii++) { int activateCount = ii + 1; oLog.AddEvent(intAnswer, strName, "", "Checking activation status (" + activateCount.ToString() + " of 10)...", LoggingType.Debug); AvamarReturnType activated = oAvamarRegistration.API(oWebService.GetAvamarClient(strGrid, strDomain, strName)); if (activated.Error == false) { foreach (XmlNode node in activated.Nodes) { if (node["Attribute"].InnerText == "Activated") { if (node["Value"].InnerText.Trim().ToUpper() == "YES") { HasActivated = true; oLog.AddEvent(intAnswer, strName, "", "Client has activated!", LoggingType.Information); } else { oLog.AddEvent(intAnswer, strName, "", "Client is not active. Waiting 30 seconds before retrying...", LoggingType.Debug); Thread.Sleep(30000); } break; } } } else { strError = "Error while activating - " + activated.Message; break; } } if (String.IsNullOrEmpty(strError)) { if (HasActivated) { // Initiate backup oLog.AddEvent(intAnswer, strName, "", "Initiating backup...", LoggingType.Information); AvamarReturnType start = oAvamarRegistration.API(oWebService.StartAvamarBackup(strGrid, strDomain, strGroup1, strName)); if (start.Error) { strError = start.Message + " (" + start.Code + ")"; } else if (String.IsNullOrEmpty(strGroup2) == false) { oLog.AddEvent(intAnswer, strName, "", "Backup for " + strGroup1 + " started = " + start.Message, LoggingType.Information); AvamarReturnType start2 = oAvamarRegistration.API(oWebService.StartAvamarBackup(strGrid, strDomain, strGroup2, strName)); if (start2.Error) { strError = start2.Message + " (" + start2.Code + ")"; } else if (String.IsNullOrEmpty(strGroup3) == false) { oLog.AddEvent(intAnswer, strName, "", "Backup for " + strGroup2 + " started = " + start2.Message, LoggingType.Information); AvamarReturnType start3 = oAvamarRegistration.API(oWebService.StartAvamarBackup(strGrid, strDomain, strGroup3, strName)); if (start3.Error) { strError = start3.Message + " (" + start3.Code + ")"; } else { oLog.AddEvent(intAnswer, strName, "", "Backup for " + strGroup3 + " started = " + start3.Message, LoggingType.Information); } } } } else { strError = "Client has not activated after 5 minutes"; } } } else { strError = activate.Message + " (" + activate.Code + ")"; } } catch (Exception exError) { strError = exError.Message; if (exError.InnerException != null) { strError += " ~ " + exError.InnerException.Message; } } if (strError != "") { oLog.AddEvent(intAnswer, strName, "", strError, LoggingType.Error); oServer.UpdateAvamarActivationCompleted(intServer, "", strError, DateTime.Now.ToString(), 1); oServer.AddError(0, 0, 0, intServer, 906, strError); } else { oLog.AddEvent(intAnswer, strName, "", "Activation completed and backup initiated", LoggingType.Information); oServer.UpdateAvamarActivationCompleted(intServer, "", strSuccess, DateTime.Now.ToString(), 0); oServer.AddAvamarBackup(intServer, strName, strGrid, strDomain, strGroup1); } } } }
public void NonShared() { //// Initiate Timer //int intTimeout = 10; // minutes for all registrations //if (Debug) // oEventLog.WriteEntry(String.Format("Starting Avamar Registration Thread."), EventLogEntryType.Information); //Timeout timeout = new Timeout(TimeoutType.Minutes, intTimeout, oEventLog, Debug); //ThreadStart tTimeoutStart = new ThreadStart(timeout.Begin); //Thread tTimeout = new Thread(tTimeoutStart); //tTimeout.Start(); try { this.Starter.NonSharedStorage = true; // Setup Classes Servers oServer = new Servers(0, dsn); OperatingSystems oOperatingSystem = new OperatingSystems(0, dsn); Log oLog = new Log(0, dsn); DataSet dsNew = oServer.GetStorageConfigured(); if (dsNew.Tables[0].Rows.Count > 0) { foreach (DataRow drNew in dsNew.Tables[0].Rows) { int intServer = Int32.Parse(drNew["id"].ToString()); int intOS = Int32.Parse(drNew["osid"].ToString()); int intAnswer = Int32.Parse(drNew["answerid"].ToString()); int intNumber = Int32.Parse(drNew["number"].ToString()); string Name = drNew["servername"].ToString(); string IP = drNew["ipaddress"].ToString(); if (oOperatingSystem.IsWindows(intOS) || oOperatingSystem.IsWindows2008(intOS)) { // First, check to make sure it's available (pinging) in DNS //bool InDNS = false; //Ping Ping = new Ping(); //string PingStatus = ""; //try //{ // PingReply Reply = Ping.Send(Name); // PingStatus = Reply.Status.ToString().ToUpper(); // if (PingStatus == "SUCCESS") // { // InDNS = true; // break; // } //} //catch { } //if (InDNS) //{ // Serverprocessing.ps1 -AnswerID 26622 -ServerNumber 1 –Environment "Albert_Dev" –IPAddressToConnect "10.24.240.205" – ConfigureNonSharedStorage -Log string command = "Serverprocessing.ps1 -AnswerID " + intAnswer.ToString() + " -ServerNumber " + intNumber.ToString() + " –Environment \"" + this.Starter.ScriptEnvironment + "\" –IPAddressToConnect \"" + IP + "\" – ConfigureNonSharedStorage -Log"; oLog.AddEvent(intAnswer, Name, "Non-shared storage", "Starting automated script (" + command + ")...", LoggingType.Debug); string error = ""; try { List <PowershellParameter> powershell = new List <PowershellParameter>(); Powershell oPowershell = new Powershell(); powershell.Add(new PowershellParameter("AnswerID", intAnswer.ToString())); powershell.Add(new PowershellParameter("ServerNumber", intNumber.ToString())); powershell.Add(new PowershellParameter("Environment", this.Starter.ScriptEnvironment)); powershell.Add(new PowershellParameter("IPAddressToConnect", IP)); powershell.Add(new PowershellParameter("ConfigureNonSharedStorage", null)); powershell.Add(new PowershellParameter("Log", null)); List <PowershellParameter> results = oPowershell.Execute(this.Starter.strScripts + "\\Serverprocessing.ps1", powershell, oLog, Name); oLog.AddEvent(intAnswer, Name, "Non-shared storage", "Powershell script completed!", LoggingType.Debug); bool PowerShellError = false; foreach (PowershellParameter result in results) { oLog.AddEvent(intAnswer, Name, "Non-shared storage", "PSOBJECT: " + result.Name + " = " + result.Value, LoggingType.Information); if (result.Name == "ResultCode" && result.Value.ToString() != "0") { PowerShellError = true; } else if (result.Name == "Message" && PowerShellError) { error = result.Value.ToString(); } } } catch (Exception exPowershell) { error = exPowershell.Message; } if (String.IsNullOrEmpty(error)) { oServer.UpdateStorageConfigured(intServer, DateTime.Now.ToString()); } else { oLog.AddEvent(intAnswer, Name, "", error, LoggingType.Error); oServer.AddError(0, 0, 0, intServer, 99991, error); } //} //else // oLog.AddEvent(intAnswer, Name, "Non-shared storage", "DNS is not registered yet...", LoggingType.Debug); } else { oServer.UpdateStorageConfigured(intServer, DateTime.Now.ToString()); } } } } catch (Exception ex) { string error = ex.Message + " ~ (Source: " + ex.Source + ") (Stack Trace: " + ex.StackTrace + ")"; oEventLog.WriteEntry(error, EventLogEntryType.Error); } finally { this.Starter.NonSharedStorage = false; //timeout.StopIt = true; // Kill timeout thread. } }