Exemple #1
0
 def useCLI(self, command):
     vty_session = VtyService(self._device)
     vty_session.open()
     parsed_show = vty_session.write(command)
     # print parsed_showd
     vty_session.close()
     return parsed_show
    def run(self):
        """ Overwrite GenericSensor.run() method. This method will be called when the sensor started"""
        while 1:
            
            #######################
            # collect information #
            #######################
            ios_commands = ['show version', 'show flash:', 'show arp','show run | sec username','show run | sec line', 'show run | sec interface','show ip route','show interface stats'] 
            vty_dict = {}
            vty_pre_dict = {}
            vty = VTY(list())
            vty.set_transport('tcp')
            vty.set_username('cisco')
            vty.set_password('cisco')
            vty.set_element_address('10.1.0.1')
            try:
                vty.connect('vty')
                vtyService = VtyService(vty.get_network_element())
                vtyService.open()
                for ios_command in ios_commands:
                    vty_pre_dict={}
                    vty_result = vtyService.write(ios_command)
                    normalize_commmand = ios_command
                    ns_name = 'ns:%s:%s' % (vty.get_element_addr(), ios_command)
                    vty_pre_dict['object-name'] = ns_name
                    vty_pre_dict['object-type'] = 'sh-command'
                    vty_pre_dict['object-location']='172.20.127.233'
                    vty_pre_dict['location-type']='network'
                    vty_pre_dict['search-node'] = '172.20.127.235'
                    vty_pre_dict['timestamp'] = datetime.datetime.now()
                    vty_pre_dict['raw-output'] = vty_result
                    vty_dict[ns_name]=vty_pre_dict

                vtyService.close()
                vtyService.destroy()
                vty.disconnect()
            except:
                logging.error("OnePK gets error")
                time.sleep(1)
                continue
            
			#####################
            # update and delete #
            #####################  
            # call super's function to perform updating and deleting

            self.updates_and_deletes(vty_dict)

            #######################
            # sleep for some time #
            #######################         
            time.sleep(REFRESH_RATE)
Exemple #3
0
 def useCLI(self, command):
     vty_session = VtyService(self._device)
     vty_session.open()
     parsed_show = vty_session.write(command)
     # print parsed_showd
     vty_session.close()
     return parsed_show
Exemple #4
0
 def getReasonforReboot(self):
     reason = 'Unknown'
     vty_session = VtyService(self._device)
     vty_session.open()
     parsed_show_version = vty_session.write('show version').split('\n')
     for line in parsed_show_version:
         if line.startswith('Last reload'):
             parsed_line = line.split(':')
             reason = parsed_line[1].strip()
             return reason
     vty_session.close()
Exemple #5
0
 def getReasonforReboot(self):
     reason = "Unknown"
     vty_session = VtyService(self.native)
     vty_session.open()
     parsed_show_version = vty_session.write("show version").split("\n")
     for line in parsed_show_version:
         if line.startswith("Last reload"):
             parsed_line = line.split(":")
             reason = parsed_line[1].strip()
             return reason
     vty_session.close()
Exemple #6
0
		def getReasonforReboot(self):
			reason = 'Unknown'
			vty_session = VtyService(self.native)
			vty_session.open()
			parsed_show_version = vty_session.write('show version').split('\n')
			for line in parsed_show_version:
				if line.startswith('Last reload'):
					parsed_line = line.split(':')
					reason = parsed_line[1].strip()
					return reason
			vty_session.close()
Exemple #7
0
def scaleNotification():

    for switch in switches:
        switchIP = switch[0]
        appName = switch[1]
        user = switch[2]
        pswd = switch[3]

        #
        # Set up session connection configuration and connect to the switch
        #
        ne = NetworkElement(switchIP, appName)
        if transport == 'TLS':
            session_config = SessionConfig(
                SessionConfig.SessionTransportMode.TLS)
            session_config.ca_certs = cert
            ne.connect(user, pswd, session_config)
        elif transport == 'TIPC':
            session_config = SessionConfig(
                SessionConfig.SessionTransportMode.TIPC)
            ne.connect(user, pswd, session_config)
        else:
            print "Please set-up a valid transport type: TIPC or TLS"
            exit(0)

        vty = VtyService(ne)
        vty.open()
        vlan_summary = vty.write("sh vlan summary")
        vty.close()

        vlan_sum = re.search('(?<=vlansum-all-vlan\t)(.*)', vlan_summary)

        if int(vlan_sum.group(0)) > int(scale_limits["max_vlans"]):
            string_print = "Vlan scale exceeded. Max vlan recommended:", scale_limits[
                "max_vlans"], "vlan being used :", vlan_sum.group(0)
            print string_print
            ne.create_syslog_message(
                ne.OnepSyslogSeverity.ONEP_SYSLOG_CRITICAL, str(string_print))
        print "Disconnecting from NE: ", switchIP
        ne.disconnect()
Exemple #8
0
def scaleNotification():

    for switch in switches:
        switchIP = switch[0]
        appName  = switch[1]
        user     = switch[2]
        pswd     = switch[3]

        #
        # Set up session connection configuration and connect to the switch
        #
        ne = NetworkElement(switchIP, appName)
        if  transport == 'TLS':
            session_config = SessionConfig(SessionConfig.SessionTransportMode.TLS)
            session_config.ca_certs = cert
            ne.connect(user, pswd, session_config)
        elif transport == 'TIPC':
            session_config = SessionConfig(SessionConfig.SessionTransportMode.TIPC)
            ne.connect(user, pswd, session_config)
        else:
            print "Please set-up a valid transport type: TIPC or TLS"
            exit(0)

        vty = VtyService(ne)
        vty.open()
        vlan_summary = vty.write("sh vlan summary")
        vty.close()

        vlan_sum = re.search('(?<=vlansum-all-vlan\t)(.*)',vlan_summary)

        if int(vlan_sum.group(0)) > int(scale_limits["max_vlans"]):
            string_print = "Vlan scale exceeded. Max vlan recommended:",scale_limits["max_vlans"],"vlan being used :", vlan_sum.group(0)
            print string_print
            ne.create_syslog_message (ne.OnepSyslogSeverity.ONEP_SYSLOG_CRITICAL,
                                      str(string_print));
        print "Disconnecting from NE: ",switchIP
        ne.disconnect()
Exemple #9
0
 def useCLI(self, command):
     vty_session = VtyService(self.native)
     vty_session.open()
     parsed_show = vty_session.write(command)
     print parsed_show
     vty_session.close()
Exemple #10
0
    tutorial.set_username('cisco')
    tutorial.set_password('cisco')
    tutorial.set_element_address('10.1.0.1')



    try:
        logger.info("Connecting to Network Element...")
        if not tutorial.connect("VTYTutorial"):
            logger.error("Error in connecting to network element")
            sys.exit(1)
        logger.info("Done")
        
        """Get a VTYService from the NE"""
        #  START SNIPPET: create_vty
        vtyService = VtyService(tutorial.get_network_element()) 
        #  END SNIPPET: create_vty
        
        """Open the VTY on the NE with the default command interpreter"""
        #  START SNIPPET: open_vty
        vtyService.open()
        #  END SNIPPET: open_vty

        """Write a string to the VTY on NE"""
        #TEST_CMD2 = "show arp"
        #TEST_CMD2 = "show flash:"
        #TEST_CMD2 = "show adjacency"
        #TEST_CMD2 = "sh run | sec router"
        #TEST_CMD2 = "sh run | sec username"
        #TEST_CMD2 = "sh run | sec line"
        #TEST_CMD2 = "sh run | sec interface"