- add option to (re)discovery only linux devices (inspired by _Robsan_ from IRC) #2088

Merged
merged 4 commits into from Oct 9, 2015

Projects

None yet

3 participants

@paszczus
paszczus commented Oct 9, 2015

No description provided.

Sławomir Paszkiewicz - add option to (re)discovery only linux devices
c94340d
@f0o
Member
f0o commented Oct 9, 2015

Would prefer it in a more generalized way and if possible without using the 'h' switch and introducing an own one (--os ?)

@paszczus
paszczus commented Oct 9, 2015

yeah it would be even better if we can use type, for example -h type:linux or type:network etcetera.. but i don`t know if i can handle this ;)

@paszczus
paszczus commented Oct 9, 2015

i will try to do this

@f0o
Member
f0o commented Oct 9, 2015

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

  • -h os:linux and such would be much better indeed :D

I'm fine with --os though to keep it simple ;)

On October 9, 2015 10:45:46 AM GMT+02:00, paszczus notifications@github.com wrote:

yeah it would be even better if we can use type, for example -h
type:linux or type:network etcetera.. but i don`t know if i can handle
this ;)


Reply to this email directly or view it on GitHub:
#2088 (comment)
-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQJPBAEBCgA5BQJWF4CmMhxEYW5pZWwgUHJldXNza2VyIChNb2JpbGVLZXkjMikg
PGYwb0BsaWJyZW5tcy5vcmc+AAoJEJMZKtVWOFzBTr8P/AtuFUQ8MlaNkiwcev5B
ijYPD9BGQul0mJFNnCMvpeO3MEjgn1t9IKisI2Iz+qcxI/fN49h/eqe8qmIIWO4S
FTHiFZqvQJvzk7RqCEu4nDi5szAjxe4aJbQzLEXOhBSRFHPl/CMzrZm27hgcCwa2
o7WsQTuzlprstXdql82IxNqGoC9wiwlbKI7dxAxf3Z5DRCzAPWsqFeeAIU1/b33+
fNdk08KP9e2tPDnk0hmPeABFXNkOz8wOc9Bb0vgGHD0ZGCS7qfnrVwGukX9L7CDt
fd9sbUlqZcwls28xzcM35l5gS5On+3UfknF81moxBs7Pj0UvIJTz3l5To9sbsVFS
tdt2hK68yTKa+wfr9sgsmVkZdj3PdCHJ35BHGFcwx9cOxNBKxzEBVgEEchb8mz55
Y+i47V+2XhOiJWvdMgRbNv2lQg2kp8+2Hw4b/03xg/eQxWpU+Sewbk2Ue1JcHGUF
F8FXKO+2PWsbrqN1YKDvyc8xO097sDkDhFCRYUR5sD293V5vXm5LkJX7XaKoqbGZ
HgMYZ4op++Vb0mJQy/MXzyIEvpTcH9NXtG9LLlueSeyjp5jl1hvWJ5Qr/B7pKAAB
gm+DM4uVlsff5XIgGE8a7gDV/Y3RaZQPmnuHM167UI+9YzrqzgA+Tc2ROSwjiurz
9CJMegj+9/W+IX5ym9sbhf/P
=r6Lw
-----END PGP SIGNATURE-----

Sławomir Paszkiewicz - poll devices with specified os with --os switch
ff89504
@paszczus
paszczus commented Oct 9, 2015

@f0o is it now ok?

Sławomir Paszkiewicz - poll devices with specified type with --type switch
457babd
@paszczus
paszczus commented Oct 9, 2015

@f0o i have added also type switch

@f0o
Member
f0o commented Oct 9, 2015

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

I'm currently only online via phone but saw that the input isn't escaped not the old switch is removed after adding the os and type switches.

We usually escape our parameters using a question-sign and appending the value to the sql-params array. I'm sure somebody on IRC can help you out there in the meantime :)

  • - f0o

On October 9, 2015 12:58:20 PM GMT+02:00, paszczus notifications@github.com wrote:

@f0o i have added also type switch


Reply to this email directly or view it on GitHub:
#2088 (comment)
-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQJPBAEBCgA5BQJWF5+wMhxEYW5pZWwgUHJldXNza2VyIChNb2JpbGVLZXkjMikg
PGYwb0BsaWJyZW5tcy5vcmc+AAoJEJMZKtVWOFzB39AP/30+YjITe2RkmmI4T5Yd
B3F8PSLyISpeyt8CHLQQuE7zbVSfuKLWC43uy8t6kgw8YaxPF5IzvlVCUGq7Xnkg
yT+CNCh8NW2nzE27m66Q3DwLVEC/5Tx4Q0aHw+l+KEHhV01CKiATikaBxSndsXy5
yZ2DeQYxPSCXvPY3SPzDy2KIYN6pUOVCMORDgEvAh/fr/yV8dSJRuYH58bdgcyfi
7tK0eWp4vlBfEHDbf4SRUZ30yoiXEWPmJ2Tj/dSuZYFzAAS8XnxgvcxmEybn5zXi
We1wcz/9uaeasRiWO11EFlzZ8lIU/Jvk/0vtpseudzqgT6KwFRmrvKiRoiEaFaab
PlHT6WS9FbWNzGnfoo6JLf9Lk5NGdB6mrIiG+Whv+/LMb5nUtwmCilIPzS/b+tQb
kKKQJaI4glWfz9g02cWKmVE3km9nyEbjDZgbHsIb1ryoEVReS6CVHuyCvaEKqwb2
KzTwH1y+6g6NNrI3d1JUp4GXWziG9jwko3kRDOarTW+7eqhrvhB3y4lNCiT8CuDX
x+8tPWla5Axkh/8M8dL/rROKBtB20FOvmbqLasGNs4UtnikFBX6ymR1Wod90ug1V
BRNSKCqXXN7X6koTkCnJAnTzapbY6V4eThyzreMs1nLekI0jaWp6k1B9dJs+egAH
HNg3vBtdCiu3G3Itu9+Ate2d
=/2nq
-----END PGP SIGNATURE-----

@paszczus
paszczus commented Oct 9, 2015

Ok so maybe we can discuss about that on IRC when you will be online, cause i don`t know what you want to me to do ;)

@f0o
Member
f0o commented Oct 9, 2015

No problem :)
I'll be around in maybe 2 hours

On October 9, 2015 1:13:48 PM GMT+02:00, paszczus notifications@github.com wrote:

Ok so maybe we can discuss about that on IRC when you will be online,
cause i don`t know what you want to me to do ;)


Reply to this email directly or view it on GitHub:
#2088 (comment)

@f0o
Member
f0o commented Oct 9, 2015

@paszczus I'll comment a patch in a bit, please apply it and commit it to this PR :)

@f0o
Member
f0o commented Oct 9, 2015
diff --git a/discovery.php b/discovery.php
index c1c4ef6..e29b4d6 100755
--- a/discovery.php
+++ b/discovery.php
@@ -22,8 +22,8 @@ require 'includes/discovery/functions.inc.php';

 $start         = utime();
 $runtime_stats = array();
-
-$options = getopt('h:m:i:n:d::a::q',['os:']);
+$sqlparams     = array();
+$options       = getopt('h:m:i:n:d::a::q',array('os:','type:'));

 if (!isset($options['q'])) {
     echo $config['project_name_version']." Discovery\n";
@@ -47,10 +47,6 @@ if (isset($options['h'])) {
         $where = 'AND `last_discovered` IS NULL';
         $doing = 'new';
     }
-    else if ($options['h'] == 'linux') {
-        $where = 'AND os = "linux"';
-        $doing = 'linux';
-    }
     else if ($options['h']) {
         if (is_numeric($options['h'])) {
             $where = "AND `device_id` = '".$options['h']."'";
@@ -64,17 +60,17 @@ if (isset($options['h'])) {
 }//end if

 if (isset($options['os'])) {
-        $where = $where." AND os = '".$options['os']."'";
-        $doing = $options['os'];
+        $where .= " AND os = ?";
+        $sqlparams[] = $options['os'];
 }

 if (isset($options['type'])) {
-        $where = $where." AND type = '".$options['type']."'";
-        $doing = $options['type'];
+        $where .= " AND type = ?";
+        $sqlparams[] = $options['type'];
 }

 if (isset($options['i']) && $options['i'] && isset($options['n'])) {
-    $where = 'AND MOD(device_id,'.$options['i'].") = '".$options['n']."'";
+    $where .= ' AND MOD(device_id,'.$options['i'].") = '".$options['n']."'";
     $doing = $options['n'].'/'.$options['i'];
 }

@@ -100,10 +96,10 @@ if (!$where) {
     echo "-h even                                      Poll even numbered devices (same as -i 2 -n 1)\n";
     echo "-h all                                       Poll all devices\n";
     echo "-h new                                       Poll all devices that have not had a discovery run before\n";
-    echo "-h [odd|even|new|all] --os <os_name>         Poll devices only with specified operating system\n";
-    echo "-h [odd|even|new|all] --type <type>          Poll devices only with specified type\n\n";
+    echo "--os <os_name>                               Poll devices only with specified operating system\n";
+    echo "--type <type>                                Poll devices only with specified type\n";
     echo "-i <instances> -n <number>                   Poll as instance <number> of <instances>\n";
-    echo "                                             Instances start at 0. 0-3 for -n 4\n\n";
+    echo "                                             Instances start at 0. 0-3 for -n 4\n";
     echo "\n";
     echo "Debugging and testing options:\n";
     echo "-d                                           Enable debugging output\n";
@@ -121,7 +117,7 @@ if ($config['distributed_poller'] === true) {
     $where .= ' AND poller_group IN('.$config['distributed_poller_group'].')';
 }

-foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC") as $device) {
+foreach (dbFetch("SELECT * FROM `devices` WHERE status = 1 AND disabled = 0 $where ORDER BY device_id DESC",$sqlparams) as $device) {
     discover_device($device, $options);
 }
Sławomir Paszkiewicz - applied changes made by f0o
462b41c
@paszczus
paszczus commented Oct 9, 2015

@f0o cool, thank you! applied and commited!

@f0o f0o merged commit e335024 into librenms:master Oct 9, 2015

2 checks passed

Auto-Deploy Build finished. No test results found.
Details
Scrutinizer No new issues
Details
@paszczus paszczus deleted the paszczus:discovery_linux_only branch Oct 9, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment