Skip to content

Instantly share code, notes, and snippets.

@joltcan
Last active June 4, 2020 09:17
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joltcan/5d0dbf22842b037702febd3d9eb68780 to your computer and use it in GitHub Desktop.
Save joltcan/5d0dbf22842b037702febd3d9eb68780 to your computer and use it in GitHub Desktop.
Simple php-curl post to Pushbullet as a wrapper for Grafana webhooks
<?php
// simple proxy from Grafana to Pushbullet. Bare minimum.
// please update Access-token to your liking. Feel free to use device_iden if
// you want to send to a specific device. Default is all.
// usage: example.com/pushbullet-proxy.php?title=test&body=testbody
// Find your token here: https://www.pushbullet.com/#settings/account
$access_token = '<my token>';
// API specification at http://docs.grafana.org/alerting/notifications/#webhook
$input = json_decode(file_get_contents('php://input'), true);
// push message
$body = "Message: " . $input['message'];
$post_data = array(
// 'device_iden' => '<a pushbullet device identifier>',
'type' => 'link',
'title' => $input['title'],
'url' => $input['ruleUrl'],
'body' => $body
);
$json_data = json_encode($post_data);
$ch = curl_init("https://api.pushbullet.com/v2/pushes");
// Prepare our JSON header
$headers = array(
'Content-Type: application/json',
'Content-Length: ' . strlen($json_data),
'Access-Token: ' . $access_token
);
// set options to send JSON
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POSTFIELDS, $json_data);
$resp = curl_exec($ch);
curl_close($ch);
// print response for debug
// var_dump($resp);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment