-
Notifications
You must be signed in to change notification settings - Fork 4
/
vzdiscover.pl
38 lines (28 loc) · 872 Bytes
/
vzdiscover.pl
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
#!/usr/bin/perl
use strict;
my $first = 1;
print "{\n";
print "\t\"data\":[\n\n";
my $VEname = `hostname`;
#cut end string
$VEname = substr($VEname, 0, -1);
my $vzresult = `/usr/sbin/vzlist -a -o veid,hostname,status,laverage -H 2>/dev/null`;
my @lines = split /\n/, $vzresult;
foreach my $l (@lines) {
if ($l =~ /^(\s*?)(\d+) (.*?)(\s+)(\S+)/)
{
my $id = $2;
my $hostname = $3;
my $status = $5;
print ",\n" if not $first;
$first = 0;
print "\t{\n";
print "\t\t\"{#CTID}\":\"$id\",\n";
print "\t\t\"{#CTHOST}\":\"$hostname\",\n";
print "\t\t\"{#CTSTATUS}\":\"$status\",\n";
print "\t\t\"{#VENAME}\":\"$VEname\"\n";
print "\t}";
}
}
print "\n\t]\n";
print "}\n";