Example #1
0
def append(args):

    argument_node = args.ip
    device = snmp(argument_node)
    new_node = yaml.dump(device, default_flow_style=False)
    with open('/database/nodes.yaml', 'a') as f:
        f.write(new_node)

    database = process_nodes()
    database.sort()
    updated_database = yaml.dump(database, default_flow_style=False)
    with open('/database/nodes.yaml', 'w') as f:
        f.write(updated_database)

    print("[+] NEW NODE SUCCESSFULLY APPENDED TO DATABASE")
Example #2
0
def append(args):

    argument_node = args.ip
    device = snmp(argument_node)
    new_node = yaml.dump(device, default_flow_style=False)
    with open('/database/nodes.yaml', 'a') as file:
        file.write(new_node)

    database = process_nodes()
    database.sort(key=sorted)
    updated_database = yaml.dump(database, default_flow_style=False)
    with open('/database/nodes.yaml', 'w') as file:
        file.write('---\n')
        file.write(updated_database)

    print('[\u2713] SNMP DISCOVERY SUCCESSFUL')
    print('[+] NEW NODE APPENDED TO DATABASE')
Example #3
0
def discover(args):
	argument_node = args.node
	database = process_nodes()
	match_node = search_node(argument_node,database)
	"""
		:param node_object: All node(s) in the database with all attributes.
		:type node_object: list
	
		:param match_node: Nodes that matches the arguements passed in by user.
		:type match_node: list
	"""
	if len(match_node) == 0:
		print('+ No matching node(s) found in database.')
		return None
	else:
		for node in match_node:
			print('{}'.format(node)) 
			index = 0
			try:
				for element in database:
					if element['name'] == node or element['mgmt_ip4'] == node:
						break
					else:
						index = index + 1
				"""
					Identified node from list.
				"""
				device = snmp(node)
				print('')
			except Exception as error:
				print('SNMP query timeout. Please ensure that FQDN or IP address is reachable via SNMP.')
		for attribute in database[index]:
			if 'created_at' == attribute or 'created_by' == attribute:
				continue
			else:
				database[index][attribute] = device[0][attribute]
		database[index]['updated_at'] = timestamp()
		database[index]['updated_by'] = '{}'.format(os.environ.get('USER'))
		updated_database = yaml.dump(database,default_flow_style = False)
		with open('{}/superloop_code/database/nodes.yaml'.format(get_home_directory()),'w') as file:
			file.write('---\n')
			file.write(updated_database)
		print('+ SNMP discovery successful.')
Example #4
0
def append(args):
	argument_node = args.node
	database = process_nodes()
	index = 0
	match_node = []
	mgmt_ip4 = get_resolve_hostname(argument_node)
#	try:
	"""
		Check if new node currently exist in database.
	"""
	print(database)
	for node in database:
		if mgmt_ip4 == node['mgmt_ip4']:
			match_node.append('MATCH')
			break
		else:
			continue
	try:
		if 'MATCH' in match_node:
			print('+ Node currently present in database.')
		else:
			device = snmp(argument_node)
			new_node = yaml.dump(device,default_flow_style = False)
			with open('{}/superloop_code/database/nodes.yaml'.format(get_home_directory()),'a') as file:
				file.write(new_node)
			database = process_nodes()
			sorted_database = sortdb(database)
			updated_database = yaml.dump(sorted_database,default_flow_style = False)
			with open('{}/superloop_code/database/nodes.yaml'.format(get_home_directory()),'w') as file:
				file.write('---\n')
				file.write(updated_database)
			print('+ SNMP discovery successful.')
			print('+ New node appended to database.')
	except FileNotFoundError as error:
			print('FileNotFoundError: file cannot be found')
			print(error)
#	except Exception as error:
#		print('SNMP query timeout. Please ensure that FQDN or IP address is reachable via SNMP.')

	return None
Example #5
0
def snmp_node_discovery_extract(node):
    node_items = None
    nodeinfor = _snmp_node_discovery(node)
    if nodeinfor:
        #convert nodeinfor into more pretty printing format
        snmpass = snmp.snmp()

        prettyinfor = []
        for entry in nodeinfor:
            for name, val in entry:
                prettyentry = [snmpass.oid2name(name), val.prettyPrint()]
                prettyinfor.append(prettyentry)

        #extract data, then save to Node class
        node_item_terms = ['sysDescr', 'sysUpTime',
                        'sysName', 'ifPhysAddress',
                        'entPhysicalDescr', 'entPhySensorType',
                        'entPhySensorScale', 'entPhySensorPrecision',
                        'entPhySensorOperStatus', 'entPhySensorUnitsDisplay',
                        'entPhySensorValueUpdateRate',]
        node_items_items = []
        [node_items_items.append(_snmp_extract_val(prettyinfor, item_term)) for item_term in node_item_terms]

        #create json data
        node_items = {}
        node_items['sys_descr'] = node_items_items[0]
        node_items['sys_uptime'] = node_items_items[1]
        node_items['sys_name'] = node_items_items[2]

        addr_list = []
        addr_str = node_items_items[3]
        #dirty hack to get rid of 0x.... in address
        if addr_str[0:2] == '0x':
            addr_str = addr_str[2:]
        for i in range(len(addr_str)/2):
            addr_list.append(addr_str[(i*2):(i*2+2)])
        addr = ':'.join(j for j in addr_list)
        print addr
        node_items['if_phys_addr'] = addr

        items = node_items_items[4].split(";")
        physical = []
        [physical.append(item) for item in items]
        node_items['ent_physical_descr'] = physical

        items = node_items_items[5].split(";")
        physical = []
        [physical.append(MIB_ENTITY_SENSOR_TYPE.get(item)) for item in items]
        node_items['physensor_type'] = physical

        items = node_items_items[6].split(";")
        physical = []
        [physical.append(MIB_ENTITY_SENSOR_SCALE.get(item)) for item in items]
        node_items['physensor_scale'] = physical

        items = node_items_items[7].split(";")
        physical = []
        [physical.append(item) for item in items]
        node_items['physensor_precision'] = physical

        items = node_items_items[8].split(";")
        physical = []
        [physical.append(MIB_ENTITY_SENSOR_OPERATION.get(item)) for item in items]
        node_items['physensor_oper_status'] = physical

        items = node_items_items[9].split(";")
        physical = []
        [physical.append(item) for item in items]
        node_items['physensor_unit_display'] = physical

        items = node_items_items[10].split(";")
        physical = []
        [physical.append(item) for item in items]
        node_items['physensor_value_update_rate'] = physical

    return node_items
Example #6
0
#!/usr/bin/env python
import snmp
import apcmib

s = snmp.snmp(DestHost="172.25.88.150",oid=apcmib.BatteryCapacity)
result = s.query()
print "Battery Capacity:", result[0]

s.oid=apcmib.BatteryTimeRemaining
result = s.query()
print "Battery Time Reamining(min):", int(result[0])/6000

s.oid=apcmib.InputLineVoltage
result = s.query()
print "Input Line Voltage:", result[0]

s.oid=apcmib.InputMaxLineVoltage
result = s.query()
print "Input Max Line Voltage:", result[0]

s.oid=apcmib.InputMinLineVoltage
result = s.query()
print "Input Min Line Voltage:", result[0]
Example #7
0
                }
            },
            "snmp_parameters":{ 
                "environment_code": "demo",  
                "radius_snmp_community": "COM-NAME-RADIUS",
                "snmp_community_name": "COM-NAME",
                "snmp_sv_prod": "1.1.1.1",
                "snmp_trap_group": "TRAP-GROUP",
                "snmp_sv_failover": "2.2.2.2",
                "Opennms_DC_dest1": "3.3.3.3",
                "Opennms_DC_dest2": "4.4.4.4",
                "Opennms_DC_dest3": "5.5.5.5",
                "Opennms_DC_dest4": "6.6.6.6",
                "snmp_sv_macmove": "1.2.3.4",
                "snmp_community_macmove": "MACMOVE-NAME",
                "region.radius_sv_primary": "1.2.2.2",
                "region.radius_sv_secondary": "1.3.3.3",
                "region.radius_sv_tertiary": "1.4.4.4"
            }
        }

        if choice == 1:
            #Implement NTP configuration
            ntp(username, password, ip_addr, restconf_port, headers, confgen_params, confgen_response)
        elif choice == 2:
            #Implement SNMP configuration
            snmp(username, password, ip_addr, restconf_port, headers, confgen_params, confgen_response)
        else:
           #Implement Logging configuration
           syslog(username, password, ip_addr, restconf_port, headers, confgen_params, confgen_response)
Example #8
0
	def config_web(cfg={}):
		# override Cherrypy's default session behaviour

		application_conf = {
			'/' : {
				'tools.staticdir.root': _curdir,
				'tools.staticdir.on' : True,
				'tools.staticdir.dir' : ".",
				'tools.sessions.on'  : True,
				'tools.sessions.storage_type' : "file",
				'tools.sessions.storage_path' : "/tmp/",
				'tools.sessions.timeout' : 60,
				'tools.sessions.locking' : 'explicit',
				'tools.auth.on': True,
				'tools.encode.on' : True,
				'tools.encode.encoding': "utf-8"
			},
			'/favicon.ico' : {
				'tools.staticfile.on' : True,
				'tools.staticfile.filename' : os.path.join(_curdir,'/image/favicon.ico')
			},
			'/css' : {
				'tools.staticdir.on' : True,
				'tools.staticdir.dir' : "css"
			},
			'/script' : {
				'tools.staticdir.on' : True,
				'tools.staticdir.dir' : "script"
			},
			'/image' : {
				'tools.staticdir.on' : True,
				'tools.staticdir.dir' : "image"
			},
		}

		#No Root controller as we provided all our own.
		#cherrypy.tree.mount(root=None, config=config)
		root = Login()
		root.logout = AuthController().logout
		root.xteralink = Interface()
		root.system = summary()
		root.system.summary = summary()
		root.system.dns = dns()
		root.system.network_header = network_header()
		root.system.network = network()
		root.system.wan_detection = wan_detection()
		root.system.fqdn = fqdn()
		root.system.ip_group = ip_group()
		root.system.service_group = service_group()
		root.system.diagnostic_tools = diagnostic_tools()
		root.system.arp_table = arp_table()
		root.system.date_time = date_time()
		root.system.ddns = ddns()
		root.system.administration = administration()
		root.service = dhcp_lan()
		root.service.dhcp_lan = dhcp_lan()
		root.service.dhcp_dmz = dhcp_dmz()
		root.service.virtual_server = virtual_server()
		root.service.firewall = firewall()
		root.service.connection_limit = connection_limit()
		root.service.auto_routing = auto_routing()
		root.service.nat = nat()
		root.service.snmp = snmp()
		root.statistics = stat_bandwidth_utilization()
		root.statistics.stat_bandwidth_utilization = stat_bandwidth_utilization()
		root.statistics.stat_wan_detection = stat_wan_detection()
		root.statistics.stat_dhcp_lan = stat_dhcp_lan()
		root.statistics.stat_dhcp_dmz = stat_dhcp_dmz()
		root.statistics.stat_fqdn = stat_fqdn()
		root.log = view();
		root.log.view = view();
		root.log.syslog = syslog();
		cherrypy.tree.mount(root, "/", config=application_conf)

		cherrypy.server.unsubscribe()
		server1 = cherrypy._cpserver.Server()
		server1.socket_port = 443
		server1._socket_host = '0.0.0.0'
		server1.ssl_certificate = '/usr/local/conf/server.crt'
		server1.ssl_private_key = '/usr/local/conf/server.key'
		server1.subscribe()

		server2 = cherrypy._cpserver.Server()
		server2.socket_port = 80
		server2._socket_host = "0.0.0.0"
		server2.subscribe()