1 | <?php |
||
2 | /* Copyright (C) 2015 Daniel Preussker <[email protected]> |
||
3 | * This program is free software: you can redistribute it and/or modify |
||
4 | * it under the terms of the GNU General Public License as published by |
||
5 | * the Free Software Foundation, either version 3 of the License, or |
||
6 | * (at your option) any later version. |
||
7 | * |
||
8 | * This program is distributed in the hope that it will be useful, |
||
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the |
||
11 | * GNU General Public License for more details. |
||
12 | * |
||
13 | * You should have received a copy of the GNU General Public License |
||
14 | * along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
||
15 | |||
16 | /** |
||
17 | * Pushbullet API Transport |
||
18 | * |
||
19 | * @author f0o <[email protected]> |
||
20 | * @copyright 2015 f0o, LibreNMS |
||
21 | * @license GPL |
||
22 | */ |
||
23 | |||
24 | namespace LibreNMS\Alert\Transport; |
||
25 | |||
26 | use LibreNMS\Alert\Transport; |
||
27 | |||
28 | class Pushbullet extends Transport |
||
29 | { |
||
30 | public function deliverAlert($obj, $opts) |
||
31 | { |
||
32 | if (! empty($this->config)) { |
||
33 | $opts = $this->config['pushbullet-token']; |
||
34 | } |
||
35 | |||
36 | return $this->contactPushbullet($obj, $opts); |
||
37 | } |
||
38 | |||
39 | public function contactPushbullet($obj, $opts) |
||
40 | { |
||
41 | // Note: At this point it might be useful to iterate through $obj['contacts'] and send each of them a note ? |
||
42 | |||
43 | $data = ['type' => 'note', 'title' => $obj['title'], 'body' => $obj['msg']]; |
||
44 | $data = json_encode($data); |
||
45 | |||
46 | $curl = curl_init('https://api.pushbullet.com/v2/pushes'); |
||
47 | set_curl_proxy($curl); |
||
48 | curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); |
||
49 | curl_setopt($curl, CURLOPT_POSTFIELDS, $data); |
||
50 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); |
||
51 | curl_setopt($curl, CURLOPT_HTTPHEADER, [ |
||
52 | 'Content-Type: application/json', |
||
53 | 'Content-Length: ' . strlen($data), |
||
54 | 'Authorization: Bearer ' . $opts, |
||
55 | ]); |
||
56 | |||
57 | $ret = curl_exec($curl); |
||
58 | $code = curl_getinfo($curl, CURLINFO_HTTP_CODE); |
||
59 | if ($code > 201) { |
||
60 | var_dump($ret); |
||
0 ignored issues
–
show
Security
Debugging Code
introduced
by
Loading history...
|
|||
61 | |||
62 | return 'HTTP Status code ' . $code; |
||
63 | } |
||
64 | |||
65 | return true; |
||
66 | } |
||
67 | |||
68 | public static function configTemplate() |
||
69 | { |
||
70 | return [ |
||
71 | 'config' => [ |
||
72 | [ |
||
73 | 'title' => 'Access Token', |
||
74 | 'name' => 'pushbullet-token', |
||
75 | 'descr' => 'Pushbullet Access Token', |
||
76 | 'type' => 'text', |
||
77 | ], |
||
78 | ], |
||
79 | 'validation' => [ |
||
80 | 'pushbullet-token' => 'required|string', |
||
81 | ], |
||
82 | ]; |
||
83 | } |
||
84 | } |
||
85 |