Пример #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
Пример #2
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
Пример #3
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()
Пример #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()
Пример #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()
Пример #6
0
    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)
Пример #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()
Пример #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()
Пример #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()