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
34 changes: 17 additions & 17 deletions alertaclient/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,22 +150,22 @@ def alert_note(self, id, text):
data = {
'text': text
}
r = self.http.put('/alert/{}/note'.format(id), data)
r = self.http.put(f'/alert/{id}/note', data)
return Note.parse(r['note'])

def get_alert_notes(self, id, page=1, page_size=None):
r = self.http.get('/alert/{}/notes'.format(id), page=page, page_size=page_size)
r = self.http.get(f'/alert/{id}/notes', page=page, page_size=page_size)
return [Note.parse(n) for n in r['notes']]

def update_alert_note(self, id, note_id, text):
data = {
'text': text,
}
r = self.http.put('/alert/{}/note/{}'.format(id, note_id), data)
r = self.http.put(f'/alert/{id}/note/{note_id}', data)
return Note.parse(r['note'])

def delete_alert_note(self, id, note_id):
return self.http.delete('/alert/{}/note/{}'.format(id, note_id))
return self.http.delete(f'/alert/{id}/note/{note_id}')

# Blackouts
def create_blackout(self, environment, service=None, resource=None, event=None, group=None, tags=None,
Expand Down Expand Up @@ -208,7 +208,7 @@ def update_blackout(self, id, **kwargs):
'text': kwargs.get('text'),
}

r = self.http.put('/blackout/{}'.format(id), data)
r = self.http.put(f'/blackout/{id}', data)
return Blackout.parse(r['blackout'])

def delete_blackout(self, id):
Expand All @@ -235,7 +235,7 @@ def update_customer(self, id, **kwargs):
'match': kwargs.get('match'),
'customer': kwargs.get('customer')
}
r = self.http.put('/customer/{}'.format(id), data)
r = self.http.put(f'/customer/{id}', data)
return Customer.parse(r['customer'])

def delete_customer(self, id):
Expand Down Expand Up @@ -292,7 +292,7 @@ def update_key(self, id, **kwargs):
'expireTime': kwargs.get('expireTime'),
'customer': kwargs.get('customer')
}
r = self.http.put('/key/{}'.format(id), data)
r = self.http.put(f'/key/{id}', data)
return ApiKey.parse(r['key'])

def delete_key(self, id):
Expand All @@ -319,7 +319,7 @@ def update_perm(self, id, **kwargs):
'match': kwargs.get('match'), # role
'scopes': kwargs.get('scopes')
}
r = self.http.put('/perm/{}'.format(id), data)
r = self.http.put(f'/perm/{id}', data)
return Permission.parse(r['permission'])

def delete_perm(self, id):
Expand Down Expand Up @@ -359,7 +359,7 @@ def get_user(self, id):
return User.parse(self.http.get('/user/%s' % id)['user'])

def get_user_groups(self, id):
r = self.http.get('/user/{}/groups'.format(id))
r = self.http.get(f'/user/{id}/groups')
return [Group.parse(g) for g in r['groups']]

def get_me(self):
Expand All @@ -383,7 +383,7 @@ def update_user(self, id, **kwargs):
'text': kwargs.get('text'),
'email_verified': kwargs.get('email_verified')
}
r = self.http.put('/user/{}'.format(id), data)
r = self.http.put(f'/user/{id}', data)
return User.parse(r['user'])

def update_me(self, **kwargs):
Expand Down Expand Up @@ -452,7 +452,7 @@ def get_group(self):
return Group.parse(self.http.get('/group/%s' % id)['group'])

def get_group_users(self, id):
r = self.http.get('/group/{}/users'.format(id))
r = self.http.get(f'/group/{id}/users')
return [User.parse(u) for u in r['users']]

def get_users_groups(self, query=None):
Expand All @@ -464,14 +464,14 @@ def update_group(self, id, **kwargs):
'name': kwargs.get('name'),
'text': kwargs.get('text')
}
r = self.http.put('/group/{}'.format(id), data)
r = self.http.put(f'/group/{id}', data)
return Group.parse(r['group'])

def add_user_to_group(self, group_id, user_id):
return self.http.put('/group/{}/user/{}'.format(group_id, user_id))
return self.http.put(f'/group/{group_id}/user/{user_id}')

def remove_user_from_group(self, group_id, user_id):
return self.http.delete('/group/{}/user/{}'.format(group_id, user_id))
return self.http.delete(f'/group/{group_id}/user/{user_id}')

def delete_group(self, id):
return self.http.delete('/group/%s' % id)
Expand Down Expand Up @@ -500,7 +500,7 @@ def __init__(self, api_key=None, auth_token=None):
self.auth_token = auth_token

def __call__(self, r):
r.headers['Authorization'] = 'Key {}'.format(self.api_key)
r.headers['Authorization'] = f'Key {self.api_key}'
return r


Expand All @@ -510,7 +510,7 @@ def __init__(self, auth_token=None):
self.auth_token = auth_token

def __call__(self, r):
r.headers['Authorization'] = 'Bearer {}'.format(self.auth_token)
r.headers['Authorization'] = f'Bearer {self.auth_token}'
return r


Expand Down Expand Up @@ -608,7 +608,7 @@ def delete(self, path):

def _handle_error(self, response):
if self.debug:
print('\nbody: {}'.format(response.text))
print(f'\nbody: {response.text}')
resp = response.json()
status = resp.get('status', None)
if status == 'ok':
Expand Down
6 changes: 3 additions & 3 deletions alertaclient/auth/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def save_token(endpoint, username, token):
try:
info = netrc(NETRC_FILE)
except Exception as e:
raise ConfigurationError('{}'.format(e))
raise ConfigurationError(f'{e}')
info.hosts[machine(endpoint)] = (username, None, token)
with open(NETRC_FILE, 'w') as f:
f.write(dump_netrc(info))
Expand All @@ -39,13 +39,13 @@ def clear_token(endpoint):
try:
info = netrc(NETRC_FILE)
except Exception as e:
raise ConfigurationError('{}'.format(e))
raise ConfigurationError(f'{e}')
try:
del info.hosts[machine(endpoint)]
with open(NETRC_FILE, 'w') as f:
f.write(dump_netrc(info))
except KeyError as e:
raise ConfigurationError('No credentials stored for {}'.format(e))
raise ConfigurationError(f'No credentials stored for {e}')


# See https://bugs.python.org/issue30806
Expand Down
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_ack.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def cli(obj, ids, query, filters, text):
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_alerts(query)]

action_progressbar(client, action='ack', ids=ids, label='Acking {} alerts'.format(total), text=text)
action_progressbar(client, action='ack', ids=ids, label=f'Acking {total} alerts', text=text)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ def cli(obj, action, ids, query, filters, text):
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_alerts(query)]

label = 'Action ({}) {} alerts'.format(action, total)
label = f'Action ({action}) {total} alerts'
action_progressbar(client, action=action, ids=ids, label=label, text=text)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_blackout.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ def cli(obj, environment, service, resource, event, group, tags, origin, custome
text=text
)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
click.echo(f'ERROR: {e}', err=True)
sys.exit(1)
click.echo(blackout.id)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_blackouts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ def cli(obj, purge):

expired = [b for b in blackouts if b.status == 'expired']
if purge:
with click.progressbar(expired, label='Purging {} blackouts'.format(len(expired))) as bar:
with click.progressbar(expired, label=f'Purging {len(expired)} blackouts') as bar:
for b in bar:
client.delete_blackout(b.id)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_close.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def cli(obj, ids, query, filters, text):
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_alerts(query)]

action_progressbar(client, action='close', ids=ids, label='Closing {} alerts'.format(total), text=text)
action_progressbar(client, action='close', ids=ids, label=f'Closing {total} alerts', text=text)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ def cli(obj):
for k, v in obj.items():
if isinstance(v, list):
v = ', '.join(v)
click.echo('{:20}: {}'.format(k, v))
click.echo(f'{k:20}: {v}')
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def cli(obj, customer, match, delete):
try:
customer = client.create_customer(customer, match)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
click.echo(f'ERROR: {e}', err=True)
sys.exit(1)
click.echo(customer.id)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_delete.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def cli(obj, ids, query, filters):
total, _, _ = client.get_count(query)
ids = [a.id for a in client.get_alerts(query)]

with click.progressbar(ids, label='Deleting {} alerts'.format(total)) as bar:
with click.progressbar(ids, label=f'Deleting {total} alerts') as bar:
for id in bar:
client.delete_alert(id)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ def cli(obj, id, name, text, user, users, delete):
try:
group = client.create_group(name, text)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
click.echo(f'ERROR: {e}', err=True)
sys.exit(1)
click.echo(group.id)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_heartbeat.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ def cli(obj, origin, environment, severity, service, group, tags, timeout, custo
try:
heartbeat = client.heartbeat(origin=origin, tags=tags, attributes=attributes, timeout=timeout, customer=customer)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
click.echo(f'ERROR: {e}', err=True)
sys.exit(1)
click.echo(heartbeat.id)
12 changes: 6 additions & 6 deletions alertaclient/commands/cmd_heartbeats.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ def cli(obj, alert, severity, timeout, purge):

not_ok = [hb for hb in heartbeats if hb.status != 'ok']
if purge:
with click.progressbar(not_ok, label='Purging {} heartbeats'.format(len(not_ok))) as bar:
with click.progressbar(not_ok, label=f'Purging {len(not_ok)} heartbeats') as bar:
for b in bar:
client.delete_heartbeat(b.id)

if alert:
with click.progressbar(heartbeats, label='Alerting {} heartbeats'.format(len(heartbeats))) as bar:
with click.progressbar(heartbeats, label=f'Alerting {len(heartbeats)} heartbeats') as bar:
for b in bar:

want_environment = b.attributes.pop('environment', 'Production')
Expand All @@ -70,8 +70,8 @@ def cli(obj, alert, severity, timeout, purge):
correlate=['HeartbeatFail', 'HeartbeatSlow', 'HeartbeatOK'],
service=want_service,
group=want_group,
value='{}'.format(b.since),
text='Heartbeat not received in {} seconds'.format(b.timeout),
value=f'{b.since}',
text=f'Heartbeat not received in {b.timeout} seconds',
tags=b.tags,
attributes=b.attributes,
origin=origin(),
Expand All @@ -88,8 +88,8 @@ def cli(obj, alert, severity, timeout, purge):
correlate=['HeartbeatFail', 'HeartbeatSlow', 'HeartbeatOK'],
service=want_service,
group=want_group,
value='{}ms'.format(b.latency),
text='Heartbeat took more than {}ms to be processed'.format(b.max_latency),
value=f'{b.latency}ms',
text=f'Heartbeat took more than {b.max_latency}ms to be processed',
tags=b.tags,
attributes=b.attributes,
origin=origin(),
Expand Down
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_key.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ def cli(obj, api_key, username, scopes, duration, text, customer, delete):
expires = datetime.utcnow() + timedelta(seconds=duration) if duration else None
key = client.create_key(username, scopes, expires, text, customer, key=api_key)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
click.echo(f'ERROR: {e}', err=True)
sys.exit(1)
click.echo(key.key)
4 changes: 2 additions & 2 deletions alertaclient/commands/cmd_login.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def cli(obj, username):
password = click.prompt('Password', hide_input=True)
token = client.login(username, password)['token']
else:
click.echo('ERROR: unknown provider {provider}'.format(provider=provider), err=True)
click.echo(f'ERROR: unknown provider {provider}', err=True)
sys.exit(1)
except Exception as e:
raise AuthError(e)
Expand All @@ -46,7 +46,7 @@ def cli(obj, username):
preferred_username = jwt.parse(token)['preferred_username']
if preferred_username:
save_token(client.endpoint, preferred_username, token)
click.echo('Logged in as {}'.format(preferred_username))
click.echo(f'Logged in as {preferred_username}')
else:
click.echo('Failed to login.')
sys.exit(1)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_me.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def cli(obj, name, email, password, status, text):
try:
user = client.update_me(name=name, email=email, password=password, status=status, attributes=None, text=text)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
click.echo(f'ERROR: {e}', err=True)
sys.exit(1)
click.echo(user.id)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_note.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ def cli(obj, alert_ids, query, filters, text, delete):
total, _, _ = client.get_count(query)
alert_ids = [a.id for a in client.get_alerts(query)]

with click.progressbar(alert_ids, label='Add note to {} alerts'.format(total)) as bar:
with click.progressbar(alert_ids, label=f'Add note to {total} alerts') as bar:
for id in bar:
client.alert_note(id, text=text)
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_notes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def cli(obj, alert_id):
client = obj['client']
if alert_id:
if obj['output'] == 'json':
r = client.http.get('/alert/{}/notes'.format(alert_id))
r = client.http.get(f'/alert/{alert_id}/notes')
click.echo(json.dumps(r['notes'], sort_keys=True, indent=4, ensure_ascii=False))
else:
timezone = obj['timezone']
Expand Down
2 changes: 1 addition & 1 deletion alertaclient/commands/cmd_perm.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ def cli(obj, role, scopes, delete):
try:
perm = client.create_perm(role, scopes)
except Exception as e:
click.echo('ERROR: {}'.format(e), err=True)
click.echo(f'ERROR: {e}', err=True)
sys.exit(1)
click.echo(perm.id)
36 changes: 18 additions & 18 deletions alertaclient/commands/cmd_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,21 @@ def cli(obj, ids, query, filters, display, from_date=None):
alert.group,
alert.event,
alert.value or 'n/a'), fg=color['fg'])
click.secho(' |{}'.format(alert.text), fg=color['fg'])
click.secho(f' |{alert.text}', fg=color['fg'])

if display == 'full':
click.secho(' severity | {} -> {}'.format(alert.previous_severity,
alert.severity), fg=color['fg'])
click.secho(' trend | {}'.format(alert.trend_indication), fg=color['fg'])
click.secho(' status | {}'.format(alert.status), fg=color['fg'])
click.secho(' resource | {}'.format(alert.resource), fg=color['fg'])
click.secho(' group | {}'.format(alert.group), fg=color['fg'])
click.secho(' event | {}'.format(alert.event), fg=color['fg'])
click.secho(' value | {}'.format(alert.value), fg=color['fg'])
click.secho(f' trend | {alert.trend_indication}', fg=color['fg'])
click.secho(f' status | {alert.status}', fg=color['fg'])
click.secho(f' resource | {alert.resource}', fg=color['fg'])
click.secho(f' group | {alert.group}', fg=color['fg'])
click.secho(f' event | {alert.event}', fg=color['fg'])
click.secho(f' value | {alert.value}', fg=color['fg'])
click.secho(' tags | {}'.format(' '.join(alert.tags)), fg=color['fg'])

for key, value in alert.attributes.items():
click.secho(' {} | {}'.format(key.ljust(10), value), fg=color['fg'])
click.secho(f' {key.ljust(10)} | {value}', fg=color['fg'])

latency = alert.receive_time - alert.create_time

Expand All @@ -96,18 +96,18 @@ def cli(obj, ids, query, filters, display, from_date=None):
DateTime.localtime(alert.receive_time, timezone)), fg=color['fg'])
click.secho(' last received | {}'.format(
DateTime.localtime(alert.last_receive_time, timezone)), fg=color['fg'])
click.secho(' latency | {}ms'.format(latency.microseconds / 1000), fg=color['fg'])
click.secho(' timeout | {}s'.format(alert.timeout), fg=color['fg'])
click.secho(f' latency | {latency.microseconds / 1000}ms', fg=color['fg'])
click.secho(f' timeout | {alert.timeout}s', fg=color['fg'])

click.secho(' alert id | {}'.format(alert.id), fg=color['fg'])
click.secho(' last recv id | {}'.format(alert.last_receive_id), fg=color['fg'])
click.secho(' customer | {}'.format(alert.customer), fg=color['fg'])
click.secho(' environment | {}'.format(alert.environment), fg=color['fg'])
click.secho(f' alert id | {alert.id}', fg=color['fg'])
click.secho(f' last recv id | {alert.last_receive_id}', fg=color['fg'])
click.secho(f' customer | {alert.customer}', fg=color['fg'])
click.secho(f' environment | {alert.environment}', fg=color['fg'])
click.secho(' service | {}'.format(','.join(alert.service)), fg=color['fg'])
click.secho(' resource | {}'.format(alert.resource), fg=color['fg'])
click.secho(' type | {}'.format(alert.event_type), fg=color['fg'])
click.secho(' repeat | {}'.format(alert.repeat), fg=color['fg'])
click.secho(' origin | {}'.format(alert.origin), fg=color['fg'])
click.secho(f' resource | {alert.resource}', fg=color['fg'])
click.secho(f' type | {alert.event_type}', fg=color['fg'])
click.secho(f' repeat | {alert.repeat}', fg=color['fg'])
click.secho(f' origin | {alert.origin}', fg=color['fg'])
click.secho(' correlate | {}'.format(','.join(alert.correlate)), fg=color['fg'])

return auto_refresh, last_time
Loading