7 Replies Latest reply on May 28, 2014 2:44 AM by leinhard

    anyone who can parse below text with powershell.

    leinhard

      Dear, Team.

      Find the method to parse below text ,

      Anyone who can tell to me the method to parse to below???

       

      ===PARSE RESULT============

      Ethernet1/49

      Tx Power   -2.67    

      Rx Power  -3.48    

       

       

       

      ===ORIGINAL=================

      Ethernet1/47

          transceiver is not applicable

      Ethernet1/48

          transceiver is not applicable

      Ethernet1/49

          transceiver is present

          type is 10Gbase-SR

          name is SumitomoElectric

          part number is SPP5100SR-YB   

          revision is A  

          serial number is 42T569100590   

          nominal bitrate is 10300 MBit/sec

          Link length supported for 50/125um OM2 fiber is 82 m

          Link length supported for 50/125um OM3 fiber is 300 m

          cisco id is --

          cisco extended id number is 4

                 SFP Detail Diagnostics Information (internal calibration)

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

                      Current              Alarms                  Warnings

                      Measurement     High        Low         High          Low

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

        Temperature   38.54 C        75.00 C     -5.00 C     70.00 C        0.00 C

        Voltage        3.28 V         3.63 V      2.97 V      3.46 V        3.13 V

        Current        5.50 mA       15.00 mA     2.00 mA    14.00 mA       2.50 mA

        Tx Power       -2.67 dBm       1.49 dBm  -11.30 dBm   -1.50 dBm     -7.30 dBm

        Rx Power       -3.48 dBm       1.99 dBm  -13.97 dBm   -1.00 dBm     -9.91 dBm

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

        Note: ++  high-alarm; +  high-warning; --  low-alarm; -  low-warning

        • Re: anyone who can parse below text with powershell.
          sw_ross

          can't seem to paste into here.  So I've attached the code as a text file.

            • Re: anyone who can parse below text with powershell.
              leinhard

              Dear, sw_ross

              thank you very much for your great coding technics :-)

              Can you give me an idea for below text data also, with the orion SDK, i am very interesting with powershell scripting works.

               

              ===PARSE RESULT============

              Chassis-1       N3K-C3048-FAN-B      --         ok

               

               

              ==ORIGINAL===============

              Fan:

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

              Fan             Model                Hw         Status

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

              Chassis-1       N3K-C3048-FAN-B      --         ok

              PS-1            N2200-PAC-400W-B     --         ok

              PS-2            N2200-PAC-400W-B     --         ok

              Temperature

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

              Module   Sensor     MajorThresh   MinorThres   CurTemp     Status

                                  (Celsius)     (Celsius)    (Celsius)        

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

              1         D0        66            52           46          ok            

              1         D1        65            51           40          ok            

              1         D2        63            49           38          ok            

              1         D3        61            47           37          ok            

              Power Supply:

              Voltage: 12 Volts

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

              PS  Model                Input Power       Current   Status

                                       Type  (Watts)     (Amps)         

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

              1   N2200-PAC-400W-B     AC     396.00     33.00     ok                 

              2   N2200-PAC-400W-B     AC     396.00     33.00     ok                 

              Mod Model                   Power     Current     Power     Current     Status

                                          Requested Requested   Allocated Allocated        

                                          (Watts)   (Amps)      (Watts)   (Amps)             

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

              1    N3K-C3048TP-1GE-SUP    349.20    29.10       349.20    29.10       powered-up

              Power Usage Summary:

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

              Power Supply redundancy mode:                 Redundant

              Power Supply redundancy operational mode:     Redundant

              Total Power Capacity                              792.00 W

              Power reserved for Supervisor(s)                  349.20 W

              Power currently used by Modules                     0.00 W

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

              Total Power Available                             442.00 W

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

                • Re: anyone who can parse below text with powershell.
                  leinhard

                  see the following script it is right or not plz

                  I tested this script for nexus 3048 when we want to find the Fan status is ok.

                  then export the result to the file

                   

                  ========SCRPT===========

                  $orgtxt = @"

                  Fan:

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

                  Fan             Model                Hw         Status

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

                  Chassis-1       N3K-C3048-FAN-B      --         ok

                  PS-1            N2200-PAC-400W-B     --         ok

                  PS-2            N2200-PAC-400W-B     --         ok

                  Temperature

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

                  Module   Sensor     MajorThresh   MinorThres   CurTemp     Status

                                      (Celsius)     (Celsius)    (Celsius)        

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

                  1         D0        66            52           46          ok            

                  1         D1        65            51           40          ok            

                  1         D2        63            49           38          ok            

                  1         D3        61            47           37          ok            

                  Power Supply:

                  Voltage: 12 Volts

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

                  PS  Model                Input Power       Current   Status

                                           Type  (Watts)     (Amps)         

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

                  1   N2200-PAC-400W-B     AC     396.00     33.00     ok                 

                  2   N2200-PAC-400W-B     AC     396.00     33.00     ok                 

                  Mod Model                   Power     Current     Power     Current     Status

                                              Requested Requested   Allocated Allocated        

                                              (Watts)   (Amps)      (Watts)   (Amps)             

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

                  1    N3K-C3048TP-1GE-SUP    349.20    29.10       349.20    29.10       powered-up

                  Power Usage Summary:

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

                  Power Supply redundancy mode:                 Redundant

                  Power Supply redundancy operational mode:     Redundant

                  Total Power Capacity                              792.00 W

                  Power reserved for Supervisor(s)                  349.20 W

                  Power currently used by Modules                     0.00 W

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

                  Total Power Available                             442.00 W

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

                  "@

                   

                   

                  $orgtxt = $orgtxt -split ("`r`n")

                   

                   

                  $lines = @()

                  foreach ($line in $orgtxt) {

                      switch -wildcard ($line)

                      {

                          "*Chassis-1*" {$A += $line.Substring(48,2)}

                      }

                      switch -wildcard ($line)

                      {

                          "*PS-1*" {$B += $line.Substring(48,2)}

                      }

                  }   

                   

                  $A

                  $B

                    • Re: anyone who can parse below text with powershell.
                      sw_ross

                      It appears to work and return

                      "ok"

                      "ok"

                       

                      Just a couple of powershell pointers here, $lines = @()  is an empty array.  It's unused in your script above.

                      when you do $B += ... you've created a string.  So if you have multiple things you're adding to $B they will be on one line.  If you added both to $A or both to $B, the output would be "okok".

                      Since $lines is defined as an array, you can do this add both values to the array and output it once:

                       

                      ====script snippet====

                      $lines = @()

                      foreach ($line in $orgtxt) {

                       

                         switch -wildcard ($line)

                         {

                       

                           "*Chassis-1*" {$lines += $line.Substring(48,2)}

                       

                           "*PS-1*" {$lines += $line.Substring(48,2)}

                         }

                      }

                      $lines

                      ====script====


                      Oh and I took out the extra switch statement.  You are only testing one variable.  The Scripting Guy has a good article on it:

                      Windows PowerShell Tip: Using the Switch Statement  I showed that to a coworker and he really liked it.


                      I like to use powershell_ise so I keep the script in one pane and a prompt below.  I can type in the variable names and examine their output.  And get more details about them by piping to get-member (gm is a shortcut for get-member).

                      $lines | gm