Ejemplo n.º 1
0
    def _format_title( self, command, interval ):
        screen_width = BasicCli.ioctl_GWINSZ()[1]
        if screen_width == 0:
            screen_width = 80

        title = "Every %.1fs: %s" % ( interval, command )
        title_time = time.strftime( "%a %b %d %H:%M:%S %Y" )
        title_size = screen_width - len(title) - len(title_time)

        if len(title) > title_size:
            title = title[:title_size - 4] + "... " + title_time
        else:
            title = title + " " * title_size + title_time

        return title
Ejemplo n.º 2
0
    try:
        conn = sqlite3.connect(DB)
        conn.row_factory = sqlite3.Row
        db = conn.cursor()
        rows = db.execute(query).fetchall()
        if not rows:
            conn.commit()
    except sqlite3.Error as e:
        mode.addError("Database error: %s" % e)
    except Exception as e:
        mode.addError("Exception in query: %s" % e)
    finally:
        if conn:
            conn.close()

    #Create Table Headers
    table = PrettyTable([
        'Src IP', 'Dest IP', 'Total Bytes', 'Total Packets', 'Protocol',
        'Src Port', 'Dst Port', 'TOS'
    ])

    #Add each row and make it pretty
    for x in rows:
        table.add_row(x)
    print table


tokenTopTalkers = CliParser.KeywordRule(
    'toptalkers', helpdesc='show toptalkers with local sflow sampling')
BasicCli.registerShowCommand(tokenTopTalkers, showTopTalkers)
Ejemplo n.º 3
0
        'Src IP', 'Dest IP', 'VLAN', 'In Intf', 'Total Bytes', 'Total Packets',
        'Protocol', 'Src Port', 'Dst Port', 'TOS'
    ])

    # Store all entries in a list that way we can parse and make it pretty
    for x in rows:
        # If its a routed port, then EOS sflow agent sends it as a 32bit number which translate to the 4 octet IP address of the interface.
        # if it's greater than 4095, we need to manipulate the data so it just shows an 'N/A' for this field.
        if x[2] > 4095:
            # We need to do some hackery here to tweak our field.
            # Can't modify this directly since its a sql object. Nor does this object support copying with list slicing.
            # So we need to copy each field into a temp list.
            modlist = []
            for eachField in x:
                modlist.append(eachField)
            #Tweak our VLAN field which is offset 2
            modlist[2] = "N/A"
            table.add_row(modlist)
        else:
            table.add_row(x)

    print table


tokenTopTalkers = CliParser.KeywordRule(
    'toptalkers', helpdesc='show toptalkers with local sflow sampling')
tokenMax = CliParser.KeywordRule('all', helpdesc='Show all toptalkers')

BasicCli.registerShowCommand(tokenTopTalkers, ['>>whatAll', tokenMax],
                             showTopTalkers)
Ejemplo n.º 4
0
    for name, object in inspect.getmembers( module,
                                            lambda object: inspect.isclass( object ) or
                                                           inspect.isfunction( object ) ):
        name = name.lower()

        if inspect.isclass( object ):
            doc = DEFAULT_DOC % name
            if object.__doc__ is not None:
                doc = object.__doc__.strip()
            tokenClass = CliParser.KeywordRule( name, doc )

            instance = object()
            if hasattr( instance, "__call__" ):
                BasicCli.registerShowCommand ( tokenUtility,
                                               tokenClass,
                                               argumentRule,
                                               instance )
            else:
                for name, object in inspect.getmembers( instance,
                                                        inspect.ismethod ):

            	    doc = DEFAULT_DOC % name
            	    if object.__doc__ is not None:
                	doc = object.__doc__.strip()
                    tokenFunction = CliParser.KeywordRule( name, doc )

                    BasicCli.registerShowCommand ( tokenUtility,
                                                   tokenClass,
                                                   tokenFunction,
                                                   argumentRule,
                                                   object )
Ejemplo n.º 5
0
#  show growl 
#------------------------------------------------------------------------------------
tokenShowGrowl = CliParser.KeywordRule( "growl", helpdesc="Show growl hosts connecten" )

#Show existing growl hosts
def showLoginGrowl( mode ):
   print "%-16s %-20s %-5s"%("Host","Password","Level")
   _config = open("/persist/sys/growl","r")
   for line in _config:
      line = line.rstrip()
      line = line.split(",")
      if len(line) <= 1:
         continue
      print "%-16s %-20s %-5s"%(line[1],line[2],line[0])

BasicCli.registerShowCommand( tokenShowGrowl, showLoginGrowl,
                              privileged=True )

ShowLion = CliParser.KeywordRule ("detail", helpdesc="show growl detail" )
tokenShowLion = CliParser.HiddenRule ( ShowLion )
def ohai( mode ):
   lion = """ GR0WLLLLLLLLL
                          ,%%%%%%%,
                        ,%%/\%%%%/\%,
                       ,%%%\c "" J/%%,
  %.                   %%%%/ d  b \%%%
  `%%.         __      %%%%    _  |%%%
   `%%      .-'  `"~--"`%%%%(=_Y_=)%%'
    //    .'     `.     `%%%%`\\7/%%%'____
   ((    /         ;      `%%%%%%%'____)))
   `.`--'         ,'   _,`-._____`-,
jgs  `\"\"\"`._____  `--,`          `)))
Ejemplo n.º 6
0
        delay = int(state['pings_per_cycle']) * int(state['ping_wait']) * int(state['fail_threshold'])

        status += '------------    show monitor %s   ------------ \n' % state['pid']
        status += 'Type of operation: icmp echo \n'
        status += 'Monitor IP Address: %s \n' % state['monitor_ip']
        status += 'Source Interface: %s \n' % state['source_int']
        status += 'ICMP Echo Timeout: %ss \n' % state['ping_wait']
        status += '  Delay before action: %s \n' % delay
        status += '\n'
        status += 'Tracking Object: \n'
        status += '  Route Type: %s \n' % state['route_type']
        status += '  Route: %s \n' % state['tracked_route']
        status += '  Route Next Hop: %s \n' % state['next_hop']
        status += '\n'
        status += 'Monitor Current State: \n'
        status += '  Process id: %s \n' % state['pid']
        status += '  Process Active: %s \n' % active
        status += '  Failed: %s \n' % state['failed']
        status += '  Counters: \n'
        status += '    Failure Counter: %s \n' % state['fail_counter']
        status += '    Success Counter: %s \n' % state['success_counter']
        status += '\n'

    return status


def do_show_icmp_monitor(mode):
    print icmp_monitor_stat(mode)

BasicCli.registerShowCommand(token_icmp, token_monitor, do_show_icmp_monitor)