Ratan Gupta | c736670 | 2017-02-22 18:05:44 +0530 | [diff] [blame^] | 1 | #! /usr/bin/perl |
| 2 | use strict; |
| 3 | use warnings; |
| 4 | |
| 5 | use mrw::Targets; |
| 6 | use mrw::Inventory; |
| 7 | use mrw::Util; |
| 8 | use Getopt::Long; # For parsing command line arguments |
| 9 | use YAML::Tiny qw(LoadFile); |
| 10 | |
| 11 | # Globals |
| 12 | my $serverwizFile = ""; |
| 13 | my $debug = 0; |
| 14 | my $metaDataFile = ""; |
| 15 | |
| 16 | # Command line argument parsing |
| 17 | GetOptions( |
| 18 | "i=s" => \$serverwizFile, # string |
| 19 | "m=s" => \$metaDataFile, # string |
| 20 | "d" => \$debug, |
| 21 | ) |
| 22 | or printUsage(); |
| 23 | |
| 24 | if (($serverwizFile eq "") or ($metaDataFile eq "")) |
| 25 | { |
| 26 | printUsage(); |
| 27 | } |
| 28 | |
| 29 | my $targetObj = Targets->new; |
| 30 | $targetObj->loadXML($serverwizFile); |
| 31 | |
| 32 | #open the mrw xml and the metaData file for the sensor. |
| 33 | #Fetch the sensorid,sensortype,class,object path from the mrw. |
| 34 | |
| 35 | my $sensorTypeConfig = LoadFile($metaDataFile); |
| 36 | |
| 37 | my @interestedTypes = keys %{$sensorTypeConfig}; |
| 38 | my %types; |
| 39 | |
| 40 | @types{@interestedTypes} = (); |
| 41 | |
| 42 | my @inventory = Inventory::getInventory($targetObj); |
| 43 | #Process all the targets in the XML |
| 44 | foreach my $target (sort keys %{$targetObj->getAllTargets()}) |
| 45 | { |
| 46 | my $sensorID = ''; |
| 47 | my $sensorType = ''; |
| 48 | my $sensorReadingType = ''; |
| 49 | my $path = ''; |
| 50 | my $obmcPath = ''; |
| 51 | |
| 52 | if ($targetObj->getTargetType($target) eq "unit-ipmi-sensor") { |
| 53 | |
| 54 | $sensorID = $targetObj->getAttribute($target, "IPMI_SENSOR_ID"); |
| 55 | |
| 56 | $sensorType = $targetObj->getAttribute($target, "IPMI_SENSOR_TYPE"); |
| 57 | |
| 58 | $sensorReadingType = $targetObj->getAttribute($target, |
| 59 | "IPMI_SENSOR_READING_TYPE"); |
| 60 | |
| 61 | $path = $targetObj->getAttribute($target, "INSTANCE_PATH"); |
| 62 | |
| 63 | #not interested in this sensortype |
| 64 | next if (not exists $types{$sensorType} ); |
| 65 | |
| 66 | #if there is ipmi sensor without sensorid or sensorReadingType or |
| 67 | #Instance path then die |
| 68 | |
| 69 | if ($sensorID eq '' or $sensorReadingType eq '' or $path eq '') { |
| 70 | die("sensor without info for target=$target"); |
| 71 | } |
| 72 | |
| 73 | #removing the string "instance:" from path |
| 74 | $path =~ s/^instance:/\//; |
| 75 | |
| 76 | $obmcPath = Util::getObmcName(\@inventory, $path); |
| 77 | |
| 78 | #if unable to get the obmc path then die |
| 79 | if (not defined $obmcPath) { |
| 80 | die("Unable to get the obmc path for path=$path"); |
| 81 | } |
| 82 | |
| 83 | printDebug("$sensorID : $sensorType : $sensorReadingType :$obmcPath \n"); |
| 84 | |
| 85 | } |
| 86 | |
| 87 | } |
| 88 | |
| 89 | # Usage |
| 90 | sub printUsage |
| 91 | { |
| 92 | print " |
| 93 | $0 -i [MRW filename] -m [SensorMetaData filename] [OPTIONS] |
| 94 | Options: |
| 95 | -d = debug mode |
| 96 | \n"; |
| 97 | exit(1); |
| 98 | } |
| 99 | |
| 100 | # Helper function to put debug statements. |
| 101 | sub printDebug |
| 102 | { |
| 103 | my $str = shift; |
| 104 | print "DEBUG: ", $str, "\n" if $debug; |
| 105 | } |
| 106 | |