Subversion Repositories camp_sysinfo_client_3

Rev

Rev 189 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 189 Rev 190
Line 1... Line 1...
1
#!/usr/bin/env perl
1
#!/usr/bin/env perl
2
use warnings;
2
use warnings;
3
use strict;
3
use strict;
4
 
4
 
5
# Description: Processes Xen Clients
5
# Description: Processes libvirt Clients
6
 
6
 
7
our $VERSION = '1.0';
7
our $VERSION = '1.0';
8
 
8
 
9
# Looks at various Xen parameters, mainly which DOMU's are running on it
9
# Looks at various libvirt information about running virtuals
10
# Written by RWR, 20160911
10
# Written by RWR and BNR, 20210228
11
 
11
 
12
BEGIN {
12
BEGIN {
13
   push @INC, shift;
13
   push @INC, shift;
14
}
14
}
15
 
15
 
Line 35... Line 35...
35
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
35
# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
36
# item, name as recognized by sysinfo is the second and the value is
36
# item, name as recognized by sysinfo is the second and the value is
37
# the last one. For multiple entries, place on separate lines (ie, newline
37
# the last one. For multiple entries, place on separate lines (ie, newline
38
# separated)
38
# separated)
39
 
39
 
40
my $virsh = &validCommandOnSystem( 'virsh' );
40
my $xl = &validCommandOnSystem( 'virsh' );
-
 
41
# print "My command is $xl\n";
41
exit 1 unless $virsh;
42
exit 1 unless $xl;
42
$virsh .= ' list';
43
$xl .= ' list';
-
 
44
# print "My command is $xl\n";
-
 
45
# die;
43
 
46
 
44
sub parseOutput {
47
sub parseOutput {
45
   my $output = shift;
48
   my $output = shift;
46
   my @lines = split( "\n", $output );
49
   my @lines = split( "\n", $output );
47
   my %domu;
50
   my %domu;
48
   return ( 'noname' ) unless $lines[0] =~ m/^\s*Id/;
51
   return ( 'noname' ) unless $lines[0] =~ m/^\s*id\s+name\s+state\s*$/i;
49
   return ( 'baddomu') unless $lines[1] =~ m/^-----/;
-
 
50
   for ( my $i = 2; $i < @lines; $i++ ) {
52
   for ( my $i = 2; $i < @lines; $i++ ) {
51
      my ( $dummy,$id,$name,$state,$title) = split( /\s+/, $lines[$i] );
53
#      print "Working on $i, value is {$lines[$i]}\n";
52
      $domu{$title}{'id'} = $id;
54
      $lines[$i] =~ s/^\s*//;
-
 
55
#      print "After cleanup, value is {$lines[$i]}\n";
-
 
56
      my ( $id,$name ) = split( /\s+/, $lines[$i] );
53
      $domu{$title}{'name'} = $name;
57
      $domu{$name}{'id'} = $id;
54
   }
58
   }
55
   return \%domu;
59
   return \%domu;
56
}
60
}
57
 
61
 
58
my $output = `$virsh --title`;
62
my $output = `$xl`;
-
 
63
 
-
 
64
#print $output;
-
 
65
#die;
-
 
66
 
59
my $hier = &parseOutput( $output );
67
my $hier = &parseOutput( $output );
60
 
68
 
-
 
69
#die;
-
 
70
 
61
foreach my $domu ( sort keys %$hier ) {
71
foreach my $domu ( sort keys %$hier ) {
62
   my $temp = $$hier{$domu};
72
   my $temp = $$hier{$domu};
63
   foreach my $key ( sort keys %$temp ) {
73
   foreach my $key ( sort keys %$temp ) {
64
      print "$CATEGORY\tvirtual\t$domu\t$key\t$$temp{$key}\n";
74
      print "$CATEGORY\tvirtual\t$domu\t$key\t$$temp{$key}\n";
65
   }
75
   }