allow to search a device by its hostname #958

Merged
merged 2 commits into from May 11, 2015

Projects

None yet

4 participants

@mmarchand
Contributor

search by hostname if ID was not found
it also permits to add a quick search for a device in most modern browsers ;)
( http://nmsinstall//device/device=dev-hostname/ )

@f0o f0o self-assigned this May 10, 2015
@f0o
Member
f0o commented May 10, 2015

We already have this with http://librenms/devices/hostname=.../ - it's a real search and doesnt require the correct hostname but any portion of it will do the job.

@mmarchand
Contributor

ha indeed, I did not know about this search
however, it still adds a few clicks (for example I use this patch to access ports page directly too)
the idea here is to come directly on the right device on the right page to save from a searching step
so not sure if you find this relevant or not ;)

@laf
Member
laf commented May 10, 2015

I can see why you would want to do this, quick access to the device itself by url. It seems like one of those features few might use. It doesn't take us back in anyway so I'd vote to add it.

@f0o
Member
f0o commented May 11, 2015

It probably doesnt do any harm.

I'd like to change the code a little bit however:

diff --git a/html/pages/device.inc.php b/html/pages/device.inc.php
index 9dcf277..0e2c166 100644
--- a/html/pages/device.inc.php
+++ b/html/pages/device.inc.php
@@ -6,10 +6,8 @@ if ($vars['tab'] == "port" && is_numeric($vars['device']) && port_permitted($var
   $permit_ports = 1;
 }

-$device  = device_by_id_cache($vars['device']);
-if (!$device) {
+if (!is_numeric($vars['device'])) {
   $vars['device'] = device_by_name($vars['device']);
-  $device  = device_by_id_cache($vars['device']);
 }

 if (device_permitted($vars['device']) || $check_device == $vars['device'])
@@ -25,6 +23,7 @@ if (device_permitted($vars['device']) || $check_device == $vars['device'])

   $select[$tab] = "active";

+  $device  = device_by_id_cache($vars['device']);
   $attribs = get_dev_attribs($device['device_id']);

   $entity_state = get_dev_entity_state($device['device_id']);
@paulgear
Member

+1 from me after @f0o's change added

@f0o f0o merged commit a585022 into librenms:master May 11, 2015

1 check passed

Scrutinizer No new issues
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment