Class: UCSStats
- Inherits:
-
Object
- Object
- UCSStats
- Defined in:
- lib/ucslib/stats.rb
Constant Summary collapse
- STATNAMES =
%w(adaptorEthPortStats adaptorEthPortErrStats adaptorEthPortMcastStats adaptorVnicStats computeMbPowerStats computeMbTempStats computePCIeFatalStats computePCIeFatalCompletionStats computePCIeFatalProtocolStats computePCIeFatalReceiveStats equipmentChassisStats equipmentFanStats equipmentFanModuleStats equipmentIOCardStats equipmentNetworkElementFanStats equipmentPsuStats equipmentPsuInputStats etherErrStats etherLossStats etherPauseStats etherRxStats etherTxStats fcStats fcErrStats memoryArrayEnvStats memoryErrorStats memoryUnitEnvStats processorEnvStats processorErrorStats swEnvStats swSystemStats)
Instance Method Summary collapse
- #fetch(tokenjson) ⇒ Object
-
#get_hash(xml, statname = :all) ⇒ Object
Translate stats XML into a hash.
- #show_all(xml, statname) ⇒ Object
- #show_sample(xml, statname, all = false) ⇒ Object
Instance Method Details
#fetch(tokenjson) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/ucslib/stats.rb', line 4 def fetch(tokenjson) = "#{JSON.parse(tokenjson)['cookie']}" ip = "#{JSON.parse(tokenjson)['ip']}" url = "https://#{ip}/nuova" #Start Build the Multi-Class XML # Note, the list of stats was gathered by changing hierarchical to "true" in # inventory.rb, pointing at UCS and then searching the 10M XML for 'Stats' :) # # Like this: # tr '>' '\n' < /tmp/ucs-play.xml | grep Stats | grep -v Policy | awk '{print $1}' | sort -u | grep -v / | tr -d '<' | grep -v Hist xml_builder = Nokogiri::XML::Builder.new do |xml| xml.configResolveClasses('cookie' => , 'inHierarchical' => 'false') { xml.inIds{ xml.classId("value" => "adaptorEthPortStats") xml.classId("value" => "adaptorEthPortErrStats") xml.classId("value" => "adaptorEthPortMcastStats") xml.classId("value" => "adaptorVnicStats") xml.classId("value" => "computeMbPowerStats") xml.classId("value" => "computeMbTempStats") xml.classId("value" => "computePCIeFatalStats") xml.classId("value" => "computePCIeFatalCompletionStats") xml.classId("value" => "computePCIeFatalProtocolStats") xml.classId("value" => "computePCIeFatalReceiveStats") xml.classId("value" => "equipmentChassisStats") xml.classId("value" => "equipmentFanStats") xml.classId("value" => "equipmentFanModuleStats") xml.classId("value" => "equipmentIOCardStats") xml.classId("value" => "equipmentNetworkElementFanStats") xml.classId("value" => "equipmentPsuStats") xml.classId("value" => "equipmentPsuInputStats") xml.classId("value" => "etherErrStats") xml.classId("value" => "etherLossStats") xml.classId("value" => "etherPauseStats") xml.classId("value" => "etherRxStats") xml.classId("value" => "etherTxStats") xml.classId("value" => "fcStats") xml.classId("value" => "fcErrStats") xml.classId("value" => "memoryArrayEnvStats") xml.classId("value" => "memoryErrorStats") xml.classId("value" => "memoryUnitEnvStats") xml.classId("value" => "processorEnvStats") xml.classId("value" => "processorErrorStats") xml.classId("value" => "swEnvStats") xml.classId("value" => "swSystemStats") } } end #End Build Multi-Class XML ucs_multi_class_XML = xml_builder.to_xml.to_s ucs_response_multi_class = RestClient.post(url, ucs_multi_class_XML, :content_type => 'text/xml').body #Uncomment the following to create a dump to review and debug elements # fh = File.new("ucs_response_multiclass.xml", "w") # fh.puts ucs_response_multi_class.inspect # fh.close return Nokogiri::XML(ucs_response_multi_class) end |
#get_hash(xml, statname = :all) ⇒ Object
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/ucslib/stats.rb', line 71 def get_hash(xml,statname=:all) statnames = STATNAMES if statname == :all h = Hash.new{|k,v| k[v] = Hash.new} statnames.each do |statname| xml.xpath("configResolveClasses/outConfigs/#{statname}").each do |stat| dn = stat.attributes['dn'].value h[statname][dn] = Hash.new stat.attributes.each do |attr,value| next if attr == 'dn' h[statname][dn][attr] = value.value end end end return h end |
#show_all(xml, statname) ⇒ Object
96 97 98 |
# File 'lib/ucslib/stats.rb', line 96 def show_all(xml,statname) show_sample(xml,statname,true) end |
#show_sample(xml, statname, all = false) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/ucslib/stats.rb', line 88 def show_sample(xml,statname,all=false) list = xml.xpath("configResolveClasses/outConfigs/#{statname}") list = [list.first] unless all list.each do |i| show_attributes(i) end end |