Python Forum
working code, suggestion required for improvement
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
working code, suggestion required for improvement
#16
Hi Buran,

changed some code... used snmp.get instead of snmp.get_bulk

now i am getting below report


#!/usr/bin/python
from easysnmp import Session
community = 'public'
with open('zyxeldslam.txt') as ipfile:
    for sr_no, line in enumerate(ipfile, start=1):
        ip = line.strip()
# Create an SNMP session to be used for all our requests
        session = Session(hostname=ip, community=community, version=2)
# You may retrieve an individual OID using an SNMP GET
        fan_oids_templ = '1.3.6.1.4.1.890.1.5.13.1.2.1.1.2.0.{}'
        temp_oids_templ = '1.3.6.1.4.1.890.1.5.13.1.2.3.1.2.0.0.{}'
        fans_oids = [fan_oids_templ.format(i) for i in range(1,4)]
        temps_oids = [temp_oids_templ.format(i) for i in range(1,4)]
        fan_values = [fan.value for fan in session.get(fans_oids)]
        temp_status = [temp.value for temp in session.get(temps_oids)]
        print (fan_values)
        print (temp_status)
output is as below

Output:
[root@localhost scripts]# python zyxelheath.py [u'4320', u'4386', u'4354'] [u'42', u'34', u'35'] [u'3958', u'4020', u'4032'] [u'41', u'32', u'33']
can you please help to print like Sr No, IP, Fan1 Fan2 Fan3 Temp1 Temp2 Temp3
Reply


Messages In This Thread
RE: working code, suggestion required for improvement - by anna - Dec-29-2017, 10:32 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Suggestion on how to speed up this code? sawtooth500 1 237 May-04-2024, 07:13 PM
Last Post: sawtooth500
  New to Python - Not sure why this code isn't working - Any help appreciated TheGreatNinx 4 1,008 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 939 Jul-18-2023, 07:16 AM
Last Post: ThomasDC
  I am new to python and Could someone please explain how this below code is working? kartheekdas 2 1,054 Dec-19-2022, 05:24 PM
Last Post: kartheekdas
Exclamation My code is not working as I expected and I don't know why! Marinho 4 1,122 Oct-13-2022, 08:09 PM
Last Post: deanhystad
  My Code isn't working... End3r 4 1,978 Mar-21-2022, 10:12 AM
Last Post: End3r
  Can you give me some suggestion about PCEP Newbie1114 0 1,047 Oct-14-2021, 03:02 PM
Last Post: Newbie1114
  instagram followers name without suggestion for you jacklee26 1 3,213 Oct-02-2021, 04:57 AM
Last Post: ndc85430
  Random coordinate generator speed improvement saidc 0 2,075 Aug-01-2021, 11:09 PM
Last Post: saidc
  I don't undestand why my code isn't working. RuyCab 2 2,013 Jun-17-2021, 03:06 PM
Last Post: RuyCab

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020