SHARE
TWEET

Untitled

a guest Oct 3rd, 2017 73 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use DBI;
  5. #use SNMP_util;
  6. #use Net::Netmask;
  7. #use POSIX qw(strftime);
  8.  
  9.  
  10. # Database parameters
  11. my $dbh;
  12. my $select;
  13. my $db_name = "DCVBase";
  14. my $db_host=`host master.cluster.dcv asu-main.dcv | grep "has address" | cut -d " " -f 4`;
  15. chomp($db_host);
  16. my $db_user = "";
  17. my $db_pass = '';
  18.  
  19. my $check_time = strftime("%M", localtime(time));
  20.  
  21. ### main ###
  22. &get_values();
  23. #&check_values();
  24. #&make_config();
  25. #&upload_config();
  26.  
  27. ### routines ###
  28.  
  29. sub get_values
  30. {
  31.         $dbh = DBI->connect("dbi:mysql:database=$db_name;host=$db_host", $db_user, $db_pass)  || die "Can't connect to mysql database!";
  32.  
  33.         # Select the main attributes of connection
  34.         $select = $dbh->prepare("SELECT NetworkConections.IDOfUnit, NetworkConections.MacAdress, NetworkConections.IDOfSwitch, NetworkConections.SwitchPort, NetworkConections.NumOfVLAN FROM NetworkConections WHERE NetworkConections.ID='$connection_id';");
  35.         $select->execute() || die "Can't select from $db_name!";;
  36.         ($unit_id, $mac, $switch_id, $switch_port, $vlan) = $select->fetchrow_array;
  37.         $select->finish();
  38.  
  39.         # Select a server name for port description
  40.         $select = $dbh->prepare("SELECT Name, User from Units where ID = '$unit_id';");
  41.         $select->execute() || die "Can't select from $db_name!";;
  42.         ($unit_name, $login)  = $select->fetchrow;
  43.         $select->finish();
  44.         $description = "$login\:$unit_name\-$connection_id";
  45.  
  46.  
  47.         # Select a switch_name
  48.         $select = $dbh->prepare("SELECT Name from Units where ID = '$switch_id';");
  49.  
  50.         $select->execute() || die "Can't select from $db_name!";;
  51.         $switch_name = $select->fetchrow;
  52.         $select->finish();
  53.  
  54.         # Select attributes of network
  55.         $select = $dbh->prepare("SELECT SubNets.Type, SubNets.SubNetAdress, SubNets.Mask FROM NetworkConections, UsedSubNets, SubNets WHERE UsedSubNets.IDOfNetworkConnection = NetworkConections.ID AND UsedSubNets.IDOfSubnet = SubNets.ID AND NetworkConections.ID = '$connection_id';");
  56.         $select->execute() || die "Can't select from $db_name!";;
  57.         ($net_type, $net_addr, $net_mask) = $select->fetchrow_array;
  58.         $select->finish();
  59.  
  60.         # Select ip addreses of connection
  61.         $select = $dbh->prepare("SELECT IP from IPAdresses where IDOfNetworkConection = '$connection_id';");
  62.         $select->execute() || die "Can't select from $db_name!";;
  63.         while ((my $temp) = $select->fetchrow_array)
  64.                 {
  65.                         push (@ip_address, "$temp");
  66.                 }
  67.         $select->finish();
  68.  
  69.         $dbh->disconnect();
  70. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top