Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- import re
- from noc.sa.models import *
- rx_line = re.compile(
- 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)
- list_f = open('/opt/noc/obj.txt', 'r')
- file_list = list_f.read()
- list_f.close()
- # Build list of NOC monitored hosts:
- mo_list = []
- for mo in tuple(ManagedObject.objects.filter(
- administrative_domain=1)):
- mo_list.append(mo.address.encode('UTF-8'))
- for match in rx_line.finditer(file_list):
- IP = match.group("IP")
- if IP not in mo_list:
- name = match.group("name")
- is_managed = True
- admin_domain = 1
- activator_id = 1
- profile = 'DLink.DxS'
- scheme=0
- login = 'admin'
- passwd = 'xxxxxx'
- super_password = ''
- remote_path = ''
- trap_community = 'public'
- snmp_ro = 'public'
- snmp_rw = ''
- description = match.group("date")
- tags = ''
- ManagedObject(name=name,
- is_managed=is_managed,
- administrative_domain_id=admin_domain,
- activator_id=activator_id,
- profile_name=profile,
- object_profile_id=1,
- shape='Workgroup Switch',
- scheme=scheme,
- address=IP,
- user=login,
- password=passwd,
- super_password=super_password,
- remote_path=remote_path,
- trap_source_ip=IP,
- trap_community=trap_community,
- is_configuration_managed=is_managed,
- repo_path=IP,
- snmp_ro=snmp_ro,
- snmp_rw=snmp_rw,
- description=description,
- max_scripts=2,
- vc_domain_id=1,
- tags=tags).save()
Advertisement
Add Comment
Please, Sign In to add comment