forked from librenms/librenms
/
Ciscospark.php
47 lines (43 loc) · 1.47 KB
/
Ciscospark.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/*
* LibreNMS
*
* Copyright (c) 2017 Søren Friis Rosiak <sorenrosiak@gmail.com>
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
namespace LibreNMS\Alert\Transport;
use LibreNMS\Interfaces\Alert\Transport;
class Ciscospark implements Transport
{
public function deliverAlert($obj, $opts)
{
$token = $opts['token'];
$roomId = $opts['roomid'];
$text = strip_tags($obj['msg']);
$data = array(
'roomId' => $roomId,
'text' => $text
);
$curl = curl_init();
set_curl_proxy($curl);
curl_setopt($curl, CURLOPT_URL, 'https://api.ciscospark.com/v1/messages');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-type' => 'application/json',
'Expect:',
'Authorization: Bearer ' . $token
));
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
$ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code != 200) {
var_dump("Cisco Spark returned Error, retry later");
return false;
}
return true;
}
}