Completed
Push — fixes ( 6830e4...798510 )
by Tony
03:34
created

Log   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 7
c 2
b 0
f 1
lcom 0
cbo 1
dl 0
loc 63
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A device() 0 4 1
A rule() 0 4 1
A user() 0 4 1
A getDetailsAttribute() 0 6 2
A getTimeLoggedAttribute() 0 6 2
1
<?php
2
/**
3
 * app/Models/Alerting/Log.php
4
 *
5
 * Model for access to alert log table data
6
 *
7
 * This program is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
19
 *
20
 * @package    LibreNMS
21
 * @link       http://librenms.org
22
 * @copyright  2016 Neil Lathwood
23
 * @author     Neil Lathwood <[email protected]>
24
 */
25
26
namespace App\Models\Alerting;
27
28
use Illuminate\Database\Eloquent\Model;
29
use Illuminate\Database\Eloquent\Builder;
30
31
/**
32
 * App\Models\Alerting\Log
33
 *
34
 * @property integer $id
35
 * @property integer $rule_id
36
 * @property integer $device_id
37
 * @property integer $state
38
 * @property mixed $details
39
 * @property string $time_logged
40
 * @property-read \App\Models\Device $device
41
 * @property-read \App\Models\Alerting\Rule $rule
42
 * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\User[] $user
43
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereId($value)
44
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereRuleId($value)
45
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereDeviceId($value)
46
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereState($value)
47
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereDetails($value)
48
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Alerting\Log whereTimeLogged($value)
49
 * @mixin \Eloquent
50
 */
51
class Log extends Model
52
{
53
    /**
54
     * Indicates if the model should be timestamped.
55
     *
56
     * @var bool
57
     */
58
    public $timestamps = false;
59
    /**
60
     * The table associated with the model.
61
     *
62
     * @var string
63
     */
64
    protected $table = 'alert_log';
65
    /**
66
     * The primary key column name.
67
     *
68
     * @var string
69
     */
70
    protected $primaryKey = 'id';
71
72
    // ---- Define Reletionships ----
73
74
    /**
75
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
76
     */
77
    public function device()
78
    {
79
        return $this->belongsTo('App\Models\Device', 'device_id');
80
    }
81
82
    /**
83
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
84
     */
85
    public function rule()
86
    {
87
        return $this->belongsTo('App\Models\Alerting\Rule', 'rule_id');
88
    }
89
90
    /**
91
     * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany
92
     */
93
    public function user()
94
    {
95
        return $this->belongsToMany('App\Models\User', 'devices_perms', 'device_id', 'user_id');
96
    }
97
98
    // ---- Accessors/Mutators ----
99
100
    public function getDetailsAttribute($details)
101
    {
102
        if ($details) {
103
            return json_decode(gzuncompress($details), true);
104
        }
105
    }
106
107
    public function getTimeLoggedAttribute($date)
108
    {
109
        if ($date) {
110
            return strtotime($date) * 1000;
111
        }
112
    }
113
}
114