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

How can I get the termination information via webhook? #161

Closed
HankChow opened this issue May 13, 2020 · 7 comments
Closed

How can I get the termination information via webhook? #161

HankChow opened this issue May 13, 2020 · 7 comments
Labels
Type: Question All types of questions to/from customers

Comments

@HankChow
Copy link

I have deployed aws-node-termination-handler as DaemonSet in an EKS cluster. I set the configuration of flags in order to receive notification via webhook when a spot instance terminates.
To test whether the flags will work, I only set the flag WEBHOOK_URL with a url which is listening for HTTP requests and leave blanks for other flags as default.
I did receive an POST request from a terminating spot instance in EKS cluster terminates. It is expected a JSON like {"text":"[NTH][Instance Interruption] EventID: {{ .EventID }} - Kind: {{ .Kind }} - Description: {{ .Description }} - State: {{ .State }} - Start Time: {{ .StartTime }}"} which provided by the official documentation. But I can't see anything in the request payload.

@bwagner5
Copy link
Contributor

The default webhook request template is for slack webhooks. Depending on what server you're sending the request to, you may need to change the template to match the expected request body.

There's an example in our end-to-end test suite where we change the template to the expected request structure for amazon chime webhooks:

--set webhookTemplate="\{\"Content\":\"[NTH][Instance Interruption] InstanceId: \{\{ \.InstanceID \}\} - InstanceType: \{\{ \.InstanceType \}\} - Kind: \{\{ \.Kind \}\} - Start Time: \{\{ \.StartTime \}\}\"\}" \

@bwagner5 bwagner5 added the Type: Question All types of questions to/from customers label May 13, 2020
@ulisse31
Copy link
Contributor

I don't know if it makes sense to post it in this thread, but our webhook is set to send notifications to Slack, and some of the fields are empty. Is it supposed to be this way?

Screenshot 2020-05-13 at 18 56 30

@bwagner5
Copy link
Contributor

@ulisse31 I believe you're seeing the same error as this issue #104. This was fixed in v1.3.0, so if you're on a version pre v1.3.0, upgrading to v1.3.1 or to the latest v1.4.0 release should fix it for you.

@HankChow
Copy link
Author

@bwagner5 Thanks for your answering.
The request is sent to an application based on Flask. I can see that the request does reach my Flask application with POST method, but there is nothing in the payload of the request.

@ulisse31
Copy link
Contributor

ulisse31 commented May 14, 2020

@ulisse31 I believe you're seeing the same error as this issue #104. This was fixed in v1.3.0, so if you're on a version pre v1.3.0, upgrading to v1.3.1 or to the latest v1.4.0 release should fix it for you.

@bwagner5 We're already running v1.3.1 on EKS 1.14.
We have planned to upgrade 1.4.0 so I'll give it a try and in case report back. Thank you for your reply!

@bwagner5
Copy link
Contributor

bwagner5 commented May 14, 2020

@HankChow I did a test with a flask server:

Flask Source Code

$ cat flaskapp.py
from flask import Flask
from flask import request
app = Flask(__name__)

@app.route('/', methods=['POST'])
def index():
    print(request.data)
    return

aws-node-termination-handler local binary

$ git clone [email protected]:aws/aws-node-termination-handler.git
$ cd aws-node-termination-handler
$ go build cmd/node-termination-handler.go
$ ./node-termination-handler --dry-run --node-name test --webhook-url http://localhost:5000 --metadata-url http://localhost:1338

EC2 Metadata Mock

$ curl -Lo ec2-metadata-mock https://github.com/aws/amazon-ec2-metadata-mock/releases/download/v0.9.0/amazon-ec2-metadata-mock-$(uname | tr '[:upper:]' '[:lower:]')-amd64
$ chmod +x ec2-metadata-mock
$ ./ec2-metadata-mock spotitn
...
2020/05/14 14:38:02 Initiating amazon-ec2-metadata-mock for EC2 Spot interruption notice on port 1338
...

Flask Stdout Log

$ pip3 install flask
$ export FLASK_APP="flaskapp.py"
$ flask run
 * Serving Flask app "flaskapp.py"
 * Environment: production
   WARNING: This is a development server. Do not use it in a production deployment.
   Use a production WSGI server instead.
 * Debug mode: off
 * Running on http://127.0.0.1:5000/ (Press CTRL+C to quit)
b'{"text":"[NTH][Instance Interruption] EventID: spot-itn-1229fe2a46345395a6df93665219d2f184213a5edefed2092a2343c2ff797b63 - Kind: SPOT_ITN - Description: Spot ITN received. Instance will be interrupted at 2020-05-14T19:34:54Z \n - Start Time: 2020-05-14 19:34:54 +0000 UTC"}'

Printing request.data from the flask handler shows the webhook data.

@HankChow
Copy link
Author

@bwagner5 Thanks for your answering.
I get the webhook data from request.data successfully. It was my mistake that I tried to get the webhook data from request.json.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Question All types of questions to/from customers
Projects
None yet
Development

No branches or pull requests

3 participants