Completed
Push — develop ( 0d1b6f...49f866 )
by Neil
05:13
created

ApiController   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 11
Bugs 3 Features 1
Metric Value
wmc 2
c 11
b 3
f 1
lcom 0
cbo 4
dl 0
loc 46
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A get_info() 0 9 1
B get_stats() 0 26 1
1
<?php
2
3
namespace App\Api\Controllers;
4
5
use DB;
6
use App\Device;
7
use App\Port;
8
9
class ApiController extends Controller
10
{
11
    /**
12
     * Get info about the install
13
     */
14
    public function get_info()
15
    {
16
        $versions              = array();
17
        $versions['git']       = `git rev-parse --short HEAD`;
18
        $versions['db_schema'] = DB::select('SELECT `version` FROM `dbSchema` LIMIT 1')[0]->version;
19
        $versions['php']       = phpversion();
20
        $versions['mysql']     = DB::select('SELECT version() AS version')[0]->version;
21
        return $versions;
22
    }
23
24
    /**
25
     * Get statistics about the install
26
     */
27
    public function get_stats()
28
    {
29
        $stats               = array();
30
        $stats['devices']    = Device::all()->count();
31
        $stats['ports']      = Port::all()->count();
32
        $stats['syslog']     = DB::select('SELECT COUNT(seq) AS `total` FROM `syslog`')[0]->total;
33
        $stats['eventlog']   = DB::select('SELECT COUNT(event_id) AS `total` FROM `eventlog`')[0]->total;
34
        $stats['apps']       = DB::select('SELECT COUNT(app_id) AS `total` FROM `applications`')[0]->total;
35
        $stats['services']   = DB::select('SELECT COUNT(service_id) AS `total` FROM `services`')[0]->total;
36
        $stats['storage']    = DB::select('SELECT COUNT(storage_id) AS `total` FROM `storage`')[0]->total;
37
        $stats['diskio']     = DB::select('SELECT COUNT(diskio_id) AS `total` FROM `ucd_diskio`')[0]->total;
38
        $stats['processors'] = DB::select('SELECT COUNT(processor_id) AS `total` FROM `processors`')[0]->total;
39
        $stats['memory']     = DB::select('SELECT COUNT(mempool_id) AS `total` FROM `mempools`')[0]->total;
40
        $stats['sensors']    = DB::select('SELECT COUNT(sensor_id) AS `total` FROM `sensors`')[0]->total;
41
        $stats['toner']      = DB::select('SELECT COUNT(toner_id) AS `total` FROM `toner`')[0]->total;
42
        $stats['hrmib']      = DB::select('SELECT COUNT(hrDevice_id) AS `total` FROM `hrDevice`')[0]->total;
43
        $stats['entmib']     = DB::select('SELECT COUNT(entPhysical_id) AS `total` FROM `entPhysical`')[0]->total;
44
        $stats['ipv4_addr']  = DB::select('SELECT COUNT(ipv4_address_id) AS `total` FROM `ipv4_addresses`')[0]->total;
45
        $stats['ipv4_net']   = DB::select('SELECT COUNT(ipv4_network_id) AS `total` FROM `ipv4_networks`')[0]->total;
46
        $stats['ipv6_addr']  = DB::select('SELECT COUNT(ipv6_address_id) AS `total` FROM `ipv6_addresses`')[0]->total;
47
        $stats['ipv6_net']   = DB::select('SELECT COUNT(ipv6_network_id) AS `total` FROM `ipv6_networks`')[0]->total;
48
        $stats['pw']         = DB::select('SELECT COUNT(pseudowire_id) AS `total` FROM `pseudowires`')[0]->total;
49
        $stats['vrf']        = DB::select('SELECT COUNT(vrf_id) AS `total` FROM `vrfs`')[0]->total;
50
        $stats['vlans']      = DB::select('SELECT COUNT(vlan_id) AS `total` FROM `vlans`')[0]->total;
51
        return $stats;
52
    }
53
54
}
55