diff --git a/etc/grafana/grafana.ini b/etc/grafana/grafana.ini index aca085f..ab3edf6 100644 --- a/etc/grafana/grafana.ini +++ b/etc/grafana/grafana.ini @@ -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 diff --git a/tendrl/monitoring_integration/grafana/alert_organization.py b/tendrl/monitoring_integration/grafana/alert_organization.py index e8f4d22..e6e1812 100644 --- a/tendrl/monitoring_integration/grafana/alert_organization.py +++ b/tendrl/monitoring_integration/grafana/alert_organization.py @@ -64,7 +64,7 @@ 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 " "is already exist") % constants.ALERT_ORG logger.log("debug", NS.get("publisher_id", None), {'message': msg}) @@ -72,7 +72,7 @@ def create_organization(): "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}) @@ -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 diff --git a/tendrl/monitoring_integration/grafana/dashboard.py b/tendrl/monitoring_integration/grafana/dashboard.py index b506a1c..8c2e822 100644 --- a/tendrl/monitoring_integration/grafana/dashboard.py +++ b/tendrl/monitoring_integration/grafana/dashboard.py @@ -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), diff --git a/tendrl/monitoring_integration/grafana/dashboard_utils.py b/tendrl/monitoring_integration/grafana/dashboard_utils.py index 9a31b3c..e5c3b4b 100644 --- a/tendrl/monitoring_integration/grafana/dashboard_utils.py +++ b/tendrl/monitoring_integration/grafana/dashboard_utils.py @@ -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) @@ -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: @@ -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 @@ -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 @@ -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, @@ -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"] diff --git a/tendrl/monitoring_integration/grafana/datasource_utils.py b/tendrl/monitoring_integration/grafana/datasource_utils.py index 73104e2..64fee5e 100644 --- a/tendrl/monitoring_integration/grafana/datasource_utils.py +++ b/tendrl/monitoring_integration/grafana/datasource_utils.py @@ -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, @@ -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 @@ -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, diff --git a/tendrl/monitoring_integration/grafana/grafana_org_utils.py b/tendrl/monitoring_integration/grafana/grafana_org_utils.py index b2bbadb..2386d33 100644 --- a/tendrl/monitoring_integration/grafana/grafana_org_utils.py +++ b/tendrl/monitoring_integration/grafana/grafana_org_utils.py @@ -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, @@ -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 @@ -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 ) @@ -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, @@ -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)) @@ -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 ) diff --git a/tendrl/monitoring_integration/grafana/notification_channel.py b/tendrl/monitoring_integration/grafana/notification_channel.py index f6f2b85..319ae76 100644 --- a/tendrl/monitoring_integration/grafana/notification_channel.py +++ b/tendrl/monitoring_integration/grafana/notification_channel.py @@ -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) diff --git a/tendrl/monitoring_integration/grafana/utils.py b/tendrl/monitoring_integration/grafana/utils.py index 5c6efe2..f210196 100644 --- a/tendrl/monitoring_integration/grafana/utils.py +++ b/tendrl/monitoring_integration/grafana/utils.py @@ -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 diff --git a/tendrl/monitoring_integration/graphite/__init__.py b/tendrl/monitoring_integration/graphite/__init__.py index bcfb425..de6d7cd 100644 --- a/tendrl/monitoring_integration/graphite/__init__.py +++ b/tendrl/monitoring_integration/graphite/__init__.py @@ -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 diff --git a/tendrl/monitoring_integration/objects/config/__init__.py b/tendrl/monitoring_integration/objects/config/__init__.py index fc13bd4..d4562b6 100644 --- a/tendrl/monitoring_integration/objects/config/__init__.py +++ b/tendrl/monitoring_integration/objects/config/__init__.py @@ -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" diff --git a/tendrl/monitoring_integration/sync/__init__.py b/tendrl/monitoring_integration/sync/__init__.py index 5913d63..6bb30c7 100644 --- a/tendrl/monitoring_integration/sync/__init__.py +++ b/tendrl/monitoring_integration/sync/__init__.py @@ -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 diff --git a/tendrl/monitoring_integration/tests/objects/alert_organization/test_init.py b/tendrl/monitoring_integration/tests/objects/alert_organization/test_init.py index 1c7bbd7..2af41c6 100644 --- a/tendrl/monitoring_integration/tests/objects/alert_organization/test_init.py +++ b/tendrl/monitoring_integration/tests/objects/alert_organization/test_init.py @@ -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() diff --git a/tendrl/monitoring_integration/upgrades/delete_dashboards.py b/tendrl/monitoring_integration/upgrades/delete_dashboards.py index b46c740..b6d192b 100644 --- a/tendrl/monitoring_integration/upgrades/delete_dashboards.py +++ b/tendrl/monitoring_integration/upgrades/delete_dashboards.py @@ -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(): @@ -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__':