Merge pull request #3429 from pngwjpgh/feat/reverse-fqdn

Add placeholder for fqdn in reverse notation
This commit is contained in:
TW 2017-12-13 00:40:55 +01:00 committed by GitHub
commit 59ac75cf17
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 1 deletions

View File

@ -42,6 +42,9 @@ The (short) hostname of the machine.
.B {fqdn}
The full name of the machine.
.TP
.B {reverse-fqdn}
The full name of the machine in reverse domain name notation.
.TP
.B {now}
The current local date and time, by default in ISO\-8601 format.
You can also supply your own \fI\%format string\fP, e.g. {now:%Y\-%m\-%d_%H:%M:%S}

View File

@ -169,6 +169,9 @@ placeholders:
{fqdn}
The full name of the machine.
{reverse-fqdn}
The full name of the machine in reverse domain name notation.
{now}
The current local date and time, by default in ISO-8601 format.
You can also supply your own `format string <https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}

View File

@ -1901,6 +1901,9 @@ class Archiver:
{fqdn}
The full name of the machine.
{reverse-fqdn}
The full name of the machine in reverse domain name notation.
{now}
The current local date and time, by default in ISO-8601 format.
You can also supply your own `format string <https://docs.python.org/3.5/library/datetime.html#strftime-and-strptime-behavior>`_, e.g. {now:%Y-%m-%d_%H:%M:%S}

View File

@ -180,9 +180,11 @@ def format_line(format, data):
def replace_placeholders(text):
"""Replace placeholders in text with their values."""
current_time = datetime.now()
fqdn = socket.getfqdn()
data = {
'pid': os.getpid(),
'fqdn': socket.getfqdn(),
'fqdn': fqdn,
'reverse-fqdn': '.'.join(reversed(fqdn.split('.'))),
'hostname': socket.gethostname(),
'now': DatetimeWrapper(current_time.now()),
'utcnow': DatetimeWrapper(current_time.utcnow()),