本文整理汇总了Python中ralph.scan.plugins.get_base_result_template函数的典型用法代码示例。如果您正苦于以下问题:Python get_base_result_template函数的具体用法?Python get_base_result_template怎么用?Python get_base_result_template使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了get_base_result_template函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: scan_address
def scan_address(ip_address, **kwargs):
if kwargs.get('http_family') not in ('sscccc',):
raise NoMatchError("It's not an ONStor.")
if 'nx-os' in (kwargs.get('snmp_name', '') or '').lower():
raise NoMatchError("Incompatible Nexus found.")
user = SETTINGS.get('user')
password = SETTINGS.get('password')
messages = []
result = get_base_result_template('ssh_onstor', messages)
if not user or not password:
result['status'] = 'error'
messages.append(
'Not configured. Set SSH_ONSTOR_USER and SSH_ONSTOR_PASSWORD in '
'your configuration file.',
)
else:
try:
device_info = _ssh_onstor(ip_address, user, password)
except ConnectionError as e:
result['status'] = 'error'
messages.append(unicode(e))
else:
result.update({
'status': 'success',
'device': device_info,
})
return result
示例2: scan_address
def scan_address(ip_address, **kwargs):
http_family = kwargs.get('http_family', '')
if http_family not in (
'Sun', 'Thomas-Krenn', 'Oracle-ILOM-Web-Server', 'IBM System X',
):
raise NoMatchError('It is not compatible device for this plugin.')
user = SETTINGS.get('user')
password = SETTINGS.get('password')
messages = []
result = get_base_result_template('ipmi', messages)
if not user or not password:
result['status'] = 'error'
messages.append('Not configured.')
else:
ipmitool = IPMITool(ip_address, user, password)
try:
device_info = _ipmi(ipmitool)
except (AuthError, Error) as e:
result['status'] = 'error'
messages.append(unicode(e))
else:
result.update({
'status': 'success',
'device': device_info,
})
return result
示例3: scan_address
def scan_address(ip_address, **kwargs):
http_family = (kwargs.get('http_family', '') or '').strip()
if http_family and http_family.lower() not in ('dell', 'embedthis-http'):
raise NoMatchError('It is not Dell.')
user = SETTINGS.get('user')
password = SETTINGS.get('password')
messages = []
result = get_base_result_template('idrac', messages)
if not user or not password:
result.update(status='error')
messages.append('Not configured.')
else:
idrac_manager = IDRAC(ip_address, user, password)
try:
device_info = idrac_device_info(idrac_manager)
except Error as e:
result.update(status='error')
messages.append(unicode(e))
else:
device_info['management_ip_addresses'] = [ip_address]
result.update({
'status': 'success',
'device': device_info,
})
return result
示例4: scan_address
def scan_address(ip_address, **kwargs):
http_family = (kwargs.get("http_family", "") or "").strip().lower()
snmp_name = (kwargs.get("snmp_name", "") or "").strip().lower()
if all(("esx" not in http_family, "esx" not in snmp_name, "vmware" not in snmp_name)):
raise NoMatchError("It is not VMWare.")
user = SETTINGS.get("user")
password = SETTINGS.get("password")
messages = []
result = get_base_result_template("vmware", messages)
if not user or not password:
result["status"] = "error"
messages.append("Not configured. Set VMWARE_USER and VMWARE_PASSWORD in your " "configuration file.")
else:
try:
server_conn = _connect(ip_address, user, password)
except VIApiException as e:
result["status"] = "error"
messages.append(unicode(e))
else:
try:
if "vcenter" in server_conn.get_server_type().lower():
raise NoMatchError(
"It is `VMware vCenter Server`. To save real "
"hypervisor - VM connecion you should scan only "
"VMware ESXi servers."
)
device_info = _vmware(server_conn, ip_address, messages)
finally:
server_conn.disconnect()
result.update({"status": "success", "device": device_info})
return result
示例5: scan_address
def scan_address(ip_address, **kwargs):
if 'nx-os' in (kwargs.get('snmp_name') or '').lower():
raise NoMatchError('Incompatible Nexus found.')
if kwargs.get('http_family') not in ('Proxmox', 'Proxmox1'):
raise NoMatchError('It is not Proxmox 1.')
user = SETTINGS.get('user')
password = SETTINGS.get('password')
messages = []
result = get_base_result_template('ssh_proxmox', messages)
if not user or not password:
result['status'] = 'error'
messages.append(
'Not configured. Set SSH_USER and SSH_PASSWORD in your '
'configuration file.',
)
else:
try:
device_info = _ssh_proxmox(ip_address, user, password)
except (ConnectionError, NoMatchError) as e:
result['status'] = 'error'
messages.append(unicode(e))
else:
result.update({
'status': 'success',
'device': device_info,
})
return result
示例6: scan_address
def scan_address(ip_address, **kwargs):
snmp_name = kwargs.get("snmp_name", "") or ""
http_family = kwargs.get("http_family", "") or ""
if (snmp_name and "juniper" not in snmp_name.lower()) and (
http_family and http_family.strip().lower() not in ("juniper",)
):
raise NoMatchError("It is not Juniper.")
user = SETTINGS.get("user")
password = SETTINGS.get("password")
messages = []
result = get_base_result_template("ssh_juniper", messages)
if not user or not password:
result["status"] = "error"
messages.append("Not configured. Set SSH_SSG_USER and SSH_SSG_PASSWORD in your " "configuration file.")
else:
try:
ssh = _connect_ssh(ip_address, user, password)
except ConnectionError as e:
result["status"] = "error"
messages.append(unicode(e))
else:
try:
device_info = _ssh_juniper(ssh, ip_address)
finally:
ssh.close()
result.update({"status": "success", "device": device_info})
return result
示例7: scan_address
def scan_address(ip_address, **kwargs):
snmp_name = kwargs.get('snmp_name', '')
snmp_version = kwargs.get('snmp_version', '2c') or '2c'
if snmp_version == '3':
snmp_community = SETTINGS['snmp_v3_auth']
else:
snmp_community = str(kwargs['snmp_community'])
messages = []
result = get_base_result_template('snmp_macs', messages)
try:
device_info = _snmp_mac(
ip_address,
snmp_name,
snmp_community,
snmp_version,
messages,
)
except Error as e:
messages.append(unicode(e))
result.update(status="error")
else:
result.update({
'status': 'success',
'device': device_info,
})
return result
示例8: scan_address
def scan_address(ip_address, **kwargs):
http_family = (kwargs.get('http_family', '') or '')
if http_family and http_family.strip().lower() not in ('juniper',):
raise NoMatchError('It is not Juniper.')
user = SETTINGS.get('user')
password = SETTINGS.get('password')
messages = []
result = get_base_result_template('ssh_juniper', messages)
if not user or not password:
result['status'] = 'error'
messages.append(
'Not configured. Set SSH_SSG_USER and SSH_SSG_PASSWORD in your '
'configuration file.',
)
else:
try:
ssh = _connect_ssh(ip_address, user, password)
except ConnectionError as e:
result['status'] = 'error'
messages.append(unicode(e))
else:
try:
device_info = _ssh_juniper(ssh, ip_address)
finally:
ssh.close()
result.update({
'status': 'success',
'device': device_info,
})
return result
示例9: scan_address
def scan_address(ip_address, **kwargs):
if 'nx-os' in (kwargs.get('snmp_name', '') or '').lower():
raise NoMatchError('Incompatible Nexus found.')
kwargs['guessmodel'] = gvendor, gmodel = guessmodel.guessmodel(**kwargs)
if gvendor != 'Cisco' or gmodel not in ('',):
raise NoMatchError('It is not Cisco.')
if not SSH_USER or not SSH_PASS:
raise NotConfiguredError(
"SSH not configured in plugin {}.".format(__name__),
)
ssh = _connect_ssh(ip_address, SSH_USER, SSH_PASS)
try:
lines = ssh.asa_command(
"show version | grep (^Hardware|Boot microcode|^Serial|address is)"
)
finally:
ssh.close()
pairs = parse.pairs(lines=[line.strip() for line in lines])
sn = pairs.get('Serial Number', None)
model, ram, cpu = pairs['Hardware'].split(',')
boot_firmware = pairs['Boot microcode']
macs = []
for i in xrange(99):
try:
junk, label, mac = pairs['%d' % i].split(':')
except KeyError:
break
mac = mac.split(',', 1)[0]
mac = mac.replace('address is', '')
mac = mac.replace('.', '').upper().strip()
label = label.strip()
if mac.replace(':', '').upper()[:6] not in MAC_PREFIX_BLACKLIST:
macs.append(mac)
ram_size = re.search('[0-9]+', ram).group()
cpu_match = re.search('[0-9]+ MHz', cpu)
cpu_speed = cpu_match.group()[:-4]
cpu_model = cpu[:cpu_match.start()][4:].strip()
result = get_base_result_template('ssh_cisco_asa')
result.update({
'status': 'success',
'device': {
'model_name': 'Cisco ' + model,
'type': str(DeviceType.firewall),
'mac_addresses': macs,
'boot_firmware': boot_firmware,
'management_ip_addresses': [ip_address],
'memory': [{
'size': int(ram_size),
}],
'processors': [{
'model_name': cpu_model,
'speed': int(cpu_speed),
'family': cpu_model,
}],
},
})
if sn not in SERIAL_BLACKLIST:
result['device']['serial_number'] = sn
return result
示例10: scan_address
def scan_address(ip_address, **kwargs):
snmp_name = kwargs.get("snmp_name", "") or ""
if "nx-os" in snmp_name.lower():
raise NoMatchError("Incompatible nexus found")
device = run_ssh_ganeti(ip_address)
ret = {"status": "success", "device": device}
tpl = get_base_result_template("ssh_ganeti")
tpl.update(ret)
return tpl
示例11: scan_address
def scan_address(ip_address, **kwargs):
http_family = kwargs.get('http_family', '') or ''
messages = []
result = get_base_result_template('software', messages)
result['status'] = 'success'
software = _detect_software(ip_address, http_family)
if software:
result['installed_software'] = software
return result
示例12: scan_address
def scan_address(ip_address, **kwargs):
messages = []
result = get_base_result_template('ssh_ibm_bladecenter', messages)
device = _blade_scan(ip_address)
if not device:
raise DeviceError("Malformed bladecenter device: %s" % ip_address)
result['device'] = device
result['status'] = 'success'
return result
示例13: scan_address
def scan_address(ip_address, **kwargs):
if 'nx-os' in (kwargs.get('snmp_name', '') or '').lower():
raise NoMatchError('Incompatible Nexus found.')
if kwargs.get('http_family') not in ('Unspecified', 'Cisco'):
raise NoMatchError('It is not Cisco.')
ssh = _connect_ssh(ip_address)
hostname = network.hostname(ip_address)
try:
ssh.cisco_command('terminal length 500')
mac = '\n'.join(ssh.cisco_command(
"show version | include Base ethernet MAC Address",
))
raw = '\n'.join(ssh.cisco_command("show inventory"))
subswitches = get_subswitches(
ssh.cisco_command("show version"), hostname, ip_address
)
finally:
ssh.close()
matches = re.match(
'Base ethernet MAC Address\s+:\s*([0-9aA-Z:]+)', mac)
if matches.groups():
mac = matches.groups()[0]
inventory = list(cisco_inventory(raw))
dev_inv, parts = inventory[0], inventory[1:]
sn = dev_inv['sn']
result = get_base_result_template('ssh_cisco_catalyst')
if subswitches:
# virtual switch doesn't have own unique id, reuse first from stack
sn += '-virtual'
model_name = 'Virtual Cisco Catalyst %s' % dev_inv['pid']
model_type = DeviceType.switch_stack
else:
model_name = 'Cisco Catalyst %s' % dev_inv['pid']
model_type = DeviceType.switch
result.update({
'status': 'success',
'device': {
'hostname': hostname if hostname else ip_address,
'model_name': model_name,
'type': model_type.raw,
'management_ip_addresses': [ip_address],
'parts': [{
'serial_number': part['sn'],
'name': part['name'],
'label': part['descr'],
} for part in parts],
},
})
if sn not in SERIAL_BLACKLIST:
result['device']['serial_number'] = sn
if subswitches:
result['device']['subdevices'] = subswitches
else:
result['device']['mac_addresses'] = [MACAddressField.normalize(mac)]
return result
示例14: scan_address
def scan_address(ip_address, **kwargs):
if 'nx-os' in kwargs.get('snmp_name', '').lower():
raise NoMatchError("Incompatible nexus found")
device = run_ssh_ganeti(ip_address)
ret = {
'status': 'success',
'device': device,
}
tpl = get_base_result_template('ssh_ganeti')
tpl.update(ret)
return tpl
示例15: scan_address
def scan_address(address, **kwargs):
messages = []
data = get_base_result_template('dns_hostname', messages)
hostname = network.hostname(address)
if hostname:
data['device'] = {
'hostname': hostname,
}
data['status'] = 'success'
else:
data['status'] = 'error'
return data