-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhosts.pl
More file actions
70 lines (53 loc) · 1.38 KB
/
hosts.pl
File metadata and controls
70 lines (53 loc) · 1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/perl
use Frontier::Client;
use Data::Dumper;
use REST::Client;
use JSON;
use MIME::Base64;
$ENV{HTTPS_CA_FILE} = "/data/scripts/sat6/katello-server-ca.crt";
=pod
print "Enter server: ";
chomp($host = <STDIN>);
print "Enter user: ";
chomp($user = <STDIN>);
system('stty -echo');
print "Enter Password: ";
chomp($pass = <STDIN>);
system('stty echo');
print "\n";
=cut
my $host = "satellite.redhat.com";
my $user = "admin";
my $pass = "xxxxxx";
my $ua = LWP::UserAgent->new();
$ua->agent('Mozilla');
my $fullserver = "https://" . $host;
my $client = REST::Client->new(host => $fullserver);
$client->addHeader('Content-Type', 'application/json');
$client->addHeader('charset', 'UTF-8');
$client->addHeader('Accept', 'application/json');
my $session = encode_base64("$user:$pass", '');
$client->GET('/api/hosts', {'Authorization' => "Basic $session", 'Accept' => 'application/json'});
#print "Response code: " . $client->responseCode() . "\n";
#print "Response: " . $client->responseContent() . "\n";
my $values = $client->responseContent();
print $values;
=podfor (@{$values})
{
print "x\n";
print $_->{'ip'} . "\n";
}
=pod
$client->setHost($fullserver);
$client->GET('/api/hosts', $headers);
if ($client->responseCode() eq '200')
{
print "got /api/hosts\n";
}
else
{
print "failed\n";
}
#my $response = from_json($client->responseContent());
#print Dumper($response);
=cut