From ddffea2d5db44a0b518673e581fc9d8058124f1c Mon Sep 17 00:00:00 2001 From: Leonidas Poulopoulos Date: Mon, 13 Feb 2012 18:19:32 +0200 Subject: [PATCH] Added FQDN resolving in mail notification templates to denote the host that an action originated --- flowspec/templatetags/tofqdn.py | 18 ++++++++++++++++++ templates/rule_add_mail.txt | 3 ++- templates/rule_delete_mail.txt | 3 ++- templates/rule_edit_mail.txt | 3 ++- 4 files changed, 24 insertions(+), 3 deletions(-) create mode 100644 flowspec/templatetags/tofqdn.py diff --git a/flowspec/templatetags/tofqdn.py b/flowspec/templatetags/tofqdn.py new file mode 100644 index 0000000..5de1dcb --- /dev/null +++ b/flowspec/templatetags/tofqdn.py @@ -0,0 +1,18 @@ +from django import template +from django.utils.safestring import mark_safe +from django.utils.encoding import force_unicode +import socket + +register = template.Library() + +@register.filter +def tofqdn(value): + try: + fqdn = socket.getfqdn(value) + if fqdn == value: + return False + else: + return fqdn + except socket.gaierror: + return False + \ No newline at end of file diff --git a/templates/rule_add_mail.txt b/templates/rule_add_mail.txt index 999e1f1..acf547f 100644 --- a/templates/rule_add_mail.txt +++ b/templates/rule_add_mail.txt @@ -1,7 +1,8 @@ +{% load tofqdn %} A new rule creation job has spawned Peer: {{route.applier.get_profile.peer.peer_name}} -User {{route.applier.username}} requested the application of the following rule from address {{address}} : +User {{route.applier.username}} requested the application of the following rule from address {{address}} {% if address|tofqdn %}({{address|tofqdn}}){% endif %}: Match * Dst Addr:{{route.destination}} diff --git a/templates/rule_delete_mail.txt b/templates/rule_delete_mail.txt index a3ef5a5..2a7c960 100644 --- a/templates/rule_delete_mail.txt +++ b/templates/rule_delete_mail.txt @@ -1,7 +1,8 @@ +{% load tofqdn %} A new rule removal job has spawned Peer: {{route.applier.get_profile.peer.peer_name}} -User {{route.applier.username}} requested the removal of the following rule from address {{address}} : +User {{route.applier.username}} requested the removal of the following rule from address {{address}} {% if address|tofqdn %}({{address|tofqdn}}){% endif %}: Match * Dst Addr:{{route.destination}} diff --git a/templates/rule_edit_mail.txt b/templates/rule_edit_mail.txt index c0996ab..974d6c3 100644 --- a/templates/rule_edit_mail.txt +++ b/templates/rule_edit_mail.txt @@ -1,7 +1,8 @@ +{% load tofqdn %} A new rule edit job has spawned Peer: {{route.applier.get_profile.peer.peer_name}} -User {{route.applier.username}} requested the application of the following rule from address {{address}} : +User {{route.applier.username}} requested the application of the following rule from address {{address}} {% if address|tofqdn %}({{address|tofqdn}}){% endif %}: Match * Dst Addr:{{route.destination}} -- 1.7.10.4