Subversion Repositories camp_sysinfo_client_3

Rev

Rev 201 | Blame | Last modification | View Log | Download | RSS feed

#!/usr/bin/env perl
use warnings;
use strict;

# Description: Processes Xen Clients

our $VERSION = '1.1';

# Looks at various Xen parameters, mainly which DOMU's are running on it
# Written by RWR, 20160911

BEGIN {
   push @INC, shift;
}

use library;

# category we will use for all values found
# see sysinfo for a list of valid categories
my $CATEGORY = 'xen';

# run the commands necessary to do whatever you want to do
# The library entered above has some helper routines
# validCommandOnSystem -- passed a name, returns the fully qualified path or
# '' if it does not exist
# cleanUp - passed a delimiter and a string, does the following (delimiter
# can be '')
#           chomps the string (removes trailing newlines)
#           removes all text BEFORE the delimiter, the delimiter, and any
# whitespace
#           thus, the string 'xxI Am x  a weird string' with a newline will
# become
#           'a weird string' with no newline

# now, return the tab delimited output (to STDOUT). $CATEGORY is the first
# item, name as recognized by sysinfo is the second and the value is
# the last one. For multiple entries, place on separate lines (ie, newline
# separated)

my $xl = &validCommandOnSystem( 'xl' );
exit 1 unless $xl;
$xl .= ' list';

sub parseOutput {
   my $output = shift;
   my @lines = split( "\n", $output );
   my %domu;
   return ( 'noname' ) unless $lines[0] =~ m/^Name/;
   return ( 'baddomu') unless $lines[1] =~ m/^Domain-0/;
   for ( my $i = 2; $i < @lines; $i++ ) {
      my ( $name,$id,$mem,$vcpu,$state,$time) = split( /\s+/, $lines[$i] );
      $domu{$name}{'id'} = $id;
      $domu{$name}{'memory'} = $mem;
      $domu{$name}{'numcpu'} = $vcpu;
   }
   return \%domu;
}

my $output = `$xl`;
my $hier = &parseOutput( $output );

foreach my $domu ( sort keys %$hier ) {
   my $temp = $$hier{$domu};
   foreach my $key ( sort keys %$temp ) {
      print "$CATEGORY\tvirtual\t$domu\t$key\t$$temp{$key}\n";
   }
} # foreach

# if you have not done an exit state above (1 indicating no data), do one
# here (exit 0 indicates success)
# NOTE: you can bail early with exit 1 if you can not process anything
# because it is the wrong system or something
exit 0;