Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Frontend team #247

Merged
merged 26 commits into from Apr 1, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
4745e29
Add tests of GFConfig view for delete_config and update_config methods.
daisycrego Mar 29, 2020
75c14d3
Pass POST data back to the form if an error is thrown - so the user d…
daisycrego Mar 29, 2020
cd109c1
Change add_panel function to work without a dashboard_uid - callers o…
daisycrego Mar 29, 2020
fce7c83
Merge branch 'frontend-team' into grafana
daisycrego Mar 29, 2020
8c63169
Update tests that reference add_panels to reflect new number of argum…
daisycrego Mar 29, 2020
2738ea4
Sync with frontend-team
daisycrego Mar 29, 2020
1f40cef
Update test that no longer needs to reference uid - failing flake8.
daisycrego Mar 29, 2020
2a21ffd
Merge pull request #231 from gcivil-nyu-org/grafana
daisycrego Mar 29, 2020
1bfad65
Finished tests for sensors view
dandipietrantonio Mar 29, 2020
b133758
black and flake8
dandipietrantonio Mar 29, 2020
e8d9434
Long line caused build failure
dandipietrantonio Mar 29, 2020
b205eb9
Fixed test for missing field name
dandipietrantonio Mar 29, 2020
9b34b92
GFConfig now automatically retrieves db credentials upon form submission
tianrunw Mar 30, 2020
d97ad31
Merge branch 'frontend-team' into view-new-sensor-models
Mar 31, 2020
efdf05e
Merge pull request #236 from gcivil-nyu-org/view-new-sensor-models
Mar 31, 2020
93ffc2c
Remove unwanted code from mercury.
sunnybansal Mar 31, 2020
077ea1e
Merge pull request #241 from gcivil-nyu-org/remove-unwanted-code
tianrunw Mar 31, 2020
91a1d5e
removed print statement
tianrunw Mar 31, 2020
73a76bb
Merge branch 'frontend-team' into grafana
tianrunw Mar 31, 2020
ffde0b1
black reformat
tianrunw Mar 31, 2020
62d1765
Merge pull request #243 from gcivil-nyu-org/grafana
sunnybansal Apr 1, 2020
54391f2
JS Fix to issue of all div's loading for configure sensors upon click…
dandipietrantonio Apr 1, 2020
bdea88e
Merge branch 'frontend-team' into view-new-sensor-models
daisycrego Apr 1, 2020
18289bc
Merge pull request #244 from gcivil-nyu-org/view-new-sensor-models
daisycrego Apr 1, 2020
dd7d3d9
Merging changes from master.
daisycrego Apr 1, 2020
4a8e3aa
Merge pull request #246 from gcivil-nyu-org/frontend-team-sync
dandipietrantonio Apr 1, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion mercury/forms.py
Expand Up @@ -51,7 +51,7 @@ class Meta:
fields = ["gf_name", "gf_host", "gf_token"]
labels = {
"gf_name": "Label (e.g. remote, local)",
"gf_host": "Hostname (e.g. https://abc123.grafana.net, localhost:3000)",
"gf_host": "Hostname (e.g. https://abc123.grafana.net, http://localhost:3000)",
"gf_token": "API Token",
}

Expand Down
32 changes: 25 additions & 7 deletions mercury/grafanaAPI/grafana_api.py
Expand Up @@ -31,7 +31,7 @@ def __init__(self, gf_config=None):
if gf_config:
self.hostname = gf_config.gf_host
self.api_token = gf_config.gf_token
self.database_hostname = gf_config.gf_host
self.database_hostname = gf_config.gf_db_host
self.database_name = gf_config.gf_db_name
self.database_username = gf_config.gf_db_username
self.database_password = gf_config.gf_db_pw
Expand Down Expand Up @@ -85,6 +85,23 @@ def validate_credentials(self):

return True

def get_dashboard_by_event_name(self, event_name):
"""
:param event_name: Event name used for the target dashboard.
:return: Returns True if a dashboard was found with this name, False otherwise.
"""
# If there are spaces in the name, the GF API will replace them with dashes
# to generate the "slug". A slug can be used to query the API.
endpoint = os.path.join(
self.hostname, "api/dashboards/db", event_name.lower().replace(" ", "-"),
)
response = requests.get(url=endpoint, auth=("api_key", self.api_token))

if "dashboard" in response.json():
return response.json()
else:
return None

def get_dashboard_with_uid(self, uid):
"""
:param uid: uid of the target dashboard
Expand Down Expand Up @@ -313,18 +330,19 @@ def delete_datasource_by_name(self, name):
except KeyError:
return False

def add_panel(self, sensor, event, dashboard_uid):
def add_panel(self, sensor, event):
"""

Adds a new panel for the sensor based on its SensorType.
The database for the new panel will be whichever database is currently in
GFConfig. The panel will be placed in the next available slot on the dashboard.
GFConfig. The dashboard for the new panel will be the dashboard with the
same name as the event.
The panel will be placed in the next available slot on the dashboard.

:param sensor: AGSensor object for this panel (panel will only display sensor
data for this sensor type.
:param event: Event object for this panel (panel will only display sensor
data for this event)
:param dashboard_uid: UID of the target dashboard

:return: New panel with SQL query based on sensor type
will be added to dashboard.
Expand All @@ -338,11 +356,11 @@ def add_panel(self, sensor, event, dashboard_uid):
for field in field_dict:
field_array.append(field)

# Retrieve current dashboard structure
dashboard_info = self.get_dashboard_with_uid(dashboard_uid)
# Find dashboard uid for event
dashboard_info = self.get_dashboard_by_event_name(event.name)

if dashboard_info is None:
raise ValueError("Dashboard uid not found.")
raise ValueError("Dashboard not found for this event.")

# Retrieve current panels
try:
Expand Down
14 changes: 14 additions & 0 deletions mercury/migrations/0018_remove_gfconfig_gf_db_grafana_name.py
@@ -0,0 +1,14 @@
# Generated by Django 2.2.10 on 2020-03-30 16:54

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("mercury", "0017_agevent"),
]

operations = [
migrations.RemoveField(model_name="gfconfig", name="gf_db_grafana_name",),
]
1 change: 0 additions & 1 deletion mercury/models.py
Expand Up @@ -15,7 +15,6 @@ class GFConfig(models.Model):
) # token only, without the prefix "Bearer "
gf_dashboard_uid = models.CharField(max_length=64)
gf_db_host = models.CharField(max_length=128)
gf_db_grafana_name = models.CharField(max_length=64)
gf_db_name = models.CharField(max_length=64)
gf_db_username = models.CharField(max_length=64)
gf_db_pw = models.CharField(max_length=256)
Expand Down
134 changes: 0 additions & 134 deletions mercury/static/mercury/js/can.js

This file was deleted.

3 changes: 3 additions & 0 deletions mercury/static/mercury/js/sensor.js
Expand Up @@ -130,6 +130,9 @@ function selectView() {
editSensorsButton.style.backgroundColor = 'var(--light-accent)';
editSensorTypesButton.style.backgroundColor = 'var(--green)';
}
else {
displayCurrentSensors()
}
}

function displayCurrentSensors() {
Expand Down