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

将插件文件继承基类

思路是创建基类使用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. vue的鼠标移入和移出

    vue的鼠标移入和移出 需求(鼠标到预约二维码显示,预约添加背景色) 实现 <!--html部分--> <ul class="person_list"> / ...

  2. Conservative GC (Part two :MostlyCopyingGC )

    目录 MostlyCopyingGC 概要 堆结构 分配 new_obj()函数 add_pages()函数 GC执行过程 mostly_copying()函数 promote_page()函数 pa ...

  3. 【转载】解决django models文件修改后的数据库同步问题——south模块

    转载链接:https://www.cnblogs.com/frchen/p/5732490.html 在使用django进行开发时,往往需要根据不同的需求对model进行更改.而这时候,python ...

  4. [HNOI2012]矿场搭建(割点)

    [HNOI2012]矿场搭建 题目描述 煤矿工地可以看成是由隧道连接挖煤点组成的无向图.为安全起见,希望在工地发生事故时所有挖煤点的工人都能有一条出路逃到救援出口处.于是矿主决定在某些挖煤点设立救援出 ...

  5. 题解 P1531 【I Hate It】

    这道题明明是裸的线段树,蒟蒻却80分了五六次... ------------ 根据题意,显然是维护一棵单点修改区间查询的线段树,于是直接套区间修改的代码... 结构体,即为树上的节点. struct ...

  6. Spring Boot学习总结(2)——Spring Boot整合Jsp

    怎么使用jsp上面起了疑问,查阅了多方资料,找到过其他人的博客的描述,也找到了spring在github上的给出的例子,看完后稍微改动后成功 整合jsp,于是决定将整合过程记载下来. 无论使用的是那种 ...

  7. XMPP使用简单介绍--登录

    在现阶段的通信服务中,各种标准都有.因此会出现无法实现相互连通,而XMPP(Extensible Message and presence Protocol)协议的出现,实现了整个及时通信服务协议的互 ...

  8. Anatomy of an IIS7 configuration path

    The concept of configuration paths is fundamental to managing and operating an IIS server, so I want ...

  9. Flask Flash闪现

    Flash介绍以及工作方式 flash中添加消息 取出flash中的消息 Flash介绍以及工作方式 - 介绍: flash :闪现 一个好的应用和用户界面都需要良好的反馈. 如果用户得不到足够的反馈 ...

  10. I want to do——输入流readline阻塞问题

    据悉,外界对程序员的印象不是木讷就是死板,不是最笨就是不爱说话,不是宅就是闷骚.昨天我们老左批评我说,自从你写了程序了,你以前的优点都退化了.放在去年,我还觉得我没什么啊,程序员就是这样啊,那是因为我 ...