Issues (2963)

LibreNMS/Alert/Transport/Ukfastpss.php (1 issue)

1
<?php
2
/* Copyright (C) 2020 Raphael Dannecker <[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
 * UKFastPSS Transport
18
 *
19
 * @author Lee Spottiswood (github.com/0x4c6565)
20
 * @copyright 2021, LibreNMS
21
 * @license GPL
22
 */
23
24
namespace LibreNMS\Alert\Transport;
25
26
use LibreNMS\Alert\Transport;
27
28
class Ukfastpss extends Transport
29
{
30
    public function deliverAlert($obj, $opts)
31
    {
32
        return $this->contactUkfastpss($obj, $opts);
33
    }
34
35
    public function contactUkfastpss($obj, $opts)
0 ignored issues
show
The parameter $opts is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

35
    public function contactUkfastpss($obj, /** @scrutinizer ignore-unused */ $opts)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
36
    {
37
        $apiKey = $this->config['api-key'];
38
        $author = $this->config['author'];
39
        $secure = $this->config['secure'];
40
        $priority = $this->config['priority'];
41
42
        $body = [
43
            'author' => [
44
                'id' => $author,
45
            ],
46
            'secure' => ($secure == 'on'),
47
            'subject' => $obj['title'],
48
            'details' => $obj['msg'],
49
            'priority' => $priority,
50
        ];
51
52
        $request_opts = [];
53
        $request_headers = [];
54
55
        $request_headers['Authorization'] = $apiKey;
56
        $request_headers['Content-Type'] = 'application/json';
57
        $request_headers['Accept'] = 'application/json';
58
59
        $client = new \GuzzleHttp\Client();
60
        $request_opts['proxy'] = get_guzzle_proxy();
61
        $request_opts['headers'] = $request_headers;
62
        $request_opts['body'] = json_encode($body);
63
64
        $res = $client->request('POST', 'https://api.ukfast.io/pss/v1/requests', $request_opts);
65
66
        $code = $res->getStatusCode();
67
        if ($code != 200) {
68
            return 'HTTP Status code ' . $code;
69
        }
70
71
        return true;
72
    }
73
74
    public static function configTemplate()
75
    {
76
        return [
77
            'config' => [
78
                [
79
                    'title' => 'API Key',
80
                    'name' => 'api-key',
81
                    'descr' => 'API key to use for authentication',
82
                    'type' => 'text',
83
                ],
84
                [
85
                    'title' => 'Author',
86
                    'name' => 'author',
87
                    'descr' => 'Author ID for new PSS request',
88
                    'type' => 'text',
89
                ],
90
                [
91
                    'title' => 'Priority',
92
                    'name' => 'priority',
93
                    'descr' => 'Priority of request. Defaults to "Normal"',
94
                    'type' => 'select',
95
                    'options' => [
96
                        'Normal' => 'Normal',
97
                        'High' => 'High',
98
                        'Critical' => 'Critical',
99
                    ],
100
                    'default' => 'Normal',
101
                ],
102
                [
103
                    'title' => 'Secure',
104
                    'name' => 'secure',
105
                    'descr' => 'Specifies whether created request should be secure',
106
                    'type'  => 'checkbox',
107
                    'default' => true,
108
                ],
109
            ],
110
            'validation' => [
111
                'api-key' => 'required',
112
                'author' => 'required',
113
            ],
114
        ];
115
    }
116
}
117