Issues (2963)

includes/polling/applications/shoutcast.inc.php (1 issue)

1
<?php
2
3
// Polls shoutcast statistics from script via SNMP
4
5
use LibreNMS\RRD\RrdDefinition;
6
7
$name = 'shoutcast';
8
$app_id = $app['app_id'];
9
10
$options = '-Oqv';
11
$oid = '.1.3.6.1.4.1.8072.1.3.2.3.1.2.9.115.104.111.117.116.99.97.115.116';
12
$shoutcast = snmp_get($device, $oid, $options);
13
14
echo ' shoutcast';
15
16
$servers = explode("\n", $shoutcast);
0 ignored issues
show
It seems like $shoutcast can also be of type false; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

16
$servers = explode("\n", /** @scrutinizer ignore-type */ $shoutcast);
Loading history...
17
18
$metrics = [];
19
foreach ($servers as $item => $server) {
20
    $server = trim($server);
21
22
    if (! empty($server)) {
23
        $data = explode(';', $server);
24
        [$host, $port] = explode(':', $data['0'], 2);
25
26
        $rrd_name = ['app', $name, $app_id, $host . '_' . $port];
27
        $rrd_def = RrdDefinition::make()
28
            ->addDataset('bitrate', 'GAUGE', 0, 125000000000)
29
            ->addDataset('traf_in', 'GAUGE', 0, 125000000000)
30
            ->addDataset('traf_out', 'GAUGE', 0, 125000000000)
31
            ->addDataset('current', 'GAUGE', 0, 125000000000)
32
            ->addDataset('status', 'GAUGE', 0, 125000000000)
33
            ->addDataset('peak', 'GAUGE', 0, 125000000000)
34
            ->addDataset('max', 'GAUGE', 0, 125000000000)
35
            ->addDataset('unique', 'GAUGE', 0, 125000000000);
36
37
        $fields = [
38
            'bitrate'  => $data['1'],
39
            'traf_in'  => $data['2'],
40
            'traf_out' => $data['3'],
41
            'current'  => $data['4'],
42
            'status'   => $data['5'],
43
            'peak'     => $data['6'],
44
            'max'      => $data['7'],
45
            'unique'   => $data['8'],
46
        ];
47
        $metrics[$server] = $fields;
48
49
        $tags = compact('name', 'app_id', 'host', 'port', 'rrd_name', 'rrd_def');
50
        data_update($device, 'app', $tags, $fields);
51
    }//end if
52
}//end foreach
53
54
update_application($app, $shoutcast, $metrics);
55