blob: fd91e6bf5067f1c23a534b146aa8cb24ff4c46e8 [file] [log] [blame]
Ratan Guptac7366702017-02-22 18:05:44 +05301#! /usr/bin/perl
2use strict;
3use warnings;
4
5use mrw::Targets;
6use mrw::Inventory;
7use mrw::Util;
8use Getopt::Long; # For parsing command line arguments
9use YAML::Tiny qw(LoadFile);
10
11# Globals
12my $serverwizFile = "";
13my $debug = 0;
14my $metaDataFile = "";
15
16# Command line argument parsing
17GetOptions(
18"i=s" => \$serverwizFile, # string
19"m=s" => \$metaDataFile, # string
20"d" => \$debug,
21)
22or printUsage();
23
24if (($serverwizFile eq "") or ($metaDataFile eq ""))
25{
26 printUsage();
27}
28
29my $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
35my $sensorTypeConfig = LoadFile($metaDataFile);
36
37my @interestedTypes = keys %{$sensorTypeConfig};
38my %types;
39
40@types{@interestedTypes} = ();
41
42my @inventory = Inventory::getInventory($targetObj);
43#Process all the targets in the XML
44foreach 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
90sub printUsage
91{
92 print "
93 $0 -i [MRW filename] -m [SensorMetaData filename] [OPTIONS]
94Options:
95 -d = debug mode
96 \n";
97 exit(1);
98}
99
100# Helper function to put debug statements.
101sub printDebug
102{
103 my $str = shift;
104 print "DEBUG: ", $str, "\n" if $debug;
105}
106