1 Reply Latest reply: Jul 16, 2017 11:07 PM by Leigh Finch RSS

Trouble passing login credentials to script in NetProfiler tutorial

Darryl Gratz

I am running through the SteelScript NetProfiler Tutorial (4.2.6).

 

I am trying to login and run the following script:

 

import optparse

 

from steelscript.netprofiler.core.filters import TimeFilter

from steelscript.netprofiler.core.report import TrafficSummaryReport

from steelscript.netprofiler.core.app import NetProfilerApp

from steelscript.common.datautils import Formatter

 

class ExampleApp(NetProfilerApp):

 

   def add_options(self, parser):

   group = optparse.OptionGroup(parser, "Example Options")

   group.add_option('-r', '--timerange', dest='timerange', default=None,

   help='Time range to limit report to, e.g. "last 5 m"')

   parser.add_option_group(group)

 

   def main(self):

   p = self.netprofiler

 

   report = TrafficSummaryReport(p)

 

   columns = [p.columns.key.host_ip,

   p.columns.value.avg_bytes,

   p.columns.value.network_rtt]

   sort_column = p.columns.value.avg_bytes

 

   timefilter = TimeFilter.parse_range(self.options.timerange)

 

   report.run('hos', columns, timefilter=timefilter, sort_col=sort_column)

   data = report.get_data()

   legend = report.get_legend()

   report.delete()

 

   header = [c.key for c in columns]

   Formatter.print_table(data[:10], header)

 

ExampleApp().run()



I am using the following command to pass the login credentials to the script:


$ python myreport_3.py $192.168.0.150 -u admin -p password -r "last 10 min"


I get the following error message:


Usage: myreport_3.py <HOST> [options] ...

 

myreport_3.py: error: no such option: -u

 

I even tied to add the following section to the script, and received the same error.

 

# connection information

username = 'admin'

password = 'password'

auth = UserAuth(username, password)

host = '192.168.0.150'

 

Thanks,

 

Darryl

  • Re: Trouble passing login credentials to script in NetProfiler tutorial
    Leigh Finch

    Hi Darryl,

    Looks like there is a minor error in the documentation. I've made a slight modification to my add_options method, and it is working for me. I'll ask the engineering team to update the documentation.

     

       def add_options(self, parser):

               super(ExampleApp, self).add_options(parser)

               group = optparse.OptionGroup(parser, "Example Options")

               group.add_option('-r', '--timerange', dest='timerange', default=None,

               help='Time range to limit report to, e.g. "last 5 m"')

               parser.add_option_group(group)

     

    Let me know if this fixes the problem for you.