Files
librenms-librenms/app/Models/Port.php
TheGreatDoc 9940c884f5 Fixed snmptraps. (#8898)
* Fixed snmptraps.

* Fixed space

* Added bgp down/up and authentication failure

* Fixed typo

* Fixed some typos, arrays, astext and format_hostname

* Updated documentation

* Moved code to a function

* Some refactor

* Minor fixes

* Minor fixes 2

* More minor fixes

* Changes requested by Tony

* Minor fixes

* Moved include to snmptrap.php

* Refactor traps to use object oriented code.

Should trigger events too/instead, but we'll leave that.
Testing todo

* Add tests and fix things so they actually work
Not checking events yet.

* Fixed typo and severity level

* Update composer deps, I think the lock file wasn't right.
add json and mbstring extension deps while I'm at it.

* Fix several issues with phpunit fixtures
2018-08-11 16:37:44 -05:00

128 lines
2.7 KiB
PHP

<?php
namespace App\Models;
class Port extends BaseModel
{
public $timestamps = false;
protected $primaryKey = 'port_id';
// ---- Helper Functions ----
/**
* Returns a human readable label for this port
*
* @return string
*/
public function getLabel()
{
if ($this->ifName) {
return $this->ifName;
}
if ($this->ifDescr) {
return $this->ifDescr;
}
return $this->ifIndex;
}
// ---- Accessors/Mutators ----
public function getIfPhysAddressAttribute($mac)
{
if (!empty($mac)) {
return preg_replace('/(..)(..)(..)(..)(..)(..)/', '\\1:\\2:\\3:\\4:\\5:\\6', $mac);
}
return null;
}
// ---- Query scopes ----
public function scopeIsDeleted($query)
{
return $query->where([
['deleted', 1],
]);
}
public function scopeIsNotDeleted($query)
{
return $query->where([
['deleted', 0],
]);
}
public function scopeIsUp($query)
{
return $query->where([
['deleted', '=', 0],
['ignore', '=', 0],
['ifOperStatus', '=', 'up'],
]);
}
public function scopeIsDown($query)
{
return $query->where([
['deleted', '=', 0],
['ignore', '=', 0],
['ifOperStatus', '=', 'down'],
['ifAdminStatus', '=', 'up'],
]);
}
public function scopeIsIgnored($query)
{
return $query->where([
['deleted', '=', 0],
['ignore', '=', 1],
]);
}
public function scopeIsDisabled($query)
{
return $query->where([
['deleted', '=', 0],
['ignore', '=', 0],
['ifAdminStatus', '=', 'down'],
]);
}
public function scopeHasErrors($query)
{
return $query->where(function ($query) {
$query->where('ifInErrors_delta', '>', 0)
->orWhere('ifOutErrors_delta', '>', 0);
});
}
public function scopeHasAccess($query, User $user)
{
return $this->hasPortAccess($query, $user);
}
// ---- Define Relationships ----
public function device()
{
return $this->belongsTo('App\Models\Device', 'device_id', 'device_id');
}
public function users()
{
// FIXME does not include global read
return $this->belongsToMany('App\Models\User', 'ports_perms', 'port_id', 'user_id');
}
public function ipv4()
{
return $this->hasMany('App\Models\Ipv4Address', 'port_id');
}
public function ipv6()
{
return $this->hasMany('App\Models\Ipv6Address', 'port_id');
}
}