Remove Laravel helpers (#11428)

* Remove Laravel helpers

* Replace qualifier with import
This commit is contained in:
Tony Murray
2020-04-17 17:37:56 -05:00
committed by GitHub
parent 729eeccaa4
commit 1c08c11a77
95 changed files with 426 additions and 359 deletions

View File

@ -2,6 +2,7 @@
namespace LibreNMS\Alert;
use Illuminate\Support\Str;
use LibreNMS\Interfaces\Alert\Transport as TransportInterface;
use LibreNMS\Config;
@ -31,7 +32,7 @@ abstract class Transport implements TransportInterface
{
$options = [];
foreach (explode(PHP_EOL, $input) as $option) {
if (str_contains($option, '=')) {
if (Str::contains($option, '=')) {
list($k,$v) = explode('=', $option, 2);
$options[$k] = trim($v);
}

View File

@ -23,6 +23,7 @@
*/
namespace LibreNMS\Alert\Transport;
use Illuminate\Support\Str;
use LibreNMS\Alert\Transport;
class Smseagle extends Transport
@ -44,7 +45,7 @@ class Smseagle extends Transport
'to' => implode(',', $opts['to']),
'message' => $obj['title'],
];
$url = starts_with($opts['url'], 'http') ? '' : 'http://';
$url = Str::startsWith($opts['url'], 'http') ? '' : 'http://';
$url .= $opts['url'] . '/index.php/http_api/send_sms?' . http_build_query($params);
$curl = curl_init($url);

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Alerting;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\DB\Schema;
use Symfony\Component\Yaml\Yaml;
@ -69,7 +70,7 @@ class QueryBuilderFilter implements \JsonSerializable
continue; // don't include the time based macros, they don't work like that
}
if ((ends_with($key, '_usage_perc')) || (starts_with($key, 'packet_loss_'))) {
if ((Str::endsWith($key, '_usage_perc')) || (Str::startsWith($key, 'packet_loss_'))) {
$this->filter[$field] = [
'id' => $field,
'type' => 'integer',
@ -114,7 +115,7 @@ class QueryBuilderFilter implements \JsonSerializable
$field = "$table.$column";
if (ends_with($column, ['_perc', '_current', '_usage', '_perc_warn'])) {
if (Str::endsWith($column, ['_perc', '_current', '_usage', '_perc_warn'])) {
$this->filter[$field] = [
'id' => $field,
'type' => 'string',
@ -145,14 +146,14 @@ class QueryBuilderFilter implements \JsonSerializable
private function getColumnType($type)
{
if (starts_with($type, ['varchar', 'text', 'double', 'float'])) {
if (Str::startsWith($type, ['varchar', 'text', 'double', 'float'])) {
return 'string';
} elseif (starts_with($type, ['int', 'tinyint', 'smallint', 'mediumint', 'bigint'])) {
} elseif (Str::startsWith($type, ['int', 'tinyint', 'smallint', 'mediumint', 'bigint'])) {
//TODO implement field selection and change back to integer
return 'string';
} elseif (starts_with($type, ['timestamp', 'datetime'])) {
} elseif (Str::startsWith($type, ['timestamp', 'datetime'])) {
return 'datetime';
} elseif (starts_with($type, 'enum')) {
} elseif (Str::startsWith($type, 'enum')) {
return 'enum';
}

View File

@ -27,6 +27,7 @@ namespace LibreNMS\Alerting;
use DB;
use Illuminate\Database\Query\Builder;
use Illuminate\Support\Str;
use Log;
class QueryBuilderFluentParser extends QueryBuilderParser
@ -132,14 +133,14 @@ class QueryBuilderFluentParser extends QueryBuilderParser
protected function expandRule($rule)
{
$field = $rule['field'];
if (starts_with($field, 'macros.')) {
if (Str::startsWith($field, 'macros.')) {
$field = DB::raw($this->expandMacro($field));
}
$op = $rule['operator'];
$value = $rule['value'];
if (!is_array($value) && starts_with($value, '`') && ends_with($value, '`')) {
if (!is_array($value) && Str::startsWith($value, '`') && Str::endsWith($value, '`')) {
$value = DB::raw($this->expandMacro(trim($value, '`')));
}
@ -175,7 +176,7 @@ class QueryBuilderFluentParser extends QueryBuilderParser
$joins = [];
foreach ($this->generateGlue() as $glue) {
list($left, $right) = explode(' = ', $glue, 2);
if (str_contains($right, '.')) { // last line is devices.device_id = ? for alerting... ignore it
if (Str::contains($right, '.')) { // last line is devices.device_id = ? for alerting... ignore it
list($leftTable, $leftKey) = explode('.', $left);
list($rightTable, $rightKey) = explode('.', $right);
$target_table = ($rightTable != 'devices' ? $rightTable : $leftTable); // don't try to join devices

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Alerting;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\DB\Schema;
@ -116,7 +117,7 @@ class QueryBuilderParser implements \JsonSerializable
foreach ($rules['rules'] as $rule) {
if (array_key_exists('rules', $rule)) {
$tables = array_merge($this->findTablesRecursive($rule), $tables);
} elseif (str_contains($rule['field'], '.')) {
} elseif (Str::contains($rule['field'], '.')) {
list($table, $column) = explode('.', $rule['field']);
if ($table == 'macros') {
@ -188,7 +189,7 @@ class QueryBuilderParser implements \JsonSerializable
$value = '1';
} else {
// value is a field, mark it with backticks
if (starts_with($value, '%')) {
if (Str::startsWith($value, '%')) {
$value = '`' . ltrim($value, '%') . '`';
} else {
// but if it has quotes just remove the %
@ -295,7 +296,7 @@ class QueryBuilderParser implements \JsonSerializable
$op = self::$operators[$builder_op];
$value = $rule['value'];
if (is_string($value) && starts_with($value, '`') && ends_with($value, '`')) {
if (is_string($value) && Str::startsWith($value, '`') && Str::endsWith($value, '`')) {
// pass through value such as field
$value = trim($value, '`');
if ($expand) {
@ -329,14 +330,14 @@ class QueryBuilderParser implements \JsonSerializable
*/
protected function expandMacro($subject, $tables_only = false, $depth_limit = 20)
{
if (!str_contains($subject, 'macros.')) {
if (!Str::contains($subject, 'macros.')) {
return $subject;
}
$macros = Config::get('alert.macros.rule');
$count = 0;
while ($count++ < $depth_limit && str_contains($subject, 'macros.')) {
while ($count++ < $depth_limit && Str::contains($subject, 'macros.')) {
$subject = preg_replace_callback('/%?macros.([^ =()]+)/', function ($matches) use ($macros) {
$name = $matches[1];
if (isset($macros[$name])) {
@ -356,7 +357,7 @@ class QueryBuilderParser implements \JsonSerializable
$subject = preg_replace('/%([^%.]+)\./', '$1.', $subject);
// wrap entire macro result in parenthesis if needed
if (!(starts_with($subject, '(') && ends_with($subject, ')'))) {
if (!(Str::startsWith($subject, '(') && Str::endsWith($subject, ')'))) {
$subject = "($subject)";
}
@ -406,7 +407,7 @@ class QueryBuilderParser implements \JsonSerializable
$this->schema->getColumns($parent),
$this->schema->getColumns($child)
), function ($table) {
return ends_with($table, '_id');
return Str::endsWith($table, '_id');
});
if (count($shared_keys) === 1) {
@ -425,7 +426,7 @@ class QueryBuilderParser implements \JsonSerializable
if (!$this->schema->columnExists($child, $child_key)) {
// if they don't match, guess the column name from the parent
if (ends_with($parent, 'xes')) {
if (Str::endsWith($parent, 'xes')) {
$child_key = substr($parent, 0, -2) . '_id';
} else {
$child_key = preg_replace('/s$/', '_id', $parent);

View File

@ -2,9 +2,8 @@
namespace LibreNMS\Authentication;
use App\Models\Notification;
use App\Models\NotificationAttrib;
use App\Models\User;
use Illuminate\Support\Str;
use LibreNMS\DB\Eloquent;
use LibreNMS\Exceptions\AuthenticationException;
use Phpass\PasswordHash;
@ -35,13 +34,13 @@ class MysqlAuthorizer extends AuthorizerBase
$this->changePassword($username, $password);
return true;
}
} elseif (starts_with($hash, '$1$')) {
} elseif (Str::startsWith($hash, '$1$')) {
// old md5 crypt
if (crypt($password, $hash) == $hash) {
$this->changePassword($username, $password);
return true;
}
} elseif (starts_with($hash, '$P$')) {
} elseif (Str::startsWith($hash, '$P$')) {
// Phpass
$hasher = new PasswordHash();
if ($hasher->CheckPassword($password, $hash)) {

View File

@ -29,6 +29,7 @@ use App\Models\GraphType;
use Exception;
use Illuminate\Database\QueryException;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use LibreNMS\DB\Eloquent;
use Log;
@ -125,7 +126,7 @@ class Config
return self::$config[$key];
}
if (!str_contains($key, '.')) {
if (!Str::contains($key, '.')) {
return $default;
}
@ -183,7 +184,7 @@ class Config
return self::$config['os'][$os][$key];
}
if (!str_contains($key, '.')) {
if (!Str::contains($key, '.')) {
return self::get($key, $default);
}
@ -213,7 +214,7 @@ class Config
}
if (!isset(self::$config['os'][$os][$key])) {
if (!str_contains($key, '.')) {
if (!Str::contains($key, '.')) {
return self::get($key, $default);
}
if (!self::has("os.$os.$key")) {
@ -298,7 +299,7 @@ class Config
return true;
}
if (!str_contains($key, '.')) {
if (!Str::contains($key, '.')) {
return false;
}
@ -385,7 +386,7 @@ class Config
if (isset($_SERVER['SERVER_NAME']) && isset($_SERVER['SERVER_PORT'])) {
$port = $_SERVER['SERVER_PORT'] != 80 ? ':' . $_SERVER['SERVER_PORT'] : '';
// handle literal IPv6
$server = str_contains($_SERVER['SERVER_NAME'], ':') ? "[{$_SERVER['SERVER_NAME']}]" : $_SERVER['SERVER_NAME'];
$server = Str::contains($_SERVER['SERVER_NAME'], ':') ? "[{$_SERVER['SERVER_NAME']}]" : $_SERVER['SERVER_NAME'];
Arr::set(self::$config, 'base_url', "http://$server$port/");
}
@ -534,7 +535,7 @@ class Config
*/
public static function locateBinary($binary)
{
if (!str_contains($binary, '/')) {
if (!Str::contains($binary, '/')) {
$output = `whereis -b $binary`;
$list = trim(substr($output, strpos($output, ':') + 1));
$targets = explode(' ', $list);

View File

@ -25,6 +25,7 @@
namespace LibreNMS\DB;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Util\Version;
use Symfony\Component\Yaml\Yaml;
@ -274,7 +275,7 @@ class Schema
public function getTableFromKey($key)
{
if (ends_with($key, '_id')) {
if (Str::endsWith($key, '_id')) {
// hardcoded
if ($key == 'app_id') {
return 'applications';
@ -283,8 +284,8 @@ class Schema
// try to guess assuming key_id = keys table
$guessed_table = substr($key, 0, -3);
if (!ends_with($guessed_table, 's')) {
if (ends_with($guessed_table, 'x')) {
if (!Str::endsWith($guessed_table, 's')) {
if (Str::endsWith($guessed_table, 'x')) {
$guessed_table .= 'es';
} else {
$guessed_table .= 's';

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Data\Store;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Data\Measure\Measurement;
use LibreNMS\Exceptions\FileExistsException;
@ -439,7 +440,7 @@ class Rrd extends BaseDatastore
if ($this->rrdcached && version_compare($this->version, '1.5', '>=')) {
$chk = $this->command('last', $filename, '');
$filename = str_replace([$this->rrd_dir . '/', $this->rrd_dir], '', $filename);
return !str_contains(implode($chk), "$filename': No such file or directory");
return !Str::contains(implode($chk), "$filename': No such file or directory");
} else {
return is_file($filename);
}

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Device;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Interfaces\Discovery\DiscoveryItem;
use LibreNMS\Interfaces\Discovery\DiscoveryModule;
@ -91,7 +92,7 @@ class Processor extends Model implements DiscoveryModule, PollerModule, Discover
$proc->hrDeviceIndex = $hrDeviceIndex;
// handle string indexes
if (str_contains($oid, '"')) {
if (Str::contains($oid, '"')) {
$oid = preg_replace_callback('/"([^"]+)"/', function ($matches) {
return string_to_oid($matches[1]);
}, $oid);

View File

@ -25,6 +25,8 @@
namespace LibreNMS\Device;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use LibreNMS\Interfaces\Discovery\DiscoveryItem;
use LibreNMS\OS;
@ -81,7 +83,7 @@ class YamlDiscovery
foreach ($data as $name => $value) {
if ($name == '$oid' || $name == 'skip_values') {
$current_data[$name] = $value;
} elseif (str_contains($value, '{{')) {
} elseif (Str::contains($value, '{{')) {
// replace embedded values
$current_data[$name] = static::replaceValues($name, $index, $count, $data, $pre_cache);
} else {
@ -223,7 +225,7 @@ class YamlDiscovery
foreach ((array)$data['oid'] as $oid) {
if (!array_key_exists($oid, $pre_cache)) {
if (isset($data['snmp_flags'])) {
$snmp_flag = array_wrap($data['snmp_flags']);
$snmp_flag = Arr::wrap($data['snmp_flags']);
} else {
$snmp_flag = ['-OteQUs'];
}
@ -260,7 +262,7 @@ class YamlDiscovery
// Dynamic skipping of data
$op = isset($skip_value['op']) ? $skip_value['op'] : '!=';
$tmp_value = static::getValueFromData($skip_value['oid'], $index, $yaml_item_data, $pre_cache);
if (str_contains($skip_value['oid'], '.')) {
if (Str::contains($skip_value['oid'], '.')) {
list($skip_value['oid'], $targeted_index) = explode('.', $skip_value['oid'], 2);
$tmp_value = static::getValueFromData($skip_value['oid'], $targeted_index, $yaml_item_data, $pre_cache);
}

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Exceptions;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Interfaces\Exceptions\UpgradeableException;
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
@ -41,8 +42,8 @@ class FilePermissionsException extends \Exception implements UpgradeableExceptio
{
// cannot write to storage directory
if ($exception instanceof \ErrorException &&
starts_with($exception->getMessage(), 'file_put_contents(') &&
str_contains($exception->getMessage(), '/storage/')) {
Str::startsWith($exception->getMessage(), 'file_put_contents(') &&
Str::contains($exception->getMessage(), '/storage/')) {
return new static();
}
@ -52,7 +53,7 @@ class FilePermissionsException extends \Exception implements UpgradeableExceptio
}
// monolog cannot init log file
if ($exception instanceof \UnexpectedValueException && str_contains($exception->getFile(), 'Monolog/Handler/StreamHandler.php')) {
if ($exception instanceof \UnexpectedValueException && Str::contains($exception->getFile(), 'Monolog/Handler/StreamHandler.php')) {
return new static();
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS;
use App\Models\Device;
use Illuminate\Support\Str;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Device\YamlDiscovery;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
@ -111,7 +112,7 @@ class OS implements ProcessorDiscovery
*/
public function getCacheByIndex($oid, $mib = null, $snmpflags = '-OQUs')
{
if (str_contains($oid, '.')) {
if (Str::contains($oid, '.')) {
echo "Error: don't use this with numeric oids!\n";
return null;
}
@ -136,7 +137,7 @@ class OS implements ProcessorDiscovery
*/
public function getCacheTable($oid, $mib = null, $depth = 1)
{
if (str_contains($oid, '.')) {
if (Str::contains($oid, '.')) {
echo "Error: don't use this with numeric oids!\n";
return null;
}

View File

@ -25,6 +25,7 @@
namespace LibreNMS\OS;
use Illuminate\Support\Str;
use LibreNMS\Device\Processor;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\OS;
@ -42,7 +43,7 @@ class Dnos extends OS implements ProcessorDiscovery
$device = $this->getDevice();
$processors = array();
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.6027.1.3')) {
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.6027.1.3')) {
d_echo('Dell S Series Chassis');
$this->findProcessors(
$processors,
@ -51,7 +52,7 @@ class Dnos extends OS implements ProcessorDiscovery
'.1.3.6.1.4.1.6027.3.10.1.2.9.1.2',
'Stack Unit'
);
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.6027.1.2')) {
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.6027.1.2')) {
d_echo('Dell C Series Chassis');
$this->findProcessors(
$processors,
@ -68,7 +69,7 @@ class Dnos extends OS implements ProcessorDiscovery
'.1.3.6.1.4.1.6027.3.8.1.5.1.1.1',
'Line Card'
);
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.6027.1.4')) {
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.6027.1.4')) {
d_echo('Dell M Series Chassis');
$this->findProcessors(
$processors,
@ -77,7 +78,7 @@ class Dnos extends OS implements ProcessorDiscovery
'.1.3.6.1.4.1.6027.3.19.1.2.8.1.2',
'Stack Unit'
);
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.6027.1.5')) {
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.6027.1.5')) {
d_echo('Dell Z Series Chassis');
$this->findProcessors(
$processors,

View File

@ -25,6 +25,7 @@
namespace LibreNMS\OS;
use Illuminate\Support\Str;
use LibreNMS\Device\Processor;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\OS;
@ -41,19 +42,19 @@ class Edgecos extends OS implements ProcessorDiscovery
{
$device = $this->getDevice();
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.24.')) { //ECS4510
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.24.')) { //ECS4510
$oid = '.1.3.6.1.4.1.259.10.1.24.1.39.2.1.0';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.22.')) { //ECS3528
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.22.')) { //ECS3528
$oid = '.1.3.6.1.4.1.259.10.1.22.1.39.2.1.0';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.39.')) { //ECS4110
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.39.')) { //ECS4110
$oid = '.1.3.6.1.4.1.259.10.1.39.1.39.2.1.0';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.45.')) { //ECS4120
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.45.')) { //ECS4120
$oid = '.1.3.6.1.4.1.259.10.1.45.1.39.2.1.0';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.42.')) { //ECS4210
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.42.')) { //ECS4210
$oid = '.1.3.6.1.4.1.259.10.1.42.101.1.39.2.1.0';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.27.')) { //ECS3510
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.27.')) { //ECS3510
$oid = '.1.3.6.1.4.1.259.10.1.27.1.39.2.1.0';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.8.1.11.')) { //ES3510MA
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.8.1.11.')) { //ES3510MA
$oid = '.1.3.6.1.4.1.259.8.1.11.1.39.2.1.0';
};

View File

@ -25,6 +25,7 @@
namespace LibreNMS\OS;
use Illuminate\Support\Str;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessClientsDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
@ -44,7 +45,7 @@ class Ios extends Cisco implements
{
$device = $this->getDevice();
if (!starts_with($device['hardware'], 'AIR-') && !str_contains($device['hardware'], 'ciscoAIR')) {
if (!Str::startsWith($device['hardware'], 'AIR-') && !Str::contains($device['hardware'], 'ciscoAIR')) {
// unsupported IOS hardware
return array();
}
@ -58,7 +59,7 @@ class Ios extends Cisco implements
$descr = $ent['entPhysicalDescr'];
unset($entPhys[$entIndex]); // only use each one once
if (ends_with($descr, 'Radio')) {
if (Str::endsWith($descr, 'Radio')) {
d_echo("Mapping entPhysicalIndex $entIndex to ifIndex $index\n");
$data[$index]['entPhysicalIndex'] = $entIndex;
$data[$index]['entPhysicalDescr'] = $descr;

View File

@ -25,6 +25,7 @@
namespace LibreNMS\OS;
use Illuminate\Support\Str;
use LibreNMS\Device\WirelessSensor;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessRssiDiscovery;
use LibreNMS\Interfaces\Discovery\Sensors\WirelessSnrDiscovery;
@ -270,7 +271,7 @@ class Pmp extends OS implements
private function isAp()
{
$device = $this->getDevice();
return str_contains($device['hardware'], 'AP') || str_contains($device['hardware'], 'Master');
return Str::contains($device['hardware'], 'AP') || Str::contains($device['hardware'], 'Master');
}
/**
@ -296,7 +297,7 @@ class Pmp extends OS implements
$boxType = snmp_get($device, 'boxDeviceType.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB');
foreach ($types as $key => $value) {
if (str_contains($boxType, $key)) {
if (Str::contains($boxType, $key)) {
return $value;
}
}

View File

@ -25,6 +25,7 @@
namespace LibreNMS\OS;
use Illuminate\Support\Str;
use LibreNMS\Device\Processor;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\Interfaces\Polling\ProcessorPolling;
@ -48,7 +49,7 @@ class Powerconnect extends OS implements ProcessorDiscovery, ProcessorPolling
public function discoverProcessors()
{
$device = $this->getDevice();
if (starts_with($device['sysObjectID'], [
if (Str::startsWith($device['sysObjectID'], [
'.1.3.6.1.4.1.674.10895.3020',
'.1.3.6.1.4.1.674.10895.3021',
'.1.3.6.1.4.1.674.10895.3030',
@ -63,7 +64,7 @@ class Powerconnect extends OS implements ProcessorDiscovery, ProcessorPolling
0
)
);
} elseif (starts_with($device['sysObjectID'], [
} elseif (Str::startsWith($device['sysObjectID'], [
'.1.3.6.1.4.1.674.10895.3024',
'.1.3.6.1.4.1.674.10895.3042',
'.1.3.6.1.4.1.674.10895.3053',

View File

@ -17,6 +17,7 @@
namespace LibreNMS\OS;
use Illuminate\Support\Str;
use LibreNMS\Device\Processor;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\OS;
@ -31,7 +32,7 @@ class Sonicwall extends OS implements ProcessorDiscovery
*/
public function discoverProcessors()
{
if (starts_with($this->getDevice()['sysObjectID'], '.1.3.6.1.4.1.8741.1')) {
if (Str::startsWith($this->getDevice()['sysObjectID'], '.1.3.6.1.4.1.8741.1')) {
return array(
Processor::discover(
'sonicwall',

View File

@ -25,6 +25,7 @@
namespace LibreNMS\OS;
use Illuminate\Support\Str;
use LibreNMS\Device\Processor;
use LibreNMS\Interfaces\Discovery\ProcessorDiscovery;
use LibreNMS\Interfaces\Polling\NacPolling;
@ -68,7 +69,7 @@ class Vrp extends OS implements
$descr = $entry['hwEntityBomEnDesc'];
$usage = $entry['hwEntityCpuUsage'];
if (empty($descr) || str_contains($descr, 'No') || str_contains($usage, 'No')) {
if (empty($descr) || Str::contains($descr, 'No') || Str::contains($usage, 'No')) {
continue;
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS;
use Exception;
use Illuminate\Support\Str;
class Proc
{
@ -299,7 +300,7 @@ class Proc
*/
private function checkAddEOL($string)
{
if (!ends_with($string, PHP_EOL)) {
if (!Str::endsWith($string, PHP_EOL)) {
$string .= PHP_EOL;
}
return $string;

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use Illuminate\Support\Str;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -57,7 +58,7 @@ class AdvaAccThresholdCrossingAlert implements SnmptrapHandler
public function getThresholdMessage($thresholdOid)
{
foreach ($this->getThresholds() as $oid => $descr) {
if (str_contains($thresholdOid, $oid)) {
if (Str::contains($thresholdOid, $oid)) {
return $descr;
}
}

View File

@ -28,6 +28,7 @@
namespace LibreNMS\Snmptrap\Handlers;
use App\Models\Device;
use Illuminate\Support\Str;
use LibreNMS\Interfaces\SnmptrapHandler;
use LibreNMS\Snmptrap\Trap;
use Log;
@ -55,7 +56,7 @@ class AdvaNetThresholdCrossingAlert implements SnmptrapHandler
public function getThresholdMessage($thresholdOid)
{
foreach ($this->getThresholds() as $oid => $descr) {
if (str_contains($thresholdOid, $oid)) {
if (Str::contains($thresholdOid, $oid)) {
return $descr;
}
}

View File

@ -27,6 +27,7 @@ namespace LibreNMS\Snmptrap;
use App\Models\Device;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use LibreNMS\Snmptrap\Handlers\Fallback;
use LibreNMS\Util\IP;
use Log;
@ -79,7 +80,7 @@ class Trap
public function findOid($search)
{
return $this->oid_data->keys()->first(function ($oid) use ($search) {
return str_contains($oid, $search);
return Str::contains($oid, $search);
});
}
@ -91,7 +92,7 @@ class Trap
public function findOids($search)
{
return $this->oid_data->keys()->filter(function ($oid) use ($search) {
return str_contains($oid, $search);
return Str::contains($oid, $search);
})->all();
}

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Util;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Exceptions\FileNotFoundException;
use LibreNMS\Exceptions\InvalidModuleException;
@ -285,7 +286,7 @@ class ModuleTestHelper
{
$full_name = basename($os_file, '.json');
if (!str_contains($full_name, '_')) {
if (!Str::contains($full_name, '_')) {
return [$full_name, ''];
} elseif (is_file(Config::get('install_dir') . "/includes/definitions/$full_name.yaml")) {
return [$full_name, ''];
@ -362,7 +363,7 @@ class ModuleTestHelper
$result[] = "$oid|4|"; // empty data, we don't know type, put string
} else {
list($raw_type, $data) = explode(':', $raw_data, 2);
if (starts_with($raw_type, 'Wrong Type (should be ')) {
if (Str::startsWith($raw_type, 'Wrong Type (should be ')) {
// device returned the wrong type, save the wrong type to emulate the device behavior
list($raw_type, $data) = explode(':', ltrim($data), 2);
}

View File

@ -216,7 +216,7 @@ class Url
unset($vars['page']);
foreach ($vars as $var => $value) {
if ($value == '0' || $value != '' && !str_contains($var, 'opt') && !is_numeric($var)) {
if ($value == '0' || $value != '' && !Str::contains($var, 'opt') && !is_numeric($var)) {
$url .= $var . '=' . urlencode($value) . '/';
}
}

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Validations;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Validator;
@ -68,7 +69,7 @@ class Programs extends BaseValidation
return;
}
if (str_contains($output, '::1 is unreachable') || str_contains($output, 'Address family not supported')) {
if (Str::contains($output, '::1 is unreachable') || Str::contains($output, 'Address family not supported')) {
$validator->warn("IPv6 is disabled on your server, you will not be able to add IPv6 devices.");
return;
}
@ -81,7 +82,7 @@ class Programs extends BaseValidation
$getcap_out = shell_exec("$getcap $cmd");
preg_match("#^$cmd = (.*)$#", $getcap_out, $matches);
if (is_null($matches) || !str_contains($matches[1], 'cap_net_raw+ep')) {
if (is_null($matches) || !Str::contains($matches[1], 'cap_net_raw+ep')) {
$validator->fail(
"$bin should have CAP_NET_RAW!",
"setcap cap_net_raw+ep $cmd"

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Validations;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Util\Env;
use LibreNMS\Util\Git;
@ -99,7 +100,7 @@ class User extends BaseValidation
);
$files = array_filter(explode(PHP_EOL, $find_result), function ($file) use ($ignore_files) {
if (starts_with($file, $ignore_files)) {
if (Str::startsWith($file, $ignore_files)) {
return false;
}

View File

@ -25,6 +25,7 @@
namespace LibreNMS;
use Illuminate\Support\Str;
use LibreNMS\Interfaces\ValidationGroup;
use ReflectionClass;
@ -174,7 +175,7 @@ class Validator
$group = 'unknown';
$bt = debug_backtrace();
foreach ($bt as $entry) {
if (starts_with($entry['class'], 'LibreNMS\Validations')) {
if (Str::startsWith($entry['class'], 'LibreNMS\Validations')) {
$group = str_replace('LibreNMS\Validations\\', '', $entry['class']);
break;
}

View File

@ -4,6 +4,7 @@ namespace App\Console\Commands;
use App\Models\Device;
use Illuminate\Console\Command;
use Illuminate\Support\Str;
use Symfony\Component\Console\Input\InputDefinition;
use Symfony\Component\Console\Input\InputOption;
@ -47,11 +48,11 @@ class BashCompletionCommand extends Command
$command_def = $commands[$command]->getDefinition();
$previous_name = ltrim($previous, '-');
if (starts_with($previous, '-') && $command_def->hasOption($previous_name) && $command_def->getOption($previous_name)->acceptValue()) {
if (Str::startsWith($previous, '-') && $command_def->hasOption($previous_name) && $command_def->getOption($previous_name)->acceptValue()) {
$completions = $this->completeOptionValue($command_def->getOption($previous_name), $current);
} else {
$completions = collect();
if (!starts_with($previous, '-')) {
if (!Str::startsWith($previous, '-')) {
$completions = $this->completeArguments($command, $current, end($words));
}
$completions = $completions->merge($this->completeOption($command_def, $current, $this->getPreviousOptions($words)));
@ -93,11 +94,11 @@ class BashCompletionCommand extends Command
});
$completions = $all_commands->filter(function ($cmd) use ($partial) {
return empty($partial) || starts_with($cmd, $partial);
return empty($partial) || Str::startsWith($cmd, $partial);
});
// handle : silliness
if (str_contains($partial, ':')) {
if (Str::contains($partial, ':')) {
$completions = $completions->map(function ($cmd) {
return substr($cmd, strpos($cmd, ':') + 1);
});
@ -144,14 +145,14 @@ class BashCompletionCommand extends Command
}
return $options->filter(function ($option) use ($partial) {
return empty($partial) || starts_with($option, $partial);
return empty($partial) || Str::startsWith($option, $partial);
});
}
private function getPreviousOptions($words)
{
return array_reduce($words, function ($result, $word) {
if (starts_with($word, '-')) {
if (Str::startsWith($word, '-')) {
$split = explode('=', $word, 2); // users may use equals for values
$result[] = reset($split);
}
@ -174,7 +175,7 @@ class BashCompletionCommand extends Command
return trim($value);
})
->filter(function ($value) use ($partial) {
return empty($partial) || starts_with($value, $partial);
return empty($partial) || Str::startsWith($value, $partial);
});
}
return collect();

View File

@ -26,6 +26,7 @@
namespace App\Http\Controllers\Ajax;
use App\Http\Controllers\Controller;
use Illuminate\Support\Str;
use \LibreNMS\Config;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
@ -71,7 +72,7 @@ class NetCommand extends Controller
function () use ($proc, $request) {
// a bit dirty, bust browser initial cache
$ua = $request->header('User-Agent');
if (str_contains($ua, ['Chrome', 'Trident'])) {
if (Str::contains($ua, ['Chrome', 'Trident'])) {
$char = "\f"; // line feed
} else {
$char = "";

View File

@ -6,6 +6,7 @@ use App\Checks;
use Illuminate\Contracts\Session\Session;
use Illuminate\Http\Request;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use LibreNMS\Config;
class LegacyController extends Controller
@ -19,16 +20,16 @@ class LegacyController extends Controller
$init_modules = ['web', 'auth'];
require base_path('/includes/init.php');
set_debug(str_contains($request->path(), 'debug'));
set_debug(Str::contains($request->path(), 'debug'));
ob_start(); // protect against bad plugins that output during start
\LibreNMS\Plugins::start();
ob_end_clean();
if (str_contains($request->path(), 'widescreen=yes')) {
if (Str::contains($request->path(), 'widescreen=yes')) {
$session->put('widescreen', 1);
}
if (str_contains($request->path(), 'widescreen=no')) {
if (Str::contains($request->path(), 'widescreen=no')) {
$session->forget('widescreen');
}

View File

@ -27,6 +27,7 @@ namespace App\Http\Controllers\Select;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use LibreNMS\Config;
class GraphAggregateController extends Controller
@ -56,7 +57,7 @@ class GraphAggregateController extends Controller
// handle search
if ($search = strtolower($request->get('term'))) {
$types = array_filter($types, function ($type) use ($search) {
return !str_contains(strtolower($type), $search);
return !Str::contains(strtolower($type), $search);
});
}

View File

@ -29,6 +29,7 @@ use App\Http\Controllers\Controller;
use App\Models\Device;
use Illuminate\Http\Request;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use LibreNMS\Util\Graph;
use LibreNMS\Util\StringHelpers;
@ -100,7 +101,7 @@ class GraphController extends Controller
private function formatGraph($top, $graph)
{
$text = $graph;
if (str_contains('_', $graph)) {
if (Str::contains('_', $graph)) {
list($type, $subtype) = explode('_', $graph, 2);
} else {
$type = $graph;
@ -131,18 +132,18 @@ class GraphController extends Controller
$terms = preg_split('/[ _-]/', $search, 2);
$first = array_shift($terms);
if (str_contains($type, $first)) {
if (Str::contains($type, $first)) {
// search matches type, show all unless there are more terms.
if (!empty($terms)) {
$sub_search = array_shift($terms);
$graphs = $graphs->filter(function ($graph) use ($sub_search) {
return str_contains(strtolower($graph), $sub_search);
return Str::contains(strtolower($graph), $sub_search);
});
}
} else {
// if the type matches, don't filter the sub values
$graphs = $graphs->filter(function ($graph) use ($search) {
return str_contains(strtolower($graph), $search);
return Str::contains(strtolower($graph), $search);
});
}
}

View File

@ -28,6 +28,7 @@ namespace App\Http\Controllers\Select;
use App\ApiClients\GraylogApi;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Log;
class GraylogStreamsController extends Controller
@ -50,7 +51,7 @@ class GraylogStreamsController extends Controller
$streams = [];
try {
$streams = collect($api->getStreams()['streams'])->filter(function ($stream) use ($search) {
return !$search || str_contains(strtolower($stream['title']), $search) || str_contains(strtolower($stream['description']), $search);
return !$search || Str::contains(strtolower($stream['title']), $search) || Str::contains(strtolower($stream['description']), $search);
})->map(function ($stream) {
$text = $stream['title'];
if ($stream['description']) {

View File

@ -26,6 +26,7 @@
namespace App\Http\Controllers\Table;
use App\Models\Port;
use Illuminate\Support\Arr;
use LibreNMS\Config;
use LibreNMS\Util\Html;
use LibreNMS\Util\Url;
@ -128,6 +129,6 @@ class CustomersController extends TableController
private function getTypeStrings()
{
return array_wrap(Config::get('customers_descr', ['cust']));
return Arr::wrap(Config::get('customers_descr', ['cust']));
}
}

View File

@ -31,6 +31,7 @@ use App\Models\AuthLog;
use App\Models\Dashboard;
use App\Models\User;
use App\Models\UserPref;
use Illuminate\Support\Str;
use LibreNMS\Authentication\LegacyAuth;
use LibreNMS\Config;
use Toastr;
@ -177,7 +178,7 @@ class UserController extends Controller
}
}
return redirect(route(str_contains(URL::previous(), 'preferences') ? 'preferences.index' : 'users.index'));
return redirect(route(Str::contains(URL::previous(), 'preferences') ? 'preferences.index' : 'users.index'));
}
/**

View File

@ -26,6 +26,7 @@
namespace App\Http\Controllers\Widgets;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
class ImageController extends WidgetController
{
@ -51,7 +52,7 @@ class ImageController extends WidgetController
$data['image_url'] = str_replace(['@AUTO_HEIGHT@', '@AUTO_WIDTH@'], [$dimensions['y'], $dimensions['x']], $data['image_url']);
// bust cache
if (str_contains($data['image_url'], '?')) {
if (Str::contains($data['image_url'], '?')) {
$data['image_url'] .= '&' . mt_rand();
} else {
$data['image_url'] .= '?' . mt_rand();

View File

@ -29,6 +29,7 @@ use App\Http\Controllers\Controller;
use App\Models\DeviceGroup;
use App\Models\UserWidget;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Illuminate\View\View;
abstract class WidgetController extends Controller
@ -115,7 +116,7 @@ abstract class WidgetController extends Controller
{
if ($view instanceof View) {
$html = $view->__toString();
$show_settings = (int)starts_with($view->getName(), 'widgets.settings.');
$show_settings = (int)Str::startsWith($view->getName(), 'widgets.settings.');
} else {
$html = (string)$view;
$show_settings = (int)$this->show_settings;

View File

@ -4,6 +4,7 @@ namespace App\Http\Middleware;
use App\Models\UserPref;
use Closure;
use Illuminate\Support\Str;
use LibreNMS\Config;
class VerifyTwoFactor
@ -20,7 +21,7 @@ class VerifyTwoFactor
// check twofactor
if (Config::get('twofactor') === true) {
// don't apply on 2fa checking routes
if (starts_with($request->route()->getName(), '2fa.')) {
if (Str::startsWith($request->route()->getName(), '2fa.')) {
return $next($request);
}

View File

@ -1275,25 +1275,6 @@ function ResolveGlues($tables, $target, $x = 0, $hist = array(), $last = array()
return false;
}
if (!function_exists('str_contains')) {
/**
* Determine if a given string contains a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*/
function str_contains($haystack, $needles)
{
foreach ((array)$needles as $needle) {
if ($needle != '' && strpos($haystack, $needle) !== false) {
return true;
}
}
return false;
}
}
/**
* Determine if a given string contains a given substring.
*
@ -1341,44 +1322,6 @@ function get_sql_filter_min_severity($min_severity, $alert_rules_name)
return "";
}
if (!function_exists('ends_with')) {
/**
* Determine if a given string ends with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*/
function ends_with($haystack, $needles)
{
foreach ((array)$needles as $needle) {
if ((string)$needle === substr($haystack, -strlen($needle))) {
return true;
}
}
return false;
}
}
if (!function_exists('starts_with')) {
/**
* Determine if a given string starts with a given substring.
*
* @param string $haystack
* @param string|array $needles
* @return bool
*/
function starts_with($haystack, $needles)
{
foreach ((array)$needles as $needle) {
if ($needle != '' && strpos($haystack, $needle) === 0) {
return true;
}
}
return false;
}
}
/**
* Print a list of items up to a max amount
* If over that number, a line will print the total items

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Str;
echo "\nCaching OIDs:";
if ($device['os'] == 'junos') {
@ -101,7 +103,7 @@ if ($device['os'] == 'saf-cfm') {
}
foreach ([1 => 'm1Description', 2 => 'm2Description', 3 => 'm3Description', 4 => 'm4Description'] as $index => $item) {
if (!str_contains($device_array[$item], 'N/A')) {
if (!Str::contains($device_array[$item], 'N/A')) {
$entity_array[] = [
'entPhysicalDescr' => $device_array[$item],
'entPhysicalVendorType' => 'module',

View File

@ -12,6 +12,7 @@
* See COPYING for more details.
*/
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Exceptions\HostExistsException;
use LibreNMS\Exceptions\InvalidIpException;
@ -913,13 +914,13 @@ function get_device_divisor($device, $os_version, $sensor_type, $oid)
}
} elseif ($device['os'] == 'huaweiups') {
if ($sensor_type == 'frequency') {
if (starts_with($device['hardware'], "UPS2000")) {
if (Str::startsWith($device['hardware'], "UPS2000")) {
return 10;
}
return 100;
}
} elseif ($device['os'] == 'hpe-rtups') {
if ($sensor_type == 'voltage' && !starts_with($oid, '.1.3.6.1.2.1.33.1.2.5.') && !starts_with($oid, '.1.3.6.1.2.1.33.1.3.3.1.3')) {
if ($sensor_type == 'voltage' && !Str::startsWith($oid, '.1.3.6.1.2.1.33.1.2.5.') && !Str::startsWith($oid, '.1.3.6.1.2.1.33.1.3.3.1.3')) {
return 1;
}
} elseif ($device['os'] == 'apc-mgeups') {
@ -934,16 +935,16 @@ function get_device_divisor($device, $os_version, $sensor_type, $oid)
return 1;
}
if ($sensor_type == 'voltage' && !starts_with($oid, '.1.3.6.1.2.1.33.1.2.5.')) {
if ($sensor_type == 'voltage' && !Str::startsWith($oid, '.1.3.6.1.2.1.33.1.2.5.')) {
return 1;
}
if ($sensor_type == 'runtime') {
if (starts_with($oid, '.1.3.6.1.2.1.33.1.2.2.')) {
if (Str::startsWith($oid, '.1.3.6.1.2.1.33.1.2.2.')) {
return 60;
}
if (starts_with($oid, '.1.3.6.1.2.1.33.1.2.3.')) {
if (Str::startsWith($oid, '.1.3.6.1.2.1.33.1.2.3.')) {
if ($device['os'] == 'routeros') {
return 60;
} else {
@ -985,7 +986,7 @@ function ignore_storage($os, $descr)
}
foreach (Config::getOsSetting($os, 'ignore_mount_string') as $ims) {
if (str_contains($descr, $ims)) {
if (Str::contains($descr, $ims)) {
d_echo("ignored $descr (matched: $ims)\n");
return true;
}
@ -1037,7 +1038,7 @@ function discovery_process(&$valid, $device, $sensor_type, $pre_cache)
if (!is_numeric($snmp_value)) {
if ($sensor_type === 'temperature') {
// For temp sensors, try and detect fahrenheit values
if (ends_with($snmp_value, array('f', 'F'))) {
if (Str::endsWith($snmp_value, array('f', 'F'))) {
$user_function = 'fahrenheit_to_celsius';
}
}

View File

@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\Config;
// FIXME should do the deletion etc in a common file perhaps? like for the sensors
@ -15,13 +16,13 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
}
foreach (Config::get('libvirt_protocols') as $method) {
if (str_contains($method, 'qemu')) {
if (Str::contains($method, 'qemu')) {
$uri = $method.'://'.$userHostname.'/system';
} else {
$uri = $method.'://'.$userHostname;
}
if (str_contains($method, 'ssh') && !$ssh_ok) {
if (Str::contains($method, 'ssh') && !$ssh_ok) {
// Check if we are using SSH if we can log in without password - without blocking the discovery
// Also automatically add the host key so discovery doesn't block on the yes/no question, and run echo so we don't get stuck in a remote shell ;-)
exec('ssh -o "StrictHostKeyChecking no" -o "PreferredAuthentications publickey" -o "IdentitiesOnly yes" '.$userHostname.' echo -e', $out, $ret);
@ -30,7 +31,7 @@ if (Config::get('enable_libvirt') && $device['os'] == 'linux') {
}
}
if ($ssh_ok || !str_contains($method, 'ssh')) {
if ($ssh_ok || !Str::contains($method, 'ssh')) {
// Fetch virtual machine list
unset($domlist);
exec(Config::get('virsh').' -rc '.$uri.' list', $domlist);

View File

@ -10,23 +10,24 @@
* the source code distribution for details.
*/
use Illuminate\Support\Str;
if ($device['os'] == 'edgecos') {
d_echo('EdgeCore Memory:');
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.24.')) { //ECS4510
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.24.')) { //ECS4510
$temp_mibs = 'ECS4510-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.22.')) { //ECS3528
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.22.')) { //ECS3528
$temp_mibs = 'ES3528MV2-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.39.')) { //ECS4110
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.39.')) { //ECS4110
$temp_mibs = 'ECS4110-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.45.')) { //ECS4120
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.45.')) { //ECS4120
$temp_mibs = 'ECS4120-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.42.')) { //ECS4210
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.42.')) { //ECS4210
$temp_mibs = 'ECS4210-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.27.')) { //ECS3510
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.27.')) { //ECS3510
$temp_mibs = 'ECS3510-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.43.')) { //ECS2100
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.43.')) { //ECS2100
$temp_mibs = 'ECS2100-MIB';
};

View File

@ -1,7 +1,9 @@
<?php
use Illuminate\Support\Str;
if ($device['os'] == 'ironware' || $device['os_type'] == 'ironware') {
if (str_contains($device['sysDescr'], array('NetIron', 'MLX', 'CER')) === false) {
if (Str::contains($device['sysDescr'], array('NetIron', 'MLX', 'CER')) === false) {
echo 'Ironware Dynamic: ';
$percent = snmp_get($device, 'snAgGblDynMemUtil.0', '-OvQ', 'FOUNDRY-SN-AGENT-MIB');

View File

@ -10,10 +10,12 @@
* the source code distribution for details.
*/
use Illuminate\Support\Str;
if ($device['os'] == 'sonicwall') {
echo 'SonicWALL-MEMORY-POOL: ';
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.8741.6')) {
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.8741.6')) {
$usage = snmp_get($device, 'SNWL-SSLVPN-MIB::memoryUtilization.0', '-Ovq');
} else {
$usage = snmp_get($device, 'SONICWALL-FIREWALL-IP-STATISTICS-MIB::sonicCurrentRAMUtil.0', '-Ovq');

View File

@ -1,11 +1,13 @@
<?php
if (starts_with($device['sysDescr'], 'Linux') || starts_with($device['sysObjectID'], '.1.3.6.1.4.1.8072.3.2.10')) {
if (starts_with($device['sysObjectID'], array('.1.3.6.1.4.1.10002.1', '.1.3.6.1.4.1.41112.1.4'))
|| str_contains(snmp_walk($device, 'dot11manufacturerName', '-Osqnv', 'IEEE802dot11-MIB'), 'Ubiquiti')
use Illuminate\Support\Str;
if (Str::startsWith($device['sysDescr'], 'Linux') || Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.8072.3.2.10')) {
if (Str::startsWith($device['sysObjectID'], array('.1.3.6.1.4.1.10002.1', '.1.3.6.1.4.1.41112.1.4'))
|| Str::contains(snmp_walk($device, 'dot11manufacturerName', '-Osqnv', 'IEEE802dot11-MIB'), 'Ubiquiti')
) {
$os = 'airos';
if (str_contains(snmp_walk($device, 'dot11manufacturerProductName', '-Osqnv', 'IEEE802dot11-MIB'), 'UAP')) {
if (Str::contains(snmp_walk($device, 'dot11manufacturerProductName', '-Osqnv', 'IEEE802dot11-MIB'), 'UAP')) {
$os = 'unifi';
} elseif (snmp_get($device, 'fwVersion.1', '-Osqnv', 'UBNT-AirFIBER-MIB', 'ubnt') !== false) {
$os = 'airos-af';

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Str;
if ($device['os_group'] == 'cisco') {
echo ' CISCO-ENTITY-SENSOR: ';
@ -164,7 +166,7 @@ if ($device['os_group'] == 'cisco') {
break;
}
if ($entity_array[$phys_index]['entPhysicalClass'] === 'port') {
if (str_contains($entity_array[$phys_index][0]['entAliasMappingIdentifier'], 'ifIndex.')) {
if (Str::contains($entity_array[$phys_index][0]['entAliasMappingIdentifier'], 'ifIndex.')) {
list(, $tmp_ifindex) = explode(".", $entity_array[$phys_index][0]['entAliasMappingIdentifier']);
$tmp_port = get_port_by_index_cache($device['device_id'], $tmp_ifindex);
if (is_array($tmp_port)) {

View File

@ -15,7 +15,9 @@
* @author LibreNMS Contributors
*/
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.8741.6')) {
use Illuminate\Support\Str;
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.8741.6')) {
$licenses = snmp_get($device, 'SNWL-SSLVPN-MIB::userLicense.0', '-Ovq');
$licenses = str_replace(' Users', '', $licenses);
$current = snmp_get($device, '.1.3.6.1.4.1.8741.6.2.1.9.0', '-Ovq');

View File

@ -1,4 +1,7 @@
<?php
use Illuminate\Support\Str;
echo ' ENTITY-SENSOR: ';
echo 'Caching OIDs:';
if (empty($entity_array)) {
@ -47,7 +50,7 @@ if (!empty($entity_oids)) {
$high_limit = null;
// Fix for Cisco ASR920, 15.5(2)S
if ($entry['entPhySensorType'] == 'other' && str_contains($entity_array[$index]['entPhysicalName'], ['Rx Power Sensor', 'Tx Power Sensor'])) {
if ($entry['entPhySensorType'] == 'other' && Str::contains($entity_array[$index]['entPhysicalName'], ['Rx Power Sensor', 'Tx Power Sensor'])) {
$entitysensor['other'] = 'dbm';
}
if ($entitysensor[$entry['entPhySensorType']] && is_numeric($entry['entPhySensorValue']) && is_numeric($index)) {
@ -131,7 +134,7 @@ if (!empty($entity_oids)) {
$valid_sensor = false;
}
}
if ($current == '-127' || ($device['os'] == 'asa' && ends_with($device['hardware'], 'sc'))) {
if ($current == '-127' || ($device['os'] == 'asa' && Str::endsWith($device['hardware'], 'sc'))) {
$valid_sensor = false;
}
// Check for valid sensors

View File

@ -23,6 +23,8 @@
* @author Neil Lathwood <gh+n@laf.io>
*/
use Illuminate\Support\Str;
$serverscheck_oids = [
'sensor1Value.0' => '.1.3.6.1.4.1.17095.3.2.0',
'sensor2Value.0' => '.1.3.6.1.4.1.17095.3.6.0',
@ -33,10 +35,10 @@ $serverscheck_oids = [
$temp_x = 1;
foreach ($pre_cache['serverscheck_control'] as $oid_name => $oid_value) {
if (str_contains($oid_name, 'name')) {
if (Str::contains($oid_name, 'name')) {
$tmp_oid = 'sensor' . $temp_x . 'Value.0';
$current = $pre_cache['serverscheck_control'][$tmp_oid];
if (str_contains($oid_value, 'Humid')) {
if (Str::contains($oid_value, 'Humid')) {
if (is_numeric($current)) {
$index = str_replace('.0', '', $oid_name);
$descr = $oid_value;

View File

@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\Config;
// IPMI - We can discover this on poll!
@ -18,7 +19,7 @@ if ($ipmi['host'] = get_dev_attrib($device, 'ipmi_hostname')) {
$results = explode(PHP_EOL, external_exec(array_merge($cmd, ['-I', $ipmi_type, 'sensor'])));
array_filter($results, function ($line) {
return !str_contains($line, 'discrete');
return !Str::contains($line, 'discrete');
});
if (!empty($results)) {

View File

@ -10,6 +10,8 @@
* the source code distribution for details.
*/
use Illuminate\Support\Str;
$temp = snmpwalk_cache_multi_oid($device, 'swIfOperSuspendedStatus', [], 'CISCOSB-rlInterfaces');
$cur_oid = '.1.3.6.1.4.1.9.6.1.101.43.1.1.24.';
@ -25,7 +27,7 @@ if (is_array($temp)) {
foreach ($temp as $index => $entry) {
$port_data = get_port_by_index_cache($device['device_id'], str_replace('1.', '', $index));
$descr = $port_data['ifDescr'] . ' Suspended Status';
if (str_contains($descr, ['ethernet','Ethernet']) && $port_data['ifOperStatus'] !== 'notPresent') {
if (Str::contains($descr, ['ethernet', 'Ethernet']) && $port_data['ifOperStatus'] !== 'notPresent') {
//Discover Sensors
discover_sensor($valid['sensor'], 'state', $device, $cur_oid . $index, $index, $state_name, $descr, 1, 1, null, null, null, null, $temp[$index]['swIfOperSuspendedStatus'], 'snmp', $index);

View File

@ -23,6 +23,8 @@
* @author Marcus Pink <mpink@avantgarde-labs.de>
*/
use Illuminate\Support\Str;
$serverscheck_oids = [
'sensor1Value.0' => '.1.3.6.1.4.1.17095.3.2.0',
'sensor2Value.0' => '.1.3.6.1.4.1.17095.3.6.0',
@ -32,7 +34,7 @@ $serverscheck_oids = [
];
foreach ($pre_cache['serverscheck_control'] as $oid_name => $oid_value) {
if ((str_contains($oid_name, 'name')) && (str_contains($oid_value, ['Flooding', 'Leckage']))) {
if ((Str::contains($oid_name, 'name')) && (Str::contains($oid_value, ['Flooding', 'Leckage']))) {
preg_match("/(\d+)/", $oid_name, $temp_x);
$tmp_oid = 'sensor' . $temp_x[0] . 'Value.0';
$current = $pre_cache['serverscheck_control'][$tmp_oid];

View File

@ -4,6 +4,7 @@
* requires snmp extend agent script from librenms-agent
*/
use Illuminate\Support\Str;
use LibreNMS\Config;
$sensor_oid = ".1.3.6.1.4.1.8072.1.3.2.4.1.2.9.114.97.115.112.98.101.114.114.121.1";
@ -15,7 +16,7 @@ if (is_numeric($value)) {
discover_sensor($valid['sensor'], 'temperature', $device, $sensor_oid, 1, $sensor_type, $descr, 1, 1, null, null, null, null, $value);
}
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.232.')) {
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.232.')) {
echo 'HP_ILO ';
$oids = snmp_walk($device, '.1.3.6.1.4.1.232.6.2.6.8.1.2.1', '-Osqn', '');
$oids = trim($oids);

View File

@ -23,6 +23,8 @@
* @author Neil Lathwood <gh+n@laf.io>
*/
use Illuminate\Support\Str;
$serverscheck_oids = [
'sensor1Value.0' => '.1.3.6.1.4.1.17095.3.2.0',
'sensor2Value.0' => '.1.3.6.1.4.1.17095.3.6.0',
@ -33,10 +35,10 @@ $serverscheck_oids = [
$temp_x = 1;
foreach ($pre_cache['serverscheck_control'] as $oid_name => $oid_value) {
if (str_contains($oid_name, 'name')) {
if (Str::contains($oid_name, 'name')) {
$tmp_oid = 'sensor' . $temp_x . 'Value.0';
$current = $pre_cache['serverscheck_control'][$tmp_oid];
if (str_contains($oid_value, ['Temp', 'BR'])) {
if (Str::contains($oid_value, ['Temp', 'BR'])) {
if (is_numeric($current)) {
$index = str_replace('.0', '', $oid_name);
$descr = $oid_value;

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Str;
$regexp = '/
\.1\.3\.6\.1\.4\.1\.22626\.1\.5\.2\.
(?P<id>\d+)
@ -51,7 +53,7 @@ if ($oids) {
$temp_unit = snmp_get($device, 'tempUnit.0', '-OevTQUs', 'T3610-MIB');
$user_func = '';
if (str_contains($temp_unit, 'F')) {
if (Str::contains($temp_unit, 'F')) {
$user_func = 'fahrenheit_to_celsius';
}

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Str;
$valid_toner = array();
if ($device['os_group'] == 'printer') {
@ -37,7 +39,7 @@ if ($device['os_group'] == 'printer') {
}
// trim part & serial number from devices that include it
if (str_contains($descr, ', PN')) {
if (Str::contains($descr, ', PN')) {
$descr = explode(', PN', $descr)[0];
}

View File

@ -12,6 +12,7 @@
*/
use App\Models\Device;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Exceptions\HostExistsException;
use LibreNMS\Exceptions\HostIpExistsException;
@ -124,7 +125,7 @@ function parse_modules($type, $options)
Config::set("{$type}_modules", []);
foreach (explode(',', $options['m']) as $module) {
// parse submodules (only supported by some modules)
if (str_contains($module, '/')) {
if (Str::contains($module, '/')) {
list($module, $submodule) = explode('/', $module, 2);
$existing_submodules = Config::get("{$type}_submodules.$module", []);
$existing_submodules[] = $submodule;
@ -228,16 +229,16 @@ function checkDiscovery($device, $array)
{
// all items must be true
foreach ($array as $key => $value) {
if ($check = ends_with($key, '_except')) {
if ($check = Str::endsWith($key, '_except')) {
$key = substr($key, 0, -7);
}
if ($key == 'sysObjectID') {
if (starts_with($device['sysObjectID'], $value) == $check) {
if (Str::startsWith($device['sysObjectID'], $value) == $check) {
return false;
}
} elseif ($key == 'sysDescr') {
if (str_contains($device['sysDescr'], $value) == $check) {
if (Str::contains($device['sysDescr'], $value) == $check) {
return false;
}
} elseif ($key == 'sysDescr_regex') {
@ -312,17 +313,17 @@ function compare_var($a, $b, $comparison = '=')
case "<":
return $a < $b;
case "contains":
return str_contains($a, $b);
return Str::contains($a, $b);
case "not_contains":
return !str_contains($a, $b);
return !Str::contains($a, $b);
case "starts":
return starts_with($a, $b);
return Str::startsWith($a, $b);
case "not_starts":
return !starts_with($a, $b);
return !Str::startsWith($a, $b);
case "ends":
return ends_with($a, $b);
return Str::endsWith($a, $b);
case "not_ends":
return !ends_with($a, $b);
return !Str::endsWith($a, $b);
case "regex":
return (bool)preg_match($b, $a);
case "not regex":
@ -351,7 +352,7 @@ function percent_colour($perc)
function getLogo($device)
{
$img = getImageName($device, true, 'images/logos/');
if (!starts_with($img, 'generic')) {
if (!Str::startsWith($img, 'generic')) {
return 'images/logos/' . $img;
}
@ -1089,14 +1090,14 @@ function is_port_valid($port, $device)
}
foreach (Config::getCombined($device['os'], 'bad_iftype') as $bt) {
if (str_contains($ifType, $bt)) {
if (Str::contains($ifType, $bt)) {
d_echo("ignored by ifType: $ifType (matched: $bt )\n");
return false;
}
}
foreach (Config::getCombined($device['os'], 'bad_ifoperstatus') as $bos) {
if (str_contains($ifOperStatus, $bos)) {
if (Str::contains($ifOperStatus, $bos)) {
d_echo("ignored by ifOperStatus: $ifOperStatus (matched: $bos)\n");
return false;
}
@ -1948,7 +1949,7 @@ function get_toner_levels($device, $raw_value, $capacity)
return 0;
}
} elseif ($device['os'] == 'brother') {
if (!str_contains($device['hardware'], 'MFC-L8850')) {
if (!Str::contains($device['hardware'], 'MFC-L8850')) {
switch ($raw_value) {
case '0':
return 100;

View File

@ -18,13 +18,15 @@ use App\Models\PortsFdb;
use App\Models\Sensor;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Routing\Router;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Str;
use LibreNMS\Alerting\QueryBuilderParser;
use LibreNMS\Config;
use LibreNMS\Data\Store\Datastore;
use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\Util\IPv4;
use LibreNMS\Util\IP;
use LibreNMS\Util\IPv4;
function api_success($result, $result_name, $message = null, $code = 200, $count = null, $extra = null)
{
@ -160,7 +162,7 @@ function get_port_stats_by_port_hostname(\Illuminate\Http\Request $request)
$ifName = $request->route('ifname');
// handle %2f in paths and pass to get_graph_by_port_hostname if needed
if (str_contains($ifName, '/')) {
if (Str::contains($ifName, '/')) {
$parts = explode('/', $request->path());
if (isset($parts[5])) {
@ -211,7 +213,7 @@ function get_graph_generic_by_hostname(\Illuminate\Http\Request $request)
$vars['output'] = $request->get('output', 'display');
if (isset($sensor_id)) {
$vars['id'] = $sensor_id;
if (str_contains($vars['type'], '_wireless')) {
if (Str::contains($vars['type'], '_wireless')) {
$vars['type'] = str_replace('device_', '', $vars['type']);
} else {
// If this isn't a wireless graph we need to fix the name.
@ -483,7 +485,7 @@ function show_endpoints(\Illuminate\Http\Request $request, Router $router)
$base = str_replace('api/v0', '', $request->url());
foreach ($router->getRoutes() as $route) {
/** @var \Illuminate\Routing\Route $route */
if (starts_with($route->getPrefix(), 'api/v0') && $route->getName()) {
if (Str::startsWith($route->getPrefix(), 'api/v0') && $route->getName()) {
$output[$route->getName()] = $base . $route->uri();
}
}
@ -633,7 +635,7 @@ function get_graph_by_portgroup(\Illuminate\Http\Request $request)
if (empty($id)) {
$ports = get_ports_from_type(explode(',', $group));
$if_list = implode(',', array_pluck($ports, 'port_id'));
$if_list = implode(',', Arr::pluck($ports, 'port_id'));
} else {
$if_list = $id;
}

View File

@ -23,6 +23,7 @@
* @author Neil Lathwood <gh+n@laf.io>
*/
use Illuminate\Support\Str;
use LibreNMS\Alerting\QueryBuilderParser;
header('Content-type: application/json');
@ -159,9 +160,9 @@ if (is_numeric($rule_id) && $rule_id > 0) {
$groups = [];
$locations = [];
foreach ((array)$vars['maps'] as $item) {
if (starts_with($item, 'l')) {
if (Str::startsWith($item, 'l')) {
$locations[] = (int)substr($item, 1);
} elseif (starts_with($item, 'g')) {
} elseif (Str::startsWith($item, 'g')) {
$groups[] = (int)substr($item, 1);
} else {
$devices[] = (int)$item;
@ -176,7 +177,7 @@ if (is_numeric($rule_id) && $rule_id > 0) {
$transports = [];
$groups = [];
foreach ((array)$vars['transports'] as $item) {
if (starts_with($item, 'g')) {
if (Str::startsWith($item, 'g')) {
$groups[] = (int)substr($item, 1);
} else {
$transports[] = (int)$item;

View File

@ -26,6 +26,8 @@
* @author Tony Murray <murraytony@gmail.com>
*/
use Illuminate\Support\Str;
header('Content-type: application/json');
if (!Auth::user()->hasGlobalAdmin()) {
@ -50,7 +52,7 @@ $new_title = convert_template($vars['title']);
function convert_template($line)
{
if (str_contains($line, '{calc')) {
if (Str::contains($line, '{calc')) {
return preg_replace(
[
'/{calc[ ]*([\w\d\s\%\.\(\)\*\/\-\+\/]+)}/',// Replaces {calc (something*100)}

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Str;
/*
* LibreNMS
*
@ -126,10 +128,10 @@ if ($sub_type == 'new-maintenance') {
foreach ($_POST['maps'] as $target) {
$type = 'device';
if (starts_with($target, 'l')) {
if (Str::startsWith($target, 'l')) {
$type = 'location';
$target = substr($target, 1);
} elseif (starts_with($target, 'g')) {
} elseif (Str::startsWith($target, 'g')) {
$type = 'device_group';
$target = substr($target, 1);
}

View File

@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\RRD\RrdDefinition;
use LibreNMS\Util\IP;
@ -236,7 +237,7 @@ if (\LibreNMS\Config::get('enable_bgp')) {
foreach ($oid_map as $source => $target) {
$v = isset($peer_data_raw[$source]) ? $peer_data_raw[$source] : '';
if (str_contains($source, 'LocalAddr')) {
if (Str::contains($source, 'LocalAddr')) {
try {
$v = IP::fromHexString($v)->uncompressed();
} catch (InvalidIpException $e) {

View File

@ -1,5 +1,6 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\RRD\RrdDefinition;
use LibreNMS\Exceptions\JsonAppException;
@ -572,7 +573,7 @@ function update_application($app, $response, $metrics = array(), $status = '')
);
if ($response != '' && $response !== false) {
if (str_contains($response, array(
if (Str::contains($response, array(
'Traceback (most recent call last):',
))) {
$data['app_state'] = 'ERROR';

View File

@ -10,21 +10,23 @@
* the source code distribution for details.
*/
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.24.')) { //ECS4510
use Illuminate\Support\Str;
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.24.')) { //ECS4510
$temp_mibs = 'ECS4510-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.22.')) { //ECS3528
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.22.')) { //ECS3528
$temp_mibs = 'ES3528MV2-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.39.')) { //ECS4110
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.39.')) { //ECS4110
$temp_mibs = 'ECS4110-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.45.')) { //ECS4120
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.45.')) { //ECS4120
$temp_mibs = 'ECS4120-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.42.')) { //ECS4210
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.42.')) { //ECS4210
$temp_mibs = 'ECS4210-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.27.')) { //ECS3510
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.27.')) { //ECS3510
$temp_mibs = 'ECS3510-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.8.1.11.')) { //ECS3510MA
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.8.1.11.')) { //ECS3510MA
$temp_mibs = 'ES3510MA-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.43.')) { //ECS2100
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.43.')) { //ECS2100
$temp_mibs = 'ECS2100-MIB';
};

View File

@ -1,10 +1,12 @@
<?php
use Illuminate\Support\Str;
$oid = $mempool['mempool_index'];
d_echo('Ironware Mempool'."\n");
if (str_contains($device['sysDescr'], array('NetIron', 'MLX', 'CER')) === false) {
if (Str::contains($device['sysDescr'], array('NetIron', 'MLX', 'CER')) === false) {
echo 'Ironware Dynamic: ';
$mempool['total'] = snmp_get($device, 'snAgGblDynMemTotal.0', '-OvQ', 'FOUNDRY-SN-AGENT-MIB');
if ($mempool['total'] < 0) {

View File

@ -10,8 +10,10 @@
* the source code distribution for details.
*/
use Illuminate\Support\Str;
echo 'SonicWALL-MEMORY-POOL: ';
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.8741.6')) {
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.8741.6')) {
$usage = snmp_get($device, 'SNWL-SSLVPN-MIB::memoryUtilization.0', '-Ovq');
} else {
$usage = snmp_get($device, 'SONICWALL-FIREWALL-IP-STATISTICS-MIB::sonicCurrentRAMUtil.0', '-Ovq');

View File

@ -1,8 +1,9 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\RRD\RrdDefinition;
if (!starts_with($device['os'], array('Snom', 'asa'))) {
if (!Str::startsWith($device['os'], array('Snom', 'asa'))) {
echo ' ICMP';
// Below have more oids, and are in trees by themselves, so we can snmpwalk_cache_oid them

View File

@ -1,8 +1,9 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\RRD\RrdDefinition;
if (!starts_with($device['os'], ['Snom', 'asa'])) {
if (!Str::startsWith($device['os'], ['Snom', 'asa'])) {
echo ' IP';
$oids = [

View File

@ -1,7 +1,9 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\RRD\RrdDefinition;
if (!starts_with($device['os'], array('Snom', 'asa'))) {
if (!Str::startsWith($device['os'], array('Snom', 'asa'))) {
echo ' IP-FORWARD';
$oid = 'ipCidrRouteNumber';

View File

@ -1,8 +1,9 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\RRD\RrdDefinition;
if (!starts_with($device['os'], ['Snom', 'asa'])) {
if (!Str::startsWith($device['os'], ['Snom', 'asa'])) {
echo ' TCP';
$oids = [
'tcpActiveOpens',

View File

@ -1,8 +1,9 @@
<?php
use Illuminate\Support\Str;
use LibreNMS\RRD\RrdDefinition;
if (!starts_with($device['os'], ['Snom', 'asa'])) {
if (!Str::startsWith($device['os'], ['Snom', 'asa'])) {
echo ' UDP';
$oids = [

View File

@ -1,4 +1,7 @@
<?php
use Illuminate\Support\Str;
if (strpos($device['sysDescr'], 'Software')) {
$hardware = str_replace("3Com ", '', substr($device['sysDescr'], 0, strpos($device['sysDescr'], 'Software')));
// Version is the last word in the sysDescr's first line
@ -7,7 +10,7 @@ if (strpos($device['sysDescr'], 'Software')) {
$hardware = str_replace("3Com ", '', $device['sysDescr']);
$version = '';
// Old Stack Units
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.43.10.27.4.1.')) {
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.43.10.27.4.1.')) {
$oids = ['stackUnitDesc.1', 'stackUnitPromVersion.1', 'stackUnitSWVersion.1', 'stackUnitSerialNumber.1','stackUnitCapabilities.1'];
$data = snmp_get_multi($device, $oids, ['-OQUs','--hexOutputLength=0'], 'A3COM0352-STACK-CONFIG');
$hardware .= ' ' . $data[1]['stackUnitDesc'];

View File

@ -10,7 +10,10 @@
* option) any later version. Please see LICENSE.txt at the top level of
* the source code distribution for details.
*/
if (!ends_with($device['hardware'], 'sc')) {
use Illuminate\Support\Str;
if (!Str::endsWith($device['hardware'], 'sc')) {
$oids = ['entPhysicalModelName.1', 'entPhysicalSoftwareRev.1', 'entPhysicalSerialNum.1', 'entPhysicalModelName.4', 'entPhysicalSoftwareRev.4'];
$data = snmp_get_multi($device, $oids, '-OQUs', 'ENTITY-MIB');

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Str;
$avocent_tmp = snmp_get_multi_oid($device, ['pmProductModel.0', 'pmSerialNumber.0', 'pmFirmwareVersion.0'], '-OUQs', 'PM-MIB');
$hardware = $avocent_tmp['pmProductModel.0'];
@ -7,9 +9,9 @@ $serial = $avocent_tmp['pmSerialNumber.0'];
$version = $avocent_tmp['pmFirmwareVersion.0'];
if (empty($hardware)) {
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.10418.16')) {
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.10418.16')) {
$avocent_oid = '.1.3.6.1.4.1.10418.16.2.1';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.10418.26')) {
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.10418.26')) {
$avocent_oid = '.1.3.6.1.4.1.10418.26.2.1';
}
if ($avocent_oid) {

View File

@ -1,22 +1,24 @@
<?php
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.6.')) { //ES3528M0
use Illuminate\Support\Str;
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.6.')) { //ES3528M0
$tmp_mib = 'ES3528MO-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.22.')) { //ES3528MV2
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.22.')) { //ES3528MV2
$tmp_mib = 'ES3528MV2-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.24.')) { //ECS4510
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.24.')) { //ECS4510
$tmp_mib = 'ECS4510-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.39.')) { //ECS4110
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.39.')) { //ECS4110
$tmp_mib = 'ECS4110-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.42.')) { //ECS4210
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.42.')) { //ECS4210
$tmp_mib = 'ECS4210-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.27.')) { //ECS3510
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.27.')) { //ECS3510
$tmp_mib = 'ECS3510-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.45.')) { //ECS4120
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.45.')) { //ECS4120
$tmp_mib = 'ECS4120-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.8.1.11')) { //ES3510MA
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.8.1.11')) { //ES3510MA
$tmp_mib = 'ES3510MA-MIB';
} elseif (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.43.')) { //ECS2100
} elseif (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.259.10.1.43.')) { //ECS2100
$tmp_mib = 'ECS2100-MIB';
};

View File

@ -10,11 +10,13 @@
* the source code distribution for details.
*/
use Illuminate\Support\Str;
$data = explode(" ", $device['sysDescr']);
$hardware = $data[0];
$version = $data[9];
if (str_contains($device['sysDescr'], 'PLANET IGS-')) {
if (Str::contains($device['sysDescr'], 'PLANET IGS-')) {
$hardware = $data[1];
$version = snmp_get($device, "1.3.6.1.2.1.47.1.1.1.1.10.1", "-Ovq");
}

View File

@ -22,7 +22,9 @@
* @copyright 2017 Paul Heinrichs
* @author Paul Heinrichs<pdheinrichs@gmail.com>
*/
use LibreNMS\RRD\RrdDefinition;
use Illuminate\Support\Str;
use LibreNMS\RRD\RrdDefinition;
$cambium_type = $device['sysDescr'];
$PMP = snmp_get($device, 'boxDeviceType.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB');
@ -47,10 +49,10 @@ $pmp = array(
);
foreach ($ptp as $desc => $model) {
if (str_contains($cambium_type, $desc)) {
if (Str::contains($cambium_type, $desc)) {
$hardware = $model;
if (str_contains($model, 'PTP')) {
if (Str::contains($model, 'PTP')) {
$masterSlaveMode = str_replace($filtered_words, "", snmp_get($device, 'bhTimingMode.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB'));
$hardware = $model . ' '. $masterSlaveMode;
$version = snmp_get($device, 'boxDeviceTypeID.0', '-Oqv', 'WHISP-BOX-MIBV2-MIB');
@ -62,15 +64,15 @@ foreach ($ptp as $desc => $model) {
if (!isset($hardware)) {
$hardware = 'PMP 100';
foreach ($pmp as $desc => $model) {
if (str_contains($PMP, $desc)) {
if (Str::contains($PMP, $desc)) {
$hardware = $model;
break;
}
}
if (str_contains($hardware, 'PMP')) {
if (str_contains($version, "AP")) {
if (Str::contains($hardware, 'PMP')) {
if (Str::contains($version, "AP")) {
$hardware .= ' AP';
} elseif (str_contains($version, "SM")) {
} elseif (Str::contains($version, "SM")) {
$hardware .= ' SM';
}
}

View File

@ -10,16 +10,18 @@
* the source code distribution for details.
*/
use Illuminate\Support\Str;
$hardware = snmp_get($device, 'sysObjectID.0', '-Osqv', 'SNMPv2-MIB:CISCO-PRODUCTS-MIB');
$version = snmp_get($device, '.1.3.6.1.2.1.54.1.1.1.1.4.1', '-Osqv');
$applist = snmp_walk($device, '.1.3.6.1.2.1.54.1.1.1.1.3', '-OQv');
if (str_contains($applist, "Cisco Unified CCX Database")) {
if (Str::contains($applist, "Cisco Unified CCX Database")) {
$features = "UCCX";
} elseif (str_contains($applist, "Cisco CallManager")) {
} elseif (Str::contains($applist, "Cisco CallManager")) {
$features = "CUCM";
} elseif (str_contains($applist, "Cisco Emergency Responder")) {
} elseif (Str::contains($applist, "Cisco Emergency Responder")) {
$features = "CER";
} elseif (str_contains($applist, "Connection System Agent")) {
} elseif (Str::contains($applist, "Connection System Agent")) {
$features = "CUC";
}

View File

@ -1,5 +1,7 @@
<?php
use Illuminate\Support\Str;
// sysDescr.0 = STRING: Hardware: x86 Family 6 Model 1 Stepping 9 AT/AT COMPATIBLE - Software: Windows NT Version 4.0 (Build Number: 1381 Multiprocessor Free )
// sysDescr.0 = STRING: Hardware: x86 Family 6 Model 3 Stepping 4 AT/AT COMPATIBLE - Software: Windows NT Version 3.51 (Build Number: 1057 Multiprocessor Free )
// sysDescr.0 = STRING: Hardware: x86 Family 16 Model 4 Stepping 2 AT/AT COMPATIBLE - Software: Windows 2000 Version 5.1 (Build 2600 Multiprocessor Free)
@ -9,106 +11,106 @@
// sysDescr.0 = STRING: Hardware: Intel64 Family 6 Model 23 Stepping 6 AT/AT COMPATIBLE - Software: Windows Version 6.1 (Build 7600 Multiprocessor Free)
// sysDescr.0 = STRING: Hardware: AMD64 Family 16 Model 8 Stepping 0 AT/AT COMPATIBLE - Software: Windows Version 6.1 (Build 7600 Multiprocessor Free)
if (str_contains($device['sysDescr'], 'AMD64')) {
if (Str::contains($device['sysDescr'], 'AMD64')) {
$hardware = 'AMD x64';
} elseif (str_contains($device['sysDescr'], array('EM64', 'Intel64'))) {
} elseif (Str::contains($device['sysDescr'], array('EM64', 'Intel64'))) {
$hardware = 'Intel x64';
} elseif (str_contains($device['sysDescr'], 'x86')) {
} elseif (Str::contains($device['sysDescr'], 'x86')) {
$hardware = 'Generic x86';
} elseif (str_contains($device['sysDescr'], 'ia64')) {
} elseif (Str::contains($device['sysDescr'], 'ia64')) {
$hardware = 'Intel Itanium IA64';
}
if ($device['sysObjectID'] == '.1.3.6.1.4.1.311.1.1.3.1.1') {
// Client
if (str_contains($device['sysDescr'], 'Build 14393')) {
if (Str::contains($device['sysDescr'], 'Build 14393')) {
$version = '10 AU (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Build 10586')) {
} elseif (Str::contains($device['sysDescr'], 'Build 10586')) {
$version = '10 U1 (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Build 10240')) {
} elseif (Str::contains($device['sysDescr'], 'Build 10240')) {
$version = '10 (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Build 9600')) {
} elseif (Str::contains($device['sysDescr'], 'Build 9600')) {
$version = '8.1 U1 (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Version 6.3 (Build 9200')) {
} elseif (Str::contains($device['sysDescr'], 'Version 6.3 (Build 9200')) {
$version = '8.1 (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Build 9200')) {
} elseif (Str::contains($device['sysDescr'], 'Build 9200')) {
$version = '8 (NT 6.2)';
} elseif (str_contains($device['sysDescr'], 'Build 7601')) {
} elseif (Str::contains($device['sysDescr'], 'Build 7601')) {
$version = '7 SP1 (NT 6.1)';
} elseif (str_contains($device['sysDescr'], 'Build 7600')) {
} elseif (Str::contains($device['sysDescr'], 'Build 7600')) {
$version = '7 (NT 6.1)';
} elseif (str_contains($device['sysDescr'], 'Build 6002')) {
} elseif (Str::contains($device['sysDescr'], 'Build 6002')) {
$version = 'Vista SP2 (NT 6.0)';
} elseif (str_contains($device['sysDescr'], 'Build 6001')) {
} elseif (Str::contains($device['sysDescr'], 'Build 6001')) {
$version = 'Vista SP1 (NT 6.0)';
} elseif (str_contains($device['sysDescr'], 'Build 6000')) {
} elseif (Str::contains($device['sysDescr'], 'Build 6000')) {
$version = 'Vista (NT 6.0)';
} elseif (str_contains($device['sysDescr'], 'Build 3790')) {
} elseif (Str::contains($device['sysDescr'], 'Build 3790')) {
$version = 'XP x64 (NT 5.2)';
} elseif (str_contains($device['sysDescr'], 'Build 2600')) {
} elseif (Str::contains($device['sysDescr'], 'Build 2600')) {
$version = 'XP (NT 5.1)';
} elseif (str_contains($device['sysDescr'], 'Build 2195')) {
} elseif (Str::contains($device['sysDescr'], 'Build 2195')) {
$version = '2000 (NT 5.0)';
} elseif (str_contains($device['sysDescr'], 'Build Number: 1381')) {
} elseif (Str::contains($device['sysDescr'], 'Build Number: 1381')) {
$version = 'NT 4.0 Workstation';
} elseif (str_contains($device['sysDescr'], 'Build Number: 1057')) {
} elseif (Str::contains($device['sysDescr'], 'Build Number: 1057')) {
$version = 'NT 3.51 Workstation';
}
} elseif ($device['sysObjectID'] == '.1.3.6.1.4.1.311.1.1.3.1.2') {
// Server
if (str_contains($device['sysDescr'], 'Build 14393')) {
if (Str::contains($device['sysDescr'], 'Build 14393')) {
$version = 'Server 2016 (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Build 9600')) {
} elseif (Str::contains($device['sysDescr'], 'Build 9600')) {
$version = 'Server 2012 R2 (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Build 9200')) {
} elseif (Str::contains($device['sysDescr'], 'Build 9200')) {
$version = 'Server 2012 (NT 6.2)';
} elseif (str_contains($device['sysDescr'], 'Build 7601')) {
} elseif (Str::contains($device['sysDescr'], 'Build 7601')) {
$version = 'Server 2008 R2 SP1 (NT 6.1)';
} elseif (str_contains($device['sysDescr'], 'Build 7600')) {
} elseif (Str::contains($device['sysDescr'], 'Build 7600')) {
$version = 'Server 2008 R2 (NT 6.1)';
} elseif (str_contains($device['sysDescr'], 'Build 6002')) {
} elseif (Str::contains($device['sysDescr'], 'Build 6002')) {
$version = 'Server 2008 SP2 (NT 6.0)';
} elseif (str_contains($device['sysDescr'], 'Build 6001')) {
} elseif (Str::contains($device['sysDescr'], 'Build 6001')) {
$version = 'Server 2008 (NT 6.0)';
} elseif (str_contains($device['sysDescr'], 'Build 3790')) {
} elseif (Str::contains($device['sysDescr'], 'Build 3790')) {
$version = 'Server 2003 (NT 5.2)';
} elseif (str_contains($device['sysDescr'], 'Build 2195')) {
} elseif (Str::contains($device['sysDescr'], 'Build 2195')) {
$version = '2000 Server (NT 5.0)';
} elseif (str_contains($device['sysDescr'], 'Build Number: 1381')) {
} elseif (Str::contains($device['sysDescr'], 'Build Number: 1381')) {
$version = 'NT Server 4.0';
} elseif (str_contains($device['sysDescr'], 'Build Number: 1057')) {
} elseif (Str::contains($device['sysDescr'], 'Build Number: 1057')) {
$version = 'NT Server 3.51';
}
} elseif ($device['sysObjectID'] == '.1.3.6.1.4.1.311.1.1.3.1.3') {
// Datacenter
if (str_contains($device['sysDescr'], 'Build 14393')) {
if (Str::contains($device['sysDescr'], 'Build 14393')) {
$version = 'Server 2016 Datacenter (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Build 9600')) {
} elseif (Str::contains($device['sysDescr'], 'Build 9600')) {
$version = 'Server 2012 R2 Datacenter (NT 6.3)';
} elseif (str_contains($device['sysDescr'], 'Build 9200')) {
} elseif (Str::contains($device['sysDescr'], 'Build 9200')) {
$version = 'Server 2012 Datacenter (NT 6.2)';
} elseif (str_contains($device['sysDescr'], 'Build 7601')) {
} elseif (Str::contains($device['sysDescr'], 'Build 7601')) {
$version = 'Server 2008 Datacenter R2 SP1 (NT 6.1)';
} elseif (str_contains($device['sysDescr'], 'Build 7600')) {
} elseif (Str::contains($device['sysDescr'], 'Build 7600')) {
$version = 'Server 2008 Datacenter R2 (NT 6.1)';
} elseif (str_contains($device['sysDescr'], 'Build 6002')) {
} elseif (Str::contains($device['sysDescr'], 'Build 6002')) {
$version = 'Server 2008 Datacenter SP2 (NT 6.0)';
} elseif (str_contains($device['sysDescr'], 'Build 6001')) {
} elseif (Str::contains($device['sysDescr'], 'Build 6001')) {
$version = 'Server 2008 Datacenter (NT 6.0)';
} elseif (str_contains($device['sysDescr'], 'Build 3790')) {
} elseif (Str::contains($device['sysDescr'], 'Build 3790')) {
$version = 'Server 2003 Datacenter (NT 5.2)';
} elseif (str_contains($device['sysDescr'], 'Build 2195')) {
} elseif (Str::contains($device['sysDescr'], 'Build 2195')) {
$version = '2000 Datacenter Server (NT 5.0)';
} elseif (str_contains($device['sysDescr'], 'Build Number: 1381')) {
} elseif (Str::contains($device['sysDescr'], 'Build Number: 1381')) {
$version = 'NT Datacenter 4.0';
} elseif (str_contains($device['sysDescr'], 'Build Number: 1057')) {
} elseif (Str::contains($device['sysDescr'], 'Build Number: 1057')) {
$version = 'NT Datacenter 3.51';
}
}//end version if
if (str_contains($device['sysDescr'], 'Multiprocessor')) {
if (Str::contains($device['sysDescr'], 'Multiprocessor')) {
$features = 'Multiprocessor';
} elseif (str_contains($device['sysDescr'], 'Uniprocessor')) {
} elseif (Str::contains($device['sysDescr'], 'Uniprocessor')) {
$features = 'Uniprocessor';
}

View File

@ -26,7 +26,9 @@
// ESI-MIB::genProductNumber.0 .1.3.6.1.4.1.683.1.4.0
// ESI-MIB::genSerialNumber.0 .1.3.6.1.4.1.683.1.5.0
// ESI-MIB::genVersion.0 .1.3.6.1.4.1.683.1.9.0
if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.683')) {
use Illuminate\Support\Str;
if (Str::startsWith($device['sysObjectID'], '.1.3.6.1.4.1.683')) {
$oids = array(
'hardware' => '.1.3.6.1.4.1.683.1.4.0',
'serial' => '.1.3.6.1.4.1.683.1.5.0',
@ -38,7 +40,7 @@ if (starts_with($device['sysObjectID'], '.1.3.6.1.4.1.683')) {
}
}
if (str_contains($device['sysDescr'], 'Wireless')) {
if (Str::contains($device['sysDescr'], 'Wireless')) {
$features = 'wireless';
} else {
$features = 'wired';

View File

@ -16,6 +16,7 @@
*/
use App\Models\Device;
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\RRD\RrdDefinition;
@ -196,7 +197,7 @@ function snmp_get_multi($device, $oids, $options = '-OQUs', $mib = null, $mibdir
$value = trim($value, "\" \n\r");
list($oid, $index) = explode('.', $oid, 2);
if (!str_contains($value, 'at this OID')) {
if (!Str::contains($value, 'at this OID')) {
if (is_null($index)) {
if (empty($oid)) {
continue; // no index or oid
@ -233,7 +234,7 @@ function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mi
$array = array();
$oid = '';
foreach ($data as $entry) {
if (str_contains($entry, '=')) {
if (Str::contains($entry, '=')) {
list($oid,$value) = explode('=', $entry, 2);
$oid = trim($oid);
$value = trim($value, "\\\" \n\r");
@ -341,7 +342,7 @@ function snmp_getnext_multi($device, $oids, $options = '-OQUs', $mib = null, $mi
$oid = trim($oid);
$value = trim($value, "\" \n\r");
list($oid, $index) = explode('.', $oid, 2);
if (!str_contains($value, 'at this OID')) {
if (!Str::contains($value, 'at this OID')) {
if (empty($oid)) {
continue; // no index or oid
} else {
@ -390,7 +391,7 @@ function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
d_echo("Invalid snmp_walk() data = " . print_r($data, true));
$data = false;
} else {
if (ends_with($data, '(It is past the end of the MIB tree)')) {
if (Str::endsWith($data, '(It is past the end of the MIB tree)')) {
$no_more_pattern = '/.*No more variables left in this MIB View \(It is past the end of the MIB tree\)[\n]?/';
$data = preg_replace($no_more_pattern, '', $data);
}
@ -645,7 +646,7 @@ function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = array(),
$line = strtok($data, "\n");
while ($line !== false) {
if (str_contains($line, 'at this OID')||str_contains($line, 'this MIB View')) {
if (Str::contains($line, 'at this OID') || Str::contains($line, 'this MIB View')) {
$line = strtok("\n");
continue;
}
@ -656,7 +657,7 @@ function snmpwalk_group($device, $oid, $mib = '', $depth = 1, $array = array(),
array_splice($parts, $depth, 0, array_shift($parts)); // move the oid name to the correct depth
$line = strtok("\n"); // get the next line and concatenate multi-line values
while ($line !== false && !str_contains($line, '=')) {
while ($line !== false && !Str::contains($line, '=')) {
$value .= $line . PHP_EOL;
$line = strtok("\n");
}

View File

@ -1,6 +1,7 @@
#!/usr/bin/php
<?php
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\Authentication\LegacyAuth;
@ -33,7 +34,7 @@ echo "Authentication Method: " . Config::get('auth_mechanism') . PHP_EOL;
// if ldap like, check selinux
if (Config::get('auth_mechanism') == 'ldap' || Config::get('auth_mechanism') == "active_directory") {
$enforce = shell_exec('getenforce 2>/dev/null');
if (str_contains($enforce, 'Enforcing')) {
if (Str::contains($enforce, 'Enforcing')) {
// has selinux
$output = shell_exec('getsebool httpd_can_connect_ldap');
if ($output != "httpd_can_connect_ldap --> on\n") {

View File

@ -2,6 +2,7 @@
<?php
use LibreNMS\Config;
use Illuminate\Support\Str;
$install_dir = realpath(__DIR__ . '/..');
chdir($install_dir);
@ -36,7 +37,7 @@ if (isset($options['h'])) {
if (is_numeric($options['h'])) {
$where = "AND `device_id` = ?";
$params = array($options['h']);
} elseif (str_contains($options['h'], ',')) {
} elseif (Str::contains($options['h'], ',')) {
$device_ids = array_map('trim', explode(',', $options['h']));
$device_ids = array_filter($device_ids, 'is_numeric');
$where = 'AND `device_id` in ' . dbGenPlaceholders(count($device_ids));

View File

@ -1,6 +1,7 @@
#!/usr/bin/env php
<?php
use Illuminate\Support\Str;
use LibreNMS\Exceptions\InvalidModuleException;
use LibreNMS\Util\ModuleTestHelper;
use LibreNMS\Util\Snmpsim;
@ -98,7 +99,7 @@ if (isset($options['v'])) {
$variant = $options['variant'];
}
if (str_contains($variant, '_')) {
if (Str::contains($variant, '_')) {
exit("Variant name cannot contain an underscore (_).\n");
}

View File

@ -1,6 +1,8 @@
#!/usr/bin/env php
<?php
use Illuminate\Support\Str;
$filename = basename(__FILE__);
$install_dir = realpath(__DIR__ . '/..');
chdir($install_dir);
@ -25,13 +27,13 @@ $map = [
];
foreach ($changed_files as $file) {
if (starts_with($file, 'doc/')) {
if (Str::startsWith($file, 'doc/')) {
$map['docs']++;
}
if (ends_with($file, '.py')) {
if (Str::endsWith($file, '.py')) {
$map['python']++;
}
if (ends_with($file, '.sh')) {
if (Str::endsWith($file, '.sh')) {
$map['bash']++;
}
@ -43,10 +45,10 @@ foreach ($changed_files as $file) {
// check if os owned file or generic php file
if (!empty($os_name = os_from_file($file))) {
$map['os'][] = $os_name;
if (ends_with($file, '.php')) {
if (Str::endsWith($file, '.php')) {
$map['os-php']++;
}
} elseif (ends_with($file, '.php')) {
} elseif (Str::endsWith($file, '.php')) {
$map['php']++;
}
}
@ -178,11 +180,11 @@ exit($return); //return the combined/single return value of tests
function os_from_file($file)
{
if (starts_with($file, 'includes/definitions/')) {
if (Str::startsWith($file, 'includes/definitions/')) {
return basename($file, '.yaml');
} elseif (starts_with($file, ['includes/polling', 'includes/discovery'])) {
} elseif (Str::startsWith($file, ['includes/polling', 'includes/discovery'])) {
return os_from_php($file);
} elseif (starts_with($file, 'LibreNMS/OS/')) {
} elseif (Str::startsWith($file, 'LibreNMS/OS/')) {
if (preg_match('#LibreNMS/OS/[^/]+.php#', $file)) {
// convert class name to os name
preg_match_all("/[A-Z][a-z]*/", basename($file, '.php'), $segments);
@ -193,7 +195,7 @@ function os_from_file($file)
}
return os_from_php(str_replace('-', '_', $osname));
}
} elseif (starts_with($file, ['tests/snmpsim/', 'tests/data/'])) {
} elseif (Str::startsWith($file, ['tests/snmpsim/', 'tests/data/'])) {
list($os,) = explode('_', basename(basename($file, '.json'), '.snmprec'), 2);
return $os;
}

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Tests;
use Illuminate\Support\Str;
use LibreNMS\Config;
class CommonFunctionsTest extends TestCase
@ -33,14 +34,14 @@ class CommonFunctionsTest extends TestCase
{
$data = 'This is a test. Just Testing.';
$this->assertTrue(str_contains($data, 'Just'));
$this->assertFalse(str_contains($data, 'just'));
$this->assertTrue(Str::contains($data, 'Just'));
$this->assertFalse(Str::contains($data, 'just'));
$this->assertTrue(str_i_contains($data, 'juSt'));
$this->assertFalse(str_i_contains($data, 'nope'));
$this->assertTrue(str_contains($data, array('not', 'this', 'This')));
$this->assertFalse(str_contains($data, array('not', 'this')));
$this->assertTrue(Str::contains($data, array('not', 'this', 'This')));
$this->assertFalse(Str::contains($data, array('not', 'this')));
$this->assertTrue(str_i_contains($data, array('not', 'thIs')));
$this->assertFalse(str_i_contains($data, array('not', 'anything')));
@ -50,22 +51,22 @@ class CommonFunctionsTest extends TestCase
{
$data = 'This is a test. Just Testing that.';
$this->assertTrue(starts_with($data, 'This'));
$this->assertFalse(starts_with($data, 'this'));
$this->assertTrue(Str::startsWith($data, 'This'));
$this->assertFalse(Str::startsWith($data, 'this'));
$this->assertTrue(starts_with($data, array('this', 'Test', 'This')));
$this->assertFalse(starts_with($data, array('this', 'Test')));
$this->assertTrue(Str::startsWith($data, array('this', 'Test', 'This')));
$this->assertFalse(Str::startsWith($data, array('this', 'Test')));
}
public function testEndsWith()
{
$data = 'This is a test. Just Testing';
$this->assertTrue(ends_with($data, 'Testing'));
$this->assertFalse(ends_with($data, 'testing'));
$this->assertTrue(Str::endsWith($data, 'Testing'));
$this->assertFalse(Str::endsWith($data, 'testing'));
$this->assertTrue(ends_with($data, array('this', 'Testing', 'This')));
$this->assertFalse(ends_with($data, array('this', 'Test')));
$this->assertTrue(Str::endsWith($data, array('this', 'Testing', 'This')));
$this->assertFalse(Str::endsWith($data, array('this', 'Test')));
}
public function testRrdDescriptions()

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Tests;
use Illuminate\Support\Str;
use \PHPUnit\Framework\ExpectationFailedException as PHPUnitException;
class DBSetupTest extends DBTestCase
@ -53,18 +54,18 @@ class DBSetupTest extends DBTestCase
foreach (explode("\n", $content) as $line) {
// skip comments and empty lines
if (empty($line) || starts_with($line, array('#', '--'))) {
if (empty($line) || Str::startsWith($line, array('#', '--'))) {
continue;
}
// each line must end with ;, prevents multiline and makes sql easy to run by hand
// Warning may include whitespace such as space and \r
if (!ends_with($line, ';')) {
if (!Str::endsWith($line, ';')) {
throw new PHPUnitException("Each line must end with a semicolin (;)\n$file: $line");
}
// cannot assume user use the librenms database name
if (str_contains($line, 'librenms.')) {
if (Str::contains($line, 'librenms.')) {
throw new PHPUnitException("Do not include the database name in schema files\n$file: $line");
}
}

View File

@ -26,6 +26,7 @@
namespace LibreNMS\Tests;
use Exception;
use Illuminate\Support\Str;
use LibreNMS\Config;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
@ -183,12 +184,12 @@ class MibTest extends TestCase
while (($line = fgets($handle)) !== false) {
$trimmed = trim($line);
if (empty($trimmed) || starts_with($trimmed, '--')) {
if (empty($trimmed) || Str::startsWith($trimmed, '--')) {
continue;
}
$header .= " $trimmed";
if (str_contains($trimmed, 'DEFINITIONS')) {
if (Str::contains($trimmed, 'DEFINITIONS')) {
preg_match('/(\S+)\s+(?=DEFINITIONS)/', $header, $matches);
fclose($handle);
return $matches[1];

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Tests;
use Illuminate\Support\Str;
use LibreNMS\Config;
class OSDiscoveryTest extends TestCase
@ -64,7 +65,7 @@ class OSDiscoveryTest extends TestCase
return basename($file, '.snmprec');
}, glob($glob));
$files = array_filter($files, function ($file) use ($os_name) {
return $file == $os_name || starts_with($file, $os_name . '_');
return $file == $os_name || Str::startsWith($file, $os_name . '_');
});
if (empty($files)) {

View File

@ -25,6 +25,7 @@
namespace LibreNMS\Tests;
use Illuminate\Support\Str;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
use RecursiveRegexIterator;
@ -43,7 +44,7 @@ class SVGTest extends TestCase
$svg = file_get_contents($file);
$this->assertFalse(
str_contains($svg, 'data:image/'),
Str::contains($svg, 'data:image/'),
"$file contains a bitmap image, please use a regular png or valid svg"
);
}
@ -72,7 +73,7 @@ class SVGTest extends TestCase
$svg = file_get_contents($file);
$this->assertTrue(
str_contains($svg, 'viewBox'),
Str::contains($svg, 'viewBox'),
"$file: SVG files must have the viewBox attribute set"
);
}

View File

@ -23,6 +23,7 @@
* @author Tony Murray <murraytony@gmail.com>
*/
use Illuminate\Support\Str;
use LibreNMS\Config;
$snmpMockCache = array();
@ -167,34 +168,34 @@ function snmp_translate_type($oid, $mib = null, $mibdir = null)
throw new Exception('Could not translate oid: ' . $oid . PHP_EOL . 'Tried: ' . $cmd);
}
if (str_contains($result, 'OCTET STRING')) {
if (Str::contains($result, 'OCTET STRING')) {
return 4;
}
if (str_contains($result, 'Integer32')) {
if (Str::contains($result, 'Integer32')) {
return 2;
}
if (str_contains($result, 'NULL')) {
if (Str::contains($result, 'NULL')) {
return 5;
}
if (str_contains($result, 'OBJECT IDENTIFIER')) {
if (Str::contains($result, 'OBJECT IDENTIFIER')) {
return 6;
}
if (str_contains($result, 'IpAddress')) {
if (Str::contains($result, 'IpAddress')) {
return 64;
}
if (str_contains($result, 'Counter32')) {
if (Str::contains($result, 'Counter32')) {
return 65;
}
if (str_contains($result, 'Gauge32')) {
if (Str::contains($result, 'Gauge32')) {
return 66;
}
if (str_contains($result, 'TimeTicks')) {
if (Str::contains($result, 'TimeTicks')) {
return 67;
}
if (str_contains($result, 'Opaque')) {
if (Str::contains($result, 'Opaque')) {
return 68;
}
if (str_contains($result, 'Counter64')) {
if (Str::contains($result, 'Counter64')) {
return 70;
}
@ -234,11 +235,10 @@ function snmp_get_multi_oid($device, $oids, $options = '-OUQn', $mib = null, $mi
$data = array();
foreach ($oids as $index => $oid) {
if (str_contains($options, 'n')) {
if (Str::contains($options, 'n')) {
$oid_name = '.' . snmp_translate_number($oid, $mib, $mibdir);
$val = snmp_get($device, $oid_name, $options, $mib, $mibdir);
} elseif (str_contains($options, 's')
&& str_contains($oid, '::')) {
} elseif (Str::contains($options, 's') && Str::contains($oid, '::')) {
$tmp = explode('::', $oid);
$oid_name = $tmp[1];
$val = snmp_get($device, $oid, $options, $mib, $mibdir);
@ -263,7 +263,7 @@ function snmp_walk($device, $oid, $options = null, $mib = null, $mibdir = null)
$output = '';
foreach ($dev as $key => $data) {
if (starts_with($key, $num_oid)) {
if (Str::startsWith($key, $num_oid)) {
if ($data[0] == 6) {
$output .= '.' . $data[1] . PHP_EOL;
} else {

View File

@ -13,6 +13,7 @@
* the source code distribution for details.
*/
use Illuminate\Support\Str;
use LibreNMS\Config;
use LibreNMS\ValidationResult;
use LibreNMS\Validator;
@ -81,18 +82,18 @@ if (!file_exists('config.php')) {
$pre_checks_failed = false;
$syntax_check = `php -ln config.php`;
if (!str_contains($syntax_check, 'No syntax errors detected')) {
if (!Str::contains($syntax_check, 'No syntax errors detected')) {
print_fail('Syntax error in config.php');
echo $syntax_check;
$pre_checks_failed = true;
}
$first_line = rtrim(`head -n1 config.php`);
if (!starts_with($first_line, '<?php')) {
if (!Str::startsWith($first_line, '<?php')) {
print_fail("config.php doesn't start with a <?php - please fix this ($first_line)");
$pre_checks_failed = true;
}
if (str_contains(`tail config.php`, '?>')) {
if (Str::contains(`tail config.php`, '?>')) {
print_fail("Remove the ?> at the end of config.php");
$pre_checks_failed = true;
}