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

Commit

Permalink
reformat
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Hanzelmann committed Aug 31, 2015
1 parent 5e68905 commit 9fc91ae
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions zmon_cli/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def validate_config(data):
def get(url):
data = get_config_data()
try:
return requests.get(data['url']+url, auth=HTTPBasicAuth(data['user'], data['password']))
return requests.get(data['url'] + url, auth=HTTPBasicAuth(data['user'], data['password']))
except Exception as e:
logging.error(e)

Expand All @@ -167,7 +167,7 @@ def get(url):
def put(url, body):
data = get_config_data()
try:
return requests.put(data['url']+url, data=body, auth=HTTPBasicAuth(data['user'], data['password']),
return requests.put(data['url'] + url, data=body, auth=HTTPBasicAuth(data['user'], data['password']),
headers={'content-type': 'application/json'})
except Exception as e:
logging.error(e)
Expand All @@ -178,7 +178,7 @@ def put(url, body):
def delete(url):
data = get_config_data()
try:
return requests.delete(data['url']+url, auth=HTTPBasicAuth(data['user'], data['password']))
return requests.delete(data['url'] + url, auth=HTTPBasicAuth(data['user'], data['password']))
except Exception as e:
logging.error(e)

Expand All @@ -191,12 +191,14 @@ def members(ctx):
"""Manage group membership"""
pass


@cli.group('alert-definitions')
@click.pass_context
def alert_definitions(ctx):
"""Manage alert definitions"""
pass


@alert_definitions.command('init')
@click.argument('yaml_file', type=click.File('wb'))
def init(yaml_file):
Expand All @@ -222,9 +224,10 @@ def init(yaml_file):
name = click.prompt('Alert name', default='Example Alert')
check_id = click.prompt('Check ID')
team = click.prompt('(Responsible-) Team', default='Example Team')
data = template.format(name=name, team=team,check_id=check_id)
data = template.format(name=name, team=team, check_id=check_id)
yaml_file.write(data.encode('utf-8'))


@alert_definitions.command('get')
@click.argument("alert_id", type=int)
def getAlertDefinition(alert_id):
Expand All @@ -238,6 +241,7 @@ def getAlertDefinition(alert_id):

print(yaml.safe_dump(data, default_flow_style=False, allow_unicode=True, encoding='utf-8').decode('utf-8'))


@alert_definitions.command("update")
@click.argument('yaml_file', type=click.File('rb'))
def updateAlertDef(yaml_file):
Expand All @@ -261,12 +265,13 @@ def updateAlertDef(yaml_file):
alert_id = post['id']

r = requests.put(data['url'] + '/alert-definitions/{}'.format(alert_id), json.dumps(post),
auth=HTTPBasicAuth(data['user'], data['password']), headers={'Content-Type': 'application/json'})
auth=HTTPBasicAuth(data['user'], data['password']), headers={'Content-Type': 'application/json'})
if r.status_code == 200:
ok(get_config_data()["url"].replace("rest/api/v1","")+"#/alert-details/"+str(r.json()["id"]))
ok(get_config_data()["url"].replace("rest/api/v1", "") + "#/alert-details/" + str(r.json()["id"]))
else:
print(r.text)


@cli.group('check-definitions')
@click.pass_context
def check_definitions(ctx):
Expand All @@ -287,7 +292,7 @@ def update(yaml_file):
r = requests.post(data['url'] + '/check-definitions', json.dumps(post),
auth=HTTPBasicAuth(data['user'], data['password']), headers={'Content-Type': 'application/json'})
if r.status_code == 200:
ok(get_config_data()["url"].replace("rest/api/v1","")+"#/check-definitions/view/"+str(r.json()["id"]))
ok(get_config_data()["url"].replace("rest/api/v1", "") + "#/check-definitions/view/" + str(r.json()["id"]))
else:
print(r.text)

Expand Down

0 comments on commit 9fc91ae

Please sign in to comment.