示例#1
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()}")); }
        }
示例#2
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);
            }
        }
示例#3
0
        public static MIBObject Parse(MIBObjectDto mibObjectDto)
        {
            if (mibObjectDto != null)
            {
                return new MIBObject
                       {
                           OID   = mibObjectDto.Oid,
                           Type  = mibObjectDto.Type,
                           Value = mibObjectDto.Value
                       }
            }
            ;

            return(new MIBObject
            {
                OID = "",
                Type = "",
                Value = ""
            });
        }
示例#4
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);
            }
        }