Skip to content
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: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ def run(self):
'console_scripts': [
'tendrl-monitoring-integration = \
tendrl.monitoring_integration.manager:main',
'tendrl-upgrade = \
tendrl.monitoring_integration.upgrades.delete_dashboards:main',
],
},
url="http://www.redhat.com",
Expand Down
Empty file.
82 changes: 82 additions & 0 deletions tendrl/monitoring_integration/upgrades/delete_dashboards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/usr/bin/python

import argparse
import ConfigParser
import requests

from requests.auth import HTTPBasicAuth


def delete_dashboards(server_ip, user, password):

dashboards = ["cluster-dashboard", "brick-dashboard", "host-dashboard",
"volume-dashboard"]

headers = {'content-type': 'application/json'}

for dashboard in dashboards:
url = "http://%s:3000/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 "
else:
print "Failed to delete", dashboard, response.json(), "\n"


# Deleting the alerts dashboards
url = "http://%s:3000/api/orgs/name/Alert_dashboard" \
% server_ip
print "Getting alerts organization id\n",url,"\n"
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
response = requests.delete(url, headers=headers,
auth=HTTPBasicAuth(user, password))
resp = response.json()
if resp == {u'message': u'Organization deleted'}:
print "Deleted Alert dashboards"
else:
print "Failed to delete Alert dashboards ", resp

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


def main():
try:
parser = argparse.ArgumentParser()
parser.add_argument("--username", help="grafana admin_user username")
parser.add_argument("--password", help="grafana admin_user password")

# getting grafana admin_username and password
config = ConfigParser.ConfigParser()
config.read('/etc/tendrl/monitoring-integration/grafana/grafana.ini')
username = config.get('security', 'admin_user')
password = config.get('security', 'admin_password')
default_ip = "127.0.0.1"

args = parser.parse_args()
if args.username:
username = args.username
if args.password:
password = args.password

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"

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


if __name__ == '__main__':
main()