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

fix: fix code samples #1805

Merged
merged 2 commits into from
Sep 3, 2024
Merged

fix: fix code samples #1805

merged 2 commits into from
Sep 3, 2024

Conversation

35C4n0r
Copy link
Contributor

@35C4n0r 35C4n0r commented Sep 2, 2024

Closes #1806

Now

Corrected code for Python:

import requests

response = requests.post("https://562a-110-235-218-103.ngrok-free.app/alerts/event",
headers={
  "Content-Type": "application/json",
  "Accept": "application/json",
  "X-API-KEY": "091a661d-6dad-4d16-9bb3-575bc2a260fb"
},
data="""{
  "id": "b1f1373b-6012-4236-b31d-ccff45e5f1c8",
  "name": "Alert name",
  "status": "firing",
  "lastReceived": "2024-09-02T18:10:56.983Z",
  "environment": "production",
  "isDuplicate": false,
  "duplicateReason": null,
  "service": "backend",
  "source": [
    "keep"
  ],
  "message": "Keep: Alert message",
  "description": "Keep: Alert description",
  "severity": "critical",
  "pushed": true,
  "event_id": "1234",
  "url": "https://www.keephq.dev?alertId=1234",
  "labels": {
    "key": "value"
  },
  "ticket_url": "https://www.keephq.dev?enrichedTicketId=456",
  "fingerprint": "c95cc937-ba82-478f-9e55-a5cfe1508c5c"
}""")
      

Corrected code for Node

const https = require('https');
const { URL } = require('url');

const url = new URL('https://562a-110-235-218-103.ngrok-free.app/alerts/event');
const data = JSON.stringify({
  "id": "a9ea407f-f0ed-4cdb-b857-b7a9e8e37a53",
  "name": "Alert name",
  "status": "firing",
  "lastReceived": "2024-09-02T18:13:42.502Z",
  "environment": "production",
  "isDuplicate": false,
  "duplicateReason": null,
  "service": "backend",
  "source": [
    "keep"
  ],
  "message": "Keep: Alert message",
  "description": "Keep: Alert description",
  "severity": "critical",
  "pushed": true,
  "event_id": "1234",
  "url": "https://www.keephq.dev?alertId=1234",
  "labels": {
    "key": "value"
  },
  "ticket_url": "https://www.keephq.dev?enrichedTicketId=456",
  "fingerprint": "7f62e659-e7c9-4fd8-b753-541e3cc1a963"
});

const options = {
  hostname: url.hostname,
  port: 443,
  path: url.pathname,
  method: 'POST',
  headers: {
    'Content-Type': 'application/json',
    'Accept': 'application/json',
    'X-API-KEY': '091a661d-6dad-4d16-9bb3-575bc2a260fb',
    'Content-Length': data.length
  }
};

const req = https.request(options, (res) => {
  console.log(`statusCode: ${res.statusCode}`);

  res.on('data', (d) => {
    process.stdout.write(d);
  });
});

req.on('error', (error) => {
  console.error(error);
});

req.write(data);
req.end();
    

Signed-off-by: 35C4n0r <jaykumar20march@gmail.com>
Copy link

vercel bot commented Sep 2, 2024

@35C4n0r is attempting to deploy a commit to the KeepHQ Team on Vercel.

A member of the Team first needs to authorize it.

@talboren talboren self-requested a review September 3, 2024 06:30
Copy link
Member

@talboren talboren left a comment

Choose a reason for hiding this comment

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

LGTM! thank you!

@talboren talboren enabled auto-merge (squash) September 3, 2024 06:30
Copy link

vercel bot commented Sep 3, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
keep ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 3, 2024 6:33am

@talboren talboren merged commit b78aa0b into keephq:main Sep 3, 2024
8 checks passed
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.

[🐛 Bug]: Bugs in code examples for Python and Node
2 participants