Skip to content

Commit

Permalink
html report
Browse files Browse the repository at this point in the history
  • Loading branch information
dancorrigan1 committed Dec 2, 2024
1 parent bb3dca3 commit d33cd93
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 4 deletions.
12 changes: 10 additions & 2 deletions tasks/dailyconnections.yml
Original file line number Diff line number Diff line change
Expand Up @@ -207,16 +207,23 @@
state: directory
mode: '0750'

- name: "Daily Connections | Template report"
- name: "Daily Connections | Template txt report"
ansible.builtin.template:
src: report.txt.j2
dest: "{{ role_iptvservice__report_path }}/{{ ansible_date_time.date }}-iptv-monitor.txt"
mode: '0600'
become: true

- name: "Daily Connections | Template html report"
ansible.builtin.template:
src: report.html.j2
dest: "{{ role_iptvservice__report_path }}/{{ ansible_date_time.date }}-iptv-monitor.html"
mode: '0600'
become: true

- name: "Daily Connections | Slurp report"
ansible.builtin.slurp:
src: "{{ role_iptvservice__report_path }}/{{ ansible_date_time.date }}-iptv-monitor.txt"
src: "{{ role_iptvservice__report_path }}/{{ ansible_date_time.date }}-iptv-monitor.html"
register: __encoded_report

- name: "Daily Connections | Decode report"
Expand All @@ -232,6 +239,7 @@
port: 25
secure: never
body: "{{ __report }}"
subtype: html
become: true
rescue:
- name: "Daily Connections | Fail playbook"
Expand Down
42 changes: 42 additions & 0 deletions templates/report.html.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<table cellspacing="5" cellpadding="5" border="1">
<tr><th colspan=6>Provider Account Summary</th></tr>
<tr><th>Provider Account</th><th>Unique Logins</th></tr>
{% for account, value in __sorted_total_collections %}
<tr><td>{{ account }}</td><td>{{ value }}</td></tr>
{% endfor %}
</table>
<br>
<br>
<table cellspacing="5" cellpadding="5" border="1">
<tr><th colspan=6>Proxy User Summary</th></tr>
<tr><th>Real Name</th><th>User Name</th><th>Provider</th><th>IP Address Info</th><th>User Agents</th></tr>
{% for user in __unique_user_ips %}
{% set agent_list = __iptv_log | select('search', '/' ~ user.user) | map('split', '\"') | flatten | select('search', role_iptvservice__allowed_user_agents | join('|')) | unique %}
<tr>
<td valign="top">{{ role_iptvservice__credentials | map(attribute='proxy_users') | flatten | selectattr('username', '==', user.user) | map(attribute='name') | first }}</td>
<td valign="top">{{ user.user }}</td>
<td valign="top">{{ user.provider }}</td>
{% if user.ip_list | length < 1 %}
<td>N/A</td><td>N/A</td>
{% else %}
<td valign="top">
{%- for ip in user.ip_list | unique -%}
{% if role_iptvservice__known_ips[ip] is defined %}{{ role_iptvservice__known_ips[ip]['name'] }} | {{ ip }} |{% else %}{{ ip }} |{% endif %}
{% if __ip_info | selectattr('ip', '==', ip) | map(attribute='reverse') | first | length > 0 and __ip_info | selectattr('ip', '==', ip) | map(attribute='reverse') | first != 'NXDOMAIN' %}
{{ __ip_info | selectattr('ip', '==', ip) | map(attribute='reverse') | first }}
{% else %}
No Reverse DNS
{% endif %}
| {{ __ip_info | selectattr('ip', '==', ip) | map(attribute='org') | first }}
{% if loop.index < (user.ip_list | length) %}<br>{% endif %}
{% endfor %}
</td>
<td valign="top">
{% for agent in agent_list %}
{{ agent }}
{% if loop.index < (agent_list | unique | length) %}<br>{% endif %}
{% endfor %}
</td>
{% endif %}
</tr>
{% endfor %}
3 changes: 1 addition & 2 deletions templates/report.txt.j2
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ User Agent(s):
No connections for user.

{% endif %}
{% endfor %}

{% endfor %}

0 comments on commit d33cd93

Please sign in to comment.