Overview
To configure alerts you will need a Remote API Key, which is not the same as the API Key used to send CDR data to Humbug.
The Remote API Key is used for:
- Adding / Configuring Alerts
- Adding / Removing sub-API keys to your account
- General Account Configuration
Remotely add and configure alerts to your account
URL for POST Request: http://analytics.humbuglabs.org/index.php/remote_api/api_remote_add_alert/
Sample API Creation POST Request:
key=asoiufb9av8h9ahaq9vh98ahvaspdfiouaba8sy7f&salt=1981938447&apikey_ident=asdf08a7gf0asd8f7ga82f8gag98h&alert_id=18&config={"daily_cost":"120","email":"1","sms":"1"}
Response: (JSON Formatted)
You will receive a JSON response providing you with the status of the request, for example:
{"result":true,"msg":"OK"}
{"result":true,"msg":"OK"}
Programatically remove alerts from your account.
URL for POST Request: http://analytics.humbuglabs.org/index.php/remote_api/remote_del_alert/
Sample API Deletion POST Request:
key=asoiufb9av8h9ahaq9vh98ahvaspdfiouaba8sy7f&salt=1981938447&apikey_ident=sd89f7hf0as978fg2s9f8h2as8f7gas0
Response: (JSON Formatted)
You will receive a JSON response:
{"result":true,"msg":"OK"}
{"result":true,"msg":"OK"}
Adding Alerts - PHP example
function set_humbug_alert() {
//the url we are sending data to
$url = 'http://analytics.humbuglabs.org/index.php/remote_api/api_remote_add_alert/';
// your Remote API Key
$remote_apikey = 'your-remote-apikey';
//Encrypt the API Key using a random string (salt)
$salt = time();
$remote_apikey = md5($remote_apikey.$salt);
//The API Key of the gateway/pbx that we want to add an alert to
$gateway_apikey = 'your-pbx-apikey';
//The ID of the alert we want to add.
$alert_id = 18;
//Sample JSON config for this alert.
//maximum daily cost threshold of $100 and emailing alerts set to ON.
$config = '{"daily_cost":"100","email":"1"}';
//in our example we're building an array of the values we need to send
$array = array (
'key' => $remote_apikey,
'salt' => $salt,
'apikey_ident' => $gateway_apikey,
'alert_id' => $alert_id,
'config' => $config
);
//turn the array into a key=value string for usage with cURL
$params = "";
foreach($array as $key => $value) {
$params .= $key.'='.$value.'&';
}
rtrim($params,'&');
//send the data
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($array));
curl_setopt($ch,CURLOPT_POSTFIELDS,$params);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
print_r($result);
}
