print_devices_oxi.pl 2.5 KB

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