1.start.py里的script.run():执行run函数-->

2.script.py run方法-->

3.判断模式MODE(Agent/SSHSALT)-->
4.执行client.py里的Agent/SSHSALT-->

5.分别执行/src/plugins/__init__.py里的exec_plugin对应的

方法(__agent/__salt/__ssh),__init__.py调用settings.py里的配置文件,exec_plugin()方法拆分settings.py里的模块和类,并分别执行
plugins/目录下的basic,board,cpu,disk,memory,nic对应的py文件,这些py文件都要导入相对应的settings.py配置文件

可插拔式的插件

/bin目录

执行流程如下:

start.py
.config.settings加入环境变量
.整个目录加入环境变量
.执行 script.py
.文件导入
{
.默认配置
.自定义配置
} .Agent
{
.实例化类
.执行execute函数-------->{.取数据;.发送给API}
client
} -->取数据{.实例化(插件).执行exec.plugin函数}---------->取数据 {
.实例化插件
.执行process函数(执行命令方式传参数)-->结果调用parse格式化数据
.获取结果
} .数据data{
basic{hostname....}
cpu
memory
Nic
disk
}
获取到数据
.获取主机名
.判断主机文件{
.有没有写入
.如果主机名不同,以文件里的主机名为主
}

sudo MegaCli -PDList -aALL
dmidecode

/bin目录:编写启动文件

import os
import sys
# print(os.environ)#存放当前的环境变量,这就是一个公共的环境变量,在程序的内存里放这么一个字典
os.environ['USER_SETTINGS'] = "config.settings"#往字典里添加一个值
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))#获取项目所在目录的路径
sys.path.append(BASE_DIR)#添加到系统路径sys.path
print(sys.path) from src import script if __name__ == '__main__':
script.run() from src.plugins import PluginManager # 导入__init__.py文件
# server_info = PluginManager.exec_plugin()
# for k,v in server_info.items():
# print(k,v)
# server_info = PluginManager().exec_plugin()
# """
# {
# "cpu": {'status':True,'data': xxxxx},
# "cpu": {'status':True,'data': xxxxx},
# "cpu": {'status':True,'data': xxxxx},
# }
# """
# for k,v in server_info.items():
# print(k,v)
# server_info = PluginManager('c1.com').exec_plugin()
# server_info = PluginManager('c1.com').exec_plugin()

start.py

/config目录,存放配置文件

# from django.conf import global_settings #Django默认配置文件
#替换全局的配置文件
"""
用户自定义配置文件
"""
import os
BASEDIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))#BASEDIR当前路径#F:\project\auto_client
USER = 'root'
PWD = 'pwd' MODE = "AGENT"#SALT,SSH DEBUG = True SSH_USER = "root"
SSH_PWD = "root"
SSH_KEY = "/xxxx/xxxx/xxxx/"#也可以用公钥和私钥
SSH_PORT = PLUGINS_DICT = {
'basic':"src.plugins.basic.Basic",#基本信息
'board':"src.plugins.board.Board",#主板
'cpu':"src.plugins.cpu.Cpu",#CPU信息
'disk':"src.plugins.disk.Disk",#硬盘信息
'memory':"src.plugins.memory.Memory",#内存信息
'nic':"src.plugins.nic.Nic",#网卡信息
}#这是关于模块路径和类名相关的配置文件
#这里跟Django的中间件很相似,但是这里是字典(字典无序),而Django的中间件是列表(列表有序,顺序执行)
#根据这个配置文件找到它自己的类,并执行对应的方法
#如果导入plugins目录,会执行__init__.py文件 # API = "http://www.oldboyedu.com"#API入库的路径
API = "http://127.0.0.1:8000/api/asset.html" #API入库的路径 CERT_PATH = os.path.join(BASEDIR,'config','cert')

settings

c2.com

cert:存储本地正确的主机名

/files目录:

SMBIOS 2.7 present.

Handle 0x0001, DMI type ,  bytes
System Information
Manufacturer: Parallels Software International Inc.
Product Name: Parallels Virtual Platform
Version: None
Serial Number: Parallels-1A 1B CB 3B 4B B0 FF 7E 2B
UUID: 3BCB1B1A--134B-86B0-86FF7E2B2030
Wake-up Type: Power Switch
SKU Number: Undefined
Family: Parallels VM

board.out

processor    :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.84
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management: processor :
vendor_id : GenuineIntel
cpu family :
model :
model name : Intel(R) Xeon(R) CPU E5- v2 @ .10GHz
stepping :
cpu MHz : 2099.921
cache size : KB
physical id :
siblings :
core id :
cpu cores :
apicid :
initial apicid :
fpu : yes
fpu_exception : yes
cpuid level :
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon pebs bts rep_good xtopology nonstop_tsc aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm ida arat xsaveopt pln pts dts tpr_shadow vnmi flexpriority ept vpid fsgsbase smep erms
bogomips : 4199.42
clflush size :
cache_alignment :
address sizes : bits physical, bits virtual
power management:

cpuinfo.out

Adapter #

Enclosure Device ID:
Slot Number:
Drive's postion: DiskGroup: 0, Span: 0, Arm: 0
Enclosure position:
Device Id:
WWN: 5000C5007272C288
Sequence Number:
Media Error Count:
Other Error Count:
Predictive Failure Count:
Last Predictive Failure Event Seq Number:
PD Type: SAS
Raw Size: 279.396 GB [0x22ecb25c Sectors]
Non Coerced Size: 278.896 GB [0x22dcb25c Sectors]
Coerced Size: 278.875 GB [0x22dc0000 Sectors]
Firmware state: Online, Spun Up
Device Firmware Level: LS08
Shield Counter:
Successful diagnostics completion on : N/A
SAS Address(): 0x5000c5007272c289
SAS Address(): 0x0
Connected Port Number: (path0)
Inquiry Data: SEAGATE ST300MM0006 LS08S0K2B5NV
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: .0Gb/s
Link Speed: .0Gb/s
Media Type: Hard Disk Device
Drive Temperature :29C (84.20 F)
PI Eligibility: No
Drive is formatted for PI information: No
PI: No PI
Drive's write cache : Disabled
Port- :
Port status: Active
Port's Linkspeed: 6.0Gb/s
Port- :
Port status: Active
Port's Linkspeed: Unknown
Drive has flagged a S.M.A.R.T alert : No Enclosure Device ID:
Slot Number:
Drive's postion: DiskGroup: 0, Span: 0, Arm: 1
Enclosure position:
Device Id:
WWN: 5000C5007272DE74
Sequence Number:
Media Error Count:
Other Error Count:
Predictive Failure Count:
Last Predictive Failure Event Seq Number:
PD Type: SAS
Raw Size: 279.396 GB [0x22ecb25c Sectors]
Non Coerced Size: 278.896 GB [0x22dcb25c Sectors]
Coerced Size: 278.875 GB [0x22dc0000 Sectors]
Firmware state: Online, Spun Up
Device Firmware Level: LS08
Shield Counter:
Successful diagnostics completion on : N/A
SAS Address(): 0x5000c5007272de75
SAS Address(): 0x0
Connected Port Number: (path0)
Inquiry Data: SEAGATE ST300MM0006 LS08S0K2B5AH
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: .0Gb/s
Link Speed: .0Gb/s
Media Type: Hard Disk Device
Drive Temperature :29C (84.20 F)
PI Eligibility: No
Drive is formatted for PI information: No
PI: No PI
Drive's write cache : Disabled
Port- :
Port status: Active
Port's Linkspeed: 6.0Gb/s
Port- :
Port status: Active
Port's Linkspeed: Unknown
Drive has flagged a S.M.A.R.T alert : No Enclosure Device ID:
Slot Number:
Drive's postion: DiskGroup: 1, Span: 0, Arm: 0
Enclosure position:
Device Id:
WWN: 50025388A075B731
Sequence Number:
Media Error Count:
Other Error Count:
Predictive Failure Count:
Last Predictive Failure Event Seq Number:
PD Type: SATA
Raw Size: 476.939 GB [0x3b9e12b0 Sectors]
Non Coerced Size: 476.439 GB [0x3b8e12b0 Sectors]
Coerced Size: 476.375 GB [0x3b8c0000 Sectors]
Firmware state: Online, Spun Up
Device Firmware Level: 1B6Q
Shield Counter:
Successful diagnostics completion on : N/A
SAS Address(): 0x500056b37789abee
Connected Port Number: (path0)
Inquiry Data: S1SZNSAFA01085L Samsung SSD PRO 512GB EXM01B6Q
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: .0Gb/s
Link Speed: .0Gb/s
Media Type: Solid State Device
Drive: Not Certified
Drive Temperature :25C (77.00 F)
PI Eligibility: No
Drive is formatted for PI information: No
PI: No PI
Drive's write cache : Disabled
Drive's NCQ setting : Disabled
Port- :
Port status: Active
Port's Linkspeed: 6.0Gb/s
Drive has flagged a S.M.A.R.T alert : No Enclosure Device ID:
Slot Number:
Drive's postion: DiskGroup: 1, Span: 0, Arm: 1
Enclosure position:
Device Id:
WWN: 50025385A02A074F
Sequence Number:
Media Error Count:
Other Error Count:
Predictive Failure Count:
Last Predictive Failure Event Seq Number:
PD Type: SATA
Raw Size: 476.939 GB [0x3b9e12b0 Sectors]
Non Coerced Size: 476.439 GB [0x3b8e12b0 Sectors]
Coerced Size: 476.375 GB [0x3b8c0000 Sectors]
Firmware state: Online, Spun Up
Device Firmware Level: 6B0Q
Shield Counter:
Successful diagnostics completion on : N/A
SAS Address(): 0x500056b37789abef
Connected Port Number: (path0)
Inquiry Data: S1AXNSAF912433K Samsung SSD PRO Series DXM06B0Q
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: .0Gb/s
Link Speed: .0Gb/s
Media Type: Solid State Device
Drive: Not Certified
Drive Temperature :28C (82.40 F)
PI Eligibility: No
Drive is formatted for PI information: No
PI: No PI
Drive's write cache : Disabled
Drive's NCQ setting : Disabled
Port- :
Port status: Active
Port's Linkspeed: 6.0Gb/s
Drive has flagged a S.M.A.R.T alert : No Enclosure Device ID:
Slot Number:
Drive's postion: DiskGroup: 1, Span: 1, Arm: 0
Enclosure position:
Device Id:
WWN: 50025385A01FD838
Sequence Number:
Media Error Count:
Other Error Count:
Predictive Failure Count:
Last Predictive Failure Event Seq Number:
PD Type: SATA
Raw Size: 476.939 GB [0x3b9e12b0 Sectors]
Non Coerced Size: 476.439 GB [0x3b8e12b0 Sectors]
Coerced Size: 476.375 GB [0x3b8c0000 Sectors]
Firmware state: Online, Spun Up
Device Firmware Level: 5B0Q
Shield Counter:
Successful diagnostics completion on : N/A
SAS Address(): 0x500056b37789abf0
Connected Port Number: (path0)
Inquiry Data: S1AXNSAF303909M Samsung SSD PRO Series DXM05B0Q
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: .0Gb/s
Link Speed: .0Gb/s
Media Type: Solid State Device
Drive: Not Certified
Drive Temperature :27C (80.60 F)
PI Eligibility: No
Drive is formatted for PI information: No
PI: No PI
Drive's write cache : Disabled
Drive's NCQ setting : Disabled
Port- :
Port status: Active
Port's Linkspeed: 6.0Gb/s
Drive has flagged a S.M.A.R.T alert : No Enclosure Device ID:
Slot Number:
Drive's postion: DiskGroup: 1, Span: 1, Arm: 1
Enclosure position:
Device Id:
WWN: 50025385A02AB5C9
Sequence Number:
Media Error Count:
Other Error Count:
Predictive Failure Count:
Last Predictive Failure Event Seq Number:
PD Type: SATA
Raw Size: 476.939 GB [0x3b9e12b0 Sectors]
Non Coerced Size: 476.439 GB [0x3b8e12b0 Sectors]
Coerced Size: 476.375 GB [0x3b8c0000 Sectors]
Firmware state: Online, Spun Up
Device Firmware Level: 6B0Q
Shield Counter:
Successful diagnostics completion on : N/A
SAS Address(): 0x500056b37789abf1
Connected Port Number: (path0)
Inquiry Data: S1AXNSAFB00549A Samsung SSD PRO Series DXM06B0Q
FDE Enable: Disable
Secured: Unsecured
Locked: Unlocked
Needs EKM Attention: No
Foreign State: None
Device Speed: .0Gb/s
Link Speed: .0Gb/s
Media Type: Solid State Device
Drive: Not Certified
Drive Temperature :28C (82.40 F)
PI Eligibility: No
Drive is formatted for PI information: No
PI: No PI
Drive's write cache : Disabled
Drive's NCQ setting : Disabled
Port- :
Port status: Active
Port's Linkspeed: 6.0Gb/s
Drive has flagged a S.M.A.R.T alert : No Exit Code: 0x00

disk.out

Memory Device
Total Width: bits
Data Width: bits
Size: MB
Form Factor: DIMM
Set: None
Locator: DIMM #
Bank Locator: BANK #
Type: DRAM
Type Detail: EDO
Speed: MHz
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown Memory Device
Total Width: bits
Data Width: bits
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: DIMM #
Bank Locator: BANK #
Type: DRAM
Type Detail: EDO
Speed: MHz
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown Memory Device
Total Width: bits
Data Width: bits
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: DIMM #
Bank Locator: BANK #
Type: DRAM
Type Detail: EDO
Speed: MHz
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown Memory Device
Total Width: bits
Data Width: bits
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: DIMM #
Bank Locator: BANK #
Type: DRAM
Type Detail: EDO
Speed: MHz
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown Memory Device
Total Width: bits
Data Width: bits
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: DIMM #
Bank Locator: BANK #
Type: DRAM
Type Detail: EDO
Speed: MHz
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown Memory Device
Total Width: bits
Data Width: bits
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: DIMM #
Bank Locator: BANK #
Type: DRAM
Type Detail: EDO
Speed: MHz
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown Memory Device
Total Width: bits
Data Width: bits
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: DIMM #
Bank Locator: BANK #
Type: DRAM
Type Detail: EDO
Speed: MHz
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown Memory Device
Total Width: bits
Data Width: bits
Size: No Module Installed
Form Factor: DIMM
Set: None
Locator: DIMM #
Bank Locator: BANK #
Type: DRAM
Type Detail: EDO
Speed: MHz
Manufacturer: Not Specified
Serial Number: Not Specified
Asset Tag: Not Specified
Part Number: Not Specified
Rank: Unknown

memory.out

: lo: <LOOPBACK,UP,LOWER_UP> mtu  qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :1c::a5::7a brd ff:ff:ff:ff:ff:ff
: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/ether :::a3:: brd ff:ff:ff:ff:ff:ff
: virbr0-nic: <BROADCAST,MULTICAST> mtu qdisc noop state DOWN qlen
link/ether :::a3:: brd ff:ff:ff:ff:ff:ff
: lo: <LOOPBACK,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/loopback ::::: brd :::::
inet 127.0.0.1/ scope host lo
inet6 ::/ scope host
valid_lft forever preferred_lft forever
: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc pfifo_fast state UP qlen
link/ether :1c::a5::7a brd ff:ff:ff:ff:ff:ff
inet 10.211.55.4/ brd 10.211.55.255 scope global eth0
inet6 fdb2:2c26:f4e4::21c:42ff:fea5:577a/ scope global dynamic
valid_lft 2591752sec preferred_lft 604552sec
inet6 fe80::21c:42ff:fea5:577a/ scope link
valid_lft forever preferred_lft forever
: virbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu qdisc noqueue state UNKNOWN
link/ether :::a3:: brd ff:ff:ff:ff:ff:ff
inet 192.168.122.1/ brd 192.168.122.255 scope global virbr0
: virbr0-nic: <BROADCAST,MULTICAST> mtu qdisc noop state DOWN qlen
link/ether :::a3:: brd ff:ff:ff:ff:ff:ff

nic.out

/lib目录:

#转换函数
def convert_to_int(value,default=):
try:
result = int(value)
except Exception as e:
result = default
return result def convert_mb_to_gb(value,default=):
try:
value = value.strip('MB')
result = int(value)
except Exception as e:
result = default
return result

convert.py(内存或硬盘由MB转换成GB)

  /conf目录: 

"""
内置配置文件
"""
EMAIL = "bing@qq.com"
# print(dir())

global_settings.py:全局配置文件

from config import settings
import os
import importlib
from . import global_settings#导入当前的settings
class Settings(object):
def __init__(self):
###################找到默认配置################## for name in dir(global_settings):
if name.isupper():
value = getattr(global_settings,name)
setattr(self,name,value)
settings_module = os.environ.get('USER_SETTINGS')
#####################找到自定义配置,自定义的优先,默认的次之######################
#根据字符串导入模块(反射) if not settings_module:
return
m = importlib.import_module(settings_module)
for name in dir(m):
if name.isupper():
value = getattr(m,name)
setattr(self,name,value) setings = Settings()#创建一个对象

config.py:导入settings.py的相关配置,用到了反射(根据字符串导入模块)

/src目录:

from lib.conf.config import settings
from .client import Agent
from .client import SSHSALT def run():#从/bin目录里的start.py,start.py的run方法
if settings.MODE == "AGENT":#模式为Agent方式采集
obj = Agent()#执行Agent方法
else:
obj = SSHSALT()
obj.execute()

script.py(根据配置文件settings.py提供的信息,做判断决定以什么方式采集资产)

import requests
import json
from src.plugins import PluginManager
from lib.conf.config import settings
from concurrent.futures import ThreadPoolExecutor class Base(object):
def post_asset(self,server_info):
requests.post(settings.API,json=server_info)#在内部会把字典,转成json,json.dumps(dict)#发送json数据给API
# body: json.dumps(server_info)
# headers= {'content-type':'application/json'}
# request.body
# json.loads(request.body) class Agent(Base):#继承Base类
def execute(self):
server_info = PluginManager().exec_plugin()
# print(server_info)
# for k,v in server_info.items():
# print(k,v)
hostname = server_info['basic']['data']['hostname']#动态获取当前主机名
certname = open(settings.CERT_PATH,'r',encoding='utf8').read().strip()
if not certname:
with open(settings.CERT_PATH,'w',encoding='utf8') as f:
f.write(hostname)
else:
server_info['basic']['data']['hostname'] = certname#以certname为准(主机名)
self.post_asset(server_info) # self.post_asset(server_info)
#body:json.dumps(server_info):字典序列化之后发到后台
#headers = {'content-type':'application/json'}
#request.body:请求体里的
#在Django后台要执行json.loads(request.body),再转化成字典
#只有content_type=application/x-www-form-urlencoded时,request.POST才有值的 但是这里request.POST是没有值的
"""
{
k:json.dumps(server_info),
}
""" """
elif self.content_type == 'application/x-www-form-urlencoded':
self._post, self._files = QueryDict(self.body, encoding=self._encoding), MultiValueDict()
"""
class SSHSALT(Base):
def get_host(self):
# 获取未采集的主机列表:
response = requests.get(settings.API)
result = json.loads(response.text)## "{status:'True',data: ['c1.com','c2.com']}"
if not result['status']:#如果返回False,什么都不做
return
return result['data']#返回True时,返回主机列表
def run(self,host):
server_info = PluginManager(host).exec_plugin()
self.post_asset(server_info)
def execute(self):#要做成并发的模式(线程池)
host_list = self.get_host()
pool = ThreadPoolExecutor()#一次采集10个资产信息
for host in host_list:
pool.submit(self.run,host) #拿到数据发送到API,还要对API加密
#高内聚,低耦合
#该自己实现的全部实现:高内聚, 不跟别人关联:低耦合
#自己完成所有的功能:高内聚

client.py(定义采集方式的函数,然后执行对应的方法,采集资产时要调用ThreadPoolExecutor模块做线程池,加快采集的速度)

  /plugins目录:

  

import importlib
import traceback
from lib.conf.config import settings#settings里有PLUGINS_DICT class PluginManager(object):
def __init__(self,hostname=None):#settings.PLUGINS_DICT放在构造方法里更好
self.hostname = hostname#SSH和SALT采集时要用到
self.plugin_dict = settings.PLUGINS_DICT
self.mode = settings.MODE
self.debug = settings.DEBUG
if self.mode == "SSH":
self.ssh_user = settings.SSH_USER
self.ssh_port = settings.SSH_PORT
self.ssh_pwd = settings.SSH_PWD
self.ssh_key = settings.SSH_KEY
#SSH和SALT方式采集需要提供主机名,而AGENT则不需要提供主机名
def exec_plugin(self):
"""
获取所有的插件,并执行获取插件返回值
:return:
"""
response = {}
for k,v in self.plugin_dict.items():
# 'basic':"src.plugins.basic.Basic",
ret = {'status':True,'data':None}
try:#做一下异常处理,因为采集资产信息有可能出错,正确的可以提交,错误信息应该把错误日志提交给日志表
module_path, class_name = v.rsplit(".", ) # module_path是模块,class_name:类名,rsplit是字符串的方法,从右边往前切片,1是切一次
m = importlib.import_module(module_path)
cls = getattr(m, class_name) # 获取模块下的类名
# obj = cls().process() #类名加括号创建对象再执行一个process方法 result = "根据v获取类,并执行其方法采集资产"
if hasattr(cls, 'initial'): # process_request:中间件里的方法
obj = cls.initial() # 如果cls有initial方法,则执行initial方法
else:
obj = cls()
result = obj.process(self.command, self.debug)#self.command传入的参数 # result = "根据v获取类,并执行其方法采集资产"
# self.command一加括号就可以执行command方法,在其他插件里的def process(self,command_func,debug)函数有个command_func参数,这个参数就是函数名,加括号可以传参数,command_func("ifconfig")
ret['data'] = result
except Exception as e:
ret['status'] = False #ret['data'] = "c1.com class_name :e" 哪台主机的哪个插件
ret['data'] = "[%s][%s] 采集数据出现错误:%s" %(self.hostname if self.hostname else "AGENT",k,traceback.format_exc())#错误堆栈信息添加进ret字典里
response[k] = ret
return response #self.hostname有可能是None,也就是AGENT方式
#中间件时:request.process request.response
#同中间件类似,定义的插件一定要加到配置文件里的PLUGINS_DICT字典里
def command(self,cmd):
if self.mode == "AGENT":
return self.__agent(cmd)
elif self.mode == "SSH":
return self.__ssh(cmd)
elif self.mode == "SALT":
return self.__salt(cmd)
else:
raise Exception("模式只能是AGENT,SSH,SALT")
def __agent(self,cmd):
import subprocess
output = subprocess.getoutput(cmd)
return output
def __salt(self,cmd):
# import salt.client
# local = salt.client.LocalClient()
# result = local.cmd(self.hostname, 'cmd.run', [cmd])
# return result[self.hostname]
salt_cmd = "salt '%s' cmd.run '%s'" %(self.hostname,cmd,)#saltstack对Python2的支持更好一点,在Python3使用得用subprocess执行命令
import subprocess
output = subprocess.getoutput(salt_cmd)
return output
def __ssh(self,cmd):#加双下划线代表私有的,只能自己调用,外部访问不到,只需知道command函数就行了,主机名,用户名,密码
import paramiko
#公钥私钥的方式连接服务器
# private_key = paramiko.RSAKey.from_private_key_file(self.ssh_key)
# ssh = paramiko.SSHClient()
# ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
# ssh.connect(hostname=self.hostname, port=self.ssh_port, username=self.ssh_user, pkey=private_key)
# stdin, stdout, stderr = ssh.exec_command(cmd)
# result = stdout.read()
# ssh.close()
#用户名密码连接服务器
ssh = paramiko.SSHClient()#创建一个ssh对象
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())#创建连接不在know_hosts文件中的主机
ssh.connect(hostname=self.hostname,port=self.ssh_port,username=self.ssh_user,password=self.ssh_pwd)#通过主机名,端口,用户名,密码
stdin,stdout,stderr = ssh.exec_command(cmd)#执行命令
result = stdout.read()#获取命令结果
ssh.close()#关闭连接
return result#返回结果

__init__.py

#baisc.py用于找到Linux系统基本信息,如操作系统平台.系统版本,主机名
from .base import BasePlugin
import os
from lib.conf.config import settings#导入配置文件模块,从而导入执行三种采集方式的模块
class Basic(object):
def __init__(self):
pass
@classmethod#类方法用于做扩展,自定制操作
def initial(cls):
#预留的钩子
return cls()#cls()是对象
def process(self,command_func,debug):
if debug:
output = {
'os_platform':"linux",
'os_version':"CentOS relese 6.6 (Final)\nKernel \r on an \m",
'hostname':'c1.com'
}
else:
output = {
'os_platform':command_func("uname").strip(),#查到系统Linux,并去空格
'os_version':command_func("cat /etc/issue").strip().split('\n')[],#查看系统版本
'hostname':command_func("hostname").strip()
}
return output """
#cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m(\r 和 \m都是转义字符)
"""

basic.py采集基本信息

import os
from lib.conf.config import setings
class Board(object):
#Linux命令:dmesg
def __init__(self):
pass @classmethod
def initial(cls):
return cls() def process(self,command_func,debug):
if debug:
output = open(os.path.join(setings.BASEDIR,'files/board.out'),'r',encoding='utf8').read()
else:
output = command_func("sudo dmidecode -t1")
return self.parse(output) def parse(self,content):
result = {}
key_map = {
'Manufacturer':'manufacturer',#制造商
'Product Name':'model',#产品名称
'Serial Number':'sn',#sn号,也就是序列号
}
for item in content.split('\n'):
row_data = item.strip().split(':')
if len(row_data) == :#如果列表里有两个元素,代表是一个key,一个value
if row_data[] in key_map:
result[key_map[row_data[]]] = row_data[].strip() if row_data[] else row_data[]
return result """
result字典:
{
'manufacturer': 'Parallels Software International Inc.',
'model': 'Parallels Virtual Platform',
'sn': 'Parallels-1A 1B CB 3B 64 66 4B 13 86 B0 86 FF 7E 2B 20 30'
}
""" """
sudo dmidecode -t1的执行结果
# dmidecode 3.0
Scanning /dev/mem for entry point.
SMBIOS 2.7 present. Handle 0x0001, DMI type , bytes
System Information
Manufacturer: VMware, Inc.
Product Name: VMware Virtual Platform
Version: None
Serial Number: VMware- 4d f9 b6 c0 5c -7c cb b4 b5 ec 4e
UUID: B6F94D56-30C0-725C-7CCB-B433B5EC814E
Wake-up Type: Power Switch
SKU Number: Not Specified
Family: Not Specified
"""

board采集网卡信息

#linux命令:cat /proc/cpuinfo
import os
from lib.conf.config import setings
class Cpu(object):
def __init__(self):
pass @classmethod
def initial(cls):
return cls() def process(self,command_func,debug):
if debug:
output = open(os.path.join(setings.BASEDIR,'files/cpuinfo.out'),'r',encoding='utf8').read()
else:
output = command_func('cat /proc/cpuinfo')
return self.parse(output) def parse(self,content):
"""
#根据split或者正则表达式
解析shell命令返回的结果
:param content: shell命令结果
:return: 解析后的结果
"""
response = {'cpu_count':,'cpu_physical_count':,'cpu_model':''}
cpu_physical_set = set()#设置一个集合
content = content.strip()
for item in content.split('\n\n'):
for row_line in item.split('\n'):
key, value = row_line.split(':')
key = key.strip()
if key == 'processor':
response['cpu_count'] +=
elif key == 'physical id':
cpu_physical_set.add(value)
elif key == 'model name':
if not response['cpu_model']:
response['cpu_model'] = value
response['cpu_physical_count'] = len(cpu_physical_set) return response

cpu.py采集CPU信息

#df -h
import re
import os
from lib.conf.config import setings
class Disk(object):
def __init__(self):
pass @classmethod
def initial(cls):
return cls()#cls代指Disk类 def process(self,command_func,debug):
if debug:
output = open(os.path.join(setings.BASEDIR,'files/disk.out'),'r',encoding='utf8').read()
else:
output = command_func("sudo MegaCli -PDList -aALL")
return self.parse(output) def parse(self,content):
"""
解析shell命令的返回结果
:param content: shell命令结果解析
:return: 解析后的结果
"""
response = {}
result = []
for row_line in content.split("\n\n\n\n"):
result.append(row_line)
for item in result:
temp_dict = {}
for row in item.split('\n'):
if not row.strip():
continue
if len(row.split(':')) != :
continue
key,value = row.split(':')
name = self.mega_patter_match(key)#mega_patter_match是匹配函数
if name:
if key == "Raw Size":
raw_size = re.search('(\d+\.\d+)',value.strip())#硬盘大小,如:Raw Size: 279.396 GB [0x22ecb25c Sectors]
if raw_size:
temp_dict[name] = raw_size.group()
else:
raw_size = ''
else:
temp_dict[name] = value.strip()
if temp_dict:
response[temp_dict['slot']] = temp_dict
return response @staticmethod
def mega_patter_match(needle):
grep_pattern = {
'Slot':'slot',
'Raw Size':'capacity',
'Inquiry':'model',
'PD Type':'pd_type'
}
for key,value in grep_pattern.items():
if needle.startswith(key):
return value
return False

disk.py采集硬盘信息

#free -m
import os
from lib import convert
from lib.conf.config import settings
class Memory(object):
def __init__(self):
pass
@classmethod
def initial(cls):
return cls() def process(self,command_func,debug):
if debug:
output = open(os.path.join(settings.BASEDIR,'files/memory.out'),'r',encoding='utf8').read()
else:
output = command_func("sudo dmidecode -q -t 17 2>/dev/null")
return self.parse(output) def parse(self,content):
"""
解析shell命令返回的结果
:param content: shell命令结果
:return: 解析后的结果
"""
ram_dict = {}
key_map = {
'Size':'capacity',
'Locator':'slot',
'Type':'model',
'Speed':'speed',
'Manufacturer':'manufacturer',
'Serial Number':'sn',
}
devices = content.split('Memory Device')#列表里的元素都是字符串,有些字符串是套着键值对
for item in devices:
item = item.strip()
if not item:
continue
if item.startswith('#'):
continue
segment = {}
lines = item.split('\n\t')
for line in lines:
if not line.strip():
continue
if len(line.split(':')):
# print(len(line.split(':')))#按照':'分割之后长度是2,因为分割之前都是键值对
key,value = line.split(':')
else:
key = line.split(':')
value = ""
if key in key_map:
if key == 'size':
segment[key_map[key_map['Size']]] = convert.convert_mb_to_gb(value,)#
else:
segment[key_map[key_map[key.strip()]]] = value.strip()
ram_dict[segment['slot']] = segment#往空字典里添加值
return ram_dict """
ram_dict输出:
{'DIMM #0': {'capacity': , 'slot': 'DIMM #0', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #1': {'capacity': , 'slot': 'DIMM #1', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #2': {'capacity': , 'slot': 'DIMM #2', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #3': {'capacity': , 'slot': 'DIMM #3', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #4': {'capacity': , 'slot': 'DIMM #4', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #5': {'capacity': , 'slot': 'DIMM #5', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #6': {'capacity': , 'slot': 'DIMM #6', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #7': {'capacity': , 'slot': 'DIMM #7', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'}}
"""

memory.py采集内存信息

#free -m
import os
from lib import convert
from lib.conf.config import settings
class Memory(object):
def __init__(self):
pass
@classmethod
def initial(cls):
return cls() def process(self,command_func,debug):
if debug:
output = open(os.path.join(settings.BASEDIR,'files/memory.out'),'r',encoding='utf8').read()
else:
output = command_func("sudo dmidecode -q -t 17 2>/dev/null")
return self.parse(output) def parse(self,content):
"""
解析shell命令返回的结果
:param content: shell命令结果
:return: 解析后的结果
"""
ram_dict = {}
key_map = {
'Size':'capacity',
'Locator':'slot',
'Type':'model',
'Speed':'speed',
'Manufacturer':'manufacturer',
'Serial Number':'sn',
}
devices = content.split('Memory Device')#列表里的元素都是字符串,有些字符串是套着键值对
for item in devices:
item = item.strip()
if not item:
continue
if item.startswith('#'):
continue
segment = {}
lines = item.split('\n\t')
for line in lines:
if not line.strip():
continue
if len(line.split(':')):
# print(len(line.split(':')))#按照':'分割之后长度是2,因为分割之前都是键值对
key,value = line.split(':')
else:
key = line.split(':')
value = ""
if key in key_map:
if key == 'size':
segment[key_map[key_map['Size']]] = convert.convert_mb_to_gb(value,)#
else:
segment[key_map[key_map[key.strip()]]] = value.strip()
ram_dict[segment['slot']] = segment#往空字典里添加值
return ram_dict """
ram_dict输出:
{'DIMM #0': {'capacity': , 'slot': 'DIMM #0', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #1': {'capacity': , 'slot': 'DIMM #1', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #2': {'capacity': , 'slot': 'DIMM #2', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #3': {'capacity': , 'slot': 'DIMM #3', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #4': {'capacity': , 'slot': 'DIMM #4', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #5': {'capacity': , 'slot': 'DIMM #5', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #6': {'capacity': , 'slot': 'DIMM #6', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'},
'DIMM #7': {'capacity': , 'slot': 'DIMM #7', 'model': 'DRAM', 'speed': '667 MHz', 'manufacturer': 'Not Specified', 'sn': 'Not Specified'}}
"""

memory.py采集内存信息

#!/usr/bin/env python
# -*- coding:utf- -*-
import os
import re
from lib.conf.config import settings class Nic(object):
def __init__(self):
pass @classmethod
def initial(cls):
return cls() def process(self, command_func, debug):
if debug:
output = open(os.path.join(settings.BASEDIR, 'files/nic.out'), 'r', encoding='utf-8').read()
interfaces_info = self._interfaces_ip(output)
else:
interfaces_info = self.linux_interfaces(command_func) self.standard(interfaces_info) return interfaces_info def linux_interfaces(self, command_func):
'''
Obtain interface information for *NIX/BSD variants
'''
ifaces = dict()
ip_path = 'ip'
if ip_path:
cmd1 = command_func('sudo {0} link show'.format(ip_path))
cmd2 = command_func('sudo {0} addr show'.format(ip_path))
ifaces = self._interfaces_ip(cmd1 + '\n' + cmd2)
return ifaces def which(self, exe):
def _is_executable_file_or_link(exe):
# check for os.X_OK doesn't suffice because directory may executable
return (os.access(exe, os.X_OK) and
(os.path.isfile(exe) or os.path.islink(exe))) if exe:
if _is_executable_file_or_link(exe):
# executable in cwd or fullpath
return exe # default path based on busybox's default
default_path = '/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin'
search_path = os.environ.get('PATH', default_path)
path_ext = os.environ.get('PATHEXT', '.EXE')
ext_list = path_ext.split(';') search_path = search_path.split(os.pathsep)
if True:
# Add any dirs in the default_path which are not in search_path. If
# there was no PATH variable found in os.environ, then this will be
# a no-op. This ensures that all dirs in the default_path are
# searched, which lets salt.utils.which() work well when invoked by
# salt-call running from cron (which, depending on platform, may
# have a severely limited PATH).
search_path.extend(
[
x for x in default_path.split(os.pathsep)
if x not in search_path
]
)
for path in search_path:
full_path = os.path.join(path, exe)
if _is_executable_file_or_link(full_path):
return full_path return None def _number_of_set_bits_to_ipv4_netmask(self, set_bits): # pylint: disable=C0103
'''
Returns an IPv4 netmask from the integer representation of that mask. Ex. 0xffffff00 -> '255.255.255.0'
'''
return self.cidr_to_ipv4_netmask(self._number_of_set_bits(set_bits)) def cidr_to_ipv4_netmask(self, cidr_bits):
'''
Returns an IPv4 netmask
'''
try:
cidr_bits = int(cidr_bits)
if not <= cidr_bits <= :
return ''
except ValueError:
return '' netmask = ''
for idx in range():
if idx:
netmask += '.'
if cidr_bits >= :
netmask += ''
cidr_bits -=
else:
netmask += '{0:d}'.format( - ( ** ( - cidr_bits)))
cidr_bits =
return netmask def _number_of_set_bits(self, x):
'''
Returns the number of bits that are set in a 32bit int
'''
# Taken from http://stackoverflow.com/a/4912729. Many thanks!
x -= (x >> ) & 0x55555555
x = ((x >> ) & 0x33333333) + (x & 0x33333333)
x = ((x >> ) + x) & 0x0f0f0f0f
x += x >>
x += x >>
return x & 0x0000003f def _interfaces_ip(self, out):
'''
Uses ip to return a dictionary of interfaces with various information about
each (up/down state, ip address, netmask, and hwaddr)
'''
ret = dict()
right_keys = ['name', 'hwaddr', 'up', 'netmask', 'ipaddrs'] def parse_network(value, cols):
'''
Return a tuple of ip, netmask, broadcast
based on the current set of cols
'''
brd = None
if '/' in value: # we have a CIDR in this address
ip, cidr = value.split('/') # pylint: disable=C0103
else:
ip = value # pylint: disable=C0103
cidr = if type_ == 'inet':
mask = self.cidr_to_ipv4_netmask(int(cidr))
if 'brd' in cols:
brd = cols[cols.index('brd') + ]
return (ip, mask, brd) groups = re.compile('\r?\n\\d').split(out)
for group in groups:
iface = None
data = dict() for line in group.splitlines():
if ' ' not in line:
continue
match = re.match(r'^\d*:\s+([\w.\-]+)(?:@)?([\w.\-]+)?:\s+<(.+)>', line)
if match:
iface, parent, attrs = match.groups()
if 'UP' in attrs.split(','):
data['up'] = True
else:
data['up'] = False
if parent and parent in right_keys:
data[parent] = parent
continue cols = line.split()
if len(cols) >= :
type_, value = tuple(cols[:]) iflabel = cols[-:][]
if type_ in ('inet',):
if 'secondary' not in cols:
ipaddr, netmask, broadcast = parse_network(value, cols)
if type_ == 'inet':
if 'inet' not in data:
data['inet'] = list()
addr_obj = dict()
addr_obj['address'] = ipaddr
addr_obj['netmask'] = netmask
addr_obj['broadcast'] = broadcast
data['inet'].append(addr_obj)
else:
if 'secondary' not in data:
data['secondary'] = list()
ip_, mask, brd = parse_network(value, cols)
data['secondary'].append({
'type': type_,
'address': ip_,
'netmask': mask,
'broadcast': brd,
})
del ip_, mask, brd
elif type_.startswith('link'):
data['hwaddr'] = value
if iface:
if iface.startswith('pan') or iface.startswith('lo') or iface.startswith('v'):
del iface, data
else:
ret[iface] = data
del iface, data
return ret def standard(self, interfaces_info): for key, value in interfaces_info.items():
ipaddrs = set()
netmask = set()
if not 'inet' in value:
value['ipaddrs'] = ''
value['netmask'] = ''
else:
for item in value['inet']:
ipaddrs.add(item['address'])
netmask.add(item['netmask'])
value['ipaddrs'] = '/'.join(ipaddrs)
value['netmask'] = '/'.join(netmask)
del value['inet']

nic.py采集网卡信息

												

CMDB Autoclient思路分析的更多相关文章

  1. 八大排序算法详解(动图演示 思路分析 实例代码java 复杂度分析 适用场景)

    一.分类 1.内部排序和外部排序 内部排序:待排序记录存放在计算机随机存储器中(说简单点,就是内存)进行的排序过程. 外部排序:待排序记录的数量很大,以致于内存不能一次容纳全部记录,所以在排序过程中需 ...

  2. 八大排序算法——堆排序(动图演示 思路分析 实例代码java 复杂度分析)

    一.动图演示 二.思路分析 先来了解下堆的相关概念:堆是具有以下性质的完全二叉树:每个结点的值都大于或等于其左右孩子结点的值,称为大顶堆:或者每个结点的值都小于或等于其左右孩子结点的值,称为小顶堆.如 ...

  3. 八大排序算法——希尔(shell)排序(动图演示 思路分析 实例代码java 复杂度分析)

    一.动图演示 二.思路分析 希尔排序是把记录按下标的一定增量分组,对每组使用直接插入排序算法排序:随着增量逐渐减少,每组包含的关键词越来越多,当增量减至1时,整个文件恰被分成一组,算法便终止. 简单插 ...

  4. 八大排序算法——基数排序(动图演示 思路分析 实例代码java 复杂度分析)

    一.动图演 二.思路分析 基数排序第i趟将待排数组里的每个数的i位数放到tempj(j=1-10)队列中,然后再从这十个队列中取出数据,重新放到原数组里,直到i大于待排数的最大位数. 1.数组里的数最 ...

  5. 八大排序算法——归并排序(动图演示 思路分析 实例代码java 复杂度分析)

    一.动图演示 二.思路分析 归并排序就是递归得将原始数组递归对半分隔,直到不能再分(只剩下一个元素)后,开始从最小的数组向上归并排序 1.  向上归并排序的时候,需要一个暂存数组用来排序, 2.  将 ...

  6. 八大排序算法——快速排序(动图演示 思路分析 实例代码Java 复杂度分析)

    一.动图演示 二.思路分析 快速排序的思想就是,选一个数作为基数(这里我选的是第一个数),大于这个基数的放到右边,小于这个基数的放到左边,等于这个基数的数可以放到左边或右边,看自己习惯,这里我是放到了 ...

  7. 2018-8-16JWTtoken用户登录认证思路分析9502751

    2018-8-16JWTtoken用户登录认证思路分析9502751 JWT token在商城中的实现 class UserView(CreateAPIView): serializer_class ...

  8. 八大排序算法——插入排序(动图演示 思路分析 实例代码java 复杂度分析)

    一.动图演示 二.思路分析 例如从小到大排序: 1.  从第二位开始遍历, 2.  当前数(第一趟是第二位数)与前面的数依次比较,如果前面的数大于当前数,则将这个数放在当前数的位置上,当前数的下标-1 ...

  9. 八大排序算法——冒泡排序(动图演示 思路分析 实例代码java 复杂度分析)

    一.动图演示 二.思路分析 1.  相邻两个数两两相比,n[i]跟n[j+1]比,如果n[i]>n[j+1],则将连个数进行交换, 2.  j++, 重复以上步骤,第一趟结束后,最大数就会被确定 ...

随机推荐

  1. 论文笔记:目标检测算法(R-CNN,Fast R-CNN,Faster R-CNN,FPN,YOLOv1-v3)

    R-CNN(Region-based CNN) motivation:之前的视觉任务大多数考虑使用SIFT和HOG特征,而近年来CNN和ImageNet的出现使得图像分类问题取得重大突破,那么这方面的 ...

  2. pom.xml文件报错:web.xml is missing and <failOnMissingWebXml> is set to true

    这个错误原因是因为项目无法加载到web.xml,所以需要配置web项目的目录.具体解决,配置步骤如下: 1.右键项目属性,配置项目目录  /src/main/webapp,如果没有,新增一条 2.配置 ...

  3. python3_unittest单元测试框架

    看见英文懵逼,强迫学习英语 The Unittest suppots test automation,sharing of setup and shutdown code of tests, aggr ...

  4. 重定向符号和tee命令区别

      来源:http://zyp88.blog.51cto.com/1481591/1604036 功能说明:读取标准输入的数据,并将其内容输出成文件. 语 法:tee [-ai][--help][-- ...

  5. [leetcode刷题笔记]Implement Trie (Prefix Tree)

    题目链接 一A,开森- ac代码: class TrieNode { // Initialize your data structure here. char content; boolean isW ...

  6. CSS 布局 - 水平 & 垂直对齐

    CSS 布局 - 水平 & 垂直对齐 一.元素居中对齐 要水平居中对齐一个元素(如 <div>), 可以使用 margin: auto;. 设置到元素的宽度将防止它溢出到容器的边缘 ...

  7. mouseover 有一个多次触发的问题

    mouseover 有一个多次触发的问题 需要注意 由于浏览器的冒泡行为.造成如果在一个DIV元素上同时定义了mouseover,mouseout的时候,当鼠标移动到DIV中的child子元素的时候, ...

  8. zookeeper可视化管理工具node-zk-browser安装

    一.安装nodejs 1. 下载 wget https://github.com/joyent/node/archive/v0.10.35.tar.gz 2. 解压 3. 安装依赖 yum -y in ...

  9. wamp 环境下配置多台虚拟主机

    首先启动wamp,成功之后,单击图标,找到Apache服务器下的 httpd.conf ,直接打开 按下Ctrl+F键,在搜索框中搜索 Virtual hosts, 搜寻结果如下图: 3. 然后打开w ...

  10. dd命令参数解析

    seek=N : 跳过N个输出块 skip=N : 跳过N个输入块 注意:sd卡的每个扇区的大小统一为512个字节