Signal   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 30
c 1
b 0
f 0
dl 0
loc 50
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A contactSignal() 0 9 1
A configTemplate() 0 26 1
A deliverAlert() 0 9 2
1
<?php
2
/* This program is free software: you can redistribute it and/or modify
3
 * it under the terms of the GNU General Public License as published by
4
 * the Free Software Foundation, either version 3 of the License, or
5
 * (at your option) any later version.
6
 *
7
 * This program is distributed in the hope that it will be useful,
8
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
10
 * GNU General Public License for more details.
11
 *
12
 * You should have received a copy of the GNU General Public License
13
 * along with this program.  If not, see <http://www.gnu.org/licenses/>. */
14
15
/**
16
 * Signal Transport
17
 *
18
 * @author kzink <[email protected]>
19
 * @copyright 2021 kzink, LibreNMS
20
 * @license GPL
21
 */
22
23
namespace LibreNMS\Alert\Transport;
24
25
use LibreNMS\Alert\Transport;
26
27
class Signal extends Transport
28
{
29
    public function deliverAlert($obj, $opts)
30
    {
31
        $signalOpts = [
32
            'path'  => escapeshellarg($this->config['path']),
33
            'recipient-type'  => ($this->config['recipient-type'] == 'group') ? ' -g ' : ' ',
34
            'recipient' => escapeshellarg($this->config['recipient']),
35
        ];
36
37
        return $this->contactSignal($obj, $signalOpts);
38
    }
39
40
    public function contactSignal($obj, $opts)
41
    {
42
        exec($opts['path']
43
           . ' --dbus-system send'
44
           . $opts['recipient-type']
45
           . $opts['recipient']
46
           . ' -m ' . escapeshellarg($obj['title']));
47
48
        return true;
49
    }
50
51
    public static function configTemplate()
52
    {
53
        return [
54
            'validation' => [],
55
            'config' => [
56
                [
57
                    'title' => 'Path',
58
                    'name' => 'path',
59
                    'descr' => 'Local Path to CLI',
60
                    'type' => 'text',
61
                ],
62
                [
63
                    'title' => 'Recipient type',
64
                    'name' => 'recipient-type',
65
                    'descr' => 'Phonenumber ',
66
                    'type' => 'select',
67
                    'options' => [
68
                        'Mobile number' => 'single',
69
                        'Group' => 'group',
70
                    ],
71
                ],
72
                [
73
                    'title' => 'Recipient',
74
                    'name' => 'recipient',
75
                    'descr' => 'Message recipient',
76
                    'type' => 'text',
77
                ],
78
            ],
79
        ];
80
    }
81
}
82