Forum Discussion

mariogolf_57851's avatar
mariogolf_57851
Icon for Nimbostratus rankNimbostratus
Dec 20, 2010

System::SystemInfo::get_fan_metrics

Can you help me formatting the output returned from this call please?

 

 

----------------------------------------------------------------------------

 

sub get_fan_metrics

 

----------------------------------------------------------------------------

 

sub get_fan_metrics()

 

{

 

$soapResponse = $SystemInfo->get_fan_metrics();

 

&checkResponse($soapResponse);

 

 

@PlatformFans = $soapResponse->result;

 

foreach $PlatformFans (@PlatformFans)

 

{

 

@FanMetric = @{$PlatformFans->{"fans"}};

 

print Dumper \@FanMetric;

 

}

 

}

 

 

$VAR1 = [

 

bless( [

 

bless( {

 

'metric_type' => 'FAN_INDEX',

 

'value' => '101'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_STATE',

 

'value' => '1'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_SPEED',

 

'value' => '4530'

 

}, 'System::FanMetric' )

 

], 'System::FanMetric[]' ),

 

bless( [

 

bless( {

 

'metric_type' => 'FAN_INDEX',

 

'value' => '102'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_STATE',

 

'value' => '1'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_SPEED',

 

'value' => '4440'

 

}, 'System::FanMetric' )

 

], 'System::FanMetric[]' ),

 

bless( [

 

bless( {

 

'metric_type' => 'FAN_INDEX',

 

'value' => '103'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_STATE',

 

'value' => '1'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_SPEED',

 

'value' => '4411'

 

}, 'System::FanMetric' )

 

], 'System::FanMetric[]' ),

 

bless( [

 

bless( {

 

'metric_type' => 'FAN_INDEX',

 

'value' => '104'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_STATE',

 

'value' => '1'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_SPEED',

 

'value' => '4272'

 

}, 'System::FanMetric' )

 

], 'System::FanMetric[]' ),

 

bless( [

 

bless( {

 

'metric_type' => 'FAN_INDEX',

 

'value' => '105'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_STATE',

 

'value' => '1'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_SPEED',

 

'value' => '4299'

 

}, 'System::FanMetric' )

 

], 'System::FanMetric[]' ),

 

bless( [

 

bless( {

 

'metric_type' => 'FAN_INDEX',

 

'value' => '106'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_STATE',

 

'value' => '1'

 

}, 'System::FanMetric' ),

 

bless( {

 

'metric_type' => 'FAN_SPEED',

 

'value' => '4245'

 

}, 'System::FanMetric' )

 

], 'System::FanMetric[]' )

 

];

 

4 Replies

  • ----------------------------------------------------------------------------
     sub get_fan_metrics
    ----------------------------------------------------------------------------
    sub get_fan_metrics()
    {
            $soapResponse = $SystemInfo->get_fan_metrics();
            $PlatformFans = $soapResponse->result;
            $TimeStamp=$PlatformFans->{'time_stamp'};
            $FanMetric=$PlatformFans->{'fans'};
    
            @AoA=$FanMetric;
    
            for $i ( 0 .. $AoA ) {
                    for $j ( 0 .. ${$AoA[$i]} ) {
                            $FanIndex = $AoA[$i][$j][0];
                            for my $Index (sort keys %{$FanIndex}) {
                                    print $Index . " " . $FanIndex->{"$Index"} . "\n";
                            }
    
                            $FanState = $AoA[$i][$j][1];
                            for my $State (sort keys %{$FanState}) {
                                    print $State . " " . $FanState->{"$State"} . "\n";
                            }
                            $FanSpeed = $AoA[$i][$j][2];
                            for my $Speed (sort keys %{$FanSpeed}) {
                                    print $Speed . " " . $FanSpeed->{"$Speed"} . "\n";
                            }
                    }
            }
    
            print "The statistics were gathered: [";
            print $TimeStamp->{'year'};
            print $TimeStamp->{'month'};
            print $TimeStamp->{'day'};
            print $TimeStamp->{'hour'};
            print $TimeStamp->{'minute'};
            print $TimeStamp->{'second'};
            print "]\n";
    
    }
     
  • This code is ugly and needs cleaned up for pretty output but it is a start and works for these types of array outputs.

     

     

    Any cleanup would be appreciated.
  • Yields:

     

     

    metric_type FAN_INDEX

     

    value 101

     

    metric_type FAN_STATE

     

    value 1

     

    metric_type FAN_SPEED

     

    value 4560

     

    metric_type FAN_INDEX

     

    value 102

     

    metric_type FAN_STATE

     

    value 1

     

    metric_type FAN_SPEED

     

    value 4440

     

    metric_type FAN_INDEX

     

    value 103

     

    metric_type FAN_STATE

     

    value 1

     

    metric_type FAN_SPEED

     

    value 4440

     

    metric_type FAN_INDEX

     

    value 104

     

    metric_type FAN_STATE

     

    value 1

     

    metric_type FAN_SPEED

     

    value 4299

     

    metric_type FAN_INDEX

     

    value 105

     

    metric_type FAN_STATE

     

    value 1

     

    metric_type FAN_SPEED

     

    value 4299

     

    metric_type FAN_INDEX

     

    value 106

     

    metric_type FAN_STATE

     

    value 1

     

    metric_type FAN_SPEED

     

    value 4245

     

    The statistics were gathered: [20101222222713]