Skip to content
This repository has been archived by the owner on Apr 22, 2020. It is now read-only.

Commit

Permalink
print correct UI links (to work in Vagrant box too)
Browse files Browse the repository at this point in the history
  • Loading branch information
hjacobs committed Dec 21, 2015
1 parent 095bfb7 commit feb8c6b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions zmon_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from requests.auth import HTTPBasicAuth
import yaml
import time
import urllib.parse

import keyring

Expand Down Expand Up @@ -73,6 +74,15 @@ def configure_logging(loglevel):
logging.getLogger('requests.packages.urllib3.connectionpool').setLevel(logging.WARNING)


def get_base_url(url):
'''
>>> get_base_url('https://localhost:8443/example/api/v123')
'https://localhost:8443/'
'''
split = urllib.parse.urlsplit(url)
return urllib.parse.urlunsplit(list(split[:2]) + ['/', '', ''])


@click.group(cls=AliasedGroup, context_settings=CONTEXT_SETTINGS)
@click.option('--config-file', help='Use alternative config file', default=DEFAULT_CONFIG_FILE, metavar='PATH')
@click.option('-v', '--verbose', help='Verbose logging', is_flag=True)
Expand Down Expand Up @@ -359,7 +369,7 @@ def updateAlertDef(yaml_file):
if r.status_code != 200:
error(r.text)
r.raise_for_status()
ok(get_config_data()["url"].replace("rest/api/v1", "") + "#/alert-details/" + str(r.json()["id"]))
ok(get_base_url(get_config_data()["url"]) + "#/alert-details/" + str(r.json()["id"]))


@cli.group('check-definitions', cls=AliasedGroup)
Expand All @@ -386,7 +396,7 @@ def update(yaml_file):
if r.status_code != 200:
error(r.text)
r.raise_for_status()
ok(get_config_data()["url"].replace("rest/api/v1", "") + "#/check-definitions/view/" + str(r.json()["id"]))
ok(get_base_url(get_config_data()["url"]) + "#/check-definitions/view/" + str(r.json()["id"]))


def remove_trailing_whitespace(text: str):
Expand Down

0 comments on commit feb8c6b

Please sign in to comment.