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/nodes.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
66 lines (54 sloc)
2.21 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; | |
my $datestamp = strftime("%m%d%y", localtime); | |
my $epoch = time; | |
open (my $MYFILE, ">", "$datestamp-IAM-NS-Nodes.csv"); | |
open (my $TMPFILE, ">", "TMPFILE"); | |
open (my $TMPHEADERS, ">", "TMPHEADERS"); | |
my $node_url = 'https://db2.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 = Internet2 TR-CPS | |
# Node_role_id 15=oob 16=lan 28=rtr 284=dcn-sw 412=sdn-sw 472=rtsw 1135=vs-sw | |
my $node_result = $node_client->get_nodes(name_logic => 'AND', network_id => ['24','14'], node_role_id => ['15', '16', '28','284','412','472','1135'], status => "active", order_by => 'node_role_id' ); | |
_check_client_results($node_result, $node_client); | |
my $I2_NODES = $node_result->{'results'}; | |
foreach my $mynodes (@$I2_NODES) { | |
print $TMPFILE $mynodes->{'name'} // "none",","; | |
print $TMPFILE $mynodes->{'management_address'} // "none",","; | |
my $hname = $mynodes->{'name'}; | |
$hname =~ s/.internet2.edu//; | |
print $TMPFILE $hname,","; | |
print $TMPFILE $mynodes->{'radius_profile_name'} // "none",","; | |
print $TMPFILE $mynodes->{'radius_key'} // "none",","; | |
print $TMPFILE $mynodes->{'status'} // "none","\n"; | |
} | |
print $TMPFILE "\n"; | |
my $cmd1 = ('cat TMPHEADERS'); | |
my $cmd2 = ('cat TMPFILE'); | |
system "${cmd1} > tmp.txt && ${cmd2} >> tmp.txt"; | |
system "mv tmp.txt `date +%m%d%y`-IAM-NS-Nodes.csv"; | |
close $TMPFILE; | |
close $TMPHEADERS; | |
system "rm -f TMPFILE > /dev/null 2>&1"; | |
system "rm -f TMPHEADERS > /dev/null 2>&1"; | |
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; | |
} |