• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python snmp_helper.snmp_get_oid函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: 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


示例2: 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


示例3: 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


示例4: 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


示例5: 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


示例6: 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


示例7: snmp_get

def snmp_get(snmp_data, device):
	access_details = (device['IP'], COMMUNITY_STRING, SNMP_PORT)
	snmp_results = snmp_helper.snmp_get_oid(access_details, snmp_data['OID'])
	output = snmp_helper.snmp_extract(snmp_results)
	print("For "+device['name']+" the "+snmp_data['name']+" is "+'\n')
	print(output)
	print('\n')
开发者ID:brianbooher,项目名称:pynet_testz,代码行数:7,代码来源:exercise4a-c-snmp-pull.py


示例8: 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


示例9: 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


示例10: 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


示例11: snmp_print_sysdescr

def snmp_print_sysdescr(l_ip, l_port='161', l_community='public'):
    '''
    Print snmp sysdescr
    '''
    conn_dev = (l_ip, l_community, l_port)
    snmp_data = snmp_extract(snmp_get_oid(conn_dev, oid='1.3.6.1.2.1.1.1.0'))
    return snmp_data
开发者ID:gleydsonm,项目名称:pynet_ex,代码行数:7,代码来源:exercise4c.py


示例12: get_cell_status

def get_cell_status():
    # community_string and snmp_port are set under global variables
    device = ('snmp.meraki.com', community_string, snmp_port)
    # devCellularStatus
    snmp_data = snmp_helper.snmp_get_oid(device, oid='.1.3.6.1.4.1.29671.1.1.4.1.14', display_errors=True)

    for row in snmp_data:
        # for each response with 'Active' cellular status, append the devName to cell_active_list
        if row[0][1] == 'Active':
            # dup of the original function to extract [0][0] vs. [0][1]
            extract_oid = snmp_helper.snmp_extract2(row)
            # replace the front of the oid to create a new oid for name lookup
            name_oid = extract_oid.replace('SNMPv2-SMI::enterprises.29671.1.1.4.1.14', '.1.3.6.1.4.1.29671.1.1.4.1.2')
            # lookup and extract the devName of the device with 'Active' cellular status
            # dup of the original function that issues a get vs. getNext
            snmp_name = snmp_helper.snmp_get_oid2(device, oid=name_oid, display_errors=True)
            dev_name = snmp_helper.snmp_extract(snmp_name)
            # append devName to cell_active_list
            cell_active_list.append(dev_name)
            # write devName to CSV
            csv_row_text = format(str(dev_name))
            csv_writer.writerow([csv_row_text])
            print "writing to CSV: %s" % csv_row_text  # for watching live
        else:
            # ignoring anything without 'Active' status
            continue
    return cell_active_list
开发者ID:meraki,项目名称:provisioning-lib,代码行数:27,代码来源:get_mx_cell_status.py


示例13: main

def main():
    for p in IP:
        for i in oid:
            a_device = (p, COMMUNITY_STRING, SNMP_PORT)
            snmp_data = snmp_get_oid(a_device, oid=i)
            output = snmp_extract(snmp_data)
            print output +"\n"
开发者ID:eaboytes,项目名称:pynet_testz,代码行数:7,代码来源:exercise4.py


示例14: snmp_get

def snmp_get(router, oids):
    data = {}
    for oid_name, oid in oids.items():
        data['router_ip'] = router[0]
        data[oid_name] = snmp_extract(snmp_get_oid(router, oid))
    print(data)
    return data
开发者ID:jbutler42,项目名称:pynet_class,代码行数:7,代码来源:exercise4.py


示例15: snmp_query

def snmp_query(node_info, oid):
    '''Query for OID on node - all necessary parameters should be part of node_info data
    structure
    '''
    snmp_output = snmp_get_oid(node_info, oid)
    output = snmp_extract(snmp_output)

    return output
开发者ID:sockduct,项目名称:pynetans,代码行数:8,代码来源:exercise4.py


示例16: main

def main():
	''''
    Create a script that connects to both routers (pynet-rtr1 and pynet-rtr2) and
    prints out both the MIB2 sysName and sysDescr.
    '''
	a_device = (ip_addr, comm_string, snmp_port)

	snmp_sys_name = snmp_get_oid(a_device, oid='1.3.6.1.2.1.1.5.0')
	snmp_sys_desc = snmp_get_oid(a_device, oid='1.3.6.1.2.1.1.1.0')
	
	output_sys_name = snmp_extract(snmp_sys_name)
	output_sys_desc = snmp_extract(snmp_sys_desc)
	
	print '\nDevice Name:'
	print output_sys_name
	print '\nSystem Description:'
	print output_sys_desc + '\n'
开发者ID:bosatsu,项目名称:pynet_automation,代码行数:17,代码来源:class2_ex4.py


示例17: 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


示例18: get_hostname

def get_hostname(device_ip, community_string):
    a_device=(device_ip, community_string, snmp_port)
    snmp_hostname = snmp_get_oid(a_device, oid='.1.3.6.1.2.1.1.5.0', display_errors=True)
    output = snmp_extract(snmp_hostname)
    if output == "No Such Instance currently exists at this OID":
        print 'No Such OID'
        sys.exit()
    else:
        hostname=output
        return hostname
开发者ID:aroramanish2009,项目名称:scripts,代码行数:10,代码来源:Cisco_ios_check_available_ports.py


示例19: main

def main():

    pynet_rtr1=(IP,COMMUNITY_STRING,7961)
    pynet_rtr2=(IP,COMMUNITY_STRING,8061)

    for a_device in (pynet_rtr1,pynet_rtr2):
        for oid_data in (SYS_DESCRP,SYS_NAME):
            snmp_data=snmp_get_oid(a_device,oid=oid_data)
            output=snmp_extract(snmp_data)
            print '\n'
            print output
开发者ID:munirmurad2165,项目名称:python-adv-course,代码行数:11,代码来源:testw2p3c.py


示例20: get_total_port

def get_total_port(device_ip, community_string):
    a_device=(device_ip, community_string, snmp_port)
    ifcount = 0
    for i in range(1,1000):
        snmp_ifType = snmp_get_oid(a_device, oid='.1.3.6.1.2.1.2.2.1.3.' + `i` , display_errors=True)
        output = snmp_extract(snmp_ifType)
        if output == "No Such Instance currently exists at this OID":
            return ifcount
            break
        else:
            ifcount = ifcount + 1
开发者ID:aroramanish2009,项目名称:scripts,代码行数:11,代码来源:Cisco_ios_check_available_ports.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python snmp_helper.snmp_get_oid_v3函数代码示例发布时间:2022-05-27
下一篇:
Python snmp_helper.snmp_extract函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap