Fix incorrect icon sometimes (#9887)

* Fix icon finding
Also fix os suggest not loading all OS.

* Fix os that would have missing icon under the new code (and one under the old code)

* forgot icon
This commit is contained in:
Tony Murray
2019-03-01 23:06:01 -06:00
committed by GitHub
parent 7c4a0c7244
commit e677d4b63e
10 changed files with 46 additions and 45 deletions

View File

@@ -29,6 +29,7 @@ use App\Models\Device;
use App\Models\Port;
use Auth;
use Carbon\Carbon;
use Illuminate\Support\Str;
use LibreNMS\Config;
class Url
@@ -364,6 +365,38 @@ class Url
return "interface-upup";
}
/**
* @param string $os
* @param string $feature
* @param string $icon
* @param string $dir directory to search in (images/os/ or images/logos)
* @return string
*/
public static function findOsImage($os, $feature, $icon = null, $dir = 'images/os/')
{
$possibilities = [$icon];
if ($os) {
if ($os == "linux") {
$distro = Str::before(strtolower(trim($feature)), ' ');
$possibilities[] = "$distro.svg";
$possibilities[] = "$distro.png";
}
$os_icon = Config::getOsSetting($os, 'icon', $os);
$possibilities[] = "$os_icon.svg";
$possibilities[] = "$os_icon.png";
}
foreach ($possibilities as $file) {
if (is_file(Config::get('html_dir') . "/$dir" . $file)) {
return $file;
}
}
// fallback to the generic icon
return 'generic.svg';
}
private static function escapeBothQuotes($string)
{
return str_replace(["'", '"'], "\'", $string);

View File

@@ -7,10 +7,12 @@ use Fico7489\Laravel\Pivot\Traits\PivotEventTrait;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\ModelNotFoundException;
use Illuminate\Database\Query\JoinClause;
use Illuminate\Support\Str;
use LibreNMS\Exceptions\InvalidIpException;
use LibreNMS\Util\IP;
use LibreNMS\Util\IPv4;
use LibreNMS\Util\IPv6;
use LibreNMS\Util\Url;
class Device extends BaseModel
{
@@ -387,11 +389,10 @@ class Device extends BaseModel
public function getIconAttribute($icon)
{
if (isset($icon)) {
return "images/os/$icon";
}
return 'images/os/generic.svg';
$this->loadOs();
return Str::start(Url::findOsImage($this->os, $this->features, $icon), 'images/os/');
}
public function getIpAttribute($ip)
{
if (empty($ip)) {

View File

@@ -56,6 +56,7 @@ function levsortos($base, $obj, $keys)
header('Content-type: application/json');
if (isset($_GET['term'])) {
load_all_os();
$_GET['term'] = clean($_GET['term']);
$sortos = levsortos($_GET['term'], $config['os'], array("text", "os"));
$sortos = array_slice($sortos, 0, 20);

Binary file not shown.

Before

Width:  |  Height:  |  Size: 693 B

View File

@@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1000 1282"><path fill="#fe8f1d" d="M221.59 450.58c21.18-21.08 42.17-42.37 63.47-63.32.36.04 1.09.12 1.45.17 42.04 41.97 84.03 84.01 126.05 126.01 7.35 7.61 15.24 14.71 22.22 22.65-34.53.09-69.05-.03-103.58.07.22 4.02.13 8.07.57 12.09.98 5.23.11 10.62 1.22 15.84 3.96 38.26 13.16 76.56 31.44 110.66 7.98 14.67 17.68 28.51 29.52 40.34 10.35 10.25 23.09 17.811 36.29 23.811 33.04 14.5 69.05 20.52 104.689 24.29 7.051.369 14.01 1.649 21.11 1.449 8.93 1.25 17.97 1.091 26.979 1.17 12.99 1.08 26.04.71 39.061.601 10.27-.99 20.609-.4 30.91-1 6.72-1.21 13.6-.73 20.399-1.15.42-.3 1.261-.899 1.681-1.189-.221.52-.66 1.569-.881 2.09-43.979 23.25-92.619 37.87-142.17 42.22-2.47.07-4.92.101-7.38.24-1.47.479-3 .86-4.55.83-8.72.04-17.439.069-26.15-.01a11.51 11.51 0 0 1-3.63-.79c-32.95-1.521-65.63-9.471-95.74-22.971-29.71-13.47-57.05-32.109-80.53-54.72-19.49-19.11-36.02-41.26-48.52-65.54-20.43-39.57-30.45-84.35-29.88-128.77-32.98-.02-65.96.1-98.94-.06 28.172-28.461 56.612-56.651 84.892-85.011m252.2-244.13c15.18-.46 30.38-.38 45.56.19l-.1.99c32.48 2.4 64.45 11.31 93.79 25.45 34.54 16.94 66.01 40.54 90.85 69.99 36 42.31 56.771 96.69 60.57 151.92.01 8.11.83 16.17 1.06 24.27 27.5-.07 55.011-.01 82.511-.03 5.39.09 10.79-.25 16.17.27-9.761 8.76-18.65 18.45-28.05 27.59-22.021 22.01-44.03 44.03-66.051 66.04-18.41 18.23-36.47 36.85-55.109 54.83-47.44-47.56-95-95-142.48-142.54-1.939-1.97-4.09-3.77-5.71-6.03 3.7-.23 7.4-.82 11.101-.23 6.039.17 12.119 0 18.119-.25 4.98.69 10 .27 14.99-.12 5.62.62 11.3.61 16.94.16 9.67.55 19.38.17 29.069.28 4.23-.14 8.551.47 12.721-.61-.931-29.21-4.851-58.39-12.641-86.62-9.649-34.53-25.66-68.22-51.34-93.73-15.72-14.59-35.57-23.67-55.67-30.51-.54-.14-1.62-.41-2.16-.54-28.449-9.23-58.229-13.52-87.89-16.34-3.09-.39-6.21-.22-9.29-.58-6.23-1.28-12.63-.55-18.92-1.08-2.26-.43-4.54-.69-6.83-.62-20.01-.49-40.03-.53-60.05-.06-5.38.22-10.77.1-16.15-.13 5.77.47 11.55.89 17.35 1.15-9.1-.26-18.21-.32-27.31.13-4.52.84-9.15 1.11-13.73.77 43.17-23.34 91.07-38.01 139.9-42.79 2.97-.07 5.94-.25 8.78-1.22M112.94 70.16c-12.96 2.11-24.79 9.67-32.57 20.2-7.65 10.12-11.62 22.97-11.11 35.64.01 253.67.01 507.33 0 761-.66 15.72 5.76 31.65 17.25 42.43 9.63 9.311 23.11 14.521 36.51 13.96 251.32-.02 502.65-.01 753.97 0 11.77.561 23.72-3.06 33.02-10.35 14.18-10.57 22.03-28.49 21.63-46.01V125.95c.41-14.99-5.35-30.04-15.66-40.94-9-8.97-21.189-15.05-33.989-15.5H118.98c-2.03-.02-4.06.15-6.04.65M115.07 0h770.38c16.96 1.45 33.87 5.61 49.01 13.57 25.4 12.979 45.61 35.39 56.57 61.67 5.18 12.49 8.72 25.84 8.97 39.42v783.61c-.42 17.94-6.2 35.45-14.65 51.171-10.39 19-25.819 35.27-44.47 46.319-15.97 9.681-34.32 15.28-52.92 16.63-9.66.24-19.33.051-28.99.11-245.66.01-491.33-.01-736.99.01-32.67.771-65.09-13.39-87.52-37.01-13.71-14.36-23.93-32.03-29.44-51.11-2.61-8.43-3.81-17.17-5.02-25.87V118.17c.68-13.34 3.41-26.6 8.19-39.08 9.93-26.37 29.16-49.229 53.72-63.13C78.05 6.5 96.54 1.64 115.07 0"/></svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@@ -1,7 +1,6 @@
os: alcoma-almp
text: Alcoma
type: wireless
icon: alcoma
over:
- { graph: device_wireless_rssi, text: 'Wireless rssi' }
- { graph: device_wireless_snr, text: 'Wireles snr' }

View File

@@ -1,10 +1,9 @@
os: marathonups
text: 'Marathon UPS'
type: power
icon: marathon
rfc1628_compat: true
over:
- { graph: device_load, text: Load }
- { graph: device_voltage, text: Voltage }
discovery:
- sysObjectID: .1.3.6.1.4.1.2021.1.1.1
- sysObjectID: .1.3.6.1.4.1.2021.1.1.1

View File

@@ -1,7 +1,6 @@
os: serverscheck
text: ServersCheck
type: network
icon: serverscheck
discovery:
- sysObjectID:
- .1.3.6.1.4.1.17095

View File

@@ -409,39 +409,7 @@ function getImageTitle($device)
function getImageName($device, $use_database = true, $dir = 'images/os/')
{
global $config;
$os = strtolower($device['os']);
// fetch from the database
if ($use_database && is_file($config['html_dir'] . "/$dir" . $device['icon'])) {
return $device['icon'];
}
// linux specific handling, distro icons
$distro = null;
if ($os == "linux") {
$features = strtolower(trim($device['features']));
list($distro) = explode(" ", $features);
}
$possibilities = array(
$distro,
$config['os'][$os]['icon'],
$os,
);
foreach ($possibilities as $basename) {
foreach (array('.svg', '.png') as $ext) {
$name = $basename . $ext;
if (is_file($config['html_dir'] . "/$dir" . $name)) {
return $name;
}
}
}
// fallback to the generic icon
return 'generic.svg';
return \LibreNMS\Util\Url::findOsImage($device['os'], $device['features'], $use_database ? $device['icon'] : null, $dir);
}
function renamehost($id, $new, $source = 'console')

View File

@@ -8,13 +8,13 @@
"sysDescr": "Temperature & Sensor Gateway",
"sysContact": null,
"version": null,
"hardware": "",
"hardware": null,
"features": null,
"location": null,
"os": "serverscheck",
"type": "network",
"serial": null,
"icon": "generic.svg"
"icon": "serverscheck.svg"
}
]
},
@@ -26,13 +26,13 @@
"sysDescr": "Temperature & Sensor Gateway",
"sysContact": "<private>",
"version": null,
"hardware": "",
"hardware": null,
"features": null,
"location": "<private>",
"os": "serverscheck",
"type": "network",
"serial": null,
"icon": "generic.svg"
"icon": "serverscheck.svg"
}
]
}