判断系统因为是公用的方法,所有要写基类方法使用,首先在插件中创建一个基类

将插件文件继承基类

思路是创建基类使用handler.cmd ,命令去获取系统信息,然后进行判断,然后去执行 磁盘 ,cpu,网卡,内存等信息的收集;

基类代码:

class BasePlugin:

    def get_os(self,handler,hostname):
os = handler.cmd("查询操作系统的命令",hostname)
# return os
return 'win32' def process(self,handler,hostname):
os = self.get_os(handler,hostname)
if os == 'win32': #测试判断执行win32
return self.win(handler,hostname)
else:
return self.linux(handler,hostname) def win(self,handler,hostname):
#约束派生类必须实现win方法
raise NotImplementedError('handler() must Implemented.') def linux(self,handler,hostname):
#约束派生类必须实现Linux方法
raise NotImplementedError('handler() must Implemented.')

disk.py ,cpu.py,memory.py,network.py 代码;

from .base import BasePlugin

class Disk(BasePlugin):
def win(self,handler,hostname):
'''
执行命令拿到结果磁盘
:return:
'''
print("执行win方法")
ret = handler.cmd('wmic diskdrive',hostname)[0:10]
return ret
def linux(self,handler,hostname):
'''
执行命令拿到结果磁盘
:return:
'''
print("执行Linux方法")
ret = handler.cmd('df -h',hostname)[0:10]
return ret
from .base import BasePlugin

class Memory(BasePlugin):
def win(self,handler,hostname):
'''
执行命令拿到结果-内存
:return:
'''
print("执行win方法")
ret = handler.cmd('wmic memphysical list brief',hostname)[0:10]
return ret
def linux(self,handler,hostname):
'''
执行命令拿到结果-内存
:return:
'''
print("执行Linux方法")
ret = handler.cmd('free',hostname)[0:10]
return ret
from .base import BasePlugin
class CPU(BasePlugin):
def win(self,handler,hostname):
'''
执行命令拿到结果-cpu
:return:
'''
print("执行win方法")
ret = handler.cmd('wmic cpu',hostname)[0:10]
return ret
def linux(self,handler,hostname):
'''
执行命令拿到结果-cpu
:return:
'''
print("执行Linux方法")
ret = handler.cmd('wmic cpu',hostname)[0:10]
return ret
from .base import BasePlugin
class Network(BasePlugin):
def win(self,handler,hostname):
'''
执行命令拿到结果-网卡
:return:
'''
print("执行win方法")
ret = handler.cmd('ipconfig',hostname)[0:10]
return ret
def linux(self,handler,hostname):
'''
执行命令拿到结果-网卡
:return:
'''
print("执行Linux方法")
ret = handler.cmd('ifconfig',hostname)[0:10]
return ret

最后测试执行结果

CMDB学习之三数据采集的更多相关文章

  1. AspectJ基础学习之三HelloWorld(转载)

    AspectJ基础学习之三HelloWorld(转载) 一.创建项目 我们将project命名为:aspectjDemo.然后我们新建2个package:com.aspectj.demo.aspect ...

  2. Linux学习之三-Linux系统的一些重要配置文件

    Linux学习之三-Linux系统的一些重要配置文件 1.网卡配置文件 /etc/sysconfig/network-scripts/ifcfg-eth0 说明: DEVICE=eth0        ...

  3. C++11并发学习之三:线程同步(转载)

    C++11并发学习之三:线程同步 1.<mutex> 头文件介绍 Mutex又称互斥量,C++ 11中与 Mutex 相关的类(包括锁类型)和函数都声明在 <mutex> 头文 ...

  4. jackson学习之三:常用API操作

    欢迎访问我的GitHub https://github.com/zq2599/blog_demos 内容:所有原创文章分类汇总及配套源码,涉及Java.Docker.Kubernetes.DevOPS ...

  5. CMDB学习之二数据采集

    首先也要调用插件的方式,来写采集数据插件,在src目录下创建一个插件 plugins ,然后在plugins下创建disk.py ,memory.py, network.py等等 src plugin ...

  6. CMDB学习之四 ——DEBUG模式

    定义一个debug,进行解析调试,到测试文件 配置文件,配置debug模式,定义环境变量, #!/usr/bin/env python # -*- coding:utf-8 -*- import os ...

  7. CMDB学习之一

    CMDB - 配置管理数据库 资产管理 自动化相关的平台(基础 CMDB): 1. 发布系统 2. 监控 3. 配管系统.装机 4. 堡垒机 CMDB的目的: 1. 替代EXCEL资产管理 —— 资产 ...

  8. TCP学习之三:客户端、服务端同步传输字符串

    参考学习张子阳大神的博客:http://www.cnblogs.com/JimmyZhang/category/101698.html 一个客户端.发送一条消息 客户端: 服务端: 注意:Networ ...

  9. 性能测试学习之三—— PV->TPS转换模型&TPS波动模型

    PV->TPS转换模型 由上一篇“性能测试学习之二 ——性能测试模型(PV计算模型)“ 得知 TPS = ( (80%*总PV)/(24*60*60*(T/24)))/服务器数量 转换需要注意: ...

随机推荐

  1. yii2.0缓存篇之文件缓存

    文件缓存: 在 frontend/config/main.php/components数组下添加: 'cache'=>[      'class'=>'yii\caching\FileCa ...

  2. d3 bubble源码分析

    技术 d3.d3.pack.d3.hierarchy 展示 https://bl.ocks.org/xunhanliu/e0688dc2ae9167c4c7fc264c0aedcdd1 关于怎么使用, ...

  3. 记intel杯比赛中各种bug与debug【其一】:安装intel caffe

    因为intel杯创新软件比赛过程中,并没有任何记录.现在用一点时间把全过程重演一次用作记录. 学习 pytorch 一段时间后,intel比赛突然不让用 pytoch 了,于是打算转战intel ca ...

  4. mysql每个表总的索引大小

    /* 指定的数据库 每个表的索引 不包含主键索引的大小*/ ,),,),'mb') as index_size from information_schema.tables where TABLE_S ...

  5. 深入理解Struts2

    简单介绍 Struts 2是Struts的下一代产品.是在 struts 1和WebWork的技术基础上进行了合并的全新的Struts 2框架. 其全新的Struts 2的体系结构与Struts 1的 ...

  6. stl之set集合容器应用基础

    set集合容器使用一种称为红黑树(Red-Black Tree) 的平衡二叉检索树的数据结构,来组织泛化的元素数据.每一个节点包括一个取值红色或黑色的颜色域.以利于进行树的平衡处理.作为节点键值的元素 ...

  7. 离线安装 Chrome

    离线安装 Chrome 在这个帮助网页中最下面切换到中文 https://support.google.com/chrome/answer/95346 在网页的中上部点击 "离线安装 Chr ...

  8. ISheet ICell

    /// <summary> /// Gets the first row on the sheet /// </summary> /// <value>the nu ...

  9. ECharts简单入门

    图1和图2是手机上显示的效果, 图3是电脑浏览器显示的效果. 如何使用ECharts? 1.下载echarts.js 2.引入echarts.js <script type="text ...

  10. hight charts

    hight charts http://www.hcharts.cn/resource/index.php http://www.hcharts.cn/api/index.php