Subversion Repositories camp_sysinfo_client_3

Rev

Rev 237 | Go to most recent revision | Details | Compare with Previous | 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
 
37 rodolico 5
# Description: Processes Xen Clients
25 rodolico 6
 
37 rodolico 7
our $VERSION = '1.1';
8
 
25 rodolico 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 $xl = &validCommandOnSystem( 'xl' );
41
exit 1 unless $xl;
42
$xl .= ' 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/^Name/;
49
   return ( 'baddomu') unless $lines[1] =~ m/^Domain-0/;
50
   for ( my $i = 2; $i < @lines; $i++ ) {
51
      my ( $name,$id,$mem,$vcpu,$state,$time) = split( /\s+/, $lines[$i] );
52
      $domu{$name}{'id'} = $id;
53
      $domu{$name}{'memory'} = $mem;
54
      $domu{$name}{'numcpu'} = $vcpu;
55
   }
56
   return \%domu;
57
}
58
 
59
my $output = `$xl`;
60
my $hier = &parseOutput( $output );
61
 
62
foreach my $domu ( sort keys %$hier ) {
63
   my $temp = $$hier{$domu};
64
   foreach my $key ( sort keys %$temp ) {
65
      print "$CATEGORY\tvirtual\t$domu\t$key\t$$temp{$key}\n";
66
   }
67
} # foreach
68
 
69
# if you have not done an exit state above (1 indicating no data), do one
70
# here (exit 0 indicates success)
71
# NOTE: you can bail early with exit 1 if you can not process anything
72
# because it is the wrong system or something
73
exit 0;