コード例 #1
0
        // Drops a Continuous Query
        async Task DropContinuousQuery()
        {
            try
            {
                if (SelectedCq == null || Database == null)
                {
                    return;
                }

                // Confirm Drop
                if (MessageBox.Show(string.Format("Drop CQ: {0}?", SelectedCq.Name), "Confirm Drop", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning)
                    == DialogResult.OK)
                {
                    var response = await InfluxDbClient.DropContinuousQueryAsync(Database, SelectedCq.Name);

                    if (response.Success)
                    {
                        SelectedCq = null;
                        await ExecuteRequestAsync();
                    }
                    else
                    {
                        AppForm.DisplayError(response.Body);
                    }

                    UpdateUIState();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #2
0
        // Validates the form values
        bool ValidatePolicyValues()
        {
            // Name
            if (string.IsNullOrWhiteSpace(nameTextBox.Text))
            {
                AppForm.DisplayError("Retention Policy name cannot be blank.");
                return(false);
            }

            // Duration
            var duration = durationTextBox.Text;

            if (string.IsNullOrWhiteSpace(duration))
            {
                AppForm.DisplayError("Duration cannot be blank. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc.");
                return(false);
            }

            duration = duration.Trim();

            if (!InfluxDbHelper.IsTimeIntervalValid(duration))
            {
                AppForm.DisplayError("Duration value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc.");
                return(false);
            }

            return(true);
        }
コード例 #3
0
        // Update password for the selected user
        async Task ChangePassword()
        {
            try
            {
                var user = SelectedUser;
                if (user == null)
                {
                    return;
                }

                userPasswordDialog.BindToUser(user);

                if (userPasswordDialog.ShowDialog() == DialogResult.OK)
                {
                    var response = await InfluxDbClient.SetPasswordAsync(user.Name, userPasswordDialog.Password);

                    // Select the user and refresh the window
                    if (!response.Success)
                    {
                        AppForm.DisplayError(response.Body);
                    }
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #4
0
        // Kills the selected query
        async Task KillQuery()
        {
            try
            {
                if (listView.SelectedItems.Count == 0)
                {
                    return;
                }
                var pid      = ((InfluxDbRunningQuery)listView.SelectedItems[0].Tag).PID;
                var response = await InfluxDbClient.KillQueryAsync(pid);

                if (!response.Success && !response.Body.Contains("query interrupted"))
                {
                    AppForm.DisplayError(response.Body);
                }
                else
                {
                    listView.BeginUpdate();
                    listView.SelectedItems[0].Remove();
                    listView.EndUpdate();
                }

                UpdateUIState();
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #5
0
        // Shows the create policy dialog
        async Task ShowCreatePolicy()
        {
            try
            {
                // Clear out the dialog values
                policyDialog.ResetPolicyValues();

                if (policyDialog.ShowDialog() == DialogResult.OK)
                {
                    var name        = policyDialog.PolicyName;
                    var duration    = policyDialog.PolicyDuration;
                    var replication = policyDialog.PolicyReplication;
                    var isDefault   = policyDialog.PolicyDefault;

                    var response = await InfluxDbClient.CreateRetentionPolicyAsync(SelectedDatabase, name, duration, replication, isDefault);

                    if (!response.Success)
                    {
                        AppForm.DisplayError(response.Body);
                    }

                    // Reload latest data
                    await ExecuteRequestAsync();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #6
0
        // Grant privilege
        async Task GrantPrivilege()
        {
            try
            {
                var user = SelectedUser;
                if (user == null)
                {
                    return;
                }

                grantPrivilegeDialog.InfluxDbClient = InfluxDbClient;
                await grantPrivilegeDialog.BindToUser(user);

                if (grantPrivilegeDialog.ShowDialog() == DialogResult.OK)
                {
                    // Get the selected database and privilege to grant
                    var username  = grantPrivilegeDialog.User.Name;
                    var database  = grantPrivilegeDialog.SelectedDatabase;
                    var privilege = grantPrivilegeDialog.SelectedPrivilege;

                    // Ensure a database was selected
                    if (string.IsNullOrWhiteSpace(database))
                    {
                        AppForm.DisplayError("You must supply a database to grant a privilege for.");
                        return;
                    }
                    // Otherwise if "None" was selected (shouldn't be possible), there's nothing to grant...
                    else if (privilege == InfluxDbPrivileges.None)
                    {
                        return;
                    }

                    // Grant the privilege
                    var response = await InfluxDbClient.GrantPrivilegeAsync(username, privilege, database);

                    // Refresh the window
                    if (response.Success)
                    {
                        await ExecuteRequestAsync();
                    }
                    else
                    {
                        AppForm.DisplayError(response.Body);
                    }

                    // Update interface buttons
                    UpdateUIState();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #7
0
        // Drops the selected policy
        async Task ShowDropPolicy()
        {
            try
            {
                var policy = SelectedRetentionPolicy;
                if (policy == null || string.IsNullOrWhiteSpace(SelectedDatabase))
                {
                    return;
                }
                var wasDefault = policy.Default;

                // Confirm the drop
                if (DialogResult.OK == MessageBox.Show(string.Format("Drop retention policy: {0}?", policy.Name), "Confirm Drop", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning))
                {
                    var response = await InfluxDbClient.DropRetentionPolicyAsync(SelectedDatabase, policy.Name);

                    if (!response.Success)
                    {
                        AppForm.DisplayError(response.Body);
                    }

                    // If this was the default policy and was dropped
                    if (wasDefault)
                    {
                        policies = await InfluxDbClient.GetRetentionPoliciesAsync(SelectedDatabase);

                        if (policies.Count() > 0)
                        {
                            // Try to find the autogen/default
                            var rp = (from r in policies where r.Name.ToLower() == "autogen" select r).FirstOrDefault();

                            // Otherwise try to find another policy with a different name
                            if (rp == null)
                            {
                                rp = (from r in policies where r.Name != policy.Name select r).FirstOrDefault();
                            }

                            if (rp != null)
                            {
                                // If a new retention policy was found, make it the default
                                response = await InfluxDbClient.AlterRetentionPolicyAsync(SelectedDatabase, rp.Name, rp.Duration, rp.ReplicationCopies, true);
                            }
                        }
                    }

                    // Reload latest data
                    await ExecuteRequestAsync();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #8
0
        // Edit the selected user
        async Task EditUser()
        {
            try
            {
                var user = SelectedUser;
                if (user == null)
                {
                    return;
                }

                editUserDialog.BindToUser(user);

                if (editUserDialog.ShowDialog() == DialogResult.OK)
                {
                    // If there was no change in user status, there's nothing to do
                    var updatedUser = editUserDialog.CreateUserFromDialog();
                    if (user.IsAdmin == updatedUser.IsAdmin)
                    {
                        return;
                    }

                    InfluxDbApiResponse response = null;

                    // Otherwise carry out the appropriate API call based on adding or removing admin privileges
                    if (updatedUser.IsAdmin)
                    {
                        response = await InfluxDbClient.GrantAdministratorAsync(updatedUser.Name);
                    }
                    else
                    {
                        response = await InfluxDbClient.RevokeAdministratorAsync(updatedUser.Name);
                    }

                    // Refresh the window
                    if (response.Success)
                    {
                        await ExecuteRequestAsync();
                    }
                    else
                    {
                        AppForm.DisplayError(response.Body);
                    }

                    // Update interface buttons
                    UpdateUIState();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #9
0
        // Creates a new user
        async Task CreateUser()
        {
            try
            {
                // Clear dialog values
                createUserDialog.ClearCreateValues();

                if (createUserDialog.ShowDialog(this) == DialogResult.OK)
                {
                    // Get the user data
                    var user = createUserDialog.CreateUserFromDialog();
                    if (user == null)
                    {
                        return;
                    }

                    // Ensure unique username
                    foreach (ListViewItem li in usersListView.Items)
                    {
                        if (li.Text == user.Name)
                        {
                            AppForm.DisplayError("User already exists: " + user.Name, "Create Error");
                            return;
                        }
                    }

                    // Create the user
                    var response = await InfluxDbClient.CreateUserAsync(user.Name, createUserDialog.Password, user.IsAdmin);

                    // Select the user and refresh the window
                    if (response.Success)
                    {
                        SelectedUser = user;
                        await ExecuteRequestAsync();
                    }
                    else
                    {
                        AppForm.DisplayError(response.Body);
                    }

                    // Update interface buttons
                    UpdateUIState();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #10
0
        /// <summary>
        /// Creates and returns a new InfluxDB user from the dialog values.
        /// </summary>
        public InfluxDbUser CreateUserFromDialog()
        {
            // Validate user name
            if (string.IsNullOrWhiteSpace(Username))
            {
                AppForm.DisplayError("User name cannot be blank.", "Bad User Name");
                return(null);
            }

            // Validate password
            if (string.IsNullOrWhiteSpace(Password))
            {
                AppForm.DisplayError("Password cannot be blank.", "Bad Password");
                return(null);
            }

            return(new InfluxDbUser(username.Text, adminCheckBox.Checked));
        }
コード例 #11
0
        // Drop the selected user
        async Task DropUser()
        {
            try
            {
                var user = SelectedUser;
                if (user == null)
                {
                    return;
                }

                // Confirm drop
                if (MessageBox.Show(string.Format("Drop user: {0}?", user.Name), "Confirm User Drop",
                                    MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel)
                {
                    return;
                }

                var response = await InfluxDbClient.DropUserAsync(user.Name);

                // Select the user and refresh the window
                if (response.Success)
                {
                    SelectedUser = null;
                    await ExecuteRequestAsync();
                }
                else
                {
                    AppForm.DisplayError(response.Body);
                }

                // Update interface buttons
                UpdateUIState();
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #12
0
        // Create a Continuous Query
        async Task CreateContinuousQuery()
        {
            try
            {
                // Pass client connection down
                createCqDialog.ResetCqForm();
                createCqDialog.InfluxDbClient = InfluxDbClient;
                createCqDialog.Database       = Database;

                // Bind dynamic data
                await createCqDialog.BindInfluxDataSources();

                if (createCqDialog.ShowDialog() == DialogResult.OK)
                {
                    // Get the resulting CQ params
                    var cqParams = createCqDialog.CqResult;

                    // Create the CQ and get the response
                    var response = await InfluxDbClient.CreateContinuousQueryAsync(cqParams);

                    if (response.Success)
                    {
                        await ExecuteRequestAsync();
                    }
                    else
                    {
                        AppForm.DisplayError(response.Body);
                    }

                    UpdateUIState();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #13
0
        // Edit privilege
        async Task EditPrivilege()
        {
            try
            {
                var user = SelectedUser;
                if (user == null)
                {
                    return;
                }

                var grant = SelectedPrivilegeGrant;
                if (grant == null)
                {
                    return;
                }

                // Bind to data
                editPrivilegeDialog.BindToGrant(user.Name, grant);

                if (editPrivilegeDialog.ShowDialog() == DialogResult.OK)
                {
                    // Get the selected database and privilege to grant
                    var username  = editPrivilegeDialog.Username;
                    var database  = editPrivilegeDialog.Database;
                    var privilege = editPrivilegeDialog.SelectedPrivilege;

                    // Ensure a database was selected
                    if (string.IsNullOrWhiteSpace(database))
                    {
                        AppForm.DisplayError("You must supply a database to update a privilege for.");
                        return;
                    }

                    InfluxDbApiResponse response = null;

                    // If "None" was selected then we actually need to revoke the existing privilege
                    if (privilege == InfluxDbPrivileges.None)
                    {
                        response = await InfluxDbClient.RevokePrivilegeAsync(username, grant.Privilege, database);
                    }
                    // Otherwise just grant the new privilege
                    else
                    {
                        response = await InfluxDbClient.GrantPrivilegeAsync(username, privilege, database);
                    }

                    // Refresh the window
                    if (response.Success)
                    {
                        await ExecuteRequestAsync();
                    }
                    else
                    {
                        AppForm.DisplayError(response.Body);
                    }

                    // Update interface buttons
                    UpdateUIState();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }
コード例 #14
0
        // Validates the current form values
        bool ValidateCqValues()
        {
            try
            {
                // Validate values
                var cqName = nameTextBox.Text;

                // CQ Name
                if (string.IsNullOrWhiteSpace(cqName))
                {
                    AppForm.DisplayError("Continuous Query name cannot be blank.");
                    return(false);
                }

                // Source & Destination
                var destination = destinationComboBox.SelectedItem as string;
                if (string.IsNullOrWhiteSpace(destination))
                {
                    destination = destinationComboBox.Text;
                }
                var source = sourceComboBox.SelectedItem as string;
                if (string.IsNullOrWhiteSpace(source))
                {
                    source = sourceComboBox.Text;
                }

                if (string.IsNullOrWhiteSpace(destination))
                {
                    AppForm.DisplayError("Destination cannot be blank.");
                    return(false);
                }

                if (string.IsNullOrWhiteSpace(source))
                {
                    AppForm.DisplayError("Source cannot be blank.");
                    return(false);
                }

                if (destination == source)
                {
                    if (MessageBox.Show("Source is the same as the Destination. These are typically different values for a Continous Query. Are you sure that you want to have duplicate values?", "Confirm",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return(false);
                    }
                }

                // Interval
                var interval = intervalTextBox.Text;

                if (string.IsNullOrWhiteSpace(interval))
                {
                    AppForm.DisplayError("Interval cannot be blank. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc.");
                    return(false);
                }

                interval = interval.Trim();

                if (!InfluxDbHelper.IsTimeIntervalValid(interval))
                {
                    AppForm.DisplayError("Interval value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc.");
                    return(false);
                }

                // Resample Every
                if (resampleCheckBox.Checked)
                {
                    var resampleEvery = resampleEveryTextBox.Text;

                    if (!string.IsNullOrWhiteSpace(resampleEvery))
                    {
                        resampleEvery = resampleEvery.Trim();

                        if (!InfluxDbHelper.IsTimeIntervalValid(resampleEvery))
                        {
                            AppForm.DisplayError("Resample Every interval value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc.");
                            return(false);
                        }
                    }
                }

                // Resample For
                if (resampleCheckBox.Checked)
                {
                    var resampleFor = resampleForTextBox.Text;

                    if (!string.IsNullOrWhiteSpace(resampleFor))
                    {
                        resampleFor = resampleFor.Trim();

                        if (!InfluxDbHelper.IsTimeIntervalValid(resampleFor))
                        {
                            AppForm.DisplayError("Resample For interval value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc.");
                            return(false);
                        }
                    }
                }

                // Subquery
                if (queryEditor.Text == null || queryEditor.Text.Length == 0 || queryEditor.Text == QueryEditorPlaceholderText)
                {
                    AppForm.DisplayError("SubQuery cannot be blank.");
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
                return(false);
            }
        }
コード例 #15
0
        // Validates the current form values
        bool ValidateBackfillValues()
        {
            try
            {
                // Source & Destination
                var destination = destinationComboBox.SelectedItem as string;
                if (string.IsNullOrWhiteSpace(destination))
                {
                    destination = destinationComboBox.Text;
                }
                var source = sourceComboBox.SelectedItem as string;
                if (string.IsNullOrWhiteSpace(source))
                {
                    source = sourceComboBox.Text;
                }

                if (string.IsNullOrWhiteSpace(destination))
                {
                    AppForm.DisplayError("Destination cannot be blank.");
                    return(false);
                }

                if (string.IsNullOrWhiteSpace(source))
                {
                    AppForm.DisplayError("Source cannot be blank.");
                    return(false);
                }

                if (destination == source)
                {
                    if (MessageBox.Show("Source is the same as the Destination. These are typically different values for a Backfill Query. Are you sure that you want to have duplicate values?", "Confirm",
                                        MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No)
                    {
                        return(false);
                    }
                }

                // Interval
                var interval = intervalTextBox.Text;

                if (string.IsNullOrWhiteSpace(interval))
                {
                    AppForm.DisplayError("Interval cannot be blank. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc.");
                    return(false);
                }

                interval = interval.Trim();

                if (!InfluxDbHelper.IsTimeIntervalValid(interval))
                {
                    AppForm.DisplayError("Interval value is invalid. It should be an InfluxDB time interval value such as: 1d, 2h, 10m, 30s, etc.");
                    return(false);
                }

                // From/To time
                var fromTime = fromDateTimePicker.Value;
                var toTime   = toDateTimePicker.Value;

                if (fromTime >= toTime)
                {
                    AppForm.DisplayError("'From Time' is later than 'To Time'. 'From Time' should come before 'To Time'.");
                    return(false);
                }

                // Subquery
                if (queryEditor.Text == null || queryEditor.Text.Length == 0 || queryEditor.Text == QueryEditorPlaceholderText)
                {
                    AppForm.DisplayError("SubQuery cannot be blank.");
                    return(false);
                }

                return(true);
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
                return(false);
            }
        }
コード例 #16
0
        // Shows the alter policy dialog
        async Task ShowAlterPolicy()
        {
            try
            {
                var policy = SelectedRetentionPolicy;
                if (policy == null || string.IsNullOrWhiteSpace(SelectedDatabase))
                {
                    return;
                }

                var prevIsDefault = policy.Default;

                // Clear out the dialog values
                policyDialog.ResetPolicyValues();

                // Bind to current policy
                policyDialog.BindToPolicy(SelectedRetentionPolicy);

                if (policyDialog.ShowDialog() == DialogResult.OK)
                {
                    var name        = policyDialog.PolicyName;
                    var duration    = policyDialog.PolicyDuration;
                    var replication = policyDialog.PolicyReplication;
                    var isDefault   = policyDialog.PolicyDefault;

                    var response = await InfluxDbClient.AlterRetentionPolicyAsync(SelectedDatabase, name, duration, replication, isDefault);

                    if (!response.Success)
                    {
                        AppForm.DisplayError(response.Body);
                    }
                    else
                    {
                        // If default status chagned, attempt to update another policy as default
                        if (prevIsDefault != isDefault && !isDefault)
                        {
                            policies = await InfluxDbClient.GetRetentionPoliciesAsync(SelectedDatabase);

                            if (policies.Count() > 0)
                            {
                                // Try to find the autogen/default
                                var rp = (from r in policies where r.Name.ToLower() == "autogen" select r).FirstOrDefault();

                                // Otherwise try to find another policy with a different name
                                if (rp == null)
                                {
                                    rp = (from r in policies where r.Name != policy.Name select r).FirstOrDefault();
                                }

                                if (rp != null)
                                {
                                    // If a new retention policy was found, make it the default
                                    response = await InfluxDbClient.AlterRetentionPolicyAsync(SelectedDatabase, rp.Name, rp.Duration, rp.ReplicationCopies, true);
                                }
                            }
                        }
                    }

                    // Reload latest data
                    await ExecuteRequestAsync();
                }
            }
            catch (Exception ex)
            {
                AppForm.DisplayException(ex);
            }
        }