Completed
Push — master ( 7d9761...77615c )
by Tony
02:53
created

ApiController::get_stats()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 26
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 8.8571
c 0
b 0
f 0
cc 1
eloc 24
nc 1
nop 0
1
<?php
2
3
namespace App\Api\Controllers;
4
5
use DB;
6
7
class ApiController extends Controller
8
{
9
    /**
10
     * Get info about the install
11
     */
12
    public function getInfo()
13
    {
14
        $versions              = array();
15
        $versions['git']       = `git rev-parse --short HEAD`;
16
        $versions['db_schema'] = DB::select('SELECT `version` FROM `dbSchema` LIMIT 1')[0]->version;
17
        $versions['php']       = phpversion();
18
        $versions['db_driver'] = strtoupper(DB::connection()->getDriverName());
19
        if ($versions['db_driver'] == 'SQLITE') {
20
            $versions['db_version'] = DB::select('SELECT sqlite_version() AS version')[0]->version;
21
        } else {
22
            $versions['db_version'] = DB::select('SELECT version() AS version')[0]->version;
23
        }
24
        return $versions;
25
    }
26
27
    /**
28
     * Get statistics about the install
29
     */
30
    public function getStats()
31
    {
32
        $stats               = array();
33
        $stats['devices']    = \App\Models\Device::all()->count();
34
        $stats['ports']      = \App\Models\Port::all()->count();
35
        $stats['syslog']     = \App\Models\General\Syslog::all()->count();
36
        $stats['eventlog']   = \App\Models\General\Eventlog::all()->count();
37
        $stats['apps']       = DB::table('applications')->count();
38
        $stats['services']   = DB::table('services')->count();
39
        $stats['storage']    = DB::table('storage')->count();
40
        $stats['diskio']     = DB::table('ucd_diskio')->count();
41
        $stats['processors'] = DB::table('processors')->count();
42
        $stats['memory']     = DB::table('mempools')->count();
43
        $stats['sensors']    = DB::table('sensors')->count();
44
        $stats['toner']      = DB::table('toner')->count();
45
        $stats['hrmib']      = DB::table('hrDevice')->count();
46
        $stats['entmib']     = DB::table('entPhysical')->count();
47
        $stats['ipv4_addr']  = DB::table('ipv4_addresses')->count();
48
        $stats['ipv4_net']   = DB::table('ipv4_networks')->count();
49
        $stats['ipv6_addr']  = DB::table('ipv6_addresses')->count();
50
        $stats['ipv6_net']   = DB::table('ipv6_networks')->count();
51
        $stats['pw']         = DB::table('pseudowires')->count();
52
        $stats['vrf']        = DB::table('vrfs')->count();
53
        $stats['vlans']      = DB::table('vlans')->count();
54
        return $stats;
55
    }
56
}
57