print_devices_oxi.pl 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #!/usr/bin/perl
  2. #
  3. # Copyright (C) Roman Dmitriev, rnd@rajven.ru
  4. #
  5. use utf8;
  6. use warnings;
  7. use Encode;
  8. use open qw(:std :encoding(UTF-8));
  9. no warnings 'utf8';
  10. use FindBin '$Bin';
  11. use lib "/opt/Eye/scripts";
  12. use strict;
  13. use DBI;
  14. use Data::Dumper;
  15. use Socket;
  16. use eyelib::config;
  17. use eyelib::main;
  18. use eyelib::database;
  19. use eyelib::common;
  20. my @router_list = get_records_sql($dbh, "
  21. SELECT
  22. D.*,
  23. DM.model_name,
  24. B.name AS building_name
  25. FROM devices D
  26. LEFT JOIN device_models DM ON D.device_model_id = DM.id
  27. LEFT JOIN building B ON D.building_id = B.id
  28. WHERE
  29. D.deleted = 0
  30. AND D.device_type <= 2
  31. AND D.protocol >= 0
  32. ORDER BY
  33. (building_name IS NULL),
  34. building_name,
  35. ip
  36. ");
  37. foreach my $device (@router_list) {
  38. next if (!$device->{password} or !$device->{login});
  39. next if (!$device->{ip});
  40. next if ($device->{protocol} eq '-1');
  41. $device = netdev_set_auth($device);
  42. my $oxi_model = 'dcnos';
  43. my $comware_cmdline = '';
  44. my $vendor = get_record_sql($dbh,"SELECT * FROM vendors WHERE id=?", $device->{vendor_id});
  45. my $model = get_record_sql($dbh,"SELECT * FROM device_models WHERE id=?", $device->{device_model_id});
  46. my $building = get_record_sql($dbh,"SELECT * FROM building WHERE id=?", $device->{building_id});
  47. if ($vendor->{name} =~/zyxel/i) { $oxi_model = 'zynoscli'; }
  48. if ($vendor->{name} =~/snr/i) { $oxi_model = 'dcnos'; }
  49. if ($vendor->{name} =~/huawei/i) { $oxi_model = 'vrp'; }
  50. if ($vendor->{name} =~/eltex/i) { $oxi_model = 'eltex'; }
  51. if ($vendor->{name} =~/raisecom/i) { $oxi_model = 'raisecom'; }
  52. if ($vendor->{name} =~/mikrotik/i) { $oxi_model = 'routeros'; }
  53. if ($vendor->{name} =~/maipu/i) { $oxi_model = 'maipu'; }
  54. if ($vendor->{name} =~/d[\-*]link/i) { $oxi_model = 'dlink'; }
  55. if ($vendor->{name} =~/tp[\-*]link/i) { $oxi_model = 'tplink'; }
  56. if ($vendor->{name} =~/hp/i) { $oxi_model = 'comwarehpe'; $comware_cmdline = '512900'; }
  57. if ($vendor->{name} =~/NetGear/i) { $oxi_model = 'netgear'; }
  58. if ($vendor->{name} =~/Allied Telesis/i) { $oxi_model = 'awplus'; }
  59. if ($oxi_model =~/awplus/ and $model->{model_name}=~/AT\-8000/i) { $oxi_model = 'powerconnect'; }
  60. #web-smart
  61. if ($oxi_model =~/awplus/ and $model->{model_name}=~/AT\-GS950/i) { next; }
  62. if ($oxi_model =~/netgear/ and $model->{model_name}=~/GS110TP/i) { next; }
  63. my $proto = 'telnet';
  64. if ($device->{protocol} eq '0') { $proto = 'ssh'; }
  65. my $location = $building->{name};
  66. my $enable_password = '';
  67. if ($oxi_model !~ /(routeros|awplus)/i) { $enable_password = $device->{password}; }
  68. print $device->{device_name}.":".$device->{ip}.":".$device->{login}.":".$device->{password}.":".$oxi_model.":".$device->{control_port}.":".$proto.":".$location.":".$enable_password;
  69. print ":$comware_cmdline\n";
  70. }
  71. $dbh->disconnect;
  72. exit 0;