Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/perl
- use strict;
- use DBI;
- #use SNMP_util;
- #use Net::Netmask;
- #use POSIX qw(strftime);
- # Database parameters
- my $dbh;
- my $select;
- my $db_name = "DCVBase";
- my $db_host=`host master.cluster.dcv asu-main.dcv | grep "has address" | cut -d " " -f 4`;
- chomp($db_host);
- my $db_user = "";
- my $db_pass = '';
- my $check_time = strftime("%M", localtime(time));
- ### main ###
- &get_values();
- #&check_values();
- #&make_config();
- #&upload_config();
- ### routines ###
- sub get_values
- {
- $dbh = DBI->connect("dbi:mysql:database=$db_name;host=$db_host", $db_user, $db_pass) || die "Can't connect to mysql database!";
- # Select the main attributes of connection
- $select = $dbh->prepare("SELECT NetworkConections.IDOfUnit, NetworkConections.MacAdress, NetworkConections.IDOfSwitch, NetworkConections.SwitchPort, NetworkConections.NumOfVLAN FROM NetworkConections WHERE NetworkConections.ID='$connection_id';");
- $select->execute() || die "Can't select from $db_name!";;
- ($unit_id, $mac, $switch_id, $switch_port, $vlan) = $select->fetchrow_array;
- $select->finish();
- # Select a server name for port description
- $select = $dbh->prepare("SELECT Name, User from Units where ID = '$unit_id';");
- $select->execute() || die "Can't select from $db_name!";;
- ($unit_name, $login) = $select->fetchrow;
- $select->finish();
- $description = "$login\:$unit_name\-$connection_id";
- # Select a switch_name
- $select = $dbh->prepare("SELECT Name from Units where ID = '$switch_id';");
- $select->execute() || die "Can't select from $db_name!";;
- $switch_name = $select->fetchrow;
- $select->finish();
- # Select attributes of network
- $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';");
- $select->execute() || die "Can't select from $db_name!";;
- ($net_type, $net_addr, $net_mask) = $select->fetchrow_array;
- $select->finish();
- # Select ip addreses of connection
- $select = $dbh->prepare("SELECT IP from IPAdresses where IDOfNetworkConection = '$connection_id';");
- $select->execute() || die "Can't select from $db_name!";;
- while ((my $temp) = $select->fetchrow_array)
- {
- push (@ip_address, "$temp");
- }
- $select->finish();
- $dbh->disconnect();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement