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

Added subpath("/grafana") in grafana root_url for reverse proxy #578

Merged
merged 4 commits into from
Nov 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion etc/grafana/grafana.ini
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

# The full public facing url you use in browser, used for redirects and emails
# If you use reverse proxy and sub path specify full url (with sub path)
;root_url = http://localhost:3000
root_url = http://localhost:3000/grafana

# Log web requests
;router_logging = false
Expand Down
12 changes: 6 additions & 6 deletions tendrl/monitoring_integration/grafana/alert_organization.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,15 @@ def create_organization():
resp = json.loads(resp)
if "id" in resp:
org_id = resp['id']
msg = ("alert organization with name %s " +
msg = ("alert organization with name %s "
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as per pep8 check, we don't need to give + symbol in between brackets for string concatenation

"is already exist") % constants.ALERT_ORG
logger.log("debug", NS.get("publisher_id", None),
{'message': msg})
elif "message" in resp and resp["message"] == \
"Organization not found":
# Create alert organization
org_id = grafana_org_utils.create_org(constants.ALERT_ORG)
msg = ("alert organization %s created " +
msg = ("alert organization %s created "
"successfully") % constants.ALERT_ORG
logger.log("debug", NS.get("publisher_id", None),
{'message': msg})
Expand All @@ -99,20 +99,20 @@ def create_auth_key():
key = grafana_org_utils.create_api_token(
GRAFANA_AUTH_KEY, GRAFANA_USER
)
msg = ("Grafana authentication key for user %s " +
msg = ("Grafana authentication key for user %s "
"is created successfully") % GRAFANA_USER
logger.log("debug", NS.get("publisher_id", None),
{'message': msg})
else:
alert_org = NS.monitoring.objects.AlertOrganization().load()
key = alert_org.auth_key
msg = ("Grafana authentication key for user %s " +
msg = ("Grafana authentication key for user %s "
"is already exist") % GRAFANA_USER
logger.log("debug", NS.get("publisher_id", None),
{'message': msg})
else:
msg = ("Unable to create grafana authentication key " +
"for user %s") % GRAFANA_USER
msg = ("Unable to create grafana authentication key "
"for user %s" % GRAFANA_USER)
logger.log("debug", NS.get("publisher_id", None),
{'message': msg})
key = None
Expand Down
2 changes: 1 addition & 1 deletion tendrl/monitoring_integration/grafana/dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def upload_default_dashboards():
logger.log("debug", NS.get("publisher_id", None),
{'message': msg})
else:
msg = ("Dashboard {0} upload failed. Error code: {1} ," +
msg = ("Dashboard {0} upload failed. Error code: {1} ,"
"Error message: " + "{2} ").format(
str(dashboard_json),
str(response.status_code),
Expand Down
29 changes: 11 additions & 18 deletions tendrl/monitoring_integration/grafana/dashboard_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ def _post_dashboard(dashboard_json, authorization_key=None):
if authorization_key:
new_header = constants.HEADERS
new_header["Authorization"] = "Bearer " + str(authorization_key)
response = post("http://{}:{}/api/dashboards/"
"db".format(config.grafana_host,
config.grafana_port),
response = post("http://{}/grafana/api/dashboards/"
"db".format(config.grafana_host),
headers=new_header,
data=upload_str)
else:
response = post("http://{}:{}/api/dashboards/"
"db".format(config.grafana_host,
config.grafana_port),
response = post("http://{}/grafana/api/dashboards/"
"db".format(config.grafana_host),
headers=constants.HEADERS,
auth=config.credentials,
data=upload_str)
Expand All @@ -40,9 +38,8 @@ def _post_dashboard(dashboard_json, authorization_key=None):
def get_dashboard(dashboard_name):
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = get("http://{}:{}/api/dashboards/"
resp = get("http://{}/grafana/api/dashboards/"
"db/{}".format(config.grafana_host,
config.grafana_port,
dashboard_name),
auth=config.credentials)
else:
Expand All @@ -54,9 +51,8 @@ def delete_dashboard(dashboard_name):
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = delete(
"http://{}:{}/api/dashboards/db/{}".format(
"http://{}/grafana/api/dashboards/db/{}".format(
config.grafana_host,
config.grafana_port,
dashboard_name
),
auth=config.credentials
Expand All @@ -69,9 +65,8 @@ def delete_dashboard(dashboard_name):
def get_all_dashboards():
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = get("http://{}:{}/api/search/"
.format(config.grafana_host,
config.grafana_port),
resp = get("http://{}/grafana/api/search/"
.format(config.grafana_host),
auth=config.credentials)
else:
raise exceptions.ConnectionFailedException
Expand All @@ -81,9 +76,8 @@ def get_all_dashboards():
def set_home_dashboard(dash_id):
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = put('http://{}:{}/api/org/'
'preferences'.format(config.grafana_host,
config.grafana_port),
resp = put('http://{}/grafana/api/org/'
'preferences'.format(config.grafana_host),
headers=constants.HEADERS,
auth=config.credentials,
data=json.dumps({"name": constants.MAIN_ORG,
Expand Down Expand Up @@ -121,9 +115,8 @@ def get_alert(alert_id):
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = get(
"http://{0}:{1}/api/alerts/{2}".format(
"http://{0}/grafana/api/alerts/{2}".format(
config["grafana_host"],
config["grafana_port"],
alert_id
),
auth=config["credentials"]
Expand Down
11 changes: 4 additions & 7 deletions tendrl/monitoring_integration/grafana/datasource_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ def _post_datasource(datasource_json):
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = post(
"http://{}:{}/api/datasources".format(
config.grafana_host,
config.grafana_port
"http://{}/grafana/api/datasources".format(
config.grafana_host
),
headers=constants.HEADERS,
auth=config.credentials,
Expand Down Expand Up @@ -64,9 +63,8 @@ def get_data_source():
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = get(
"http://{}:{}/api/datasources/id/{}".format(
"http://{}/grafana/api/datasources/id/{}".format(
config.grafana_host,
config.grafana_port,
config.datasource_name
),
auth=config.credentials
Expand All @@ -85,9 +83,8 @@ def update_datasource(datasource_id):
datasource_str = json.dumps(datasource_json)
if utils.port_open(config.grafana_port, config.grafana_host):
response = put(
"http://{}:{}/api/datasources/{}".format(
"http://{}/grafana/api/datasources/{}".format(
config.grafana_host,
config.grafana_port,
datasource_id
),
headers=constants.HEADERS,
Expand Down
26 changes: 10 additions & 16 deletions tendrl/monitoring_integration/grafana/grafana_org_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,8 @@ def create_org(org_name):
upload_str = {"name": org_name}
if utils.port_open(config.grafana_port, config.grafana_host):
response = post(
"http://{}:{}/api/orgs".format(
config.grafana_host,
config.grafana_port
"http://{}/grafana/api/orgs".format(
config.grafana_host
),
headers=constants.HEADERS,
auth=config.credentials,
Expand All @@ -36,9 +35,8 @@ def get_org_id(org_name):
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = get(
"http://{}:{}/api/orgs/name/{}".format(
"http://{}/grafana/api/orgs/name/{}".format(
config.grafana_host,
config.grafana_port,
org_name
),
auth=config.credentials
Expand All @@ -55,9 +53,8 @@ def get_current_org_name():
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
resp = get(
"http://{}:{}/api/org/".format(
config.grafana_host,
config.grafana_port
"http://{}/grafana/api/org/".format(
config.grafana_host
),
auth=config.credentials
)
Expand All @@ -73,9 +70,8 @@ def switch_context(org_id):
config = maps.NamedDict(NS.config.data)
upload_str = ''
if utils.port_open(config.grafana_port, config.grafana_host):
response = post("http://{}:{}/api/user/using"
response = post("http://{}/grafana/api/user/using"
"/{}".format(config.grafana_host,
config.grafana_port,
org_id),
headers=constants.HEADERS,
auth=config.credentials,
Expand All @@ -95,9 +91,8 @@ def create_api_token(key_name, role):
config = maps.NamedDict(NS.config.data)
request_body = {"name": key_name, "role": role}
if utils.port_open(config.grafana_port, config.grafana_host):
response = post("http://{}:{}/api/auth/"
"keys".format(config.grafana_host,
config.grafana_port),
response = post("http://{}/grafana/api/auth/"
"keys".format(config.grafana_host),
headers=constants.HEADERS,
auth=config.credentials,
data=json.dumps(request_body))
Expand All @@ -111,9 +106,8 @@ def get_auth_keys():
config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
response = get(
"http://{}:{}/api/auth/keys".format(
config.grafana_host,
config.grafana_port
"http://{}/grafana/api/auth/keys".format(
config.grafana_host
),
auth=config.credentials
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,8 @@ def create_notification_channel():

config = maps.NamedDict(NS.config.data)
if utils.port_open(config.grafana_port, config.grafana_host):
response = post("http://{}:{}/api/alert-notifications"
.format(config.grafana_host,
config.grafana_port),
response = post("http://{}/grafana/api/alert-notifications"
.format(config.grafana_host),
headers=constants.HEADERS,
auth=config.credentials,
data=channel_details)
Expand Down
4 changes: 2 additions & 2 deletions tendrl/monitoring_integration/grafana/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ def get_resource_keys(key, resource_name):
"debug",
NS.get("publisher_id", None),
{
'message': "Error while fetching " +
str(resource_name).split('/')[0] + str(ex)
'message': "Error while fetching " + str(
resource_name).split('/')[0] + str(ex)
}
)
return resource_list
5 changes: 3 additions & 2 deletions tendrl/monitoring_integration/graphite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,9 @@ def set_brick_count(self, cluster_data):
down = 0
for brick in cluster["Brick"]:
if(
brick["host_name"] ==
node["fqdn"].replace(".", "_")
brick["host_name"] == node["fqdn"].replace(
".", "_"
)
):
if brick["status"] == 0 or brick["status"] == 1:
total = total + 1
Expand Down
2 changes: 1 addition & 1 deletion tendrl/monitoring_integration/objects/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def __init__(self, config=None, *args, **kwargs):

self.data = config or cmn_config.load_config(
'monitoring-integration',
"/etc/tendrl/monitoring-integration/" +
"/etc/tendrl/monitoring-integration/"
"monitoring-integration.conf.yaml"
)
self.value = "_NS/monitoring/config"
4 changes: 2 additions & 2 deletions tendrl/monitoring_integration/sync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ def run(self):
"error",
NS.get("publisher_id", None),
{
'message': "Unable to parse tendrl-gluster-" +
"integration config 'sync_interval'"
'message': "Unable to parse tendrl-gluster-"
"integration config 'sync_interval'"
}
)
raise ex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,8 @@ def test_alert_organization():
'key': '/_NS/monitoring/alert_organization/org_name',
'value': '',
'dir': False
},
{
'key': '/_NS/monitoring/alert_organization/hash',
'value': 'dbe23ea17c68ff20e8b8b678997531a4',
'name': 'hash',
'dir': False
}
]
for atrr in obj.render():
if atrr not in result:
for attr in obj.render():
if "hash" not in attr['key']and attr not in result:
raise AssertionError()
30 changes: 15 additions & 15 deletions tendrl/monitoring_integration/upgrades/delete_dashboards.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,38 @@ def delete_dashboards(server_ip, user, password):
headers = {'content-type': 'application/json'}

for dashboard in dashboards:
url = "http://%s:3000/api/dashboards/db/%s" % (server_ip, dashboard)
url = "http://%s/grafana/api/dashboards/db/%s" % (server_ip, dashboard)
print (url)
response = requests.delete(url, headers=headers,
auth=HTTPBasicAuth(user, password))
if response.status_code == 200:
print "Deleted", dashboard, "\n "
print ("Deleted %s \n" % dashboard)
else:
print "Failed to delete", dashboard, response.json(), "\n"

print ("Failed to delete %s %s \n" % (dashboard, response.json()))

# Deleting the alerts dashboards
url = "http://%s:3000/api/orgs/name/Alert_dashboard" \
url = "http://%s/grafana/api/orgs/name/Alert_dashboard" \
% server_ip
print "Getting alerts organization id\n",url,"\n"
print ("Getting alerts organization id\n %s \n" % url)
response = requests.get(url, headers=headers,
auth=HTTPBasicAuth(user, password))
resp = response.json()

if 'id' in resp:
id = resp['id']
url = "http://%s:3000/api/orgs/%s" % (server_ip, id)
print "Deleting alerts organization\n", url
url = "http://%s/grafana/api/orgs/%s" % (server_ip, id)
print ("Deleting alerts organization\n %s" % url)
response = requests.delete(url, headers=headers,
auth=HTTPBasicAuth(user, password))
resp = response.json()
if resp == {u'message': u'Organization deleted'}:
print "Deleted Alert dashboards"
print ("Deleted Alert dashboards")
else:
print "Failed to delete Alert dashboards ", resp
print ("Failed to delete Alert dashboards %s" % resp)

else:
print "Failed to delete Alert dashboards."
print "Organization id not found", resp
print ("Failed to delete Alert dashboards.")
print ("Organization id not found %s" % resp)


def main():
Expand All @@ -69,13 +68,14 @@ def main():
if args.password:
password = args.password

print "\n Clearing grafana dashboards \n"
print ("\n Clearing grafana dashboards \n")
delete_dashboards(server_ip=default_ip, user=username,
password=password)
print "\n Complete -- Please start tendrl-monitoring-integration service"
print ("\n Complete -- Please start tendrl-monitoring-integration "
"service")

except Exception as e:
print "Failed in deleting dashboards with error: %s" % e
print ("Failed in deleting dashboards with error: %s" % e)


if __name__ == '__main__':
Expand Down