Get last backup status for PRTG sensor


#1

Hi there

I would like to write a prtg sensor to monitor the backup status. Inspired by this PRTG Sensor https://mycloudrevolution.com/2016/03/21/veeam-prtg-sensor-reloaded/

If I do have a Backupjob for example DJob1, is ther a possibility to get the following info from the console?
Last run time
Last status (Success, Warning, Error)
Last backup size

Thanks in advance
Steff


#2

Hi @ts-man, welcome to the forum!

Adding PRTG Sensor support is an interesting idea - and yes, anything you can see in the GUI (including the 3 items you mentioned) is potentially available in console.

The first trick is getting authentication to connect to the Duplicati server (which is where the information comes from).

I haven’t read through the code you linked to, but some thing to consider include:

  • How to handle if there are multiple backup jobs (some may be scheduled, others now)

  • How to handle if there are multiple Duplicati servers (such as a service / daemon and one more my per-user Tray-Icon servers)

In the end you may find it easier to code a new PRTG specific module directly into Duplicati than to try and authenticate and connect to the existing API…


#3

Thank you @JonMikelV

There are a lot of possibilities to consider.
I’ll start with the following configuration. Windows 2012 R2 Server with Duplicati2 running as a Service.
My Idea was to write a Powershell or Console Script which collects the items per Task (possibly by the Task Name). The script would then outputs PRTG XML Code (What is the XML Schema for EXEXML sensor? | Paessler Knowledge Base). I’ve allready created such scripts.
With this solution you have to add a PRTG Sensor for each backup Task. Which, in my opinion, isn’t the badest idea.

So to start. How can i get the mentioned items for a backup task from the console?

Lets name the Task TestDATA


#6

The Duplicati commandline is not strictly connected to the Duplicati server. So what you’ll likely want is to pull the data from the servers web API.

I’ve written a python client that can fetch this data from the API, so in principle you can just call it and extract the info you want. GitHub - Pectojin/duplicati_client: A command line client for controlling the Duplicati Server

An example of the output from the client:

# duplicati_client get backup 3
- Server:
    ID: '3'
    Last run:
      Duration: 00:09:22
      Started: 11:00 PM
      Stopped: 11:09 PM
    Local database: /root/.config/Duplicati/MXDZYFYGEQ.sqlite
    Progress:
      Backend:
        Action: Get
        Progress: 100.00%
        Speed: 70.34 KB/s
      State: Backup_WaitForUpload
      Task ID: 29
    Schedule:
      Last run: 11:00 PM
      Next run: 03:00 AM
      Repeat: 4h
    Size:
      Backend: 139.33 GB
      Local: 176.66 GB
    Versions: 28

And you can extrapolate the ID’s from the list command:

# duplicati_client list backups
- Server:
    ID: '3'
    Last run: 11:00 PM
    Next run: 03:00 AM
    Running:
      State: Backup_WaitForUpload
      Task ID: 29
- Email:
    ID: '19'
    Last run: 24/04/2018
    Next run: 01/05/2018

#7

This is awesome. I’ll have a look at it next week.

Thank you @Pectojin


#8

This looks interesting… can I use it to trigger actions in the web server? Like telling it to execute a certain job?

In my setup I have two backup jobs: the main one and then a separate job that backs up JUST the database from the main job. Right now I am using the duplicati command line to accomplish that but don’t like how it runs completely independent of the web server piece.

EDIT: Never mind, I actually read the documentation and see that it will do this. Cool, going to play around with it!


#9

Yep, exactly :slight_smile:

That’s the main reason for the client :slight_smile:
It does it’s actions through the web server so it never has that problem


#10

@Pectojin
Thank you. Your script led me to the right track

For those interested in a first view. Check out https://github.com/TS-Steff/PRTG-Duplicati

It’s in a very early state now. I’ll spend my free time in this. So be patient. It’ll take time to progress.


#11

I am playing around with this now and it works great on a Windows PC…thanks!

Also trying it out on a Synology NAS. I got the Linux binary and the “logon” and “logout” commands work, but when I tell it to “list backups” it just hangs.

Any ideas? (I hit CTRL+C after about 5 minutes in the below snippet)

bash-4.3# ./duplicati_client login
Login successful
bash-4.3# ./duplicati_client list backups
^CTraceback (most recent call last):
  File "urllib3/connectionpool.py", line 380, in _make_request
TypeError: getresponse() got an unexpected keyword argument 'buffering'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "duplicati_client.py", line 1115, in <module>
  File "duplicati_client.py", line 99, in main
  File "duplicati_client.py", line 196, in list_resources
  File "duplicati_client.py", line 213, in fetch_backup_list
  File "duplicati_client.py", line 235, in fetch_resource_list
  File "requests_wrapper.py", line 28, in get
  File "requests/api.py", line 72, in get
  File "requests/api.py", line 58, in request
  File "requests/sessions.py", line 508, in request
  File "requests/sessions.py", line 618, in send
  File "requests/adapters.py", line 440, in send
  File "urllib3/connectionpool.py", line 601, in urlopen
  File "urllib3/connectionpool.py", line 383, in _make_request
  File "http/client.py", line 1197, in getresponse
  File "http/client.py", line 297, in begin
  File "http/client.py", line 258, in _read_status
  File "socket.py", line 575, in readinto
KeyboardInterrupt
[7727] Failed to execute script duplicati_client
bash-4.3# ./duplicati_client logout
Logging out...
bash-4.3#

#12

Hmm, that looks pretty strange. From the trace it definitely makes the request, but on the socket layer it hangs.

It could either be failing to make the request or the target server isn’t responding (and apparently it doesn’t timeout)

Is this using the Linux binary? I must admit I haven’t tested it on Synology :slight_smile:


#13

Yep Linux binary. Synology does have a Python3 package I can install to possibly run the script directly, but they don’t have a package for the yaml library.


#14

Just bumping this thread… Anyone able to get duplicati_client working on Synology yet?