当前位置: 首页>>代码示例>>Python>>正文


Python snmp_helper.snmp_extract函数代码示例

本文整理汇总了Python中snmp_helper.snmp_extract函数的典型用法代码示例。如果您正苦于以下问题:Python snmp_extract函数的具体用法?Python snmp_extract怎么用?Python snmp_extract使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了snmp_extract函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get_snmp_data

def get_snmp_data (router_data, oid):

    if router_data ['snmp_v'] < 3:

        a_device = ( 
                router_data['IP'], 
                router_data['SNMP Community'], 
                router_data['SNMP Port'], 
        )

        snmp_data = snmp_get_oid ( a_device, oid)

        if snmp_data:
            return snmp_extract (snmp_data)

    if router_data ['snmp_v'] == 3:
        a_device = ( 
                router_data['IP'], 
                router_data['SNMP Port'], 
        )
        snmp_user = router_data ['snmp_user']

        snmp_data = snmp_get_oid_v3 ( a_device, snmp_user, oid)

        if snmp_data:
            return snmp_extract (snmp_data)
    
            
    return None
开发者ID:blahu,项目名称:pynet-mat,代码行数:29,代码来源:cl2ex2.py

示例2: was_config_changed

def was_config_changed( router, snmp_user ):

    # System up time
    sysUptimeOID = '1.3.6.1.2.1.1.3.0'
    # Uptime when running config last changed
    ccmHistoryRunningLastChanged = '1.3.6.1.4.1.9.9.43.1.1.1.0'   

    # Uptime when running config last saved (note any 'write' constitutes a save)    
    ccmHistoryRunningLastSaved = '1.3.6.1.4.1.9.9.43.1.1.2.0'   

    # Uptime when startup config last saved   
    ccmHistoryStartupLastChanged = '1.3.6.1.4.1.9.9.43.1.1.3.0'

    snmp_data = snmp_helper.snmp_get_oid_v3(router, snmp_user, oid=sysUptimeOID)
    router_uptime = int(snmp_helper.snmp_extract(snmp_data))
#    print 'uptime:  ' + str( router_uptime ) + ': ' + covert_seconds_to_human_time( router_uptime )

    snmp_data = snmp_helper.snmp_get_oid_v3(router, snmp_user, oid=ccmHistoryRunningLastChanged)
    running_last_change_time = int(snmp_helper.snmp_extract(snmp_data))
#    print 'running last change: ' + str( running_last_change_time ) + ' ' + str( router_uptime - running_last_change_time )

    snmp_data = snmp_helper.snmp_get_oid_v3(router, snmp_user, oid=ccmHistoryRunningLastSaved)
    running_last_save_time = int(snmp_helper.snmp_extract(snmp_data))
#    print 'running last save:   ' + str( running_last_save_time ) + ' ' + str( router_uptime - running_last_save_time )

    snmp_data = snmp_helper.snmp_get_oid_v3(router, snmp_user, oid=ccmHistoryStartupLastChanged)
    startup_last_change_time = int(snmp_helper.snmp_extract(snmp_data))
#    print 'startup last change: ' + str( startup_last_change_time ) + ' ' + str( router_uptime - startup_last_change_time )

    if (running_last_change_time > 600 and (running_last_change_time > startup_last_change_time)):
        output = covert_seconds_to_human_time(router_uptime - running_last_change_time) + 'since last change of running config\n'
        output += covert_seconds_to_human_time(router_uptime - startup_last_change_time) + 'since last save of running config\n'
        return output

    return ''
开发者ID:kadamski-york,项目名称:pynet_testz,代码行数:35,代码来源:save_needed_check.py

示例3: main

def main():
   ipaddr = '50.76.53.27'

   for i in (7961, 8061):
      print i,":\n";
      print "name     >>> ",snmp_helper.snmp_extract(snmp_helper.snmp_get_oid([ipaddr, "galileo", i], '.1.3.6.1.2.1.1.5.0'))
      print "sysdescr >>> ",snmp_helper.snmp_extract(snmp_helper.snmp_get_oid([ipaddr, "galileo", i], '.1.3.6.1.2.1.1.1.0'))
开发者ID:gizzygizmo,项目名称:pyclass,代码行数:7,代码来源:test_snmp.py

示例4: main

def main():
    a_user = 'pysnmp'
    auth_key = 'galileo1'
    encrypt_key = 'galileo1'
    rtr_ip = '50.76.53.27'
    snmp_user = (a_user, auth_key, encrypt_key)
    f = open(device_file, "rb")

    #prev_rtr1_info = pickle.load(f)
    #prev_rtr2_info = pickle.load(f)
    #f.close()

    pynet_rtr1 = (rtr_ip, 7961)
    pynet_rtr2 = (rtr_ip, 8061)


    if hostname == "pynet-rtr1":
        router = pynet_rtr1
    elif hostname == "pynet-rtr2":
        router = pynet_rtr2

    rtr_name = snmp_get_oid_v3(router,snmp_user,oid=router_name)
    rtr_description = snmp_get_oid_v3(router,snmp_user,oid=router_description)
    rtr_uptime = snmp_get_oid_v3(router,snmp_user,oid=router_uptime)
    last_changed = snmp_get_oid_v3(router,snmp_user,oid=config_last_changed)

    name_output = snmp_extract(rtr_name)
    desc_output = snmp_extract(rtr_description)
    uptime_output = snmp_extract(rtr_uptime)
    changed_output = snmp_extract(last_changed)

    device_info = (name_output,desc_output,uptime_output,changed_output)

    compare_device_info(hostname, device_info)
开发者ID:jordanwimb,项目名称:kbpython,代码行数:34,代码来源:exercise4d.py

示例5: get_sysinfo

	def get_sysinfo(self):
		# Uptime when running config last changed
		ccmHistoryRunningLastChanged = '1.3.6.1.4.1.9.9.43.1.1.1.0'   

		# Uptime when running config last saved (note any 'write' constitutes a save)    
		ccmHistoryRunningLastSaved = '1.3.6.1.4.1.9.9.43.1.1.2.0'   

		# Uptime when startup config last saved   
		ccmHistoryStartupLastChanged = '1.3.6.1.4.1.9.9.43.1.1.3.0'

		#system uptime
		sysUptime = '1.3.6.1.2.1.1.3.0'

		oidRunningLastChanged = snmp_helper.snmp_get_oid_v3(self.a_device, self.snmp_user, ccmHistoryRunningLastChanged, display_errors=True)
		self.RunningLastChanged = snmp_helper.snmp_extract(oidRunningLastChanged)
		oidRunningLastSaved = snmp_helper.snmp_get_oid_v3(self.a_device, self.snmp_user, ccmHistoryRunningLastSaved, display_errors=True)
		self.RunningLastSaved = snmp_helper.snmp_extract(oidRunningLastSaved)
		oidStartupLastChanged = snmp_helper.snmp_get_oid_v3(self.a_device, self.snmp_user, ccmHistoryStartupLastChanged, display_errors=True)
		self.StartupLastChanged = snmp_helper.snmp_extract(oidStartupLastChanged)
		sysuptime_oid = snmp_helper.snmp_get_oid_v3(self.a_device, self.snmp_user, sysUptime, display_errors=True)
		self.sysuptime = snmp_helper.snmp_extract(sysuptime_oid)
		sysname_oid = snmp_helper.snmp_get_oid_v3(self.a_device, self.snmp_user, '.1.3.6.1.2.1.1.5.0', display_errors=True)
		self.sysName = snmp_helper.snmp_extract(sysname_oid)
		print "\n" + self.sysName
		print "uptime %s" % self.sysuptime
		self.RunningLastChangedDelta = int(self.sysuptime) - int(self.RunningLastChanged)
		self.RunningLastSavedDelta = int(self.sysuptime) - int(self.RunningLastSaved)
		self.StartupLastChangedDelta = int(self.sysuptime) - int(self.StartupLastChanged)
		print "running changed %s delta %i minutes" % (self.RunningLastChanged, self.RunningLastChangedDelta/6000)
		print "running saved %s delta %i minutes" % (self.RunningLastSaved, self.RunningLastSavedDelta/6000)
		print "startup changed %s delta %i minutes" % (self.StartupLastChanged, self.StartupLastChangedDelta/6000)
开发者ID:Mattinet,项目名称:pynet-class3,代码行数:31,代码来源:q1_snmp.py

示例6: main

def main():
    a_user = 'pysnmp'
    auth_key = 'galileo1'
    encrypt_key = 'galileo1'
    rtr_ip = '50.76.53.27'
    snmp_user = (a_user, auth_key, encrypt_key)

    #prev_rtr1_info = pickle.load(f)
    #print(prev_rtr1_info)
    #prev_rtr2_info = pickle.load(f)
    #print(prev_rtr2_info)

    f = open(device_file, "wb")

    pynet_rtr1 = (rtr_ip, 7961)
    pynet_rtr2 = (rtr_ip, 8061)

    for router in (pynet_rtr1, pynet_rtr2):
        rtr_name = snmp_get_oid_v3(router,snmp_user,oid=router_name)
        rtr_description = snmp_get_oid_v3(router,snmp_user,oid=router_description)
        rtr_uptime = snmp_get_oid_v3(router,snmp_user,oid=router_uptime)
        last_changed = snmp_get_oid_v3(router,snmp_user,oid=config_last_changed)

        name_output = snmp_extract(rtr_name)
        desc_output = snmp_extract(rtr_description)
        uptime_output = snmp_extract(rtr_uptime)
        changed_output = snmp_extract(last_changed)
    
        device_info = (name_output,desc_output,uptime_output,changed_output)

        pickle.dump(device_info, f)
    f.close()
开发者ID:jordanwimb,项目名称:kbpython,代码行数:32,代码来源:get_device_info.py

示例7: main

def main():
	'''
	'''
	DEBUG = False
	
	COMMUNITY_STRING = 'secret'
	IP = '1.1.1.1'
	
	my_devices = {
		"Device1": (IP, COMMUNITY_STRING, 7061),
		"Device2": (IP, COMMUNITY_STRING, 8061),
	}

	#Uptime when running config last changed
	ccmHistoryRunningLastChanged = '1.3.6.1.4.1.9.9.43.1.1.1.0'
	# Uptime when running config last saved (note any 'write' constitutes a save)
	ccmHistoryRunningLastSaved = '1.3.6.1.4.1.9.9.43.1.1.2.0'
	# Uptime when startup config last saved
	ccmHistoryStartupLastChanged = '1.3.6.1.4.1.9.9.43.1.1.3.0'

	sys_uptime_oid = '1.3.6.1.2.1.1.3.0'


	for device_name, snmp_device in my_devices.items():
		
		# Gather data from device
		snmp_data = snmp_get_oid(snmp_device, oid=sys_uptime_oid)
		sys_uptime = snmp_extract(snmp_data)

		uptime_hours = convert_uptime_hours(sys_uptime)
	
		snmp_data = snmp_get_oid(snmp_device, oid=ccmHistoryRunningLastChanged)
		last_run_change = int(snmp_extract(snmp_data))
		
		snmp_data = snmp_get_oid(snmp_device, oid=ccmHistoryStartupLastChanged)
		last_start_save = int(snmp_extract(snmp_data))
		
		# Determine whether run-start are in sync
		
		run_save_status = determine_run_start_sync_state(last_run_change, last_start_save)

		# Display Output
		print "\nDevice = %s" % device_name
		print "Current Uptime = %.1f hours" % uptime_hours

		if DEBUG:
			print "Run change time = %s" % last_run_change
			print "Last save time = %s" % last_start_save

		# check for a reboot and no save
		if not(last_start_save):
			print "This device has never been saved since the last reboot"
		else:
			if run_save_status:
				print "Running config has been saved"
			else:
				print "Running config not saved"

		print	
开发者ID:rnilekani,项目名称:Python-SNMP,代码行数:59,代码来源:running-startup-config-sync.py

示例8: main

def main():
    a_user = 'pysnmp'
    auth_key = 'galileo1'
    encrypt_key = 'galileo1'
    rtr_ip = '50.76.53.27'
    snmp_user = (a_user, auth_key, encrypt_key)
    f = open(device_file, "rb")

    prev_rtr1_info = pickle.load(f)
    prev_rtr2_info = pickle.load(f)
    f.close()

    pynet_rtr1 = (rtr_ip, 7961)
    pynet_rtr2 = (rtr_ip, 8061)

    hostname = raw_input("Please enter the hostname: ")

    if hostname == "pynet-rtr1":
        router = pynet_rtr1
    elif hostname == "pynet-rtr2":
        router = pynet_rtr2

    rtr_name = snmp_get_oid_v3(router,snmp_user,oid=router_name)
    rtr_description = snmp_get_oid_v3(router,snmp_user,oid=router_description)
    rtr_uptime = snmp_get_oid_v3(router,snmp_user,oid=router_uptime)
    last_changed = snmp_get_oid_v3(router,snmp_user,oid=config_last_changed)

    name_output = snmp_extract(rtr_name)
    desc_output = snmp_extract(rtr_description)
    uptime_output = snmp_extract(rtr_uptime)
    changed_output = snmp_extract(last_changed)
    
    device_info = (name_output,desc_output,uptime_output,changed_output)
    
    if hostname == "pynet-rtr1":
        print(device_info[3], prev_rtr1_info[3])
        if device_info[3] > prev_rtr1_info[3]:
            f = open(device_file, "wb")
            pickle.dump(device_info,f)
            pickle.dump(prev_rtr2_info,f)
            f.close()
        else:
            print("No changes have been made to this device.")

    elif hostname == "pynet-rtr2":
        if device_info[3] > prev_rtr2_info[3]:
            print("Device configuration has been changed.")
            f = open(device_file, "wb")
            pickle.dump(prev_rtr1_info,f)
            pickle.dump(device_info,f)
            f.close()
        else:
            print("No changes have been made to this device.")

    f = open("device_info.pkl", "rb")

    prev_rtr1_info = pickle.load(f)
    prev_rtr2_info = pickle.load(f)
    f.close()
开发者ID:jordanwimb,项目名称:kbpython,代码行数:59,代码来源:exercise4c.py

示例9: get_router_info

def get_router_info(router_info,SYSNAME,SYSDESC):

     snmp_data = snmp_get_oid(router_info,oid=SYSNAME)
     router = snmp_extract(snmp_data)
     print "Router: %s" % router
     snmp_data = snmp_get_oid(router_info,oid=SYSDESC)
     output = snmp_extract(snmp_data)
     print "SYSDESC: %s" % output
开发者ID:cocoloco69,项目名称:pynet,代码行数:8,代码来源:w2e4.py

示例10: main

def main(args):
    parser = OptionParser()
    parser.add_option('-c', '--community', default='public', help='community string')
    options, args = parser.parse_args()

    for arg in args:
        host, port = arg.split(':')
        device = (host, options.community, port)
        for name, oid in OIDS.iteritems():
            print snmp_extract(snmp_get_oid(device, oid=oid))
开发者ID:sfromm,项目名称:pyn,代码行数:10,代码来源:1-1.py

示例11: getSnmpInfo

def getSnmpInfo(router,comm):
    rtr_ip = '50.76.53.27'
    if router == "rtr1":
        snmp_port = 7961
    else:
        snmp_port = 8061

    device = (rtr_ip,comm,snmp_port) 
    rtr_name = snmp_get_oid(device,oid='.1.3.6.1.2.1.1.5.0',display_errors=True)
    rtr_desc = snmp_get_oid(device,oid='.1.3.6.1.2.1.1.1.0',display_errors=True)
    name_output = snmp_extract(rtr_name)
    desc_output = snmp_extract(rtr_desc)
    return(name_output,desc_output)
开发者ID:jordanwimb,项目名称:kbpython,代码行数:13,代码来源:exercise4.py

示例12: main

def main():
    '''
    Using SNMP Write a program that detects if the running configuration has
    been changed but not saved to startup-config.
    '''

    ip_addr = '50.242.94.227'

    my_devices = {
        "pynet_rtr1": (ip_addr, COMMUNITY_STRING, 7961),
        "pynet_rtr2": (ip_addr, COMMUNITY_STRING, 8061),
    }

    sys_uptime_oid = '1.3.6.1.2.1.1.3.0'


    for device_name, snmp_device in my_devices.items():

        # Gather data from device
        snmp_data = snmp_get_oid(snmp_device, oid=sys_uptime_oid)
        sys_uptime = snmp_extract(snmp_data)

        uptime_hours = convert_uptime_hours(sys_uptime)

        snmp_data = snmp_get_oid(snmp_device, oid=OID_RUN_LAST_CHANGED)
        last_run_change = int(snmp_extract(snmp_data))

        snmp_data = snmp_get_oid(snmp_device, oid=OID_START_LAST_CHANGED)
        last_start_save = int(snmp_extract(snmp_data))

        # Determine whether run-start are in sync
        run_save_status = determine_run_start_sync_state(last_run_change, last_start_save)

        # Display output
        print "\nDevice = %s" % device_name
        print "Current Uptime = %.1f hours" % uptime_hours
        if DEBUG:
            print "Run change time = %s" % last_run_change
            print "Last save time = %s" % last_start_save

        # Check for a reboot and no save
        if not last_start_save:
            print 'This device has never been saved since the last reboot'
        else:
            if run_save_status:
                print 'Running config has been saved'
            else:
                print 'Running config not saved'

        print
开发者ID:hgbenga,项目名称:Python,代码行数:50,代码来源:class1_ex3.py

示例13: main

def main(args):
    parser = OptionParser()
    parser.add_option('-c', '--community', default='public', help='community string')
    parser.add_option('-D', '--debug', action='store_true', help='be verbose')
    options, args = parser.parse_args()

    data = {}
    for arg in args:
        host, port = arg.split(':')
        device = (host, options.community, port)
        data[arg] = {}
        for name, oid in OIDS.iteritems():
            data[arg][name] = snmp_extract(snmp_get_oid(device, oid=oid))
    for host in data:

# From the mib:
# If the value of ccmHistoryRunningLastChanged is greater than
# ccmHistoryRunningLastSaved, the configuration has been
# changed but not saved.

        if options.debug:
            print data[host]

        if data[host]['runningLastChanged'] > data[host]['runningLastSaved']:
            print "%s config modified (%s), but not saved (%s)" % (
                host, data[host]['runningLastChanged'], data[host]['startupLastChanged']
            )
开发者ID:sfromm,项目名称:pyn,代码行数:27,代码来源:1-2.py

示例14: poll_print_oid

 def poll_print_oid(self, oid):
     # Combines both snmp_get_oid and snmp_extract into one class method
     self.oid = oid
     self.a_device = (self.ip_address, self.community, self.snmp_port)
     self.snmp_data = snmp_get_oid(self.a_device, self.oid)
     self.output = snmp_extract(self.snmp_data)
     return self.output
开发者ID:ahsec,项目名称:PyNet_Class_Exercises,代码行数:7,代码来源:exercise_4c.py

示例15: main

def main():

    rtr1 = (IP, COMMUNITY, 7961)
    rtr2 = (IP, COMMUNITY, 8061)

    rtr1_sysname = snmp_helper.snmp_get_oid(rtr1, SYSNAME_OID)
    rtr1_sysdescr = snmp_helper.snmp_get_oid(rtr1, SYSDESCR_OID)

    rtr2_sysname = snmp_helper.snmp_get_oid(rtr2, SYSNAME_OID)
    rtr2_sysdescr = snmp_helper.snmp_get_oid(rtr2, SYSDESCR_OID)

    print "rtr1 sysname: %s\n" % snmp_helper.snmp_extract(rtr1_sysname)
    print "rtr1 sysdescr: %s\n" % snmp_helper.snmp_extract(rtr1_sysdescr)

    print "rtr2 sysname: %s\n" % snmp_helper.snmp_extract(rtr2_sysname)
    print "rtr2 sysdescr: %s\n" % snmp_helper.snmp_extract(rtr2_sysdescr)
开发者ID:adleff,项目名称:python_ansible,代码行数:16,代码来源:ex4.py


注:本文中的snmp_helper.snmp_extract函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。