# Path: alertaclient/utils.py
# def origin():
#     prog = os.path.basename(sys.argv[0])
#     return f'{prog}/{platform.uname()[1]}'


import json
import click
from datetime import datetime, timedelta
from tabulate import tabulate
from alertaclient.utils import origin

    if obj['output'] == 'json':
        r = client.http.get('/keys')
        click.echo(json.dumps(r['keys'], sort_keys=True, indent=4, ensure_ascii=False))
    else:
        timezone = obj['timezone']
        headers = {
            'id': 'ID', 'key': 'API KEY', 'user': 'USER', 'scopes': 'SCOPES', 'text': 'TEXT',
            'expireTime': 'EXPIRES', 'count': 'COUNT', 'lastUsedTime': 'LAST USED', 'customer': 'CUSTOMER'
        }
        click.echo(tabulate([k.tabular(timezone) for k in client.get_keys()], headers=headers, tablefmt=obj['output']))

    if alert:
        keys = r['keys']
        service = ['Alerta']
        group = 'System'
        environment = 'Production'
        with click.progressbar(keys, label=f'Analysing {len(keys)} keys') as bar:
            for b in bar:
                if b['status'] == 'expired':
                    client.send_alert(
                        resource=b['id'],
                        event='ApiKeyExpired',
                        environment=environment,
                        severity=severity,
                        correlate=['ApiKeyExpired', 'ApiKeyExpiring', 'ApiKeyOK'],
                        service=service,
                        group=group,
                        value='Expired',
                        text=f"Key expired on {b['expireTime']}",

# Path: alertaclient/utils.py
# def origin():
#     prog = os.path.basename(sys.argv[0])
#     return f'{prog}/{platform.uname()[1]}'


# Path: alertaclient/commands/cmd_keys.py
import json
import click
from datetime import datetime, timedelta
from tabulate import tabulate
from alertaclient.utils import origin


    if obj['output'] == 'json':
        r = client.http.get('/keys')
        click.echo(json.dumps(r['keys'], sort_keys=True, indent=4, ensure_ascii=False))
    else:
        timezone = obj['timezone']
        headers = {
            'id': 'ID', 'key': 'API KEY', 'user': 'USER', 'scopes': 'SCOPES', 'text': 'TEXT',
            'expireTime': 'EXPIRES', 'count': 'COUNT', 'lastUsedTime': 'LAST USED', 'customer': 'CUSTOMER'
        }
        click.echo(tabulate([k.tabular(timezone) for k in client.get_keys()], headers=headers, tablefmt=obj['output']))

    if alert:
        keys = r['keys']
        service = ['Alerta']
        group = 'System'
        environment = 'Production'
        with click.progressbar(keys, label=f'Analysing {len(keys)} keys') as bar:
            for b in bar:
                if b['status'] == 'expired':
                    client.send_alert(
                        resource=b['id'],
                        event='ApiKeyExpired',
                        environment=environment,
                        severity=severity,
                        correlate=['ApiKeyExpired', 'ApiKeyExpiring', 'ApiKeyOK'],
                        service=service,
                        group=group,
                        value='Expired',
                        text=f"Key expired on {b['expireTime']}",

                        origin=origin(),