diff options
author | Ratan Gupta <ratagupt@in.ibm.com> | 2017-02-22 18:05:44 +0530 |
---|---|---|
committer | Patrick Williams <patrick@stwcx.xyz> | 2017-03-09 19:19:15 +0000 |
commit | c736670674c931860d1c2fa1ca940c9d4557ebbf (patch) | |
tree | 1f28e66e51c93d2d797ee84b8fbffa96686142bc | |
parent | 37c2e96a08c3f58f5fa525f859436d3e9762cce7 (diff) | |
download | phosphor-mrw-tools-c736670674c931860d1c2fa1ca940c9d4557ebbf.tar.gz phosphor-mrw-tools-c736670674c931860d1c2fa1ca940c9d4557ebbf.zip |
gen_ipmi_sensor.pl : Fetch sensor information from MRW
This commit serves as a building block since the script can now just
print certain attributes (see output example below) for sensors
defined in the MRW.
Output example:
sensorID: sensorType: sensorReadingType: ObjectPath
0xa1 : 0x07 : 0x6F : /sys/chassis/board/cpu1/core0
Change-Id: Ice89a6b6294d94fded4eb92f628b8f62ef02b7ed
Signed-off-by: Ratan Gupta <ratagupt@in.ibm.com>
-rwxr-xr-x | gen_ipmi_sensor.pl | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/gen_ipmi_sensor.pl b/gen_ipmi_sensor.pl new file mode 100755 index 0000000..fd91e6b --- /dev/null +++ b/gen_ipmi_sensor.pl @@ -0,0 +1,106 @@ +#! /usr/bin/perl +use strict; +use warnings; + +use mrw::Targets; +use mrw::Inventory; +use mrw::Util; +use Getopt::Long; # For parsing command line arguments +use YAML::Tiny qw(LoadFile); + +# Globals +my $serverwizFile = ""; +my $debug = 0; +my $metaDataFile = ""; + +# Command line argument parsing +GetOptions( +"i=s" => \$serverwizFile, # string +"m=s" => \$metaDataFile, # string +"d" => \$debug, +) +or printUsage(); + +if (($serverwizFile eq "") or ($metaDataFile eq "")) +{ + printUsage(); +} + +my $targetObj = Targets->new; +$targetObj->loadXML($serverwizFile); + +#open the mrw xml and the metaData file for the sensor. +#Fetch the sensorid,sensortype,class,object path from the mrw. + +my $sensorTypeConfig = LoadFile($metaDataFile); + +my @interestedTypes = keys %{$sensorTypeConfig}; +my %types; + +@types{@interestedTypes} = (); + +my @inventory = Inventory::getInventory($targetObj); +#Process all the targets in the XML +foreach my $target (sort keys %{$targetObj->getAllTargets()}) +{ + my $sensorID = ''; + my $sensorType = ''; + my $sensorReadingType = ''; + my $path = ''; + my $obmcPath = ''; + + if ($targetObj->getTargetType($target) eq "unit-ipmi-sensor") { + + $sensorID = $targetObj->getAttribute($target, "IPMI_SENSOR_ID"); + + $sensorType = $targetObj->getAttribute($target, "IPMI_SENSOR_TYPE"); + + $sensorReadingType = $targetObj->getAttribute($target, + "IPMI_SENSOR_READING_TYPE"); + + $path = $targetObj->getAttribute($target, "INSTANCE_PATH"); + + #not interested in this sensortype + next if (not exists $types{$sensorType} ); + + #if there is ipmi sensor without sensorid or sensorReadingType or + #Instance path then die + + if ($sensorID eq '' or $sensorReadingType eq '' or $path eq '') { + die("sensor without info for target=$target"); + } + + #removing the string "instance:" from path + $path =~ s/^instance:/\//; + + $obmcPath = Util::getObmcName(\@inventory, $path); + + #if unable to get the obmc path then die + if (not defined $obmcPath) { + die("Unable to get the obmc path for path=$path"); + } + + printDebug("$sensorID : $sensorType : $sensorReadingType :$obmcPath \n"); + + } + +} + +# Usage +sub printUsage +{ + print " + $0 -i [MRW filename] -m [SensorMetaData filename] [OPTIONS] +Options: + -d = debug mode + \n"; + exit(1); +} + +# Helper function to put debug statements. +sub printDebug +{ + my $str = shift; + print "DEBUG: ", $str, "\n" if $debug; +} + |