sebastianfeldmann / phpbu

PHP Backup Utility - Creates and encrypts database and file backups, syncs your backups to other servers or cloud services and assists you monitor your backup process
https://phpbu.de
Other
1.29k stars 110 forks source link

Webhook json template example? #363

Open YouveGotMeowxy opened 7 months ago

YouveGotMeowxy commented 7 months ago

Does anybody have one for us not-so-technically-savvy? lol

I tried using several different online XML to JSON converters with the XML example from:

https://phpbu.de/manual/current/en/logging.html#logging.webhook

but they're not working (I get errors). Plus the XML example seems(?) like it doesn't include all possible results (available result vars).

Should I just copy the 'default result body example':

{
  "status": 0,
  "timestamp": 12783781381,
  "duration": 234.3402,
  "backupCount": 1,
  "backupFailed": 0,
  "errorCount": 0,
  "errors": [],
  "backups": [
    {
      "name":
      "status":
      "checks": {
          "executed": 1,
          "failed": 0,
      },
      "crypt": {
          "executed": 1,
          "skipped": 0,
          "failed": 0,
      },
      "syncs" => {
          "executed": 1,
          "skipped": 0,
          "failed": 0
      },
      "cleanup" => {
          "executed": 1,
          "skipped": 0,
          "failed": 0
      }
    }
  ]
}

and hunt down the available matching vars to place on their respective lines? Where can I find that list of all available vars?

thanks in advance! :)

sebastianfeldmann commented 7 months ago

So the web hook works like this.

Put this in your phpbu config file

{
  "type": "webhook",
  "options": {
     "uri": "http://example.com/hook"
   }
}

phpbu will then call your configured uri and send some data to that url. So you have to setup a URL that phpbu can call and that reads the data and does something with it.

For example you want to write every backup result into your own database somehow. You can use the webhook to call a script of yours that connects to your database and writes the infos.

If you develop the script on your end you can use the json example from the documentation.

{
  "status": 0,
  "timestamp": 12783781381,
  "duration": 234.3402,
  "backupCount": 1,
  "backupFailed": 0,
  "errorCount": 0,
  "errors": [],
  "backups": [
    {
      "name":
      "status":
      "checks": {
          "executed": 1,
          "failed": 0,
      },
      "crypt": {
          "executed": 1,
          "skipped": 0,
          "failed": 0,
      },
      "syncs" => {
          "executed": 1,
          "skipped": 0,
          "failed": 0
      },
      "cleanup" => {
          "executed": 1,
          "skipped": 0,
          "failed": 0
      }
    }
  ]
}

This is what will be sent to your URL. So you have to program some logic that reads this data and uses it in a way you want to.

YouveGotMeowxy commented 7 months ago

@sebastianfeldmann What are all of the variables available to use though?

for example, the % vars in this:

{
  "tag": "phpbu",
  "title": "phpbu test title",
  "type": "info",
  "body": "Backup done: %status% - %timestamp%"
}

i.e. should I create something that sends this in the body?:

{
  "status": %status% ,
  "timestamp": %timestamp%",
  "duration": %varname?%,
  "backupCount": %varname?%,
  "backupFailed": %varname?%,
  "errorCount": %etc.-for all the rest below as well%,
  "errors": [],
  "backups": [
    {
      "name":
      "status":
      "checks": {
          "executed": 1,
          "failed": 0,
      },
      "crypt": {
          "executed": 1,
          "skipped": 0,
          "failed": 0,
      },
      "syncs" => {
          "executed": 1,
          "skipped": 0,
          "failed": 0
      },
      "cleanup" => {
          "executed": 1,
          "skipped": 0,
          "failed": 0
      }
    }
  ]
}