Subversion Repositories camp_sysinfo_client_3

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
189 rodolico 1
#!/usr/bin/env perl
2
use warnings;
3
use strict;
4
 
5
# Description: Processes Xen Clients
6
 
7
our $VERSION = '1.0';
8
 
9
# Looks at various Xen parameters, mainly which DOMU's are running on it
10
# Written by RWR, 20160911
11
 
12
BEGIN {
13
   push @INC, shift;
14
}
15
 
16
use library;
17
 
18
# category we will use for all values found
19
# see sysinfo for a list of valid categories
20
my $CATEGORY = 'xen';
21
 
22
# run the commands necessary to do whatever you want to do
23
# The library entered above has some helper routines
24
# validCommandOnSystem -- passed a name, returns the fully qualified path or
25
# '' if it does not exist
26
# cleanUp - passed a delimiter and a string, does the following (delimiter
27
# can be '')
28
#           chomps the string (removes trailing newlines)
29
#           removes all text BEFORE the delimiter, the delimiter, and any
30
# whitespace
31
#           thus, the string 'xxI Am x  a weird string' with a newline will
32
# become
33
#           'a weird string' with no newline
34
 
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
37
# the last one. For multiple entries, place on separate lines (ie, newline
38
# separated)
39
 
40
my $virsh = &validCommandOnSystem( 'virsh' );
41
exit 1 unless $virsh;
42
$virsh .= ' list';
43
 
44
sub parseOutput {
45
   my $output = shift;
46
   my @lines = split( "\n", $output );
47
   my %domu;
48
   return ( 'noname' ) unless $lines[0] =~ m/^\s*Id/;
49
   return ( 'baddomu') unless $lines[1] =~ m/^-----/;
50
   for ( my $i = 2; $i < @lines; $i++ ) {
51
      my ( $dummy,$id,$name,$state,$title) = split( /\s+/, $lines[$i] );
52
      $domu{$title}{'id'} = $id;
53
      $domu{$title}{'name'} = $name;
54
   }
55
   return \%domu;
56
}
57
 
58
my $output = `$virsh --title`;
59
my $hier = &parseOutput( $output );
60
 
61
foreach my $domu ( sort keys %$hier ) {
62
   my $temp = $$hier{$domu};
63
   foreach my $key ( sort keys %$temp ) {
64
      print "$CATEGORY\tvirtual\t$domu\t$key\t$$temp{$key}\n";
65
   }
66
} # foreach
67
 
68
# if you have not done an exit state above (1 indicating no data), do one
69
# here (exit 0 indicates success)
70
# NOTE: you can bail early with exit 1 if you can not process anything
71
# because it is the wrong system or something
72
exit 0;