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

Implement webhooks endpoints in hostd API #189

Closed
justmert opened this issue Oct 14, 2023 · 9 comments · Fixed by #229
Closed

Implement webhooks endpoints in hostd API #189

justmert opened this issue Oct 14, 2023 · 9 comments · Fixed by #229
Assignees
Labels
feature A new feature request or enhancement good first issue Good for newcomers
Milestone

Comments

@justmert
Copy link

Description

I am developing a Telegram bot to forward urgent Renterd alerts to the Telegram app of end-user. This require registering a new webhook for alert modules, and subsequently monitor and forward any triggered alerts to the Telegram user. I could do in renterd API since it has webhooks endpoints.

I wanted to do also include hostd alerts, but since it doesn't have any webhooks endpoints (that includes alerts), this seems not possible to do.

Could we add webhooks that includes alerts for hostd API?

Version

No response

What operating system are you running (e.g. Ubuntu 22.04, macOS, Windows 11)?

No response

Anything else?

No response

@justmert justmert added the feature A new feature request or enhancement label Oct 14, 2023
@n8maninger n8maninger added the good first issue Good for newcomers label Oct 14, 2023
@n8maninger n8maninger added this to the v1.0.0 milestone Oct 14, 2023
@multikatt
Copy link

I'm giving this a go, not completely sure I'm to the task though but if it's not urgent then give me a few days and i'll let you know how i fare.

@n8maninger
Copy link
Member

n8maninger commented Oct 15, 2023

@multikatt if you need any help on the design or have any questions, ping me here or in Discord.

@multikatt multikatt mentioned this issue Oct 16, 2023
@multikatt
Copy link

@n8maninger I've added a partly finished solution here, but I've some questions about the way I'm solving it that I've added to the PR that I think is for you.

@justmert
Copy link
Author

Thanks for the development of these endpoints since I needed those for my project!

@n8maninger
Copy link
Member

@n8maninger I've added a partly finished solution here, but I've some questions about the way I'm solving it that I've added to the PR that I think is for you.

I'll review today and get back to you

@justmert
Copy link
Author

justmert commented Nov 3, 2023

Hi, is this available to use?

@n8maninger
Copy link
Member

Not yet. The PR is still in progress #192

@justmert
Copy link
Author

justmert commented Nov 7, 2023

I want to ask a question apart from this issue @n8maninger.

Is there a way to detect which webhook response is coming from where? Let me explain it,

I am developing a Telegram bot that alert users when renterd/hostd alert event occurs.

Initial scheme was this,

  • Deploy Telegram Bot: a telegram bot would be deployed by me with DB integration (like Firestore).
    Register Webhook: a code snippet would be shared with renterd user that can be found in Github doc of this project. The snippet would be used to register webhook for their renterd.

  • Get user ID: user then make interact with bot (like register button) to give us their unique ID (this may be wallet address that will be used in renterd). Then I would save this ID in relation with that user’s Telegram chat ID in my DB.

  • Alert Trigger: when an alert is triggered in any user’s renterd instance, the event would come to bot (thanks to webhook) and the bot would check if the user is registered in our DB based on alert message. So the problem arises here.

  • There is no information that stores unique ID or wallet ID in alert messages. There can be, but as far as I know (speaking of API) there isn’t always. Alers can be like in below:

  [{
    "id": "h:d6c6d018c1fb11b78213ebfe0c3f6e59ceb525ca62de6ab29c142314b5343ce5",
    "severity": "error",
    "message": "failed to refill account: couldn't fund account: unable to fetch revision with contract: LatestRevision: failed to fetch pricetable, err: PriceTable: couldn't process payment: ReadResponse: stream was gracefully closed (29.109478968s)\n",
    "data": {
      "accountID": "ed25519:9a70a6e3023863a5a23cddb064336b845744f764609d40dd7d4d50bf3870c278",
      "contractID": "fcid:194e2d0216fd24c1e2e457965c60075c644f32fb3fa74e0a1310ef006fd8bc0d",
      "hostKey": "ed25519:573096e26690c796b023eb8385b7fe476a8cc7ae645294ce736f442d26f3d782",
      "origin": "autopilot.autopilot"
    },
    "timestamp": "2023-08-30T14:48:05.239891201Z"
  },
  {
    "id": "h:ff24699354782e8cf58d7074f3fa63c030ac0d81d674e141542006de99ecfa36",
    "severity": "info",
    "message": "wallet is low on funds",
    "data": {
      "address": "addr:a9adb468928455e381f8468fff2e5d0dc95e0755aef27daa9d845ed40565bf696f2637c7b19e",
      "balance": "141738724911491675264573908846",
      "origin": "autopilot.autopilot"
    },
    "timestamp": "2023-08-30T14:45:19.922778399Z"
  }]
  

So the first alarm stores accountID, but the second alarm doesn’t store it. Or second alarm stores address, but first one doesn’t.

If it is guarantee that any of the alarm stores consistent unique ID information, then the above scheme would work. So that, I would fetch Telegram chat ID from my DB based on unique ID and sent message to the user.

But, because of above problem, I don’t any option to host it. Is there a solution for it? Thank you

@n8maninger
Copy link
Member

n8maninger commented Nov 13, 2023

I want to ask a question apart from this issue @n8maninger.

Is there a way to detect which webhook response is coming from where? Let me explain it,

I am developing a Telegram bot that alert users when renterd/hostd alert event occurs.

Initial scheme was this,

  • Deploy Telegram Bot: a telegram bot would be deployed by me with DB integration (like Firestore).
    Register Webhook: a code snippet would be shared with renterd user that can be found in Github doc of this project. The snippet would be used to register webhook for their renterd.
  • Get user ID: user then make interact with bot (like register button) to give us their unique ID (this may be wallet address that will be used in renterd). Then I would save this ID in relation with that user’s Telegram chat ID in my DB.
  • Alert Trigger: when an alert is triggered in any user’s renterd instance, the event would come to bot (thanks to webhook) and the bot would check if the user is registered in our DB based on alert message. So the problem arises here.
  • There is no information that stores unique ID or wallet ID in alert messages. There can be, but as far as I know (speaking of API) there isn’t always. Alers can be like in below:
  [{
    "id": "h:d6c6d018c1fb11b78213ebfe0c3f6e59ceb525ca62de6ab29c142314b5343ce5",
    "severity": "error",
    "message": "failed to refill account: couldn't fund account: unable to fetch revision with contract: LatestRevision: failed to fetch pricetable, err: PriceTable: couldn't process payment: ReadResponse: stream was gracefully closed (29.109478968s)\n",
    "data": {
      "accountID": "ed25519:9a70a6e3023863a5a23cddb064336b845744f764609d40dd7d4d50bf3870c278",
      "contractID": "fcid:194e2d0216fd24c1e2e457965c60075c644f32fb3fa74e0a1310ef006fd8bc0d",
      "hostKey": "ed25519:573096e26690c796b023eb8385b7fe476a8cc7ae645294ce736f442d26f3d782",
      "origin": "autopilot.autopilot"
    },
    "timestamp": "2023-08-30T14:48:05.239891201Z"
  },
  {
    "id": "h:ff24699354782e8cf58d7074f3fa63c030ac0d81d674e141542006de99ecfa36",
    "severity": "info",
    "message": "wallet is low on funds",
    "data": {
      "address": "addr:a9adb468928455e381f8468fff2e5d0dc95e0755aef27daa9d845ed40565bf696f2637c7b19e",
      "balance": "141738724911491675264573908846",
      "origin": "autopilot.autopilot"
    },
    "timestamp": "2023-08-30T14:45:19.922778399Z"
  }]
  

So the first alarm stores accountID, but the second alarm doesn’t store it. Or second alarm stores address, but first one doesn’t.

If it is guarantee that any of the alarm stores consistent unique ID information, then the above scheme would work. So that, I would fetch Telegram chat ID from my DB based on unique ID and sent message to the user.

But, because of above problem, I don’t any option to host it. Is there a solution for it? Thank you

Add the unique ID to your webhook URL: https://my.webhook.com?uid=1234. renterd will call the URL and you can match the UID with your backend.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature request or enhancement good first issue Good for newcomers
Projects
Status: Released
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants