Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
NOCdb/interface.pl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
executable file
114 lines (91 sloc)
4.73 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
# | |
# | |
use strict; | |
use warnings; | |
use POSIX qw( strftime ); | |
# | |
use GRNOC::CLI; | |
use GRNOC::WebService::Client; | |
use RRD::Simple; | |
my $datestamp = strftime("%m%d%y", localtime); | |
my $epoch = time; | |
open (my $MYFILE, ">", "$datestamp-NS-Metrics.txt"); | |
open (my $TMPFILE, ">", "TMPFILE"); | |
open (my $TMPHEADERS, ">", "TMPHEADERS"); | |
my $node_url = 'https://db2-stage.grnoc.iu.edu/cds2/node.cgi'; | |
my $cli = GRNOC::CLI->new(); | |
my $user = $cli->get_input("Username: "); | |
my $pass = $cli->get_password("Password: "); | |
my $node_client = GRNOC::WebService::Client->new(uid => $user, | |
passwd => $pass, | |
url => $node_url); | |
# Network ID 14 = I2, Network ID 24 = TR-CPS | |
# Node role 28=rtr 412=sdn-sw 207=TR-CPS Router | |
my $router_result = $node_client->get_nodes(name_logic => 'AND', network_id => ['24','14'], node_role_id => ['28','412','207'], status => "active", order_by => 'pop_code' ); | |
_check_client_results($router_result, $node_client); | |
my $I2_RTRs = $router_result->{'results'}; | |
my $sumL3_10gig = 0; | |
my @aggL3_10gig = (); | |
foreach my $node (@$I2_RTRs) { | |
# Need the name logic set in the next line so we get everything BUT those interface names | |
my $node_id = $node->{'node_id'}; | |
my $ten_gig_interfaces_result = $node_client->get_interfaces(name_logic => 'AND', description_logic => 'AND', node_id => $node_id, admin_state_not_like => 'decom', parent_interface_id => '', name_not_like => ['fxp','gr','ip','lt'], name_logic => 'AND', description_not_like => ['available', 'reserved', 'constituent', 'BACKBONE', 'pas-tst','rtr','sw','sdn','lan','HP'], interface_type_id => '109'); | |
my $ten_gig_interfaces = $ten_gig_interfaces_result->{'results'}; | |
my $total1 = @$ten_gig_interfaces; | |
push @aggL3_10gig, $total1; | |
my $total2 = $ten_gig_interfaces_result->{'total'}; | |
print $TMPFILE $node->{'pop_code'} . " Total 10gig Interfaces:\t" . $total1 . "\n"; | |
foreach my $interface (@$ten_gig_interfaces) { | |
print $TMPFILE $interface->{'name'} // "none","\t"; | |
print $TMPFILE $interface->{'description'} // "none","\t"; | |
print $TMPFILE $interface->{'admin_state'} // "none","\n"; | |
} | |
print $TMPFILE "\n"; | |
} | |
$sumL3_10gig = eval join '+', @aggL3_10gig; | |
my $sumL3_100gig = 0; | |
my @aggL3_100gig = (); | |
foreach my $node (@$I2_RTRs) { | |
# Need the name logic set in the next line so we get everything BUT those interface names | |
my $node_id = $node->{'node_id'}; | |
my $hundred_gig_interfaces_result = $node_client->get_interfaces(name_logic => 'AND', description_logic => 'AND', node_id => $node_id, admin_state_not_like => 'decom', parent_interface_id => '', name_not_like => ['fxp','gr','ip'], name_logic => 'AND', description_not_like => ['available', 'reserved', 'constituent', 'BACKBONE','pas-tst','rtr','sw','sdn','lan','HP'], interface_type_id => '345261'); | |
my $hundred_gig_interfaces = $hundred_gig_interfaces_result->{'results'}; | |
my $total1 = @$hundred_gig_interfaces; | |
push @aggL3_100gig, $total1; | |
my $total2 = $hundred_gig_interfaces_result->{'total'}; | |
print $TMPFILE $node->{'pop_code'} . " Total 100gig Interfaces:\t" . $total1 . "\n"; | |
foreach my $interface (@$hundred_gig_interfaces) { | |
print $TMPFILE $interface->{'name'} // "none","\t"; | |
print $TMPFILE $interface->{'description'} // "none","\t"; | |
print $TMPFILE $interface->{'admin_state'} // "none","\n"; | |
} | |
print $TMPFILE "\n"; | |
} | |
$sumL3_100gig = eval join '+', @aggL3_100gig; | |
print $TMPHEADERS "***Aggregate Total 10gig Interfaces:\t$sumL3_10gig\n"; | |
print $TMPHEADERS "***Aggregate Total 100gig Interfaces:\t$sumL3_100gig\n\n"; | |
#my $MYFILE = "$datestamp-NS-Metrics.txt"; | |
#open (MYFILE, ">", "$datestamp-NS-Metrics.txt"); | |
my $cmd1 = ('cat TMPHEADERS'); | |
my $cmd2 = ('cat TMPFILE'); | |
system "${cmd1} > tmp.txt && ${cmd2} >> tmp.txt"; | |
system "mv tmp.txt `date +%m%d%y`-NS-Metrics.txt"; | |
close $TMPFILE; | |
close $TMPHEADERS; | |
system "rm -f TMPFILE > /dev/null 2>&1"; | |
system "rm -f TMPHEADERS > /dev/null 2>&1"; | |
#system ("echo '****Aggregate Total 10gig Interfaces: $sumL3_10gig ****' > temp-headers.txt"); | |
#system ("echo '****Aggregate Total 100gig Interfaces: $sumL3_100gig ****' >> temp-headers.txt"); | |
#my $cmd = "cat TMPHEADERS > $MYFILE"; | |
sub _check_client_results { | |
my $result = shift; | |
my $client = shift; | |
if (! defined $result){ | |
die "Error getting result - " . $client->get_error(); | |
} | |
if ($result->{'error'}){ | |
die "Error in result - " . $result->{'error_text'}; | |
} | |
return 1; | |
} |