Ejemplo n.º 1
0
        public async Task <IActionResult> OnPostGETAsync()
        {
            await LoadRSUData(snmpGETModel.ManagerId, snmpGETModel.RsuId);

            if (string.IsNullOrEmpty(snmpGETModel.OID))
            {
                return(Page());
            }

            var user = await _applicationDbContext.Users
                       .Include(u => u.UserManagerUsers)
                       .FirstOrDefaultAsync(u => u.UserName == HttpContext.User.Identity.Name);

            var manager = await _applicationDbContext.Managers
                          .Include(m => m.Users)
                          .FirstOrDefaultAsync(m => m.Id == snmpGETModel.ManagerId);

            if (manager == null)
            {
                NotFound($"No manager with id: {snmpGETModel.ManagerId}");
            }
            var manageruser = user.UserManagerUsers.FirstOrDefault(umu => umu.ManagerUserManagerId == manager.Id)?.ManagerUser;

            MIBObject mibo = await _snmpService.GetAsync(manageruser, snmpGETModel.RsuId, snmpGETModel.OID);

            snmpGETModel.Type  = mibo.Type;
            snmpGETModel.Value = mibo.Value;
            ResetSetModel();

            return(Page());
        }
Ejemplo n.º 2
0
        private object SetData(ManagerUser manageruser, int rsuId, string OID)
        {
            MIBObject mibo = _snmpService.GetAsync(manageruser, rsuId, OID).Result;

            if (mibo != null)
            {
                if (mibo.Value.Equals("Timeout"))
                {
                    return(null);
                }

                if (mibo.Type == "Integer32" || mibo.Type == "Counter32" || mibo.Type == "Integer")
                {
                    int value = (int.TryParse(mibo.Value, out value)) ? value : 0;
                    return(value);
                }

                /*else if (data is double)
                 * {
                 *  double value = (double.TryParse(mibo.Value, out value)) ? value / 1000000 : 0.0;
                 *  return value;
                 * }*/
                else if (mibo.Type == "OctetString")
                {
                    return(mibo.Value);
                }
            }

            return(null);
        }
Ejemplo n.º 3
0
        public IActionResult Set(string username, string token, int rsuid, [FromBody] MIBObjectDto mibObject)
        {
            var securityProblem = AuthenticateAuthorize(username, token);

            if (securityProblem != null)
            {
                return(securityProblem);
            }

            var user = _contextService.GetUser(username);

            var rsu = _contextService.GetRSU(rsuid);

            if (rsu == null)
            {
                return(NotFound($"RSU with id {rsuid} not found!"));
            }

            MIBObject mibo = new MIBObject(mibObject.Oid, mibObject.Type, mibObject.Value);

            try
            {
                if (_snmpManagerService.Set(rsu, user, mibo.OID, mibo.Type, mibo.Value))
                {
                    return(Ok());
                }
                else
                {
                    return(StatusCode(500));
                }
            }
            catch (ReplyIsReportMessage) { return(NotFound()); }
            catch (InvalidDataType) { return(BadRequest("Invalid data type")); }
            catch (FormatException) { return(BadRequest($"Invalid value for type {mibObject.Type.ToString()}")); }
        }
Ejemplo n.º 4
0
        public async Task <MIBObject> GetAsync(ManagerUser managerUser, int rsuId, string oid)
        {
            var host = GetHost(managerUser);

            try
            {
                var result = await _httpClinet.GetStringAsync($"http://{host}:{managerUser.Manager.Port}/{controller}/{managerUser.Name}/{managerUser.Token}/{rsuId}/{oid}");

                var mibo = MIBObjectDto.FromJsonCollection(result);

                return(MIBObject.Parse(mibo.FirstOrDefault()));
            }
            catch (HttpRequestException ex)
            {
                return(null);
            }
        }
Ejemplo n.º 5
0
        public async Task <bool> SetAsync(ManagerUser managerUser, int rsuId, MIBObject mibo)
        {
            var host = GetHost(managerUser);

            MIBObjectDto miboDto = mibo.ConvertToDTO();

            try
            {
                var result = await _httpClinet.PostAsJsonAsync($"http://{host}:{managerUser.Manager.Port}/{controller}/{managerUser.Name}/{managerUser.Token}/{rsuId}", miboDto);

                if (result.IsSuccessStatusCode)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (HttpRequestException ex)
            {
                return(false);
            }
        }