print_devices_oxi.pl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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::logconfig;
  19. use eyelib::database;
  20. use eyelib::common;
  21. my @router_list = get_records_sql($dbh, "
  22. SELECT
  23. D.*,
  24. DM.model_name,
  25. B.name AS building_name
  26. FROM devices D
  27. LEFT JOIN device_models DM ON D.device_model_id = DM.id
  28. LEFT JOIN building B ON D.building_id = B.id
  29. WHERE
  30. D.deleted = 0
  31. AND D.device_type <= 2
  32. AND D.protocol >= 0
  33. ORDER BY
  34. (building_name IS NULL),
  35. building_name,
  36. ip
  37. ");
  38. foreach my $device (@router_list) {
  39. next if (!$device->{password} or !$device->{login});
  40. next if (!$device->{ip});
  41. next if ($device->{protocol} eq '-1');
  42. $device = netdev_set_auth($device);
  43. my $oxi_model = 'dcnos';
  44. my $comware_cmdline = '';
  45. my $vendor = get_record_sql($dbh,"SELECT * FROM vendors WHERE id=?", $device->{vendor_id});
  46. my $model = get_record_sql($dbh,"SELECT * FROM device_models WHERE id=?", $device->{device_model_id});
  47. my $building = get_record_sql($dbh,"SELECT * FROM building WHERE id=?", $device->{building_id});
  48. if ($vendor->{name} =~/zyxel/i) { $oxi_model = 'zynoscli'; }
  49. if ($vendor->{name} =~/snr/i) { $oxi_model = 'dcnos'; }
  50. if ($vendor->{name} =~/huawei/i) { $oxi_model = 'vrp'; }
  51. if ($vendor->{name} =~/eltex/i) { $oxi_model = 'eltex'; }
  52. if ($vendor->{name} =~/raisecom/i) { $oxi_model = 'raisecom'; }
  53. if ($vendor->{name} =~/mikrotik/i) { $oxi_model = 'routeros'; }
  54. if ($vendor->{name} =~/maipu/i) { $oxi_model = 'maipu'; }
  55. if ($vendor->{name} =~/d[\-*]link/i) { $oxi_model = 'dlink'; }
  56. if ($vendor->{name} =~/tp[\-*]link/i) { $oxi_model = 'tplink'; }
  57. if ($vendor->{name} =~/hp/i) { $oxi_model = 'comwarehpe'; $comware_cmdline = '512900'; }
  58. if ($vendor->{name} =~/NetGear/i) { $oxi_model = 'netgear'; }
  59. if ($vendor->{name} =~/Allied Telesis/i) { $oxi_model = 'awplus'; }
  60. if ($oxi_model =~/awplus/ and $model->{model_name}=~/AT\-8000/i) { $oxi_model = 'powerconnect'; }
  61. #web-smart
  62. if ($oxi_model =~/awplus/ and $model->{model_name}=~/AT\-GS950/i) { next; }
  63. if ($oxi_model =~/netgear/ and $model->{model_name}=~/GS110TP/i) { next; }
  64. my $proto = 'telnet';
  65. if ($device->{protocol} eq '0') { $proto = 'ssh'; }
  66. my $location = $building->{name};
  67. my $enable_password = '';
  68. if ($oxi_model !~ /(routeros|awplus)/i) { $enable_password = $device->{password}; }
  69. print $device->{device_name}.":".$device->{ip}.":".$device->{login}.":".$device->{password}.":".$oxi_model.":".$device->{control_port}.":".$proto.":".$location.":".$enable_password;
  70. print ":$comware_cmdline\n";
  71. }
  72. $dbh->disconnect;
  73. exit 0;