Should only be cosmetic
This commit is contained in:
Jellyfrog
2021-03-24 15:13:43 +01:00
committed by GitHub
parent d06c65a746
commit 3cfffb9912
37 changed files with 89 additions and 71 deletions

View File

@@ -68,6 +68,9 @@ class Boxcar extends Transport
$data['notification[sound]'] = $api['sound_warning']; $data['notification[sound]'] = $api['sound_warning'];
} }
break; break;
default:
$severity = 'Unknown';
break;
} }
switch ($obj['state']) { switch ($obj['state']) {
case AlertState::RECOVERED: case AlertState::RECOVERED:
@@ -82,6 +85,10 @@ class Boxcar extends Transport
case AlertState::ACKNOWLEDGED: case AlertState::ACKNOWLEDGED:
$title_text = 'Acknowledged'; $title_text = 'Acknowledged';
break; break;
default:
$title_text = $severity;
break;
} }
$data['notification[title]'] = $title_text . ' - ' . $obj['hostname'] . ' - ' . $obj['name']; $data['notification[title]'] = $title_text . ' - ' . $obj['hostname'] . ' - ' . $obj['name'];
$message_text = 'Timestamp: ' . $obj['timestamp']; $message_text = 'Timestamp: ' . $obj['timestamp'];

View File

@@ -46,7 +46,9 @@ class Clickatell extends Transport
$ret = curl_exec($curl); $ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code > 200) { if ($code > 200) {
return var_dump($ret); var_dump($ret);
return;
} }
return true; return true;

View File

@@ -82,6 +82,9 @@ class Elasticsearch extends Transport
case AlertState::BETTER: case AlertState::BETTER:
$state = 'better'; $state = 'better';
break; break;
default:
$state = 'unknown';
break;
} }
$data = [ $data = [

View File

@@ -31,6 +31,7 @@ class Osticket extends Transport
{ {
$url = $opts['url']; $url = $opts['url'];
$token = $opts['token']; $token = $opts['token'];
$email = '';
foreach (parse_email(Config::get('email_from')) as $from => $from_name) { foreach (parse_email(Config::get('email_from')) as $from => $from_name) {
$email = $from_name . ' <' . $from . '>'; $email = $from_name . ' <' . $from . '>';

View File

@@ -53,7 +53,9 @@ class Playsms extends Transport
$ret = curl_exec($curl); $ret = curl_exec($curl);
$code = curl_getinfo($curl, CURLINFO_HTTP_CODE); $code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
if ($code > 202) { if ($code > 202) {
return var_dump($ret); var_dump($ret);
return;
} }
return true; return true;

View File

@@ -144,6 +144,7 @@ class Schema
public function getAllRelationshipPaths($base = 'devices') public function getAllRelationshipPaths($base = 'devices')
{ {
$update_cache = true; $update_cache = true;
$cache = [];
$cache_file = Config::get('install_dir') . "/cache/{$base}_relationships.cache"; $cache_file = Config::get('install_dir') . "/cache/{$base}_relationships.cache";
$db_version = Version::get()->database(); $db_version = Version::get()->database();

View File

@@ -357,6 +357,7 @@ class Rrd extends BaseDatastore
{ {
global $vdebug; global $vdebug;
$stat = Measurement::start($this->coalesceStatisticType($command)); $stat = Measurement::start($this->coalesceStatisticType($command));
$output = null;
try { try {
$cmd = self::buildCommand($command, $filename, $options); $cmd = self::buildCommand($command, $filename, $options);

View File

@@ -100,9 +100,9 @@ class Allied extends OS implements OSDiscovery
$hardware = $e; $hardware = $e;
} }
$device->version = str_replace(['"', ','], '', $version); $device->version = str_replace(['"', ','], '', $version ?? null);
$device->features = str_replace('"', '', $features); $device->features = str_replace('"', '', $features ?? null);
$device->hardware = str_replace('"', '', $hardware); $device->hardware = str_replace('"', '', $hardware ?? null);
$device->serial = $serial; $device->serial = $serial ?? null;
} }
} }

View File

@@ -79,6 +79,9 @@ class OspfIfStateChange implements SnmptrapHandler
case 'loopback': case 'loopback':
$severity = 4; $severity = 4;
break; break;
default:
$severity = 0;
break;
} }
Log::event("OSPF interface $port->ifName is $ospfPort->ospfIfState", $device->device_id, 'trap', $severity); Log::event("OSPF interface $port->ifName is $ospfPort->ospfIfState", $device->device_id, 'trap', $severity);

View File

@@ -84,7 +84,7 @@ class Clean
$value = htmlentities($value); $value = htmlentities($value);
} }
if (! isset($purifier)) { if (! $purifier instanceof HTMLPurifier) {
// initialize HTML Purifier here since this is the only user // initialize HTML Purifier here since this is the only user
$p_config = HTMLPurifier_Config::createDefault(); $p_config = HTMLPurifier_Config::createDefault();
$p_config->set('Cache.SerializerPath', Config::get('temp_dir', '/tmp')); $p_config->set('Cache.SerializerPath', Config::get('temp_dir', '/tmp'));

View File

@@ -67,12 +67,10 @@ class RipeApi extends BaseApi
} }
/** /**
* @param $uri
* @param $options
* @return array|mixed * @return array|mixed
* @throws ApiException * @throws ApiException
*/ */
private function makeApiCall($uri, $options) private function makeApiCall(string $uri, array $options)
{ {
try { try {
$response = $this->getClient()->get($uri, $options); $response = $this->getClient()->get($uri, $options);

View File

@@ -85,10 +85,9 @@ class SetConfigCommand extends LnmsCommand
/** /**
* Convert the string input into the appropriate PHP native type * Convert the string input into the appropriate PHP native type
* *
* @param $value
* @return mixed * @return mixed
*/ */
private function juggleType($value) private function juggleType(string $value)
{ {
$json = json_decode($value, true); $json = json_decode($value, true);

View File

@@ -124,6 +124,7 @@ class SmokepingGenerateCommand extends LnmsCommand
public function buildTargetsConfiguration($devices) public function buildTargetsConfiguration($devices)
{ {
// Take the devices array and build it into a hierarchical list // Take the devices array and build it into a hierarchical list
$smokelist = [];
foreach ($devices as $device) { foreach ($devices as $device) {
$smokelist[$device->type][$device->hostname] = ['transport' => $device->transport]; $smokelist[$device->type][$device->hostname] = ['transport' => $device->transport];
} }
@@ -222,7 +223,7 @@ class SmokepingGenerateCommand extends LnmsCommand
/** /**
* Determine if a list of targets is needed, and write one if so * Determine if a list of targets is needed, and write one if so
* *
* @param array $devices A list of devices to create a a config block for * @param array $smokelist A list of devices to create a a config block for
* *
* @return array * @return array
*/ */

View File

@@ -49,7 +49,9 @@ class Kernel extends ConsoleKernel
{ {
if (is_null($this->artisan)) { if (is_null($this->artisan)) {
parent::getArtisan(); parent::getArtisan();
/** @phpstan-ignore-next-line */
$this->artisan->setName(\LibreNMS\Config::get('project_name', 'LibreNMS')); $this->artisan->setName(\LibreNMS\Config::get('project_name', 'LibreNMS'));
/** @phpstan-ignore-next-line */
$this->artisan->setVersion(Version::get()->local()); $this->artisan->setVersion(Version::get()->local());
} }

View File

@@ -60,7 +60,7 @@ class RegisterController extends Controller
* Create a new user instance after a valid registration. * Create a new user instance after a valid registration.
* *
* @param array $data * @param array $data
* @return \App\User * @return User
*/ */
protected function create(array $data) protected function create(array $data)
{ {

View File

@@ -199,10 +199,9 @@ class TwoFactorController extends Controller
} }
/** /**
* @param $user
* @return mixed * @return mixed
*/ */
private function loadSettings($user) private function loadSettings(User $user)
{ {
if (Session::has('twofactoradd')) { if (Session::has('twofactoradd')) {
return Session::get('twofactoradd'); return Session::get('twofactoradd');

View File

@@ -53,7 +53,7 @@ class CopyDashboardController extends Controller
$success = $dashboard_copy->save(); $success = $dashboard_copy->save();
} }
if ($success) { if ($success && isset($dashboard_copy)) {
$widgets = UserWidget::where(['dashboard_id' => $dashboard_id, 'user_id' => Auth::id()])->get(); $widgets = UserWidget::where(['dashboard_id' => $dashboard_id, 'user_id' => Auth::id()])->get();
foreach ($widgets as $widget) { foreach ($widgets as $widget) {

View File

@@ -58,6 +58,7 @@ class LegacyController extends Controller
$html = ob_get_clean(); $html = ob_get_clean();
ob_end_clean(); ob_end_clean();
/** @phpstan-ignore-next-line */
if (isset($pagetitle) && is_array($pagetitle)) { if (isset($pagetitle) && is_array($pagetitle)) {
// if prefix is set, put it in front // if prefix is set, put it in front
if (Config::get('page_title_prefix')) { if (Config::get('page_title_prefix')) {

View File

@@ -126,7 +126,6 @@ abstract class PaginatedAjaxController extends Controller
{ {
if ($search) { if ($search) {
$query->where(function ($query) use ($fields, $search) { $query->where(function ($query) use ($fields, $search) {
/** @var Builder $query */
foreach ($fields as $field) { foreach ($fields as $field) {
$query->orWhere($field, 'like', '%' . $search . '%'); $query->orWhere($field, 'like', '%' . $search . '%');
} }

View File

@@ -54,6 +54,9 @@ class ApplicationController extends SelectController
return $query; return $query;
} }
/**
* @param Application $app
*/
public function formatItem($app) public function formatItem($app)
{ {
return [ return [

View File

@@ -211,9 +211,9 @@ class ServiceTemplateController extends Controller
}, $updated)) > 0; }, $updated)) > 0;
} }
if ($template->isDirty() || $devices_updated || $device_groups_updated) { if ($template->isDirty() || $devices_updated || isset($device_groups_updated)) {
try { try {
if ($template->save() || $devices_updated || $device_groups_updated) { if ($template->save() || $devices_updated || isset($device_groups_updated)) {
Toastr::success(__('Service Template :name updated', ['name' => $template->name])); Toastr::success(__('Service Template :name updated', ['name' => $template->name]));
} else { } else {
Toastr::error(__('Failed to save')); Toastr::error(__('Failed to save'));

View File

@@ -255,10 +255,10 @@ class DeviceController extends TableController
} }
/** /**
* @param $device * @param int|Device $device
* @param $count * @param mixed $count
* @param $tab * @param mixed $tab
* @param $icon * @param mixed $icon
* @return string * @return string
*/ */
private function formatMetric($device, $count, $tab, $icon) private function formatMetric($device, $count, $tab, $icon)

View File

@@ -144,7 +144,7 @@ class GraylogController extends SimpleTableController
/** /**
* Cache device lookups so we don't lookup for every entry * Cache device lookups so we don't lookup for every entry
* @param $source * @param mixed $source
* @return mixed * @return mixed
*/ */
private function deviceFromSource($source) private function deviceFromSource($source)

View File

@@ -164,6 +164,9 @@ class RoutesTablesController extends TableController
return $query; return $query;
} }
/**
* @param Route $route_entry
*/
public function formatItem($route_entry) public function formatItem($route_entry)
{ {
$item = $route_entry->toArray(); $item = $route_entry->toArray();

View File

@@ -25,7 +25,6 @@
namespace App\Http\Controllers\Table; namespace App\Http\Controllers\Table;
use App\Models\Syslog; use App\Models\Syslog;
use Illuminate\Database\Eloquent\Builder;
class SyslogController extends TableController class SyslogController extends TableController
{ {
@@ -68,7 +67,6 @@ class SyslogController extends TableController
*/ */
public function baseQuery($request) public function baseQuery($request)
{ {
/** @var Builder $query */
return Syslog::hasAccess($request->user()) return Syslog::hasAccess($request->user())
->with('device') ->with('device')
->when($request->device_group, function ($query) use ($request) { ->when($request->device_group, function ($query) use ($request) {
@@ -109,7 +107,7 @@ class SyslogController extends TableController
/** /**
* @param int $syslog_priority * @param int $syslog_priority
* @return string $syslog_priority_icon * @return string|void
*/ */
private function priorityLabel($syslog_priority) private function priorityLabel($syslog_priority)
{ {

View File

@@ -202,7 +202,7 @@ class UserController extends Controller
/** /**
* @param User $user * @param User $user
* @param $dashboard * @param mixed $dashboard
* @return bool * @return bool
*/ */
protected function updateDashboard(User $user, $dashboard) protected function updateDashboard(User $user, $dashboard)

View File

@@ -123,7 +123,7 @@ class TopDevicesController extends WidgetController
* @param string $left_table * @param string $left_table
* @return Builder * @return Builder
*/ */
private function withDeviceQuery($query, $left_table) private function withDeviceQuery(Builder $query, $left_table)
{ {
$settings = $this->getSettings(); $settings = $this->getSettings();
@@ -136,12 +136,12 @@ class TopDevicesController extends WidgetController
->groupBy("$left_table.device_id") ->groupBy("$left_table.device_id")
->where('devices.last_polled', '>', Carbon::now()->subMinutes($settings['time_interval'])) ->where('devices.last_polled', '>', Carbon::now()->subMinutes($settings['time_interval']))
->when($settings['device_group'], function ($query) use ($settings) { ->when($settings['device_group'], function ($query) use ($settings) {
/** @var Builder<\App\Models\DeviceRelatedModel> $query */
$query->inDeviceGroup($settings['device_group']); $query->inDeviceGroup($settings['device_group']);
}); });
} }
/** /**
* @param Builder $query
* @return Builder * @return Builder
*/ */
private function deviceQuery() private function deviceQuery()

View File

@@ -60,14 +60,11 @@ abstract class WidgetController extends Controller
public function __invoke(Request $request) public function __invoke(Request $request)
{ {
$this->show_settings = (bool) $request->get('settings'); $this->show_settings = (bool) $request->get('settings');
$settings = $this->getSettings();
if ($this->show_settings) { if ($this->show_settings) {
$view = $this->getSettingsView($request); $view = $this->getSettingsView($request);
} } else {
$settings = $this->getSettings();
if (! $this->show_settings) {
if (! empty($settings['device_group'])) { if (! empty($settings['device_group'])) {
$this->title .= ' (' . DeviceGroup::find($settings['device_group'])->name . ')'; $this->title .= ' (' . DeviceGroup::find($settings['device_group'])->name . ')';
} }

View File

@@ -223,9 +223,9 @@ class PingCheck implements ShouldQueue
* If the device is on the current tier, record the data and remove it * If the device is on the current tier, record the data and remove it
* $data should have keys: hostname, status, and conditionally rtt * $data should have keys: hostname, status, and conditionally rtt
* *
* @param $data * @param array $data
*/ */
private function recordData($data) private function recordData(array $data)
{ {
global $vdebug; global $vdebug;
@@ -280,7 +280,7 @@ class PingCheck implements ShouldQueue
/** /**
* Done processing $hostname, remove it from our active data * Done processing $hostname, remove it from our active data
* *
* @param $hostname * @param string $hostname
*/ */
private function complete($hostname) private function complete($hostname)
{ {
@@ -292,9 +292,9 @@ class PingCheck implements ShouldQueue
* Defer this data processing until all parent devices are complete * Defer this data processing until all parent devices are complete
* *
* *
* @param $data * @param array $data
*/ */
private function defer($data) private function defer(array $data)
{ {
$device = $this->devices->get($data['hostname']); $device = $this->devices->get($data['hostname']);

View File

@@ -34,7 +34,7 @@ class AlertRule extends BaseModel
// ---- Query scopes ---- // ---- Query scopes ----
/** /**
* @param Builder $query * @param Builder<AlertRule> $query
* @return Builder * @return Builder
*/ */
public function scopeEnabled($query) public function scopeEnabled($query)
@@ -45,7 +45,7 @@ class AlertRule extends BaseModel
/** /**
* Scope for only alert rules that are currently in alarm * Scope for only alert rules that are currently in alarm
* *
* @param Builder $query * @param Builder<AlertRule> $query
* @return Builder * @return Builder
*/ */
public function scopeIsActive($query) public function scopeIsActive($query)
@@ -59,7 +59,7 @@ class AlertRule extends BaseModel
* Scope to filter rules for devices permitted to user * Scope to filter rules for devices permitted to user
* (do not use for admin and global read-only users) * (do not use for admin and global read-only users)
* *
* @param $query * @param Builder<AlertRule> $query
* @param User $user * @param User $user
* @return mixed * @return mixed
*/ */

View File

@@ -328,10 +328,9 @@ class Device extends BaseModel
* Update the location to the correct location and update GPS if needed * Update the location to the correct location and update GPS if needed
* *
* @param \App\Models\Location|string $new_location location data * @param \App\Models\Location|string $new_location location data
* @param string $hostname
* @param bool $doLookup try to lookup the GPS coordinates * @param bool $doLookup try to lookup the GPS coordinates
*/ */
public function setLocation($new_location, $doLookup = false) public function setLocation($new_location, bool $doLookup = false)
{ {
$new_location = $new_location instanceof Location ? $new_location : new Location(['location' => $new_location]); $new_location = $new_location instanceof Location ? $new_location : new Location(['location' => $new_location]);
$new_location->location = $new_location->location ? Rewrite::location($new_location->location) : null; $new_location->location = $new_location->location ? Rewrite::location($new_location->location) : null;

View File

@@ -35,7 +35,7 @@ class Notification extends Model
* @param bool $enabled * @param bool $enabled
* @return bool * @return bool
*/ */
public function markRead($enabled = true) public function markRead(bool $enabled = true): bool
{ {
return $this->setAttrib('read', $enabled); return $this->setAttrib('read', $enabled);
} }
@@ -46,17 +46,17 @@ class Notification extends Model
* @var bool * @var bool
* @return bool * @return bool
*/ */
public function markSticky($enabled = true) public function markSticky(bool $enabled = true): bool
{ {
return $this->setAttrib('sticky', $enabled); return $this->setAttrib('sticky', $enabled);
} }
/** /**
* @param $name * @param string $name
* @param $enabled * @param bool $enabled
* @return bool * @return bool
*/ */
private function setAttrib($name, $enabled) private function setAttrib($name, bool $enabled): bool
{ {
if ($enabled === true) { if ($enabled === true) {
$read = new NotificationAttrib; $read = new NotificationAttrib;
@@ -74,7 +74,8 @@ class Notification extends Model
// ---- Query Scopes ---- // ---- Query Scopes ----
/** /**
* @param Builder $query * @param Builder<Notification> $query
* @param User $user
* @return mixed * @return mixed
*/ */
public function scopeIsUnread(Builder $query, User $user) public function scopeIsUnread(Builder $query, User $user)
@@ -90,7 +91,7 @@ class Notification extends Model
/** /**
* Get all sticky notifications * Get all sticky notifications
* *
* @param Builder $query * @param Builder<Notification> $query
*/ */
public function scopeIsSticky(Builder $query) public function scopeIsSticky(Builder $query)
{ {
@@ -99,7 +100,7 @@ class Notification extends Model
} }
/** /**
* @param Builder $query * @param Builder<Notification> $query
* @param User $user * @param User $user
* @return mixed * @return mixed
*/ */
@@ -113,7 +114,7 @@ class Notification extends Model
} }
/** /**
* @param Builder $query * @param Builder<Notification> $query
* @return $this * @return $this
*/ */
public function scopeLimit(Builder $query) public function scopeLimit(Builder $query)
@@ -122,7 +123,7 @@ class Notification extends Model
} }
/** /**
* @param Builder $query * @param Builder<Notification> $query
* @return Builder|static * @return Builder|static
*/ */
public function scopeSource(Builder $query) public function scopeSource(Builder $query)

View File

@@ -43,7 +43,7 @@ class DeviceGroupPolicy
/** /**
* Determine whether the user can view any device group. * Determine whether the user can view any device group.
* *
* @param \App\User $user * @param \App\Models\User $user
* @return mixed * @return mixed
*/ */
public function viewAny(User $user) public function viewAny(User $user)

View File

@@ -96,7 +96,6 @@ class PollerClusterPolicy
* Determine whether the user can manage the poller cluster. * Determine whether the user can manage the poller cluster.
* *
* @param \App\Models\User $user * @param \App\Models\User $user
* @param \App\Models\PollerCluster $pollerCluster
* @return mixed * @return mixed
*/ */
public function manage(User $user) public function manage(User $user)

View File

@@ -12,7 +12,7 @@ class UserPolicy
/** /**
* Determine whether the user can manage users. * Determine whether the user can manage users.
* *
* @param \App\Models\User $user * @param User $user
* @return bool * @return bool
*/ */
public function manage(User $user) public function manage(User $user)
@@ -23,8 +23,8 @@ class UserPolicy
/** /**
* Determine whether the user can view the user. * Determine whether the user can view the user.
* *
* @param \App\Models\User $user * @param User $user
* @param \App\Models\User $target * @param User $target
* @return bool * @return bool
*/ */
public function view(User $user, User $target) public function view(User $user, User $target)
@@ -35,7 +35,7 @@ class UserPolicy
/** /**
* Determine whether the user can view any user. * Determine whether the user can view any user.
* *
* @param \App\User $user * @param User $user
* @return mixed * @return mixed
*/ */
public function viewAny(User $user) public function viewAny(User $user)
@@ -46,7 +46,7 @@ class UserPolicy
/** /**
* Determine whether the user can create users. * Determine whether the user can create users.
* *
* @param \App\Models\User $user * @param User $user
* @return bool * @return bool
*/ */
public function create(User $user) public function create(User $user)
@@ -57,8 +57,8 @@ class UserPolicy
/** /**
* Determine whether the user can update the user. * Determine whether the user can update the user.
* *
* @param \App\Models\User $user * @param User $user
* @param \App\Models\User $target * @param User $target
* @return bool * @return bool
*/ */
public function update(User $user, User $target) public function update(User $user, User $target)
@@ -69,8 +69,8 @@ class UserPolicy
/** /**
* Determine whether the user can delete the user. * Determine whether the user can delete the user.
* *
* @param \App\Models\User $user * @param User $user
* @param \App\Models\User $target * @param User $target
* @return bool * @return bool
*/ */
public function delete(User $user, User $target) public function delete(User $user, User $target)

View File

@@ -138,9 +138,8 @@ class LegacyUserProvider implements UserProvider
} }
\Toastr::error($auth_message); \Toastr::error($auth_message);
if (empty($username)) { $username = $username ?? Session::get('username', $credentials['username']);
$username = Session::get('username', $credentials['username']);
}
DB::table('authlog')->insert(['user' => $username, 'address' => Request::ip(), 'result' => $auth_message]); DB::table('authlog')->insert(['user' => $username, 'address' => Request::ip(), 'result' => $auth_message]);
} finally { } finally {
error_reporting(-1); error_reporting(-1);

View File

@@ -58,7 +58,7 @@ class Submenu extends Component
/** /**
* Determine if the given option is the current selected option. * Determine if the given option is the current selected option.
* *
* @param string $option * @param string $url
* @return bool * @return bool
*/ */
public function isSelected($url) public function isSelected($url)