Guest User

Untitled

a guest
Mar 26th, 2014
133
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2.  
  3. import re
  4. from noc.sa.models import *
  5.  
  6. rx_line = re.compile(
  7. r"^(?P<street>\S+)\s+(?P<house>(\d+\s\S|\d+))\s+(?P<ring>\S+)\s+(?P<pod>\d+)\s+(?P<IP>\S+)\s+(?P<name>\S+)\s+(?P<date>\S+)$", re.MULTILINE)
  8.  
  9. list_f = open('/opt/noc/obj.txt', 'r')
  10. file_list = list_f.read()
  11. list_f.close()
  12.  
  13. # Build list of NOC monitored hosts:
  14. mo_list = []
  15. for mo in tuple(ManagedObject.objects.filter(
  16. administrative_domain=1)):
  17. mo_list.append(mo.address.encode('UTF-8'))
  18.  
  19. for match in rx_line.finditer(file_list):
  20. IP = match.group("IP")
  21. if IP not in mo_list:
  22. name = match.group("name")
  23. is_managed = True
  24. admin_domain = 1
  25. activator_id = 1
  26. profile = 'DLink.DxS'
  27. scheme=0
  28. login = 'admin'
  29. passwd = 'xxxxxx'
  30. super_password = ''
  31. remote_path = ''
  32. trap_community = 'public'
  33. snmp_ro = 'public'
  34. snmp_rw = ''
  35. description = match.group("date")
  36. tags = ''
  37.  
  38. ManagedObject(name=name,
  39. is_managed=is_managed,
  40. administrative_domain_id=admin_domain,
  41. activator_id=activator_id,
  42. profile_name=profile,
  43. object_profile_id=1,
  44. shape='Workgroup Switch',
  45. scheme=scheme,
  46. address=IP,
  47. user=login,
  48. password=passwd,
  49. super_password=super_password,
  50. remote_path=remote_path,
  51. trap_source_ip=IP,
  52. trap_community=trap_community,
  53. is_configuration_managed=is_managed,
  54. repo_path=IP,
  55. snmp_ro=snmp_ro,
  56. snmp_rw=snmp_rw,
  57. description=description,
  58. max_scripts=2,
  59. vc_domain_id=1,
  60. tags=tags).save()
Advertisement
Add Comment
Please, Sign In to add comment