Ejemplo n.º 1
0
        public void Registrations()
        {
            //// 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.Registrations = true;
                AvamarRegistration oAvamarRegistration = new AvamarRegistration(0, dsn);
                oAvamarRegistration.Registrations(EnvironmentID, this.Starter.strScripts, this.Starter.dsnAsset, this.Starter.dsnServiceEditor, this.Starter.dsnIP, this.Starter.intViewPage, this.Starter.intAssignPage);
            }
            catch (Exception ex)
            {
                string error = ex.Message + " ~ (Source: " + ex.Source + ") (Stack Trace: " + ex.StackTrace + ")";
                oEventLog.WriteEntry(error, EventLogEntryType.Error);
            }
            finally
            {
                this.Starter.Registrations = false;
                //timeout.StopIt = true;  // Kill timeout thread.
            }
        }
Ejemplo n.º 2
0
        protected void btnRegister_Click(object sender, EventArgs e)
        {
            AvamarRegistration oAvamarAutomation = new AvamarRegistration(0, dsn);
            string             strScripts        = Server.MapPath("/scripts/");

            oAvamarAutomation.Registrations(EnvironmentID, strScripts, dsnAsset, dsnServiceEditor, dsnIP, intViewPage, intAssignPage);
        }
Ejemplo n.º 3
0
        protected void btnActivated_Click(object sender, EventArgs e)
        {
            string grid = "yb19-avr01-01.test.pncbank.com";
            ClearViewWebServices oWebService = new ClearViewWebServices();

            oWebService.Url = "http://localhost:64919/ClearViewWebServices.asmx";

            AvamarRegistration oAvamarRegistration = new AvamarRegistration(0, dsn);
            AvamarReturnType   activated           = oAvamarRegistration.API(oWebService.GetAvamarClient(grid, "/BRII", "WCIRU301A.pncbank.com"));

            if (activated.Error == false)
            {
                foreach (XmlNode node in activated.Nodes)
                {
                    if (node["Attribute"].InnerText == "Activated")
                    {
                        Response.Write(node["Value"].InnerText + "<br/>");
                    }
                }
            }
            else
            {
                Response.Write(activated.Message + "<br/>");
            }
        }
Ejemplo n.º 4
0
        protected void btnRecom_Click(object sender, EventArgs e)
        {
            Variables oVariable = new Variables((int)CurrentEnvironment.PNCNT_DEV);
            string    client    = "WDCLV015A.pncbank.com";
            string    strError  = "";

            Avamar               oAvamar             = new Avamar(0, dsn);
            AvamarRegistration   oAvamarRegistration = new AvamarRegistration(0, dsn);
            ClearViewWebServices oWebService         = new ClearViewWebServices();

            System.Net.NetworkCredential oCredentialsDNS = new System.Net.NetworkCredential(oVariable.ADUser(), oVariable.ADPassword(), oVariable.Domain());
            oWebService.Credentials = oCredentialsDNS;
            oWebService.Url         = oVariable.WebServiceURL();

            // First, query for groups.
            DataSet dsGroups = oAvamar.GetDecoms(client);

            if (dsGroups.Tables[0].Rows.Count > 0)
            {
                string grid   = dsGroups.Tables[0].Rows[0]["grid"].ToString();
                string domain = dsGroups.Tables[0].Rows[0]["domain"].ToString();
                // Second, add the groups.
                foreach (DataRow drGroup in dsGroups.Tables[0].Rows)
                {
                    if (String.IsNullOrEmpty(strError) == false)
                    {
                        break;
                    }
                    AvamarReturnType restore = oAvamarRegistration.API(oWebService.AddAvamarGroup(grid, domain, client, drGroup["group"].ToString()));
                    if (restore.Error == false)
                    {
                    }
                    else
                    {
                        strError = restore.Message;
                    }
                }
                // Third, remove the /Decom group
                AvamarReturnType decom = oAvamarRegistration.API(oWebService.DeleteAvamarGroup(grid, domain, client, oAvamar.DecomGroup));
                if (decom.Error == false)
                {
                    // Fourth, recommission the saved decom groups.
                    oAvamar.UpdateDecom(client);
                }
                else
                {
                    strError = decom.Message;
                }
            }
        }
Ejemplo n.º 5
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);
                    }
                }
            }
        }
Ejemplo n.º 6
0
        protected void btnSubmit_Click(Object Sender, EventArgs e)
        {
            int    intUser   = 0;
            string strAssets = "";

            if (Int32.TryParse(Request.Form["hdnAJAXValue"], out intUser) == true && intUser > 0)
            {
                foreach (RepeaterItem ri in rptDevices.Items)
                {
                    CheckBox chkDevice    = (CheckBox)ri.FindControl("chkDevice");
                    Label    lblName      = (Label)ri.FindControl("lblName");
                    Label    lblSerial    = (Label)ri.FindControl("lblSerial");
                    Label    lblStatus    = (Label)ri.FindControl("lblStatus");
                    bool     boolComplete = lblStatus.Text.ToUpper().Contains("COMPLETED");
                    oLog.AddEvent(lblName.Text, lblSerial.Text, "RECOMMISSION: Started by " + oUser.GetFullNameWithLanID(intProfile), LoggingType.Information);

                    if (chkDevice.Checked == true)
                    {
                        if (chkDevice.ToolTip[0].ToString() == "S")
                        {
                            int     intServer = Int32.Parse(chkDevice.ToolTip.Substring(1));
                            DataSet dsServers = oServer.GetAssetsServer(intServer);
                            foreach (DataRow drServer in dsServers.Tables[0].Rows)
                            {
                                int    intAsset = Int32.Parse(drServer["assetid"].ToString());
                                string strName  = lblName.Text;
                                if (drServer["dr"].ToString() == "1")
                                {
                                    strName += "-DR";
                                }
                                // Update Recommission Reason
                                oAsset.UpdateDecommissionRecommission(intAsset, intUser, txtReason.Text);
                                // Set status to InUse
                                oAsset.AddStatus(intAsset, strName, (int)AssetStatus.InUse, intUser, DateTime.Now);
                                // Clear cv_servers_assets DECOM field
                                oServer.UpdateAssetDecom(intServer, intAsset, "");
                                if (boolComplete == true)
                                {
                                    DataSet dsOrders = oAssetOrder.GetByAsset(intAsset, false);
                                    foreach (DataRow drOrders in dsOrders.Tables[0].Rows)
                                    {
                                        int intOrder = Int32.Parse(drOrders["orderid"].ToString());
                                        // Cancel Resource Requests
                                        int intResource = 0;
                                        if (Int32.TryParse(drOrders["resourceid"].ToString(), out intResource) == true)
                                        {
                                            oResourceRequest.UpdateStatusOverallWorkflow(intResource, (int)ResourceRequestStatus.Cancelled);
                                        }
                                        // Delete Order
                                        oAssetOrder.DeleteOrder(intOrder);
                                        // Delete Asset Order Asset Selection
                                        oAssetOrder.DeleteAssetOrderAssetSelection(intOrder, intAsset);
                                    }
                                    // Set NewOrderID = 0
                                    oAsset.updateNewOrderId(0, intAsset);
                                }
                                // Set strAssets to assets recommissioned (for status message on postback)
                                if (strAssets != "")
                                {
                                    strAssets += strSplit[0].ToString();
                                }
                                strAssets += intAsset.ToString();
                            }
                            // Remove previous decom records
                            if (boolComplete == true)
                            {
                                bool boolPNC = (oServer.Get(intServer, "pnc") == "1");
                                // Update Server Name Record
                                int intName = Int32.Parse(oServer.Get(intServer, "nameid"));
                                if (boolPNC)
                                {
                                    oServerName.UpdateFactory(intName, 0);
                                }
                                else
                                {
                                    oServerName.Update(intName, 0);
                                }
                            }
                            // Clear cv_servers DECOM field
                            oServer.UpdateDecommissioned(intServer, "");
                            // Update IP Address(es) availability
                            DataSet dsIP = oServer.GetIP(intServer, 0, 0, 0, 0);
                            foreach (DataRow drIP in dsIP.Tables[0].Rows)
                            {
                                int intIP = Int32.Parse(drIP["ipaddressid"].ToString());
                                oIPAddresses.UpdateAvailable(intIP, 0);
                            }
                            // Restore Avamar Group(s)
                            if (chkAvamar.Checked)
                            {
                                Avamar                       oAvamar             = new Avamar(0, dsn);
                                AvamarRegistration           oAvamarRegistration = new AvamarRegistration(0, dsn);
                                ClearViewWebServices         oWebService         = new ClearViewWebServices();
                                System.Net.NetworkCredential oCredentialsDNS     = new System.Net.NetworkCredential(oVariable.ADUser(), oVariable.ADPassword(), oVariable.Domain());
                                oWebService.Credentials = oCredentialsDNS;
                                oWebService.Url         = oVariable.WebServiceURL();
                                string strError = "";

                                // First, query for groups.
                                DataSet dsGroups = oAvamar.GetDecoms(lblName.Text);
                                if (dsGroups.Tables[0].Rows.Count > 0)
                                {
                                    string client = dsGroups.Tables[0].Rows[0]["client"].ToString();
                                    string grid   = dsGroups.Tables[0].Rows[0]["grid"].ToString();
                                    string domain = dsGroups.Tables[0].Rows[0]["domain"].ToString();
                                    // Second, add the groups.
                                    foreach (DataRow drGroup in dsGroups.Tables[0].Rows)
                                    {
                                        if (String.IsNullOrEmpty(strError) == false)
                                        {
                                            break;
                                        }
                                        AvamarReturnType restore = oAvamarRegistration.API(oWebService.AddAvamarGroup(grid, domain, client, drGroup["group"].ToString()));
                                        if (restore.Error == true)
                                        {
                                            strError = restore.Message;
                                        }
                                    }
                                    // Third, remove the /Decom group
                                    AvamarReturnType decom = oAvamarRegistration.API(oWebService.DeleteAvamarGroup(grid, domain, client, oAvamar.DecomGroup));
                                    if (decom.Error == false)
                                    {
                                        // Fourth, recommission the saved decom groups.
                                        oAvamar.UpdateDecom(client);
                                    }
                                    else
                                    {
                                        strError = decom.Message;
                                    }
                                }
                                if (String.IsNullOrEmpty(strError))
                                {
                                    oLog.AddEvent(lblName.Text, lblSerial.Text, "RECOMMISSION: Avamar completed.", LoggingType.Information);
                                }
                                else
                                {
                                    oLog.AddEvent(lblName.Text, lblSerial.Text, "RECOMMISSION: Avamar encountered an error = " + strError, LoggingType.Error);
                                }
                            }
                            // Add log entry
                            oLog.AddEvent(lblName.Text, lblSerial.Text, "Asset Recommissioned (Client = " + oUser.GetFullName(intUser) + ")", LoggingType.Information);
                        }
                        else
                        {
                            // Manual recommission - just delete the resource request to get out of the person's queue
                            int intResource = Int32.Parse(chkDevice.ToolTip.Substring(1));
                            oResourceRequest.UpdateStatusOverall(intResource, -2);
                        }
                    }
                }
            }
            Response.Redirect(Request.Path + "?assets=" + strAssets);
        }
Ejemplo n.º 7
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 8
0
        protected void btnDecom_Click(object sender, EventArgs e)
        {
            Variables oVariable = new Variables((int)CurrentEnvironment.PNCNT_DEV);
            string    grid      = "yb19-avr01-01.test.pncbank.com";
            string    domain    = "/BRII";
            string    client    = "WDCLV015A.pncbank.com";
            string    strError  = "";


            Avamar               oAvamar             = new Avamar(0, dsn);
            AvamarRegistration   oAvamarRegistration = new AvamarRegistration(0, dsn);
            ClearViewWebServices oWebService         = new ClearViewWebServices();

            System.Net.NetworkCredential oCredentialsDNS = new System.Net.NetworkCredential(oVariable.ADUser(), oVariable.ADPassword(), oVariable.Domain());
            oWebService.Credentials = oCredentialsDNS;
            oWebService.Url         = oVariable.WebServiceURL();

            // First, query for groups.
            AvamarReturnType groups = oAvamarRegistration.API(oWebService.GetAvamarClient(grid, domain, client));

            if (groups.Error == false)
            {
                List <string> members = new List <string>();
                foreach (XmlNode node in groups.Nodes)
                {
                    if (node["Attribute"].InnerText == "Member of Group")
                    {
                        members.Add(node["Value"].InnerText);
                    }
                }

                if (members.Count > 0)
                {
                    // Second, add /Decom group (so there will always be at least one group)
                    AvamarReturnType decom = oAvamarRegistration.API(oWebService.AddAvamarGroup(grid, domain, client, oAvamar.DecomGroup));
                    if (decom.Error == false)
                    {
                        oAvamar.DeleteDecom(client);
                        foreach (string member in members)
                        {
                            if (String.IsNullOrEmpty(strError) == false)
                            {
                                break;
                            }
                            // Third, remove groups (one at a time)
                            AvamarReturnType remove = oAvamarRegistration.API(oWebService.DeleteAvamarGroup(grid, domain, client, member));
                            if (remove.Error == false)
                            {
                                // Fourth, save groups.
                                oAvamar.AddDecom(client, grid, domain, member);
                            }
                            else
                            {
                                strError = remove.Message;
                            }
                        }
                    }
                    else
                    {
                        strError = decom.Message;
                    }
                }
            }
            else
            {
                strError = groups.Message;
            }
        }