hostinfo.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #!/usr/bin/python2.7
  2. # -*- coding: utf-8 -*-
  3. """
  4. Created on Fri Nov 30 15:28:17 2018
  5. @author: dufs
  6. id ip_address port account password pwdkey
  7. """
  8. import logging.config
  9. import ConfigParser
  10. import decodepasswd as decpwd
  11. import databaseconn as dbcn
  12. #logging.config.fileConfig('conf/logging.conf')
  13. #logger = logging.getLogger(__name__)
  14. logger = logging.getLogger('autocheck.hostinfo')
  15. def get_hostinfo(if_decodepasswd=True):
  16. '''
  17. '''
  18. try:
  19. cf = ConfigParser.SafeConfigParser()
  20. cf.read('conf/autocheck.conf')
  21. db_url=cf.get('db', 'url')
  22. nls_lang=cf.get('db', 'nls_lang')
  23. except Exception as e:
  24. logger.error('parse config file error: ' + str(e) , exc_info=True)
  25. return [-1, ]
  26. if len(nls_lang)==0:
  27. nls_lang='SIMPLIFIED CHINESE_CHINA.UTF8'
  28. v_sql='''select id,ip_address,nvl(port,0),nvl(account,''),nvl(password,''),nvl(pwdkey,'') from isp_autoinspection_device where ip_address is not null'''
  29. try:
  30. dbclt=dbcn.DataBaseConn(db_url, nls_lang=nls_lang)
  31. except Exception as e:
  32. logger.error('connect db faild : ' + str(e) , exc_info=True)
  33. return [-1, ]
  34. try:
  35. v_set=set()
  36. res=dbclt.exec_sql(v_sql)
  37. #logger.info('get hostinfo total %d', len(res))
  38. if if_decodepasswd==True:
  39. dp=decpwd.DecodePassword()
  40. for dev_id, dev_ip, port, account, password, pwdkey in res:
  41. logger.debug("id = %s, ip = %s, port = %d, account = %s, password = %s, pwdkey = %s" % (dev_id, dev_ip, int(port), account, password, pwdkey))
  42. if if_decodepasswd==True:
  43. desPass=dp.getdecodePassword(password, pwdkey)
  44. else:
  45. desPass=password
  46. v_set.add(tuple([dev_id, dev_ip, port, account, desPass]))
  47. #logger.debug("id = %s, ip = %s, port = %d, account = %s, password = %s" % (dev_id, dev_ip, int(port), account, desPass))
  48. return [0, v_set]
  49. except Exception as e:
  50. logger.error('get Exception : ' + str(e) , exc_info=True)
  51. return [-99, ]
  52. finally:
  53. dbclt.close_connect()