Report templating formatted variables/additional variables

I’ve been using the reports feature for backups, trying to get something going that posts notifications to Discord. I was able to get the payload structure working, but I had a few requests since the formatting of certain variables is giving me issues. I’ve copied my payload and an example of the resulting notification at the bottom, if anyone is interested and wants to use/expand on it.

Seems golang templating is limited, is there a way to get the file sizes formatted into MB/GB/TB? This is already being calculated to some degree for the stats that are logged.

2020-10-10 00:17:44.454 INFO BACKUP_STATS Files: 1128007 total, 133,320M bytes; 37 new, 1,886M bytes

I also couldn’t find basic arithmetic functions for golang templating, so I was struggling to calculate time taken even though it would be {{.end_time}} - {{.start_time}}, then formatted into hours/minutes/seconds. Could it be possible to expose this variable natively? This is also already being logged in a reasonable format. It could also help to get endtime/starttime in UTC format so that they can be used for timestamps in Discord (Unix doesn’t work)

INFO BACKUP_STATS Total running time: 00:02:43

I also couldn’t find a variable for revision number, which is also appearing in the logs

BACKUP_END Backup for /backuproot at revision 15 completed

Finally, I hope we can get the opportunity to define report templates for copies, prunes, and checks, though copy is the most important one since that acts as an additional backup. I have a scheduled job that runs multiple iterations of each command, and being able to generate a report for the entire job would be ideal.

{
    "username": "Duplicacy",
    "avatar_url": "https://avatars3.githubusercontent.com/u/10550069?s=400&v=4",
    "embeds": [
    {
        "author": {
            "name": "Duplicacy",
            "url": "https://duplicacy.com",
            "icon_url": "https://avatars3.githubusercontent.com/u/10550069?s=400&v=4"
        },
        "title": "{{.computer}} {{.storage}} Backup: {{if eq .result "Success"}} :white_check_mark: {{else}} :x: {{end}}",
        "url": "https://duplicacy.domain.com",
        "color": {{if eq .result "Success"}} 4961603 {{else}} 13369344 {{end}},
        "fields": [
            {
                "name": "New Files",
                "value": "{{.new_files}}",
                "inline": false
            },
            {
                "name": "New File Size",
                "value": "{{.new_file_size}}",
                "inline": false
            },
            {
                "name": "New Chunks",
                "value": "{{.new_chunks}}",
                "inline": false
            },
            {
                "name": "New Chunk Size",
                "value": "{{.new_chunk_size}}",
                "inline": false
            },
            {
                "name": "Total Files",
                "value": "{{.total_files}}",
                "inline": false
            },
            {
                "name": "Total File Size",
                "value": "{{.total_file_size}}",
                "inline": false
            },
            {
                "name": "Total Chunks",
                "value": "{{.total_chunks}}",
                "inline": false
            },
            {
                "name": "Total Chunk Size",
                "value": "{{.total_chunk_size}}",
                "inline": false
            }
        ]
    }
    ]
}

image

2 Likes

I can add a variable for the revision number, but not others (running time, formatted sizes etc). I believe those are more of an issue for the display frontend. Does Discord bot support javascript? With any web-based interface it should be fairly easy to implement simple javascript functions that convert raw data into more readable formats.

It’s not a web-based interface, but more like Slack. It has its own internal logic that converts the payload shown above into that screenshot. I can define which fields data is displayed in, but it will just show whatever data you map against those fields.

Typically, I send data to Discord via Python where I can make the changes to the data within the template itself fairly easily. It may be possible with golang, but it just seemed a lot harder since it didn’t even have basic arithmetic functions predefined. I’m also not sure if I would be able to define functions within the report.tmpl file that I can then use to modify the data.

I’m just sending to a Discord webhook. I can see if there are some bots/services that allow formatting of the data in between, but it’s not a typical usecase from what I’ve seen.