Skip to content

Allow specifying webhooks to get installer event notifications #57

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

Merged
merged 2 commits into from
Mar 30, 2021

Conversation

bk201
Copy link
Member

@bk201 bk201 commented Mar 10, 2021

Relate issue
harvester/harvester#469

With this change, the user can add webhooks in the config and the installer will send HTTP
requests to custom URLs on some predefined events.

The user can add webhooks under the install key of the harvester configuration file:

The following is a configuration example:

install:
  webhooks:
    - event: SUCCEEDED
      method: GET
      url: http://10.100.0.100/cblr/svc/op/nopxe/system/{{.Hostname}}
    - event: STARTED
      method: GET
      url: https://10.100.0.100/started/{{.Hostname}}
      insecure: true
      basicAuth:
        user: admin
        password: p@assword
    - event: FAILED
      method: POST
      url: http://10.100.0.100/record
      headers:
        Content-Type:
           - 'application/json; charset=utf-8'
      payload: |
        {
          "host": "{{.Hostname}}",
          "device": "hd"
        }

Explanation of the fields:

  • event: Event type to trigger HTTP action on the webhook

    • STARTED: The installer just begins to perform installation.
    • SUCCEEDED: The installation completes without errors.
    • FAILED: The installation is failed.

    Example:

    event: SUCCEEDED
  • method: HTTP method

    Example:

    method: GET
  • url*: The URL to send the HTTP request.

    url: http://mycompany.com
  • insecure: Do not verify server's certificate if true. Default is false.

    Example:

    insecure: true
  • basicAuth: Use 'Basic' HTTP Authentication.

    Example:

    basicAuth:
      user: admin
      password: p@ssword
  • headers: Include custom headers in the HTTP requests.

    Example:

    headers:
      Content-Type:
        - 'application/json; charset=utf-8'

    Above configuration will includes Content-Type: application/json; charset=utf-8 in the HTTP request.

    NOTE: Headers like Content-Length are automatically included.

  • payload*: The payload data to be sent with the request.

    Example:

    payload: |
      {
        "host": "{{.Hostname}}",
        "device": "hd"
      }

    NOTE: The user might need to set the correct Content-Type header with the headers configuration to make the server accept the request.

* The values for url and payload can be written in Go template, the following variables will be substituted with appropriate values of the node that is being installed:

  • Hostname: the hostname of the node.
  • MACAddr: the MAC address of the management interface
  • IPAddrV4: the IPv4 address of the management interface
  • IPAddrV6: the IPv6 address of the management interface

Additional information

  • The installer can send multiple requests for a single event. But if one of them fails, the remaining requests will not be sent.
  • The installer will retry 3 times with a 5 seconds-sleep if the request is timed out.

@bk201 bk201 requested review from innobead and gitlawr March 10, 2021 10:31
@guangbochen
Copy link
Contributor

@bk201 can u please rebase the PR and take a look at the above comments, thanks.

Kiefer Chang added 2 commits March 29, 2021 19:06
To do things in the go code after running install script, we need to
prevent the install script rebooting or shutting down.

Signed-off-by: Kiefer Chang <[email protected]>
The user can add webhooks in the config and the installer will send HTTP
requests to custom URLs on some predefined events:

- `STARTED`: The installer just begins to perform installation.
- `SUCCEEDED`: The installation completes without errors.
- `FAILED`: The installation is failed.

The following configuration makes the installer send:
- a GET request to the defined URL when the installation is succeeded.
- a PUT request to the defined URL with payload when the installation is
  failed.

```
install:
  webhooks:
    - event: SUCCEEDED
      method: GET
      url: http://10.100.0.100/cblr/svc/op/nopxe/system/{{.Hostname}}
    - event: FAILED
      method: PUT
      url: http://10.100.0.100/record
      payload: |
        {
          "host": "{{.Hostname}}",
          "device": "hd"
        }
```

Note the values for `url` and `payload` can be Golang template, the
following variables will be substituted with appropriate values of the
node that is being installed:

- `Hostname`: the hostname of the node.
- `MACAddr`: the MAC address of the management interface
- `IPAddrV4`: the IPv4 address of the management interface
- `IPAddrV6`: the IPv6 address of the management interface

Signed-off-by: Kiefer Chang <[email protected]>
@bk201
Copy link
Member Author

bk201 commented Mar 29, 2021

@bk201 can u please rebase the PR and take a look at the above comments, thanks.

Rebased!

@bk201 bk201 requested a review from gitlawr March 29, 2021 15:44
Copy link
Contributor

@gitlawr gitlawr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

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

Successfully merging this pull request may close these issues.

3 participants