Subversion Repositories camp_sysinfo_client_3

Rev

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

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