check脚本:

import paramiko
import ConfigParser
import sys
# -*- coding: UTF-8 -*-
username="root"
pwd="YDYP1F1@flzx3kc"
host_ip=[]
reload(sys)
sys.setdefaultencoding('utf8')

with open("/tmp/hostip.txt") as hostips:
    for hostip in hostips:
        host_ip.append(hostip.strip())
print(host_ip)
print("---------------------------------------------------------------------------------------")
print("---------------------------------------------------------------------------------------")
cf=ConfigParser.ConfigParser()
cf.read("/tmp/cmd.txt")

def get_ssh(ip,username,pwd,cmd_trans):

    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    ssh.connect(ip, 22, username, pwd)

    stdin,stdout,stderr=ssh.exec_command(cmd_trans)
    #print(ip,stdout.readlines())
    bb=stdout.readline().strip()
    #print("------",bb)
    cpuinfo[ip]=bb

cmd_lists=cf.sections()

for cmd_list in cmd_lists:
    #print(cmd_list)
    cpu = {}
    cpuinfo = {}
    key=[]
    cmd_trans = cf.get(cmd_list, 'cmd_trans')
    property=cf.get(cmd_list,'property')
    #print(cmd_trans)
    for ip in host_ip:
        get_ssh(ip, username, pwd, cmd_trans)
   # print(property,'\033[1;34;43m %s nihao \033[0m' % cpuinfo)
    print(property)
    for key, value in cpuinfo.items():
      print(key+'  '+'\033[1;34;43m %s  \033[0m' % value)
    print("-----------------------------------------------------------------------------------")
    print("-----------------------------------------------------------------------------------")

cmd.txt

[CPU_ALL_thread]
cmd_trans=cat /proc/cpuinfo | grep processor | wc -l
property=检查总CPU线程


[one_cpu_thread]
cmd_trans=cat /proc/cpuinfo | grep 'cpu cores'  | uniq | awk '{print $4}'
property=检查单个CPU线程

[CPU_work_pattern ]
cmd_trans=cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor  | grep performance | wc -l
property=CPU工作模式(cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor  | grep performance | wc -l)

[fdisk_num]
cmd_trans=fdisk  -l | grep 'Disk /dev' | wc -l
property=fdisk_num(fdisk  -l | grep 'Disk /dev' | wc -l)

[raid1]
cmd_trans=/opt/MegaRAID/storcli/storcli64 /c0/vall  show | grep "RAID1"
property=raid1

[raid6]
cmd_trans=/opt/MegaRAID/storcli/storcli64 /c0/vall  show | grep "RAID6"
property=raid6

[free_g]
cmd_trans=free -g | grep Mem | awk '{print $2}'
property=free_size_g

[bond0_speed]
cmd_trans=ethtool bond0 | grep Speed | awk '{print $2}'
property=bond0_speed

[bond1_speed]
cmd_trans=ethtool bond1 | grep Speed | awk '{print $2}'
property=bond1_speed

[bond2_speed]
cmd_trans=ethtool bond2 | grep Speed | awk '{print $2}'
property=bond2_speed


[bond0_mode_1]
cmd_trans=cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep "mode=1"
property=bond0_mode_1

[bond0_mode_6]
cmd_trans=cat /etc/sysconfig/network-scripts/ifcfg-bond0 | grep "mode=6"
property=bond0_mode_6_ok

[bond1_mode_4]
cmd_trans=cat /etc/sysconfig/network-scripts/ifcfg-bond1 | grep "mode=4"
property=bond1_mode_4

[route_n]
cmd_trans=route -n | grep 10.206.196.254 
property=route_n

[docker_v]
cmd_trans=docker -v | awk '{print $3}' | sed 's/,//g'
property=docker_v

[numa]
cmd_trans=dmesg | grep -i numa | grep "No NUMA" | wc -l
property=numa_ok_1(dmesg | grep -i numa | grep 'No NUMA' | wc -l)


[chronyd_status]
cmd_trans=systemctl status chronyd.service | grep running 
property=chronyd_status

[date_R]
cmd_trans=date -R | grep '+0800' | wc -l
property=date_R_OK_1

[date]
cmd_trans=date |grep CST | wc -l
property=date_OK_1

[hostname]
cmd_trans=hostname
property=hostname


[firewalld_ok_1]
cmd_trans=systemctl status firewalld  | grep dead 
property=firewalld

[selinux]
cmd_trans=/usr/sbin/sestatus -v | grep disabled 
property=selinux

[system]
cmd_trans=cat /etc/redhat-release
property=系统

[uname]
cmd_trans=uname -r
property=uname内核

[users_apps]
cmd_trans=cat /etc/passwd | grep apps
property=usrs_apps用户

[users_deployer]
cmd_trans=cat /etc/passwd | grep deployer
property=users_deployer用户

[dir_apps]
cmd_trans=ls -l / | grep apps
property=dir_apps_775

[users_apps]
cmd_trans=cat /etc/passwd | grep apps
property=usrs_apps用户

[users_apps]
cmd_trans=cat /etc/passwd | grep apps
property=usrs_apps用户

[locale]
cmd_trans=locale | grep 'en_US.UTF-8'  | wc -l
property=locale(locale | grep 'en_US.UTF-8'  | wc -l)

[sys_per1]
cmd_trans=cat /etc/sysctl.conf | grep net.netfilter.nf_conntrack_tcp_be_liberal
property=sys_per1

[sys_per2]
cmd_trans=cat /etc/sysctl.conf | grep fs.pipe-user-pages-soft
property=sys_per2

[sys_per3]
cmd_trans=cat /etc/sysctl.conf | grep fs.pipe-max-size
property=sys_per3

[apps_clouddb]
cmd_trans=lsblk | grep '/apps/clouddb'
property=apps_clouddb

[apps_sharedstorage]
cmd_trans=lsblk | grep '/apps/sharedstorage'
property=apps_sharedstorage

[apps]
cmd_trans=lsblk | grep '/apps'
property=apps
View Code

host.ip