Example #1
0
        public async Task <IOrderedEnumerable <Event> > GetEvents(string triggerId, uint?limit, EventSortField sortBy, Select selectHosts, Select selectTriggers)
        {
            ParamsRequestBody <GetEventsParams> requestBody =
                RequestBodyBuilder.Build(new GetEventsParams
            {
                TriggerId = triggerId,
                Limit     = limit,
                SortBy    = new[] { sortBy.ToDescriptionString() },
                Order     = SortOrderField.Desc.ToDescriptionString(),
                Filter    = new Filter {
                    Value = new[] { 0, 1 }, Object = new[] { 0 }
                },
                SelectHosts    = selectHosts == Select.None ? Query.None : Query.Extend,
                SelectTriggers = selectTriggers == Select.None ? Query.None : Query.Extend,
                Output         = new Query {
                    Value = QueryValues.Extend
                }
            });

            ResultResponseBody <IEnumerable <GetEventsResult> > responceBody = await WebChannel.GetResponseAsync
                                                                               <ParamsRequestBody <GetEventsParams>, ResultResponseBody <IEnumerable <GetEventsResult> > >(requestBody);

            if (responceBody.Error != null)
            {
                throw new WebServiceException(responceBody.Error.Code,
                                              responceBody.Error.Message);
            }

            // Where(t => t.Object == 0) use only triggers
            return(responceBody.Result.Where(t => t.Object == 0).Select(t => t.ToEvent()).Where(e => e != null).OrderByDescending(e => e.Time));
        }
Example #2
0
        public async Task <string> LoginAsync(string userName, string password)
        {
            if (userName == null)
            {
                throw new ArgumentNullException("userName");
            }

            if (password == null)
            {
                throw new ArgumentNullException("password");
            }

            var loginParams = new LoginParams {
                Login = userName, Password = password
            };
            ParamsRequestBody <LoginParams> loginRequestBody  = RequestBodyBuilder.Build(loginParams);
            ResultResponseBody <string>     loginResponseBody = await WebChannel.GetResponseAsync <ParamsRequestBody <LoginParams>, ResultResponseBody <string> >(loginRequestBody);

            if (loginResponseBody.Error != null)
            {
                throw new AuthorizationException(loginResponseBody.Error.Code, loginResponseBody.Error.Message);
            }

            return(loginResponseBody.Result);
        }
        public async Task <IList <Graph> > GetGraphsAsync(string groupId, string hostId)
        {
            ParamsRequestBody <GetGraphsParams> requestBody =
                RequestBodyBuilder.Build(new GetGraphsParams
            {
                GroupId = groupId,
                HostId  = hostId,
                Output  = new Query {
                    Params = new List <string> {
                        "name"
                    }
                }
            });

            ResultResponseBody <IList <GetGraphsResult> > responceBody = await WebChannel.GetResponseAsync
                                                                         <ParamsRequestBody <GetGraphsParams>, ResultResponseBody <IList <GetGraphsResult> > >(requestBody);

            if (responceBody.Error != null)
            {
                throw new WebServiceException(responceBody.Error.Code,
                                              responceBody.Error.Message);
            }

            return(responceBody.Result.Select(t => t.ToGraph()).Where(g => g != null).ToList());
        }
        public async Task <IEnumerable <Host> > GetHostsAsync(string hostGroupId, HostSortField[] sortFields, string[] hostIds = null)
        {
            ParamsRequestBody <GetHostsParams> requestBody =
                RequestBodyBuilder.Build(new GetHostsParams()
            {
                GroupId = hostGroupId,
                SortBy  = sortFields != null ? sortFields.Select(sortField => sortField.ToDescriptionString()).ToArray() : null,
                Output  = new Query {
                    Params = new List <string> {
                        "name"
                    }
                },
                HostIds = hostIds
            });

            ResultResponseBody <IEnumerable <GetHostsResult> > responceBody = await WebChannel.GetResponseAsync
                                                                              <ParamsRequestBody <GetHostsParams>, ResultResponseBody <IEnumerable <GetHostsResult> > >(requestBody);

            if (responceBody.Error != null)
            {
                throw new WebServiceException(responceBody.Error.Code,
                                              responceBody.Error.Message);
            }

            return(responceBody.Result.Select(t => t.ToHost()).Where(h => h != null).ToList());
        }
        public async Task <IEnumerable <HostGroup> > GetHostGroups(HostGroupsSortField[] sortFields, uint?limit)
        {
            ParamsRequestBody <GetHostGroupsParams> getHostGroupsRequestBody =
                RequestBodyBuilder.Build(new GetHostGroupsParams
            {
                SortBy         = sortFields != null ? sortFields.Select(sortField => sortField.ToDescriptionString()).ToArray() : null,
                Limit          = limit,
                MonitoredHosts = true,
                Output         = new Query {
                    Params = new List <string> {
                        "name"
                    }
                }
            });

            ResultResponseBody <IEnumerable <GetHostGroupsResult> > getHostGroupsResponseBody =
                await WebChannel.GetResponseAsync
                <ParamsRequestBody <GetHostGroupsParams>, ResultResponseBody <IEnumerable <GetHostGroupsResult> > >
                    (getHostGroupsRequestBody);

            if (getHostGroupsResponseBody.Error != null)
            {
                throw new WebServiceException(getHostGroupsResponseBody.Error.Code,
                                              getHostGroupsResponseBody.Error.Message);
            }

            return(getHostGroupsResponseBody.Result.Select(hostGroupResult => hostGroupResult.ToHostGroup()).Where(h => h != null).ToList());
        }
Example #6
0
        public async Task <bool> LogoutAsync()
        {
            ParamsRequestBody <LogoutParams> logoutRequestBody = RequestBodyBuilder.Build(new LogoutParams());

            ResultResponseBody <bool> logoutResponseBody =
                await WebChannel.GetResponseAsync <ParamsRequestBody <LogoutParams>, ResultResponseBody <bool> >(logoutRequestBody);

            if (logoutResponseBody.Error != null)
            {
                throw new WebServiceException(logoutResponseBody.Error.Code, logoutResponseBody.Error.Message);
            }

            return(logoutResponseBody.Result);
        }
Example #7
0
        public async Task <IList <Item> > GetItemsAsync(string groupId, string hostId)
        {
            var requestBody = RequestBodyBuilder.Build(new GetDataParams
            {
                GroupId           = groupId,
                HostId            = hostId,
                Output            = Query.Extend,
                ExpandDescription = true,
                Monitored         = true,
                SortField         = "description"
            });

            var responceBody = await WebChannel.GetResponseAsync
                               <ParamsRequestBody <GetDataParams>, ResultResponseBody <IList <GetDataResult> > >(requestBody);

            if (responceBody.Error != null)
            {
                throw new WebServiceException(responceBody.Error.Code,
                                              responceBody.Error.Message);
            }

            return(responceBody.Result.Select(t => t.ToItem()).Where(g => g != null).ToList());
        }
Example #8
0
        public async Task <IEnumerable <Trigger> > GetTriggers(string hostId, uint?limit, TriggersSortField[] sortFields, Select selectHosts, IList <string> triggerIds = null)
        {
            ParamsRequestBody <GetTriggersParams> requestBody =
                RequestBodyBuilder.Build(new GetTriggersParams()
            {
                TriggerIds        = triggerIds,
                HostId            = hostId,
                Limit             = limit,
                ActiveOnly        = true,
                SelectHosts       = selectHosts == Select.None ? Query.None : Query.Extend,
                SortBy            = sortFields != null ? sortFields.Select(field => field.ToDescriptionString()).ToArray() : null,
                ExpandDescription = true,
                Output            = new Query {
                    Params = new List <string> {
                        "description", "priority", "value"
                    }
                }
            });

            ResultResponseBody <IEnumerable <GetTriggersResult> > responceBody = await WebChannel.GetResponseAsync
                                                                                 <ParamsRequestBody <GetTriggersParams>, ResultResponseBody <IEnumerable <GetTriggersResult> > >(requestBody);

            if (responceBody.Error != null)
            {
                throw new WebServiceException(responceBody.Error.Code,
                                              responceBody.Error.Message);
            }

            return(responceBody.Result.Select(t => t.ToTrigger()).Where(t => t != null).ToList());
        }