
synopsis:

    Activation-keys defined on the system, and their associated data

description:

    Lists all activation-keys and entitlements, channels, config-channels, server-groups, and packages associated with them

columns:

        org_id            The organization that owns the key
        token             The token for a key
        note              Description of this key
        usage_limit       What is the key's usage-limit?
        is_disabled       Is the key disabled?
        deploys_configs   Does this key require config-files be deployed?
        entitlement       Entitlements the key assigns
        channel_label     Channels that the key subscribes a system to
        base_channel_id   Base channel id the key subscribes a system to
        child_channel_id  Child channel ids the key subscribes a system to
        cfg_channel_pos   "cfg-channel-label | position" for each cfg-channel in this key
        server_group      Server-groups that the key places the server into
        server_group_id   IDs of Server-groups that the key places the server into
        package_name      Packages that the key deploys to the system

multival_columns:

        org_id
        token
        entitlement     : entitlement
        channel_label   : channel_label
        base_channel_id : base_channel_id
        child_channel_id : child_channel_id
        cfg_channel_pos : cfg_channel_pos
        server_group    : server_group
        server_group_id : server_group_id
        package_name    : package_name

sql:

    select * from (
      select rt.org_id,
             ak.token,
             rt.note note,
             rt.usage_limit usage_limit,
             rt.disabled is_disabled,
             rt.deploy_configs deploys_configs,
             sgt.label entitlement,
             rc.label channel_label,
             CASE WHEN rc.parent_channel IS NULL THEN rc.id ELSE NULL END AS base_channel_id,
             CASE WHEN rc.parent_channel IS NULL THEN NULL ELSE rc.id END AS child_channel_id,
             rcc.label || '|' || rtcc.position cfg_channel_pos,
             sg.name server_group,
             sg.id server_group_id,
             pn.name package_name
      from rhnactivationkey ak
           inner join rhnregtoken rt ON rt.id = ak.reg_token_id
           left outer join rhnregtokenentitlement rte on rte.reg_token_id = rt.id
           left outer join rhnservergrouptype sgt on sgt.id = rte.server_group_type_id
           left outer join rhnregtokenchannels rtc on rtc.token_id = rt.id
           left outer join rhnchannel rc on rc.id = rtc.channel_id
           left outer join rhnregtokenconfigchannels rtcc on rtcc.token_id = rt.id
           left outer join rhnconfigchannel rcc on rcc.id = rtcc.config_channel_id
           left outer join rhnregtokengroups rtg on rtg.token_id = rt.id
           left outer join rhnservergroup sg on sg.id = rtg.server_group_id
           left outer join rhnregtokenpackages rtp on rtp.token_id = rt.id
           left outer join rhnpackagename pn on pn.id = rtp.name_id
           where ak.ks_session_id is null
           and ak.token not like 're-%'
    ) X
    -- where placeholder
    order by org_id, token, note, entitlement, base_channel_id, child_channel_id, cfg_channel_pos, server_group_id, package_name

