Created
February 1, 2013 07:31
-
-
Save sergiopena/4689918 to your computer and use it in GitHub Desktop.
Check detail data against resources tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl -w | |
# | |
# | |
# | |
use strict; | |
use warnings; | |
use DBI; | |
use Getopt::Long; | |
use Data::Dumper; | |
use Switch; | |
# setup the default options | |
my $dbhost = 'localhost'; | |
my $dbport = 3306; | |
my $dbuser = 'root'; | |
my $dbpass = ''; | |
my $help; | |
my $date='2013-01-29 23:00:00'; | |
# database handlers | |
my $dsn; | |
my $dbh; | |
my $sth; | |
my $ref; | |
GetOptions( | |
'dbhost=s' => \$dbhost, | |
'dbport=i' => \$dbport, | |
'dbuser=s' => \$dbuser, | |
'dbpass=s' => \$dbpass, | |
'date=s' => \$date, | |
'help!' => \$help, | |
) or die "Incorrect ussage\n"; | |
if ($help) { | |
print 'Usage:'; | |
} | |
$dsn = "DBI:mysql:database=kinton:host=$dbhost:port=$dbport"; | |
$dbh = DBI->connect($dsn, $dbuser, $dbpass); | |
$sth = $dbh->prepare("SELECT *,UNIX_TIMESTAMP(startTime) as startTS FROM accounting_event_detail WHERE startTime >= '$date';"); | |
$sth->execute(); | |
my $events = $sth->fetchall_hashref('idAccountingEvent'); | |
$sth = $dbh->prepare("SELECT *,UNIX_TIMESTAMP(startTime) as startTS, UNIX_TIMESTAMP(stopTime) as stopTS FROM accounting_event_vm where startTime < '$date' and (stopTime > '$date' or stopTime is null);"); | |
$sth->execute(); | |
my $acc_vm = $sth->fetchall_hashref('idVM'); | |
# MEGALOOP!!! | |
foreach my $idEvent (keys %{$events}) | |
{ | |
switch ($events->{$idEvent}->{idAccountingResourceType}) | |
{ | |
case 1 { | |
if ( $acc_vm->{$events->{$idEvent}->{idVirtualMachine}} ) | |
{ | |
if ( $acc_vm->{$events->{$idEvent}->{idVirtualMachine}}->{cpu} != $events->{$idEvent}->{resourceUnits} ) | |
{ | |
print "idVM $events->{$idEvent}->{idVirtualMachine}\tFOUND\t$events->{$idEvent}->{resourceUnits}\tCPU EXPECTED\t$acc_vm->{$events->{$idEvent}->{idVirtualMachine}}->{cpu}\t$events->{$idEvent}->{startTime}\n"; | |
} | |
} | |
} | |
case 2 { | |
if ( $acc_vm->{$events->{$idEvent}->{idVirtualMachine}} ) | |
{ | |
if ( $acc_vm->{$events->{$idEvent}->{idVirtualMachine}}->{ram} != $events->{$idEvent}->{resourceUnits} ) | |
{ | |
print "idVM $events->{$idEvent}->{idVirtualMachine}\tFOUND\t$events->{$idEvent}->{resourceUnits}\tRAM EXPECTED\t$acc_vm->{$events->{$idEvent}->{idVirtualMachine}}->{ram}\t$events->{$idEvent}->{startTime}\n"; | |
} | |
} | |
} | |
case 3 { | |
if ( $acc_vm->{$events->{$idEvent}->{idVirtualMachine}} ) | |
{ | |
if ( $acc_vm->{$events->{$idEvent}->{idVirtualMachine}}->{hd} != $events->{$idEvent}->{resourceUnits} ) | |
{ | |
print "idVM $events->{$idEvent}->{idVirtualMachine}\tFOUND\t$events->{$idEvent}->{resourceUnits}\tvHD EXPECTED\t$acc_vm->{$events->{$idEvent}->{idVirtualMachine}}->{hd}\t$events->{$idEvent}->{startTime}\n"; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment