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
#11
Hi Buran,

this is my full code

#!/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()
        try:
# 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)]
            fans_status = ['Fail' if fan.value < 2000 else 'Ok' for fan in session.get_bulk(fans_oids)]
            temp_status = ['Cool' if temp.value < 50 else 'Hot' for temp in session.get_bulk(temps_oids)]
            data = fans_status
            data.extend(temp_status)
            print('{} {} {} {} {} {} {} {}'.format(sr_no, ip, *data))
        except Exception as excp:
            print('Connection time out!')
            print(excp)
Reply


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

Possibly Related Threads…
Thread Author Replies Views Last Post
  code isnt working. nezercat33 1 680 Mar-14-2025, 03:45 AM
Last Post: deanhystad
  Simple code not working properly tmv 2 559 Feb-28-2025, 09:27 PM
Last Post: deanhystad
  I'm new to Python - can someone help with this code as it is not working? lminc123 1 560 Feb-13-2025, 06:13 PM
Last Post: lminc123
  my code is not working erTurko 1 693 Nov-11-2024, 08:43 AM
Last Post: buran
  Coding help required in Python using VS Code KakashiSenpai 3 1,162 Jul-04-2024, 12:32 PM
Last Post: jefsummers
  Suggestion on how to speed up this code? sawtooth500 1 1,082 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 2,400 Jul-22-2023, 10:21 PM
Last Post: Pedroski55
  code not working when executed from flask app ThomasDC 1 3,576 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,847 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 2,250 Oct-13-2022, 08:09 PM
Last Post: deanhystad

Forum Jump:

User Panel Messages

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