Skip to content

Instantly share code, notes, and snippets.

@jhersh
Created January 14, 2014 00:46
Show Gist options
  • Save jhersh/8410973 to your computer and use it in GitHub Desktop.
Save jhersh/8410973 to your computer and use it in GitHub Desktop.
Crashlytics -> PushOver
<?php
/**
* This script accepts a JSON payload from Crashlytics and forwards it to pushover,
* so you get a push notification when your app has a new crash!
*
* 1. Put this script on a server somewhere.
* 2. Fill in your pushover token and user keys.
* 3. Set up a web hook in Crashlytics with the URL to this script.
*/
define('PUSHOVER_URL', 'https://api.pushover.net/1/messages.json');
define('PUSHOVER_TOKEN', '-- YOUR PUSHOVER TOKEN --');
define('PUSHOVER_USER', '-- YOUR PUSHOVER USER/GROUP KEY --');
// Crashlytics crash receiver
function twohundred() {
header('HTTP/1.1 200 OK');
}
function fivehundred() {
header('HTTP/1.1 500 Internal Server Error');
}
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
echo "<strong>Missing POST</strong>";
exit(0);
}
$payload = urldecode(file_get_contents('php://input'));
$arr = json_decode($payload, true);
$event = $arr['event'];
if (!isset($event)) {
fivehundred();
echo 'Missing event';
exit(0);
}
// Initial crashlytics setup -- sends a special payload with a verification key.
// Script must respond with a 200
if ($event === 'verification') {
twohundred();
exit(0);
}
$arr = $arr['payload'];
if (!isset($arr)) {
fivehundred();
echo "Missing payload";
exit(0);
}
$url = $arr['url'];
$title = $arr["title"];
$message = "New crash: $title";
$ch = curl_init(PUSHOVER_URL);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "url=$url&token=" . PUSHOVER_TOKEN ."&user=" . PUSHOVER_USER . "&message=$message");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
// Execute
$received = curl_exec($ch);
curl_close($ch);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment