Skip to content

Instantly share code, notes, and snippets.

@justynroberts
Created May 20, 2022 09:22
Show Gist options
  • Save justynroberts/b4dea6bfbe40ab221e8833fe57fd9417 to your computer and use it in GitHub Desktop.
Save justynroberts/b4dea6bfbe40ab221e8833fe57fd9417 to your computer and use it in GitHub Desktop.
Trigger a PagerDuty event from a local page. Add your own Routing key, Modify the payload
<!doctype html>
<html lang="en">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@4.0.0/dist/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
</head>
<body>
<div class="jumbotron">
<h1 class="display-4">FireDuty</h1>
<p class="lead">Trigger a real-time Pagerduty Event using the events API </p>
<hr class="my-4">
<p>Add your own routing key below</p>
<p class="lead">
<input type="text" name="globalkey" value="Enter Routing Key">
</p>
<p class="lead">
<button name="button" class="btn btn-outline-danger btn.lg "type="button" >A BIG RED INCIDENT TRIGGER
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" fill="currentColor" class="bi bi-exclamation-diamond-fill" viewBox="0 0 16 16">
<path d="M9.05.435c-.58-.58-1.52-.58-2.1 0L.436 6.95c-.58.58-.58 1.519 0 2.098l6.516 6.516c.58.58 1.519.58 2.098 0l6.516-6.516c.58-.58.58-1.519 0-2.098L9.05.435zM8 4c.535 0 .954.462.9.995l-.35 3.507a.552.552 0 0 1-1.1 0L7.1 4.995A.905.905 0 0 1 8 4zm.002 6a1 1 0 1 1 0 2 1 1 0 0 1 0-2z"/>
</svg>
</button>
</p>
</div>
</html>
<script>
var button = document.querySelector('button');
button.onclick = function() {
var xhr = new XMLHttpRequest();
var url = "https://events.pagerduty.com/v2/enqueue";
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/json");
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var json = JSON.parse(xhr.responseText);
console.log(data);
}
};
var globalkey = document.getElementsByName('globalkey')[0].value
var data = JSON.stringify({
"payload": {
"summary": "[Synthetic Warning] TravelDuty Synthetic Failure",
"source": "Alertmanager",
"component": "Alertmanager",
"group": "Customer Website,Checkout",
"class": "Prometheus",
"custom_details": {
"AlarmName": "Transactions-Web",
"Customer": "Global Cheese Farm",
"AlarmDescription": "Transactions completed via website",
"AlertValue": "WARNING",
"AlertReason": "Transactions on *WEBSITE* > *EXPECTED VAL*",
"Table": "GLOBAL-VIEW"
},
"client": "Alertmanager",
"severity": "critical",
"client_url": "https://www.Alertmanager.com",
"images": [
{
"src": "https://logz.io/wp-content/uploads/2017/03/memory-graph.png",
"alt": "Snapshot of Alertmanager Dashboard",
"href": "https://logz.io/wp-content/uploads/2017/03/memory-graph.png"
}
]
},
"routing_key": globalkey,
"event_action": "trigger"
}
);
xhr.send(data);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment