Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Webhook json template example? #363

Open
YouveGotMeowxy opened this issue Jan 25, 2024 · 3 comments
Open

Webhook json template example? #363

YouveGotMeowxy opened this issue Jan 25, 2024 · 3 comments
Labels

Comments

@YouveGotMeowxy
Copy link

YouveGotMeowxy commented Jan 25, 2024

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
Copy link
Owner

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
Copy link
Author

YouveGotMeowxy commented Feb 9, 2024

@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
      }
    }
  ]
}

@sebastianfeldmann
Copy link
Owner

You have to create something that is able to receive this json body.

The phpbu web hook will call your URL with the json request body.
On your end you can read that body see if a backup failed and then take the appropriate steps.

your web hook pseudo code

// read the http request body
json = http_request_body()

// parse json
info = json_decode( json )

// check if the backups where successful
if ( info.backupFailed > 0 ) 
  // do something appropriate
  alert()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants