{% set found = data['found'] | default({}) %}
{% set resources = data['resources'] | default({'n/a': {}}) %}
{% set address = found['ip-address'] %}
{% set hostkey = found['host-key'] | default('n/a') %}
{% set domainkey = found['domain-key'] | default('n/a') %}
{% set server = resources[hostkey] | default(False) %}
{% set domain = resources[domainkey] | default(False) %}

{% if found['ip-address'] != target %}Address:
    {{ target }} resolves to IPv4 address {{ found['ip-address'] }}
{%- endif %}

{% if domain %}Domain: {{ domain['data'].name }}
    Registrar: {{ domain['data'].registrar }}
{% if domain['data'].nameservers %}
    Nameservers: {% for nameserver in domain['data'].nameservers %}{{nameserver}}{% if not loop.last %}, {% endif %}{% endfor %}

{% endif %}
{% if domain['data'].days_until_expires %}
    Expires: {{ domain['data'].days_until_expires }} days
{% endif %}
{%- endif %}
{% if server and server.type == 'OS::Nova::Instance' %}
Host:
    {{ found['ip-address'] }} ({{ target }}) is hosted on a Nova instance
{% if 'data' in server %}    Instance Information:
        URI: {{ server['data'].uri | default('n/a')  }}
        Name: {{ server['data'].name | default('n/a') }}
        ID: {{ server['data'].id | default('n/a')  }}
{% if 'addresses' in server['data'] %}    ip-addresses:
{% for name, addresses in server['data'].addresses.items() %}
        {{ name }}:
{% for address in addresses %}
            {{ address.addr }}
{% endfor %}
{% endfor %}{% endif %}{% endif %}
{% elif found['ip-address'] %}
Host:
    ip-address: {{ found['ip-address'] }}
{% else %}Host not found
{% endif %}
{% if server and 'data' in server and server['data'].system_info %}
{% if 'remote_services' in server['data'].system_info %}
    Listening Services:
{% for remote in server['data'].system_info.remote_services | sort %}
        {{ remote.ip }}:{{ remote.port }}  {{ remote.process }}
{% endfor %}{% endif %}
{% if 'connections' in server['data'].system_info %}
    Talking to:
{% for connection in server['data'].system_info.connections | dictsort %}
        {{ connection[0] }}{% if connection[1] %} on {% for port in connection[1] %}{{ port }}{% if not loop.last %}, {% endif %}{% endfor %}{% endif %}

{% endfor %}{% endif %}
{% endif %}
