mirror of
https://github.com/librenms/librenms.git
synced 2024-10-07 16:52:45 +00:00
Remove legacy function calls (#12651)
* massive inlines * fix style and wtf * remove rrdtool.inc.php include * fix CommonFunctions namespace issues * looking for missing class space, fix undefined class issues * style fixes
This commit is contained in:
@@ -24,25 +24,6 @@ use LibreNMS\Util\IP;
|
||||
use LibreNMS\Util\Laravel;
|
||||
use Symfony\Component\Process\Process;
|
||||
|
||||
function generate_priority_label($priority)
|
||||
{
|
||||
$map = [
|
||||
'emerg' => 'label-danger',
|
||||
'alert' => 'label-danger',
|
||||
'crit' => 'label-danger',
|
||||
'err' => 'label-danger',
|
||||
'warning' => 'label-warning',
|
||||
'notice' => 'label-info',
|
||||
'info' => 'label-info',
|
||||
'debug' => 'label-default',
|
||||
'' => 'label-info',
|
||||
];
|
||||
|
||||
$barColor = isset($map[$priority]) ? $map[$priority] : 'label-info';
|
||||
|
||||
return '<span class="alert-status ' . $barColor . '"> </span>';
|
||||
}
|
||||
|
||||
function generate_priority_status($priority)
|
||||
{
|
||||
$map = [
|
||||
@@ -194,7 +175,7 @@ function print_message($text)
|
||||
|
||||
function get_sensor_rrd($device, $sensor)
|
||||
{
|
||||
return rrd_name($device['hostname'], get_sensor_rrd_name($device, $sensor));
|
||||
return Rrd::name($device['hostname'], get_sensor_rrd_name($device, $sensor));
|
||||
}
|
||||
|
||||
function get_sensor_rrd_name($device, $sensor)
|
||||
@@ -207,14 +188,9 @@ function get_sensor_rrd_name($device, $sensor)
|
||||
}
|
||||
}
|
||||
|
||||
function getPortRrdName($port_id, $suffix = '')
|
||||
{
|
||||
return Rrd::portName($port_id, $suffix);
|
||||
}
|
||||
|
||||
function get_port_rrdfile_path($hostname, $port_id, $suffix = '')
|
||||
{
|
||||
return rrd_name($hostname, getPortRrdName($port_id, $suffix));
|
||||
return Rrd::name($hostname, Rrd::portName($port_id, $suffix));
|
||||
}
|
||||
|
||||
function get_port_by_index_cache($device_id, $ifIndex)
|
||||
@@ -369,20 +345,6 @@ function truncate($substring, $max = 50, $rep = '...')
|
||||
}
|
||||
}
|
||||
|
||||
function mres($string)
|
||||
{
|
||||
return $string; // FIXME bleh
|
||||
// short function wrapper because the real one is stupidly long and ugly. aesthetics.
|
||||
global $database_link;
|
||||
|
||||
return mysqli_real_escape_string($database_link, $string);
|
||||
}
|
||||
|
||||
function getifhost($id)
|
||||
{
|
||||
return dbFetchCell('SELECT `device_id` from `ports` WHERE `port_id` = ?', [$id]);
|
||||
}
|
||||
|
||||
function gethostbyid($device_id)
|
||||
{
|
||||
return DeviceCache::get((int) $device_id)->hostname;
|
||||
@@ -429,21 +391,6 @@ function getidbyname($hostname)
|
||||
return DeviceCache::getByHostname($hostname)->device_id;
|
||||
}
|
||||
|
||||
function safename($name)
|
||||
{
|
||||
return \LibreNMS\Data\Store\Rrd::safeName($name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function format the rrdtool description text correctly.
|
||||
* @param $descr
|
||||
* @return mixed
|
||||
*/
|
||||
function safedescr($descr)
|
||||
{
|
||||
return \LibreNMS\Data\Store\Rrd::safeDescr($descr);
|
||||
}
|
||||
|
||||
function zeropad($num, $length = 2)
|
||||
{
|
||||
return str_pad($num, $length, '0', STR_PAD_LEFT);
|
||||
@@ -480,38 +427,6 @@ function del_dev_attrib($device, $attrib_type)
|
||||
return DeviceCache::get((int) $device['device_id'])->forgetAttrib($attrib_type);
|
||||
}
|
||||
|
||||
function formatRates($value, $round = '2', $sf = '3')
|
||||
{
|
||||
$value = format_si($value, $round, $sf) . 'bps';
|
||||
|
||||
return $value;
|
||||
}
|
||||
|
||||
function formatStorage($value, $round = '2', $sf = '3')
|
||||
{
|
||||
return \LibreNMS\Util\Number::formatBi($value, $round, $sf);
|
||||
}
|
||||
|
||||
function format_si($value, $round = 2, $sf = 3)
|
||||
{
|
||||
return \LibreNMS\Util\Number::formatSi($value, $round, $sf, '');
|
||||
}
|
||||
|
||||
function format_bi($value, $round = 2, $sf = 3)
|
||||
{
|
||||
return \LibreNMS\Util\Number::formatBi($value, $round, $sf, '');
|
||||
}
|
||||
|
||||
function format_number($value, $base = 1000, $round = 2, $sf = 3)
|
||||
{
|
||||
return \LibreNMS\Util\Number::formatBase($value, $base, $round, $sf, '');
|
||||
}
|
||||
|
||||
function is_valid_hostname($hostname)
|
||||
{
|
||||
return \LibreNMS\Util\Validate::hostname($hostname);
|
||||
}
|
||||
|
||||
/*
|
||||
* convenience function - please use this instead of 'if ($debug) { echo ...; }'
|
||||
*/
|
||||
@@ -700,21 +615,6 @@ function can_ping_device($attribs)
|
||||
}
|
||||
} // end can_ping_device
|
||||
|
||||
/*
|
||||
* @return true if every string in $arr begins with $str
|
||||
*/
|
||||
function begins_with($str, $arr)
|
||||
{
|
||||
foreach ($arr as $s) {
|
||||
$pos = strpos($s, $str);
|
||||
if ($pos === false || $pos > 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
} // begins_with
|
||||
|
||||
function search_phrase_column($c)
|
||||
{
|
||||
global $searchPhrase;
|
||||
@@ -738,7 +638,7 @@ function ceph_rrd($gtype)
|
||||
$var = $vars['pool'];
|
||||
}
|
||||
|
||||
return rrd_name($device['hostname'], ['app', 'ceph', $vars['id'], $gtype, $var]);
|
||||
return Rrd::name($device['hostname'], ['app', 'ceph', $vars['id'], $gtype, $var]);
|
||||
} // ceph_rrd
|
||||
|
||||
/**
|
||||
@@ -844,7 +744,7 @@ function format_hostname($device, $hostname = null)
|
||||
}
|
||||
|
||||
if (Config::get('force_hostname_to_sysname') && ! empty($device['sysName'])) {
|
||||
if (is_valid_hostname($hostname) && ! IP::isValid($hostname)) {
|
||||
if (\LibreNMS\Util\Validate::hostname($hostname) && ! IP::isValid($hostname)) {
|
||||
return $device['sysName'];
|
||||
}
|
||||
}
|
||||
@@ -1096,30 +996,6 @@ function get_sql_filter_min_severity($min_severity, $alert_rules_name)
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param bool $strip_tags
|
||||
* @return string
|
||||
*/
|
||||
function clean($value, $strip_tags = true)
|
||||
{
|
||||
if ($strip_tags === true) {
|
||||
return strip_tags(mres($value));
|
||||
} else {
|
||||
return mres($value);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $value
|
||||
* @param array $purifier_config (key, value pair)
|
||||
* @return string
|
||||
*/
|
||||
function display($value, $purifier_config = [])
|
||||
{
|
||||
return \LibreNMS\Util\Clean::html($value, $purifier_config);
|
||||
}
|
||||
|
||||
/**
|
||||
* Load the os definition for the device and set type and os_group
|
||||
* $device['os'] must be set
|
||||
@@ -1279,23 +1155,6 @@ function str_to_class($name, $namespace = null)
|
||||
return $namespace . $class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks file permissions against a minimum permissions mask.
|
||||
* This only check that bits are enabled, not disabled.
|
||||
* The mask is in the same format as posix permissions. For example, 600 means user read and write.
|
||||
*
|
||||
* @param string $file the name of the file to check
|
||||
* @param $mask
|
||||
* @return bool
|
||||
*/
|
||||
function check_file_permissions($file, $mask)
|
||||
{
|
||||
$perms = fileperms($file);
|
||||
$mask = octdec($mask);
|
||||
|
||||
return ($perms & $mask) === $mask;
|
||||
}
|
||||
|
||||
/**
|
||||
* Index an array by a column
|
||||
*
|
||||
|
Reference in New Issue
Block a user