示例#1
0
        public IHttpActionResult LogLijstOvm(string id)
        {
            List <LogModel>      model     = new List <LogModel>();
            List <LogLijst>      logs      = mgr.GetLogLijstsOVM(id).ToList();
            var                  orderLogs = logs.OrderByDescending(l => l.ActionDate);
            OracleVirtualMachine ovm       = mgr.GetOVMById(id);
            Admin                admin     = admgr.GetAdmin();

            if (logs.Count() != 0)
            {
                if (logs.Count() >= 10)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        Gebruiker user     = userManager.GetGebruiker(orderLogs.ElementAt(i).GebruikerId);
                        LogModel  logmodel = new LogModel();
                        logmodel.Naam       = orderLogs.ElementAt(i).Naam;
                        logmodel.ActionDate = orderLogs.ElementAt(i).ActionDate;
                        try
                        {
                            logmodel.Gebruiker = user.Email;
                            model.Add(logmodel);
                        }
                        catch
                        {
                        }
                    }
                }
                if (logs.Count() < 10)
                {
                    for (int i = 0; i < logs.Count(); i++)
                    {
                        Gebruiker user     = userManager.GetGebruiker(orderLogs.ElementAt(i).GebruikerId);
                        LogModel  logmodel = new LogModel();
                        logmodel.Naam       = orderLogs.ElementAt(i).Naam;
                        logmodel.ActionDate = orderLogs.ElementAt(i).ActionDate;
                        logmodel.Gebruiker  = user.Email;
                        //if (admin.Email == User.Identity.Name)
                        //{
                        //    model.Add(logmodel);
                        //}
                        //else
                        //{
                        //if (!logmodel.Gebruiker.Equals(admin.Email))
                        // {
                        model.Add(logmodel);
                        //}
                        //}
                    }
                }
            }
            if (!model.Any())
            {
                return(Ok(false));
            }
            else
            {
                return(Ok(model));
            }
        }
示例#2
0
        public IHttpActionResult AccountOVMs(List <VmModel> model)
        {
            model = new List <VmModel>();
            List <OracleVirtualMachine> ovms = new List <OracleVirtualMachine>();
            Klant           k       = klantmgr.GetKlant(User.Identity.GetUserName());
            List <OVMLijst> lijsten = mgr.GetLijstAccount(k.KlantId).ToList();

            for (int i = 0; i < lijsten.Count(); i++)
            {
                OracleVirtualMachine ovm = mgr.GetOVMById(lijsten[i].OVMId);
                ovms.Add(ovm);
            }
            foreach (OracleVirtualMachine vm in ovms)
            {
                VmModel vmModel = new VmModel();
                vmModel.Name = vm.Naam;
                vmModel.id   = vm.OvmId;
                model.Add(vmModel);
            }
            if (!model.Any())
            {
                return(Ok(false));
            }
            else
            {
                return(Ok(model));
            }
        }
示例#3
0
        public string[] GetInfo(string vmId, SshClient ssh, string[] vmInfo2)
        {
            vmInfo2 = new string[8];
            string[] vmLines;
            ssh.Connect();
            var commandResult = ssh.RunCommand("show vm id=" + "'" + vmId + "'");

            ssh.Disconnect();
            vmLines = commandResult.Result.Split('\n');
            int j = 1;

            vmInfo2[0] = vmId;
            for (int i = 0; i < vmLines.Length; i++)
            {
                if (vmLines[i].Contains("Data:") ||
                    vmLines[i].Contains("Status =") ||
                    vmLines[i].Contains("Memory") || vmLines[i].Contains("Processors"))
                {
                    vmInfo2[j] = vmLines[i];
                    j++;
                }
            }
            OracleVirtualMachine vm = mgr.GetOVMById(vmId);

            if (vm.KlantId == 0)
            {
                vmInfo2[7] = "NULL";
            }
            else
            {
                vmInfo2[7] = Convert.ToString(klantmgr.GetKlant(vm.KlantId).Naam);
            }
            return(vmInfo2);
        }
示例#4
0
        //Deze methode updatet een Oracle Virtueel Machine.
        public void UpdateMachine(OracleVirtualMachine ovm)
        {
            OracleVirtualMachine ovM = ctx.OracleVirtualMachines.Find(ovm.OracleVirtualMachineId);

            ctx.Entry(ovM).CurrentValues.SetValues(ovm);
            ctx.Entry(ovM).State = System.Data.Entity.EntityState.Modified;
            ctx.SaveChanges();
        }
示例#5
0
        public IHttpActionResult LogLijstUser(List <LogModel> model)
        {
            List <LogModel> OrderModel = new List <LogModel>();

            model = new List <LogModel>();
            Gebruiker       user = userManager.GetGebruiker(User.Identity.GetUserName());
            List <LogLijst> logs = mgr.GetLogLijstsKlant(user.GebruikerId).ToList();

            if (logs.Count() != 0)
            {
                if (logs.Count() >= 10)
                {
                    for (int i = 0; i < 10; i++)
                    {
                        OracleVirtualMachine ovm      = mgr.GetOVMById(logs[i].OvmId);
                        LogModel             logmodel = new LogModel();
                        logmodel.Gebruiker  = user.Email;
                        logmodel.Naam       = logs[i].Naam;
                        logmodel.ActionDate = logs[i].ActionDate;
                        logmodel.Ovm        = ovm.Naam;
                        model.Add(logmodel);
                    }
                }
                else
                {
                    if (logs.Count() < 10)
                    {
                        for (int i = 0; i < logs.Count(); i++)
                        {
                            OracleVirtualMachine ovm      = mgr.GetOVMById(logs[i].OvmId);
                            LogModel             logmodel = new LogModel();
                            logmodel.Gebruiker  = user.Email;
                            logmodel.Naam       = logs[i].Naam;
                            logmodel.ActionDate = logs[i].ActionDate;
                            logmodel.Ovm        = ovm.Naam;
                            model.Add(logmodel);
                        }
                    }
                }
            }
            if (!model.Any())
            {
                return(Ok(false));
            }
            else
            {
                OrderModel = model.OrderByDescending(o => o.ActionDate).ToList();;
                return(Ok(OrderModel));
            }
        }
示例#6
0
        //Voegt een Oracle Virtual Machine toe.
        public OracleVirtualMachine AddOVM(string naam, string ovmId, int klantId, int serverId)
        {
            //Hier wordt een nieuwe Oracle Virtueel Machine aangemaakt.
            OracleVirtualMachine ovm = new OracleVirtualMachine()
            {
                Naam     = naam,
                OvmId    = ovmId,
                KlantId  = klantId,
                ServerId = serverId
            };
            //deze wordt hier aangemaakt in onze SSHRepsoitory.
            OracleVirtualMachine created = repo.AddMachine(ovm);

            return(created);
        }
示例#7
0
        public IHttpActionResult SetKlantOVM(string id, string k)
        {
            List <OVMLijst> lijsten = mgr.GetLijstOvm(id).ToList();

            if (lijsten != null)
            {
                mgr.RemoveLijstenOvm(id);
            }
            OracleVirtualMachine ovm = mgr.GetOVMById(id);
            Klant klant = klantmgr.GetKlantByName(k);

            if (klant == null)
            {
                klant = klantmgr.GetKlant(k);
            }
            ovm.KlantId = klant.KlantId;
            mgr.ChangeOVM(ovm);
            return(Ok(ovm.OvmId));
        }
示例#8
0
        public IHttpActionResult PushDowntime(string id, int duur)
        {
            DateTime             start_time = DateTime.Now;
            DateTime             end_time   = DateTime.Now.AddMinutes(duur);
            Gebruiker            user       = userManager.GetGebruiker(User.Identity.GetUserName());
            OracleVirtualMachine ovm        = mgr.GetOVMById(id);
            var client  = new RestClient("https://api.monitoring.be/command/prod/op5command");
            var request = new RestRequest(Method.POST);

            request.AddHeader("x-api-key", "ZCeD4fSfqR8GeEJU4jGv43muowCGTybIabBVTpcK");
            request.AddHeader("content-type", "application/json");
            request.AddParameter("application/json", "{\"$\":[{\n \"method\": \"POST\"" +
                                 ",\n \"endpoint\": \"command/SCHEDULE_HOST_DOWNTIME\",\n \"data\": {\n  \"host_name\"" +
                                 ": \"TEST-" + ovm.Naam + "\",\n  \"start_time\":" + start_time + ",\n  \"end_time\":" + end_time +
                                 ",\n\t\"fixed\": true,\n  \"comment\": \"MONIN-PORTAL: automatic downtime for "
                                 + ovm.Naam + " by " + user.Naam +
                                 "\",\n\t\"trigger_id\": 0,\n\t\"duration\": \"none\"\n\t}\n}]\n}", ParameterType.RequestBody);
            IRestResponse response = client.Execute(request);

            return(Ok());
        }
示例#9
0
        //Deze Methode haalt een Oracle Virtueel Machine uit de databank op aan de hand van de Oracle Virtueel Machine id.
        public OracleVirtualMachine GetMachineById(string id)
        {
            OracleVirtualMachine ovm = ctx.OracleVirtualMachines.Where(o => o.OvmId.Contains(id)).FirstOrDefault();

            return(ovm);
        }
示例#10
0
        //Deze Methode haalt een Oracle Virtueel Machine uit de databank op aan de hand van een id.
        public OracleVirtualMachine GetMachine(int id)
        {
            OracleVirtualMachine ovm = ctx.OracleVirtualMachines.Find(id);

            return(ovm);
        }
示例#11
0
 //Deze Methode verwijdert een Oracle Virtueel Machine uit de databank.
 public void DeleteMachine(OracleVirtualMachine ovm)
 {
     ctx.OracleVirtualMachines.Remove(ovm);
     ctx.SaveChanges();
 }
示例#12
0
 //Deze Methode voegt een Oracle Virtueel Machine toe aan de databank.
 public OracleVirtualMachine AddMachine(OracleVirtualMachine ovm)
 {
     ctx.OracleVirtualMachines.Add(ovm);
     ctx.SaveChanges();
     return(ovm);
 }
示例#13
0
 //Deze methode verandert een Oracle Virtueel machine
 public void ChangeOVM(OracleVirtualMachine ovm)
 {
     repo.UpdateMachine(ovm);
 }
示例#14
0
        //Deze methode verwijderd een Oracle Virtueel Machine.
        public void RemoveOVM(string id)
        {
            OracleVirtualMachine ovm = repo.GetMachineById(id);

            repo.DeleteMachine(ovm);
        }
示例#15
0
        public IHttpActionResult LogLijstKlant(List <LogModel> model, int id)
        {
            List <LogModel> OrderModel = new List <LogModel>();

            model = new List <LogModel>();
            Klant k = klantmgr.GetKlant(id);

            if (k.IsKlantAccount == false)
            {
                var          logs        = mgr.GetLogLijstsKlant(id).ToList();;
                var          orderLogs   = logs.OrderByDescending(l => l.ActionDate);
                List <Klant> medewerkers = klantmgr.GetKlantenAccounts(k).ToList();
                if (logs.Count() != 0)
                {
                    if (logs.Count() >= 10)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            OracleVirtualMachine ovm      = mgr.GetOVMById(logs[i].OvmId);
                            LogModel             logmodel = new LogModel();
                            logmodel.Naam       = orderLogs.ElementAt(i).Naam;
                            logmodel.ActionDate = orderLogs.ElementAt(i).ActionDate;
                            logmodel.Ovm        = ovm.Naam;
                            logmodel.Gebruiker  = k.Email;
                            model.Add(logmodel);
                        }
                    }
                    else
                    {
                        for (int i = 0; i < logs.Count(); i++)
                        {
                            OracleVirtualMachine ovm      = mgr.GetOVMById(logs[i].OvmId);
                            LogModel             logmodel = new LogModel();
                            logmodel.Naam       = orderLogs.ElementAt(i).Naam;
                            logmodel.ActionDate = orderLogs.ElementAt(i).ActionDate;
                            logmodel.Ovm        = ovm.Naam;
                            logmodel.Gebruiker  = k.Email;
                            model.Add(logmodel);
                        }
                    }
                    for (int i = 0; i < medewerkers.Count(); i++)
                    {
                        List <LogLijst> logsM      = mgr.GetLogLijstsKlant(medewerkers[i].KlantId).ToList();
                        var             orderLogsM = logsM.OrderByDescending(l => l.ActionDate);
                        for (int j = 0; j < logsM.Count(); j++)
                        {
                            OracleVirtualMachine ovm      = mgr.GetOVMById(logsM[j].OvmId);
                            LogModel             logmodel = new LogModel();
                            logmodel.Naam       = orderLogsM.ElementAt(j).Naam;
                            logmodel.ActionDate = orderLogsM.ElementAt(j).ActionDate;
                            logmodel.Ovm        = ovm.Naam;
                            logmodel.Gebruiker  = medewerkers[i].Email;
                            model.Add(logmodel);
                        }
                    }
                }
            }
            else
            {
                List <LogLijst> logs      = mgr.GetLogLijstsKlant(id).ToList();
                var             orderLogs = logs.OrderByDescending(l => l.ActionDate);
                if (logs.Count() != 0)
                {
                    if (logs.Count() >= 10)
                    {
                        for (int i = 0; i < 10; i++)
                        {
                            OracleVirtualMachine ovm      = mgr.GetOVMById(logs[i].OvmId);
                            LogModel             logmodel = new LogModel();
                            logmodel.Naam       = orderLogs.ElementAt(i).Naam;
                            logmodel.ActionDate = orderLogs.ElementAt(i).ActionDate;
                            logmodel.Ovm        = ovm.Naam;
                            logmodel.Gebruiker  = k.Email;
                            model.Add(logmodel);
                        }
                    }
                    if (logs.Count() < 10)
                    {
                        for (int i = 0; i < logs.Count(); i++)
                        {
                            OracleVirtualMachine ovm      = mgr.GetOVMById(logs[i].OvmId);
                            LogModel             logmodel = new LogModel();
                            logmodel.Naam       = orderLogs.ElementAt(i).Naam;
                            logmodel.ActionDate = orderLogs.ElementAt(i).ActionDate;
                            logmodel.Ovm        = ovm.Naam;
                            logmodel.Gebruiker  = k.Email;
                            model.Add(logmodel);
                        }
                    }
                }
            }
            OrderModel = model.OrderByDescending(m => m.ActionDate).ToList();
            if (!OrderModel.Any())
            {
                return(Ok(false));
            }
            else
            {
                OrderModel = model.OrderByDescending(m => m.ActionDate).ToList();
                try
                {
                    OrderModel.RemoveRange(9, OrderModel.Count() - 10);
                    return(Ok(OrderModel));
                }
                catch
                {
                    return(Ok(OrderModel));
                }
            }
        }
示例#16
0
        public IHttpActionResult checkForVms()
        {
            List <OracleVirtualMachine> serverVms = new List <OracleVirtualMachine>();

            string[]                    ResultLines;
            IEnumerable <Server>        serverlist     = sshmgr.GetServers();
            List <OracleVirtualMachine> OrderServerVms = new List <OracleVirtualMachine>();

            using (ssh)
            {
                for (int i = 0; i < serverlist.Count(); i++)
                {
                    ssh.Connect();
                    var ServerResult = ssh.RunCommand("show Server name="
                                                      + serverlist.ElementAt(i).ServerNaam);
                    ResultLines = ServerResult.Result.Split('\n');
                    ssh.Disconnect();


                    string patternVM = @"Vm [0-9]+";

                    for (int j = 0; j < ResultLines.Length; j++)
                    {
                        OracleVirtualMachine vm = new OracleVirtualMachine();
                        var resId = Regex.Match(ResultLines[j], patternVM);
                        if (resId.Length != 0)
                        {
                            string name = ResultLines[j].Substring(ResultLines[j].IndexOf("[") + 1
                                                                   , ResultLines[j].IndexOf("]") - ResultLines[j].IndexOf("[") - 1);
                            string id = ResultLines[j].Substring(ResultLines[j].IndexOf("=") + 1
                                                                 , (ResultLines[j].IndexOf("[")) - ResultLines[j].IndexOf("=") - 1).Trim();
                            vm.OvmId    = id;
                            vm.Naam     = name;
                            vm.KlantId  = 0;
                            vm.ServerId = serverlist.ElementAt(i).Id;
                            serverVms.Add(vm);
                        }
                    }
                }
            }
            List <OracleVirtualMachine> ovms = new List <OracleVirtualMachine>();

            ovms = mgr.GetOVMs().ToList();
            List <OracleVirtualMachine> orderDbVms = new List <OracleVirtualMachine>();
            List <string> databaseId = new List <string>();
            List <string> serverId   = new List <string>();

            orderDbVms     = ovms.OrderBy(o => o.OvmId).ToList();
            OrderServerVms = serverVms.OrderBy(o => o.OvmId).ToList();

            for (int i = 0; i < orderDbVms.Count(); i++)
            {
                databaseId.Add(orderDbVms[i].OvmId);
            }
            for (int i = 0; i < OrderServerVms.Count(); i++)
            {
                serverId.Add(OrderServerVms[i].OvmId);
            }

            for (int i = 0; i < OrderServerVms.Count(); i++)
            {
                if (!databaseId.Contains(OrderServerVms[i].OvmId))
                {
                    mgr.AddOVM(OrderServerVms[i].Naam,
                               OrderServerVms[i].OvmId, 0, OrderServerVms[i].ServerId);
                    orderDbVms.Add(OrderServerVms[i]);
                }
            }
            for (int i = 0; i < orderDbVms.Count(); i++)
            {
                if (!serverId.Contains(orderDbVms[i].OvmId))
                {
                    mgr.RemoveOVM(orderDbVms[i].OvmId);
                    orderDbVms.Remove(orderDbVms[i]);
                }
            }
            return(Ok(orderDbVms));
        }