Forum Discussion

nkingcade_12003's avatar
nkingcade_12003
Icon for Nimbostratus rankNimbostratus
Sep 05, 2013

Export to Excel or .CSV

I would like to export CLI information, mostly performance information, to MSExcel or to a CSV file. I tried redirection from the command line. Is this redirection possible?

 

13 Replies

  • possible, but would require some scripting work in tmsh, bash, perl, or python.

     

  • You can get stats in a reasonably usable for using the field-fmt option of the show commands. For example

    tmsh show ltm virtual field-fmt raw

    It's not csv, but not too hard to parse either

  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus

    You can get stats in a reasonably usable for using the field-fmt option of the show commands. For example

    tmsh show ltm virtual field-fmt raw

    It's not csv, but not too hard to parse either

  • I'm working on a script to look at real time interface statistics, and I'm parsing with TMSH using lindex and splitting on line numbers.

    proc script::run {} {
        tmsh::clear_screen
        if { $tmsh::argc == 1 } {
            set int [getFeedback "Please enter the interface number (ie, 1.1): "]
        } else {
            set int [lindex $tmsh::argv 1]
        }
    
        set l1 []
        set l2 []
        set interval [getFeedback "Please enter refresh rate for the stats (in seconds): "]
        set delay [expr $interval * 1000]
    
        lappend l1 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 1] 1]
        lappend l1 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 2] 1]
    
        while { true } {
            after $delay
            lappend l2 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 1] 1]
            lappend l2 [lindex [lindex [split [tmsh::show net interface $int raw field-fmt] "\n"] 2] 1]
            tmsh::clear_screen
    
            set s1 $l1
            set s2 $l2
    
            set statsIn [expr ([lindex $s2 0] - [lindex $s1 0]) / $interval]
            set statsOut [expr ([lindex $s2 1] - [lindex $s1 1]) / $interval]
    
            puts "Interface\t\tInbound (bps)\t\tOutbound (bps)"
            puts "$int\t\t\t$statsIn\t\t\t$statsOut"
    
            set l1 $l2
            unset l2
        }
    }
    

    I would suggest instead of using a while loop, you can just use puts and commas for each field.

  • FYI, the getFeedback is a proc in the same TMSH script:

    proc getFeedback { question } {
        puts -nonewline $question
        flush stdout
        return [gets stdin]
    }
    
  • Jason's method above is great if it is long term. For a quick-and-dirty solution, this perl will convert your output for you. Put it in a file, such as field-to-csv, and run it like this:

    tmsh show ltm virtual field-fmt raw | field-to-csv

    !/usr/bin/perl
    while ($line = <>) {
      chomp($line);
      if    ($line =~ /{/) { $out = ""}
      elsif ($line =~ /}/) { print "$out\n" }
      else {
        $out .= "," if (length($out) != 0);
        ($field,$value) = split(" ",$line,2);
        if ($value =~ /,/)
          { $out .= "\"$value\"" }
        else
          { $out .= $value }
      }
    }
    
    • gratlmichael_22's avatar
      gratlmichael_22
      Icon for Nimbostratus rankNimbostratus
      Has anyone the script ready for the export the performance data to csv? mem usage, packets, ssl transactions, http,.. Thanks!
  • uni's avatar
    uni
    Icon for Altostratus rankAltostratus

    Jason's method above is great if it is long term. For a quick-and-dirty solution, this perl will convert your output for you. Put it in a file, such as field-to-csv, and run it like this:

    tmsh show ltm virtual field-fmt raw | field-to-csv

    !/usr/bin/perl
    while ($line = <>) {
      chomp($line);
      if    ($line =~ /{/) { $out = ""}
      elsif ($line =~ /}/) { print "$out\n" }
      else {
        $out .= "," if (length($out) != 0);
        ($field,$value) = split(" ",$line,2);
        if ($value =~ /,/)
          { $out .= "\"$value\"" }
        else
          { $out .= $value }
      }
    }
    
    • uni's avatar
      uni
      Icon for Altostratus rankAltostratus
      finally got the formatting right
    • gratlmichael_22's avatar
      gratlmichael_22
      Icon for Nimbostratus rankNimbostratus
      Has anyone the script ready for the export the performance data to csv? mem usage, packets, ssl transactions, http,.. Thanks!