Exemplo n.º 1
0
        public async void GetSingleSignOnData()
        {
            var allOpsNotes = await PortalClient.GetAsync <SingleSignOn>().ConfigureAwait(false);

            // Text should be set
            Assert.NotEmpty(allOpsNotes.SamlVersion);
        }
Exemplo n.º 2
0
        public async void CreateUpdateDelete()
        {
            // Ensure there is no existing UserGroup called "Test"
            var existingUserGroup = (await PortalClient
                                     .GetAllAsync(new Filter <UserGroup> {
                FilterItems = new List <FilterItem <UserGroup> > {
                    new Eq <UserGroup>(nameof(UserGroup.Name), Value)
                }
            })
                                     .ConfigureAwait(false))
                                    .SingleOrDefault();

            if (existingUserGroup != null)
            {
                await PortalClient.DeleteAsync(existingUserGroup).ConfigureAwait(false);
            }

            var userGroup = await PortalClient.CreateAsync(new UserGroupCreationDto
            {
                Name        = Value,
                Description = "Desc",
            }).ConfigureAwait(false);

            // Refetch
            var refetch = await PortalClient.GetAsync <UserGroup>(userGroup.Id).ConfigureAwait(false);

            Assert.NotNull(refetch);

            // Delete
            await PortalClient.DeleteAsync(userGroup).ConfigureAwait(false);
        }
        public async void Get()
        {
            var accountSettings = await PortalClient.GetAsync <AccountSettings>().ConfigureAwait(false);

            Assert.NotNull(accountSettings);
            Assert.True(accountSettings.DeviceCount > 0);
        }
        public async void Get()
        {
            var messageTemplate = await PortalClient.GetAsync <NewUserMessageTemplate>().ConfigureAwait(false);

            Assert.False(string.IsNullOrWhiteSpace(messageTemplate.Subject));
            Assert.False(string.IsNullOrWhiteSpace(messageTemplate.Body));
        }
Exemplo n.º 5
0
        public async void Clone()
        {
            // This one has all the different widget types on
            var originalDashboard = await PortalClient.GetByNameAsync <Dashboard>("All Widgets").ConfigureAwait(false);

            var newDashboard = await PortalClient.CloneAsync(originalDashboard.Id, new DashboardCloneRequest
            {
                Name             = "All widgets clone",
                Description      = "I'm a clone and so if my wife.",
                DashboardGroupId = originalDashboard.DashboardGroupId,
                WidgetsConfig    = originalDashboard.WidgetsConfig,
                WidgetsOrder     = originalDashboard.WidgetsOrder
            }).ConfigureAwait(false);

            var newDashboardRefetch = await PortalClient.
                                      GetAsync <Dashboard>(newDashboard.Id)
                                      .ConfigureAwait(false);

            // Ensure that it is as expected
            Assert.NotNull(newDashboardRefetch);

            // Delete the clone
            await PortalClient
            .DeleteAsync(newDashboard)
            .ConfigureAwait(false);
        }
Exemplo n.º 6
0
        public async void CanGetNetscanById()
        {
            var netscan = (await PortalClient.GetAllAsync <Netscan>().ConfigureAwait(false))[0];

            var refetchedNetscan = await PortalClient.GetAsync <Netscan>(netscan.Id).ConfigureAwait(false);

            Assert.NotNull(refetchedNetscan);
        }
Exemplo n.º 7
0
        public async void GetConfigSourceById()
        {
            var configSources = await PortalClient.GetAllAsync <ConfigSource>().ConfigureAwait(false);

            Assert.NotEmpty(configSources);
            var configSource = await PortalClient.GetAsync <ConfigSource>(configSources[0].Id).ConfigureAwait(false);

            Assert.NotNull(configSource);
        }
Exemplo n.º 8
0
        public async void DateTimeSetCorrectly()
        {
            var device = await GetWindowsDeviceAsync().ConfigureAwait(false);

            var refresh = await PortalClient.GetAsync <Device>(device.Id).ConfigureAwait(false);

            Assert.True(refresh.CreatedOnSeconds > 0);
            Assert.True(refresh.CreatedOnUtc.Value > DateTime.Parse("2012-07-24"));
        }
Exemplo n.º 9
0
        public async void GetDeviceGroupsByParentId()
        {
            var deviceGroup = await PortalClient.GetAsync <DeviceGroup>(1).ConfigureAwait(false);

            // Make sure that some are returned
            Assert.True(deviceGroup.SubGroups.Count > 0);

            // Make sure that all children have Unique Ids
            Assert.False(deviceGroup.SubGroups.Select(c => c.Id).HasDuplicates());
        }
Exemplo n.º 10
0
        public async void GetCollector()
        {
            var collectors = await PortalClient.GetAllAsync <Collector>().ConfigureAwait(false);

            Assert.NotNull(collectors);
            Assert.NotEmpty(collectors);
            var refetchedCollector = await PortalClient
                                     .GetAsync <Collector>(collectors[0].Id)
                                     .ConfigureAwait(false);

            Assert.NotNull(refetchedCollector);
        }
Exemplo n.º 11
0
        public async void GetCollectorGroupSettings()
        {
            var collectorGroups = await PortalClient
                                  .GetAllAsync <CollectorGroup>()
                                  .ConfigureAwait(false);

            var pulsantCollectorGroupSettings = await PortalClient
                                                .GetAsync <CollectorGroup>(collectorGroups[0].Id)
                                                .ConfigureAwait(false);

            Assert.NotNull(pulsantCollectorGroupSettings);
        }
Exemplo n.º 12
0
        public async void GetWebsiteGroupById()
        {
            var websiteGroup = await PortalClient.GetAsync <WebsiteGroup>(1).ConfigureAwait(false);

            Assert.NotNull(websiteGroup);
            Assert.NotNull(websiteGroup.ChildWebsiteGroups);
            Assert.True(websiteGroup.ChildWebsiteGroups.Count > 0);
            Assert.Equal(0, websiteGroup.ParentId);
            Assert.Equal(1, websiteGroup.Id);
            Assert.False(string.IsNullOrWhiteSpace(websiteGroup.Name));
            Assert.False(websiteGroup.FullPath == null);
        }
Exemplo n.º 13
0
        public async void CrudCollectorGroup()
        {
            // Try to get this item
            var collectorGroups = await PortalClient.GetAllAsync(new Filter <CollectorGroup>
            {
                FilterItems = new List <FilterItem <CollectorGroup> >
                {
                    new Eq <CollectorGroup>(nameof(CollectorGroup.Name), TestName)
                }
            }).ConfigureAwait(false);

            foreach (var priorCollectorGroup in collectorGroups)
            {
                await PortalClient.DeleteAsync(priorCollectorGroup).ConfigureAwait(false);
            }
            // There are now none with this name

            // Create one
            var newCollectorGroup = await PortalClient.CreateAsync(new CollectorGroupCreationDto
            {
                Name             = TestName,
                Description      = TestDescription,
                CustomProperties = new List <Property>
                {
                    new Property {
                        Name = "a", Value = "b"
                    }
                }
            }).ConfigureAwait(false);

            Assert.NotNull(newCollectorGroup);
            Assert.NotEqual(0, newCollectorGroup.Id);

            var newCollectorGroupRefetch = await PortalClient.GetAsync <CollectorGroup>(newCollectorGroup.Id).ConfigureAwait(false);

            Assert.NotNull(newCollectorGroupRefetch);
            Assert.NotNull(newCollectorGroupRefetch.Name);
            Assert.NotNull(newCollectorGroupRefetch.Description);
            Assert.NotNull(newCollectorGroupRefetch.CustomProperties);
            Assert.NotEmpty(newCollectorGroupRefetch.CustomProperties);
            Assert.Single(newCollectorGroupRefetch.CustomProperties);
            Assert.Equal("a", newCollectorGroupRefetch.CustomProperties[0].Name);
            Assert.Equal("b", newCollectorGroupRefetch.CustomProperties[0].Value);

            // Put
            await PortalClient.PutAsync(newCollectorGroupRefetch).ConfigureAwait(false);

            // Delete
            await PortalClient.DeleteAsync(newCollectorGroupRefetch).ConfigureAwait(false);
        }
Exemplo n.º 14
0
        public async void GetRoleGroups()
        {
            var roleGroups = await PortalClient.GetAllAsync <RoleGroup>().ConfigureAwait(false);

            Assert.NotNull(roleGroups);
            Assert.NotEmpty(roleGroups);

            foreach (var role in roleGroups)
            {
                var refetchedRole = await PortalClient.GetAsync <RoleGroup>(role.Id).ConfigureAwait(false);

                Assert.True(refetchedRole.Name == role.Name);
            }
        }
Exemplo n.º 15
0
        public async void GetRecipientGroupTests()
        {
            var recipientGroups = await PortalClient.GetAllAsync <RecipientGroup>().ConfigureAwait(false);

            Assert.NotNull(recipientGroups);
            Assert.True(recipientGroups.Count > 0);

            foreach (var recipientGroup in recipientGroups)
            {
                var refetchedRole = await PortalClient.GetAsync <RecipientGroup>(recipientGroup.Id).ConfigureAwait(false);

                Assert.True(refetchedRole.GroupName == recipientGroup.GroupName);
            }
        }
Exemplo n.º 16
0
        public async void GetBillingInformation()
        {
            if (!AccountHasBillingInformation)
            {
                // Our test account does not have billing information - we can't test this.
                return;
            }

            var billingInformation = await PortalClient.GetAsync <BillingInformation>().ConfigureAwait(false);

            Assert.NotNull(billingInformation);
            Assert.NotNull(billingInformation.InvoiceDetails);
            Assert.NotNull(billingInformation.PaymentInformation);
        }
Exemplo n.º 17
0
        public async void GetUserGroups()
        {
            var userGroups = await PortalClient.GetAllAsync <UserGroup>().ConfigureAwait(false);

            Assert.NotNull(userGroups);
            Assert.NotEmpty(userGroups);

            foreach (var user in userGroups)
            {
                var refetchedUser = await PortalClient.GetAsync <UserGroup>(user.Id).ConfigureAwait(false);

                Assert.True(refetchedUser.Name == user.Name);
            }
        }
Exemplo n.º 18
0
        public async void GetAllCollectors()
        {
            var collectors = await PortalClient.GetAllAsync <Collector>().ConfigureAwait(false);

            Assert.NotNull(collectors);
            Assert.True(collectors.Count > 0);

            // Re-fetch each
            foreach (var collector in collectors)
            {
                var refetch = await PortalClient.GetAsync <Collector>(collector.Id).ConfigureAwait(false);

                Assert.NotNull(refetch);
            }
        }
Exemplo n.º 19
0
        public async void GetRoles()
        {
            var roles = await PortalClient.GetPageAsync(new Filter <Role> {
                Skip = 0, Take = 300
            }).ConfigureAwait(false);

            Assert.NotNull(roles);
            Assert.NotNull(roles.Items);
            Assert.True(roles.Items.Count > 0);

            foreach (var role in roles.Items)
            {
                var refetchedRole = await PortalClient.GetAsync <Role>(role.Id).ConfigureAwait(false);

                Assert.True(refetchedRole.Name == role.Name);
            }
        }
Exemplo n.º 20
0
        public async void GetCollectors()
        {
            var collectors = await PortalClient.GetAllAsync <Collector>().ConfigureAwait(false);

            // Make sure that some are returned
            Assert.NotEmpty(collectors);

            // Make sure that all have Unique Ids
            Assert.False(collectors.Select(c => c.Id).HasDuplicates());

            // Get each one by id
            foreach (var collector in collectors)
            {
                var refetchedCollector = await PortalClient.GetAsync <Collector>(collector.Id).ConfigureAwait(false);

                // TODO - make sure they match
            }
        }
Exemplo n.º 21
0
        public async void GetUsers()
        {
            var users = await PortalClient.GetPageAsync(new Filter <User> {
                Skip = 0, Take = 300
            }).ConfigureAwait(false);

            Assert.NotNull(users);
            Assert.NotNull(users.Items);
            Assert.True(users.Items.Count > 0);

            foreach (var user in users.Items)
            {
                var refetchedUser = await PortalClient.GetAsync <User>(user.Id).ConfigureAwait(false);

                var roles = refetchedUser.Roles;
                Assert.True(roles.Count > 0);
                Assert.NotEmpty(user.UserGroupIds);
            }
        }
Exemplo n.º 22
0
        public async void GetConfigSourceAndAssociatedDevices()
        {
            var configSource = await PortalClient.GetByNameAsync <ConfigSource>("Cisco_IOS").ConfigureAwait(false);

            Assert.NotNull(configSource);

            // Refetch and check
            var refetch = await PortalClient.GetAsync <ConfigSource>(configSource.Id).ConfigureAwait(false);

            Assert.Equal("Cisco_IOS", refetch.Name);
            Assert.Equal(configSource.DisplayName, refetch.DisplayName);

            // Get associated devices
            var devices = await PortalClient.GetConfigSourceDevicesPageAsync(configSource.Id, new Filter <DeviceConfigSource> {
                Skip = 0, Take = 300
            }).ConfigureAwait(false);

            Assert.NotEmpty(devices.Items);
        }
Exemplo n.º 23
0
        public async void GetDeviceGroupDeviceDataSourceInstances()
        {
            var deviceGroup = await PortalClient.GetDeviceGroupByFullPathAsync(DeviceGroupFullPath).ConfigureAwait(false);

            Assert.NotNull(deviceGroup);
            Assert.NotEqual(0, deviceGroup.Id);
            // We have the device group

            // Determine the DataSources
            var dataSourcesIds = new List <DataSource>
            {
                await PortalClient.GetDataSourceByUniqueNameAsync("Ping").ConfigureAwait(false),
                await PortalClient.GetDataSourceByUniqueNameAsync("dns").ConfigureAwait(false)
            }
            .Select(ds => ds.Id)
            .ToList();

            var deviceDataSourceInstances = await PortalClient
                                            .GetInstancesAsync(LogicModuleType.DataSource, deviceGroup.Id, dataSourcesIds)
                                            .ConfigureAwait(false);

            Assert.NotNull(deviceDataSourceInstances);
            Assert.NotEmpty(deviceDataSourceInstances);

            var sum = 0;

            foreach (var deviceDataSourceInstance in deviceDataSourceInstances)
            {
                var device = await PortalClient
                             .GetAsync <Device>(deviceDataSourceInstance.DeviceId.Value)
                             .ConfigureAwait(false);

                var refetchedDeviceDataSourceInstanceCount = (await PortalClient
                                                              .GetDeviceDataSourceByDeviceIdAndDataSourceIdAsync(deviceDataSourceInstance.DeviceId.Value, deviceDataSourceInstance.DataSourceId.Value)
                                                              .ConfigureAwait(false)).InstanceCount;

                Assert.NotEqual(0, refetchedDeviceDataSourceInstanceCount);
                sum += refetchedDeviceDataSourceInstanceCount;
            }
            Assert.Equal(deviceDataSourceInstances.Count, sum);
        }
Exemplo n.º 24
0
        public async void GetAlertRules()
        {
            var alertRules = await PortalClient.GetAllAsync <AlertRule>().ConfigureAwait(false);

            Assert.NotNull(alertRules);
            Assert.True(alertRules.Count > 0);

            // Get each one individually and check everything matches
            foreach (var alertRule in alertRules)
            {
                // Save it
                await PortalClient.SaveAlertRuleAsync(alertRule).ConfigureAwait(false);

                var refetchedAlertRule = await PortalClient.GetAsync <AlertRule>(alertRule.Id).ConfigureAwait(false);

                Assert.Equal(alertRule.Id, refetchedAlertRule.Id);
                // Other tests?

                // Only do one for now
                break;
            }
        }
        private static async Task ProcessStructureAsync <TGroup, TItem>(
            PortalClient portalClient,
            Mode mode,
            Structure <TGroup, TItem> structure,
            List <Property> variables,
            List <Property> properties,
            TGroup parentGroup,
            ILogger <Application> logger,
            CancellationToken cancellationToken)
            where TGroup : IdentifiedItem, IHasEndpoint, new()
            where TItem : IdentifiedItem, IHasEndpoint, new()
        {
            if (!structure.Enabled)
            {
                logger.LogInformation($"Not processing {typeof(TGroup)}, as they are disabled.");
                return;
            }
            // Structure is enabled
            logger.LogInformation($"Processing {typeof(TGroup)}...");

            // Get any existing Groups
            // Filter on the group name
            var filterItems = new List <FilterItem <TGroup> >
            {
                new Eq <TGroup>(nameof(NamedEntity.Name), Substitute(structure.Name, variables))
            };

            // For hierarchical groups, also filter on the parent id
            switch (typeof(TGroup).Name)
            {
            case nameof(DashboardGroup):
                filterItems.Add(new Eq <TGroup>(nameof(DashboardGroup.ParentId), parentGroup?.Id ?? 1));
                break;

            case nameof(DeviceGroup):
                filterItems.Add(new Eq <TGroup>(nameof(DeviceGroup.ParentId), parentGroup?.Id ?? 1));
                break;

            case nameof(WebsiteGroup):
                filterItems.Add(new Eq <TGroup>(nameof(WebsiteGroup.ParentId), parentGroup?.Id ?? 1));
                break;
            }
            var currentGroup = (await portalClient
                                .GetAllAsync(new Filter <TGroup>
            {
                FilterItems = filterItems
            }, cancellationToken)
                                .ConfigureAwait(false)).SingleOrDefault();

            // existingGroup is now set to either the existing group, or null

            // What mode are we in?
            switch (mode)
            {
            case Mode.Delete:
                // Delete
                // Is there an existing group?
                if (currentGroup == null)
                {
                    // No.  There's nothing to do here.
                    return;
                }
                // There's deletion to be done.

                // Recurse child groups first
                foreach (var childStructure in structure.Groups
                         ?? Enumerable.Empty <Structure <TGroup, TItem> >())
                {
                    await ProcessStructureAsync(
                        portalClient,
                        mode,
                        childStructure,
                        variables,
                        properties,
                        currentGroup,
                        logger,
                        cancellationToken)
                    .ConfigureAwait(false);
                }

                // Delete child nodes
                await DeleteChildNodesAsync <TGroup, TItem>(portalClient, currentGroup)
                .ConfigureAwait(false);

                // Try to delete this node
                await DeleteAsync <TGroup>(portalClient, currentGroup.Id)
                .ConfigureAwait(false);

                return;

            case Mode.Create:
                // Create.
                // Is there an existing group?
                if (currentGroup == null)
                {
                    // No.  We need to create one.
                    currentGroup = await CreateGroupAsync <TGroup, TItem>(
                        portalClient,
                        parentGroup,
                        structure,
                        variables,
                        properties)
                                   .ConfigureAwait(false);

                    // Create individual items (e.g. Dashboards)
                    foreach (var item in structure.Items ?? Enumerable.Empty <ItemSpec>())
                    {
                        // Ensure that the name is set
                        if (item.Name == null)
                        {
                            throw new ConfigurationException($"Creating items of type '{typeof(TItem).Name}' requires that the Name property is set.");
                        }

                        // Create any child items
                        switch (typeof(TItem).Name)
                        {
                        case nameof(Dashboard):
                            // Ensure that the name and id are set
                            if (item.CloneFromId == null)
                            {
                                throw new ConfigurationException($"Creating items of type '{typeof(TItem).Name}' requires that the CloneFromId property is set.");
                            }

                            var originalDashboard = await portalClient
                                                    .GetAsync <Dashboard>(item.CloneFromId.Value, cancellationToken)
                                                    .ConfigureAwait(false);

                            var newDashboard = await portalClient
                                               .CloneAsync(item.CloneFromId.Value,
                                                           new DashboardCloneRequest
                            {
                                Name             = Substitute(item.Name, variables),
                                Description      = Substitute(item.Description, variables),
                                DashboardGroupId = currentGroup.Id,
                                WidgetsConfig    = originalDashboard.WidgetsConfig,
                                WidgetsOrder     = originalDashboard.WidgetsOrder
                            }, cancellationToken)
                                               .ConfigureAwait(false);

                            // All is well
                            break;

                        default:
                            throw new NotSupportedException($"Creating items of type '{typeof(TItem).Name}' is not yet supported.");
                        }
                    }
                }
                // We now have a group.  Process child structure
                foreach (var childStructure in structure.Groups
                         ?? Enumerable.Empty <Structure <TGroup, TItem> >())
                {
                    await ProcessStructureAsync(
                        portalClient,
                        mode,
                        childStructure,
                        variables,
                        properties,
                        currentGroup,
                        logger,
                        cancellationToken)
                    .ConfigureAwait(false);
                }

                return;

            default:
                // Unexpected mode
                var message = $"Unexpected mode: {mode}";
                logger.LogError(message);
                throw new ConfigurationException(message);
            }
        }
Exemplo n.º 26
0
        public async void GetAlertStat()
        {
            var alertStat = await PortalClient.GetAsync <AlertStat>().ConfigureAwait(false);

            Assert.NotNull(alertStat);
        }
Exemplo n.º 27
0
        public async void CreateUpdateDelete()
        {
            // Ensure there is no existing role called "Test"
            var existingRole = (await PortalClient
                                .GetAllAsync(new Filter <Role> {
                FilterItems = new List <FilterItem <Role> > {
                    new Eq <Role>(nameof(Role.Name), Value)
                }
            })
                                .ConfigureAwait(false))
                               .SingleOrDefault();

            if (existingRole != null)
            {
                await PortalClient.DeleteAsync(existingRole).ConfigureAwait(false);
            }

            var dashboardGroup = (await PortalClient.GetAllAsync(new Filter <DashboardGroup> {
                Take = 1
            }).ConfigureAwait(false)).SingleOrDefault();
            var deviceGroup    = (await PortalClient.GetAllAsync(new Filter <DeviceGroup> {
                Take = 1
            }).ConfigureAwait(false)).SingleOrDefault();
            var websiteGroup   = (await PortalClient.GetAllAsync(new Filter <WebsiteGroup> {
                Take = 1
            }).ConfigureAwait(false)).SingleOrDefault();
            var reportGroup    = (await PortalClient.GetAllAsync(new Filter <ReportGroup> {
                Take = 1
            }).ConfigureAwait(false)).SingleOrDefault();
            var role           = await PortalClient.CreateAsync(new RoleCreationDto
            {
                CustomHelpLabel = "",
                CustomHelpUrl   = "",
                Description     = "Desc",
                Name            = Value,
                RequireEULA     = false,
                TwoFactorAuthenticationRequired = false,
                Privileges = new List <RolePrivilege>
                {
                    new RolePrivilege
                    {
                        ObjectType = PrivilegeObjectType.DashboardGroup,
                        ObjectId   = dashboardGroup.Id.ToString(),
                        Operation  = RolePrivilegeOperation.Read
                    },
                    new RolePrivilege
                    {
                        ObjectType = PrivilegeObjectType.DeviceGroup,
                        ObjectId   = deviceGroup.Id.ToString(),
                        Operation  = RolePrivilegeOperation.Read
                    },
                    new RolePrivilege
                    {
                        ObjectType = PrivilegeObjectType.WebsiteGroup,
                        ObjectId   = websiteGroup.Id.ToString(),
                        Operation  = RolePrivilegeOperation.Read
                    },
                    new RolePrivilege
                    {
                        ObjectType = PrivilegeObjectType.ReportGroup,
                        ObjectId   = reportGroup.Id.ToString(),
                        Operation  = RolePrivilegeOperation.Read
                    },
                    new RolePrivilege
                    {
                        ObjectType = PrivilegeObjectType.Help,
                        ObjectId   = "*",
                        Operation  = RolePrivilegeOperation.Read
                    },
                    new RolePrivilege
                    {
                        ObjectType = PrivilegeObjectType.DeviceDashboard,
                        Operation  = RolePrivilegeOperation.Read
                    },
                    new RolePrivilege
                    {
                        ObjectType = PrivilegeObjectType.ConfigNeedDeviceManagePermission,
                        ObjectId   = "",
                        Operation  = RolePrivilegeOperation.Write
                    },
                    new RolePrivilege
                    {
                        ObjectType = PrivilegeObjectType.ReportGroup,
                        ObjectId   = reportGroup.Id.ToString(),
                        Operation  = RolePrivilegeOperation.Read
                    },
                }
            }).ConfigureAwait(false);

            // Refetch
            var refetch = await PortalClient.GetAsync <Role>(role.Id).ConfigureAwait(false);

            Assert.NotNull(refetch);

            // Delete
            await PortalClient.DeleteAsync(role).ConfigureAwait(false);
        }
Exemplo n.º 28
0
        public async void GetDeviceGroupById()
        {
            var rootDeviceGroup = await PortalClient.GetAsync <DeviceGroup>(1).ConfigureAwait(false);

            Assert.NotNull(rootDeviceGroup);
        }
Exemplo n.º 29
0
        public async void GetDeviceById66()
        {
            var device = await PortalClient.GetAsync <Device>(66).ConfigureAwait(false);

            Assert.NotNull(device);
        }