Active IQ Unified Manager Discussions

from wfa command Data not writting to .CSV file

Aswani_Kumar
2,745 Views

I am trying to create a command in perl that retrives volumes details and ouputs to a file (.CSV)

 

 

use strict;
use Getopt::Long;
use WFAUtil;

my $FileName;
my $FileNamePrefix = 'c:/vol_report';

#Creating CSV file name
$FileName = $FileNamePrefix.".csv";

my $wfa_util = WFAUtil->new();
$wfa_util->sendLog('INFO', 'Creating CSV file: ' . $FileName);

my $query="SELECT
    aggr.name AS aggr_name,
    (((aggr.used_size_mb )/ aggr.size_mb) * 100) AS aggr_used_percentage,
    ((aggr.available_size_mb/aggr.size_mb)*100) AS aggr_Available_Percentage,
    aggr.available_size_mb AS aggr_available_size_mb,
    vol.name AS 'name',
    (((vol.used_size_mb )/ vol.size_mb) * 100) AS vol_used_percentage,
    vol.available_size_mb,
    ((( vol.available_size_mb)/vol.size_mb)*100) AS vol_avilable_percentage,
    cluster.primary_address as 'vserver.cluster.primary_address',
    vserver.name as 'vserver.name'
FROM
    cm_storage.cluster AS cluster,
    cm_storage.vserver AS vserver,
    cm_storage.aggregate AS aggr
JOIN
    cm_storage.volume AS vol
        ON aggr.id = vol.aggregate_id
WHERE
    (
        (
            vol.used_size_mb
        ) / vol.size_mb
    ) * 100 >= 40
    AND (
        (
            aggr.used_size_mb
        ) / aggr.size_mb
    ) * 100 >= 30
group by
    vol.name,
    aggr.name";
my $database="cm_storage";
my @data;
my $length;

eval {
@data = $wfa_util->invokeMySqlQuery($query,$database);

};

$length = @data;

open(FILE, ">$FileName");
print FILE "aggr_name,aggr_used_percentage,name,vol_avilable_percentage,vol.available_size_mb,vserver.cluster.primary_address,vserver.name";
for (my $index =0; $index < $length; $index++)
{
if ($data[$index] ne "\n")
{
if ($data[$index] eq "")
{
print FILE "-,";
}
else {
print FILE "$data[$index]" . ",";
}
}
else
{
print FILE $data[$index];
}
}
close(FILE);

 

file is creating but data was not getting written into it.

6 REPLIES 6

abhit
2,738 Views

I am able to print with the same code below.

Are you not able to see this line in the file: "aggr_name,aggr_used_percentage,name,vol_avilable_percentage,vol.available_size_mb,vserver.cluster.primary_address,vserver.name"?

If you are able to see the above line and not anything else, it might be that the query is not returning any results.

 

Regards

Abhi

 

Aswani_Kumar
2,732 Views

Yes i can see that line.

I think the query is working and i tested the query by creating the filter.

 

And how to chek the data is coming to "@data array" from query.

 

trentino123
2,696 Views

Simplified the query to test it and it worked, the rest of the code seems to be fine,  saved the aggregate names , could the problem be in the query ?. 

 

#!/usr/bin/perl

 

use strict;
use Getopt::Long;
use WFAUtil;

my $FileName;
my $FileNamePrefix = 'c:/temp/vol_report';

#Creating CSV file name
$FileName = $FileNamePrefix.".csv";

my $wfa_util = WFAUtil->new();
$wfa_util->sendLog('INFO', 'Creating CSV file: ' . $FileName);

my $query="SELECT name from cm_storage.aggregate";
my $database="cm_storage";
my @data;
my $length;

eval {
@data = $wfa_util->invokeMySqlQuery($query,$database);

};

$length = @data;

open(FILE, ">$FileName");
print FILE "aggr_name,aggr_used_percentage,name,vol_avilable_percentage,vol.available_size_mb,vserver.cluster.primary_address,vserver.name";
for (my $index =0; $index < $length; $index++)
{
if ($data[$index] ne "\n")
{
if ($data[$index] eq "")
{
print FILE "-,";
}
else {
print FILE "$data[$index]" . ",";
}
}
else
{
print FILE $data[$index];
}
}
close(FILE);

trentino123
2,695 Views

tested if fully and it worked for me.

 

what I did was clone the create qtree in perl command, changed the String Representation to 'test' , and removed al the Parameters definition.

 

the csv was successfully saved to : c:\temp\ as vol_report.csv ( note I changed the c:\ to c:\temp )

Aswani_Kumar
2,678 Views

for the above code too, only csv file is creating .

What ever query is retriving those are not getting written to the csv file.

 

The only data present in csv file is from this line not from the query .

 

print FILE "aggr_name,aggr_used_percentage,name,vol_avilable_percentage,vol.available_size_mb,vserver.cluster.primary_address,vserver.name";

 

could u please  check the file if u are getting query values or not .

 

 

where can i find the "wfautil" module.I want to know what are the functions in it.

Aswani_Kumar
2,675 Views

could u please post the modified qtree code .

Public