1 | <?php |
||
2 | /* Copyright (C) 2014 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 | * IRC Transport |
||
18 | * |
||
19 | * @author f0o <[email protected]> |
||
20 | * @copyright 2014 f0o, LibreNMS |
||
21 | * @license GPL |
||
22 | */ |
||
23 | |||
24 | namespace LibreNMS\Alert\Transport; |
||
25 | |||
26 | use LibreNMS\Alert\Transport; |
||
27 | use LibreNMS\Config; |
||
28 | |||
29 | class Irc extends Transport |
||
30 | { |
||
31 | public function deliverAlert($obj, $opts) |
||
32 | { |
||
33 | return $this->contactIrc($obj, $opts); |
||
34 | } |
||
35 | |||
36 | public function contactIrc($obj, $opts) |
||
37 | { |
||
38 | $f = Config::get('install_dir') . '/.ircbot.alert'; |
||
39 | if (file_exists($f) && filetype($f) == 'fifo') { |
||
40 | $f = fopen($f, 'w+'); |
||
41 | $r = fwrite($f, json_encode($obj) . "\n"); |
||
42 | $f = fclose($f); |
||
0 ignored issues
–
show
Unused Code
introduced
by
Loading history...
|
|||
43 | if ($r === false) { |
||
44 | return false; |
||
45 | } else { |
||
46 | return true; |
||
47 | } |
||
48 | } |
||
49 | |||
50 | return false; |
||
51 | } |
||
52 | |||
53 | public static function configTemplate() |
||
54 | { |
||
55 | return [ |
||
56 | 'config' => [ |
||
57 | [ |
||
58 | 'title' => 'IRC', |
||
59 | 'name' => 'irc', |
||
60 | 'descr' => 'Enable IRC alerts', |
||
61 | 'type' => 'checkbox', |
||
62 | 'default' => true, |
||
63 | ], |
||
64 | ], |
||
65 | 'validation' => [ |
||
66 | 'irc' => 'required', |
||
67 | ], |
||
68 | ]; |
||
69 | } |
||
70 | } |
||
71 |