1、查看MASTER的BASE路径,在对应的路径建立_modules文件夹,存放.py的模块

[root@v72 _modules]# cat /etc/salt/master | grep file_roots -A 5

--

file_roots:

base:

- /srv/salt

建立目录:

mkdir -p /srv/salt/_modules

2、在/srv/salt/_modules目录下编写python代码

[root@v72 _modules]# pwd

/srv/salt/_modules

[root@v72 _modules]# cat infos.py

#!/usr/bin/env python

#encoding: utf-8

from subprocess import Popen, PIPE

import os,sys

import time

def getipaddr():

p = Popen(['hostname','-I'], stdout = PIPE)

ip=p.stdout.read()

return ip

def gethostname():

p = Popen(['hostname'], stdout = PIPE)

hostname=p.stdout.read()

return hostname

def getdiskinfo():

p = Popen(['df','-h'], stdout = PIPE)

disks=p.stdout.read()

return disks

def getmemoryinfo():

p = Popen(['free','-m'], stdout = PIPE)

memorys=p.stdout.read()

return memorys

def getbiosinfo():

p = Popen(['dmidecode','-t','bios'], stdout = PIPE)

bios=p.stdout.read()

return bios

def getcpu():

p = Popen(['sar','-u','1','3'], stdout = PIPE)

time.sleep(3)

cpus=p.stdout.read()

return cpus

def getallinfos():

ip="IP地址: "+getipaddr()

hostname="主机名: "+gethostname()

disk="磁盘信息: "+getdiskinfo()

memory="内存信息: "+getmemoryinfo()

bios="BIOS信息: "+getbiosinfo()

cpu="CPU信息: "+getcpu()

return ip,hostname,disk,memory,bios,cpu

#getallinfos()

3、同步模块,执行验证

[root@v72 _modules]# salt '*' saltutil.sync_modules

v72:

- modules.infos

v73:

- modules.infos

运行,验证

[root@v72 _modules]# salt '*' infos.getallinfos

v73:

- IP地址: 192.168.156.73 192.168.122.1

- 主机名: v73

- 磁盘信息: 文件系统                 容量  已用  可用 已用% 挂载点

/dev/mapper/centos-root   18G  8.0G  9.5G   46% /

devtmpfs                 903M     0  903M    0% /dev

tmpfs                    914M   92K  914M    1% /dev/shm

tmpfs                    914M  9.1M  905M    1% /run

tmpfs                    914M     0  914M    0% /sys/fs/cgroup

/dev/sda1                497M  127M  370M   26% /boot

//192.168.156.1/d$       201G   98G  103G   49% /shared

tmpfs                    183M   12K  183M    1% /run/user/42

tmpfs                    183M     0  183M    0% /run/user/0

- 内存信息:               total        used        free      shared  buff/cache   available

Mem:           1826         389         357           9        1079        1201

Swap:          2047           0        2047

- BIOS信息: # dmidecode 2.12

SMBIOS 2.7 present.

Handle 0x0000, DMI type 0, 24 bytes

BIOS Information

Vendor: Phoenix Technologies LTD

Version: 6.00

Release Date: 07/02/2015

Address: 0xEA5E0

Runtime Size: 88608 bytes

ROM Size: 64 kB

Characteristics:

ISA is supported

PCI is supported

PC Card (PCMCIA) is supported

PNP is supported

APM is supported

BIOS is upgradeable

BIOS shadowing is allowed

ESCD support is available

Boot from CD is supported

Selectable boot is supported

EDD is supported

Print screen service is supported (int 5h)

8042 keyboard services are supported (int 9h)

Serial services are supported (int 14h)

Printer services are supported (int 17h)

CGA/mono video services are supported (int 10h)

ACPI is supported

Smart battery is supported

BIOS boot specification is supported

Function key-initiated network boot is supported

Targeted content distribution is supported

BIOS Revision: 4.6

Firmware Revision: 0.0

- CPU信息: Linux 3.10.0-229.el7.x86_64 (v73)        2019年02月22日  _x86_64_        (1 CPU)

17时06分18秒     CPU     %user     %nice   %system   %iowait    %steal     %idle

17时06分19秒     all      0.00      0.00      0.00      0.00      0.00    100.00

17时06分20秒     all      1.00      0.00      0.00      0.00      0.00     99.00

17时06分21秒     all      0.00      0.00      0.00      0.00      0.00    100.00

平均时间:     all      0.33      0.00      0.00      0.00      0.00     99.67

v72:

- IP地址: 192.168.156.72 192.168.122.1

- 主机名: v72

- 磁盘信息: 文件系统                 容量  已用  可用 已用% 挂载点

/dev/mapper/centos-root   18G   12G  5.7G   68% /

devtmpfs                 903M     0  903M    0% /dev

tmpfs                    914M   96K  914M    1% /dev/shm

tmpfs                    914M  9.2M  905M    2% /run

tmpfs                    914M     0  914M    0% /sys/fs/cgroup

/dev/sda1                497M  127M  370M   26% /boot

//192.168.156.1/d$       201G   98G  103G   49% /shared

tmpfs                    183M   12K  183M    1% /run/user/42

tmpfs                    183M     0  183M    0% /run/user/0

- 内存信息:               total        used        free      shared  buff/cache   available

Mem:           1826         719         316          10         791         871

Swap:          2047           0        2047

- BIOS信息: # dmidecode 2.12

SMBIOS 2.7 present.

Handle 0x0000, DMI type 0, 24 bytes

BIOS Information

Vendor: Phoenix Technologies LTD

Version: 6.00

Release Date: 07/02/2015

Address: 0xEA5E0

Runtime Size: 88608 bytes

ROM Size: 64 kB

Characteristics:

ISA is supported

PCI is supported

PC Card (PCMCIA) is supported

PNP is supported

APM is supported

BIOS is upgradeable

BIOS shadowing is allowed

ESCD support is available

Boot from CD is supported

Selectable boot is supported

EDD is supported

Print screen service is supported (int 5h)

8042 keyboard services are supported (int 9h)

Serial services are supported (int 14h)

Printer services are supported (int 17h)

CGA/mono video services are supported (int 10h)

ACPI is supported

Smart battery is supported

BIOS boot specification is supported

Function key-initiated network boot is supported

Targeted content distribution is supported

BIOS Revision: 4.6

Firmware Revision: 0.0

- CPU信息: Linux 3.10.0-229.el7.x86_64 (v72)        2019年02月22日  _x86_64_        (2 CPU)

17时06分20秒     CPU     %user     %nice   %system   %iowait    %steal     %idle

17时06分21秒     all      0.00      0.00      0.00      0.00      0.00    100.00

17时06分22秒     all      0.51      0.00      0.00      0.00      0.00     99.49

17时06分23秒     all      0.00      0.00      0.51      0.00      0.00     99.49

平均时间:     all      0.17      0.00      0.17      0.00      0.00     99.66

加载哪一部份的信息,只需要在saltstack上面调用对应的方法就可以了

salt 服务器信息收集,使用saltstack自定义模块获取服务器的信息相关推荐

  1. WEB渗透测试(一)被动信息收集1(DNS信息收集、DNS字典爆破、DNS注册信息)

    被动信息收集1 >被动信息收集 >域名系统DNS >DNS信息收集--nslookup >DNS信息收集->dig >DNS区域传输 >DNS字典爆破 > ...

  2. 微信小程序控制台 报错 对应的服务器证书无效 控制台输入 showRequestInfo() 可以获取更详细信息 原因是ssl证书过期 重新申请即可

    微信小程序控制台 报错 对应的服务器证书无效.控制台输入 showRequestInfo() 可以获取更详细信息 报错原因:域名下的SSL证书过期 我这边报错的原因是ssl证书过期 重新申请后就好了, ...

  3. 获取服务器信息目录失败是怎么回事,获取服务器列表失败...(是怎么回事)附解决方法...

    获取服务器列表失败...这种是什么错误,是怎么回事呢?我相信很多成人都遇到过这种错误,无论你是玩家还是开的GM,既然有问题,那么比如就会有解决的方法,今天我们就说说获取服务器列表失败...(是怎么回事 ...

  4. linux查看java堆栈信息_Java运行状态分析2:获取线程堆栈信息

    Java运行状态分析2:获取线程堆栈信息 基本概念 出现内存泄漏或者运行缓慢场景,有时候无法直接从业务日志看出问题时候,需要分析jvm内存和线程堆栈 线程堆栈信息主要记录jvm线程在某时刻线程执行情况 ...

  5. c 怎么跨服务器取文件,c语言远程文件获取服务器

    c语言远程文件获取服务器 内容精选 换一换 用户可根据产品型号获取所需软件包以及数字签名文件.{version}表示软件版本号,{arch}表示CPU架构,{os}表示操作系统版本.{version} ...

  6. 淘宝/天猫API接口,item_sku - 淘宝商品SKU详细信息查询,淘宝/天猫获取sku详细信息 API 返回值说明

    欢迎使用淘宝API接口(item_sku - 淘宝商品SKU详细信息查询 ) 你好! 这是你使用我们的淘宝API接口获取商品详细接口说明. 测试地址:获取Key和secret 测试结果: Reques ...

  7. Java使用百度AI实现识别身份证照片信息,根据身份证号码,获取相关个人信息

    Java使用百度AI实现识别身份证照片信息 百度智能云-登录 1.登录百度智能云,选择文字识别,创建相关信息 2.获取APP_ID.API_KEY.SECRET_KEY 核心处理代码 import c ...

  8. java异常自定义返回信息,Spring Boot 如何自定义返回错误码错误信息

    说明 在实际的开发过程中,很多时候要定义符合自己业务的错误码和错误信息,而不是统一的而不是统一的下面这种格式返回到调用端 INTERNAL_SERVER_ERROR(500, "Intern ...

  9. python爬虫和信息收集_python爬站长之家写一个信息搜集器

    前言: 不知道写什么好,绕来绕去还是写回爬虫这一块. 之前的都爬了一遍.这次爬点好用一点的网站. 0x01: 自行备好requests模块 目标站:http://tool.chinaz.com/ 0x ...

最新文章

  1. git 换行符LF与CRLF转换问题
  2. EdoGantt甘特图中间件的事件对象
  3. 1.大数据处理架构Hadoop
  4. python中cgi到底是什么_十分钟搞懂什么是CGI(转)
  5. 使用Sublime Text作为Markdown编辑器
  6. python2019慕课答案_中国大学慕课mooc2020Python编程基础章节测试答案
  7. 数据库SQL优化大总结之 百万级数据库优化方案(转载)
  8. 04_使用Influxdb自带函数查询
  9. 【转】XP远程桌面连接2008提示:远程计算机需要网络级别身份验证,而您的计算机不支持该验证 ....
  10. Qt实现的局域网通信软件(仿QQ版本)
  11. 下载 | 954页《数据可视化》手册
  12. 2008服务器系统怎么备份,服务器2008系统备份
  13. 图案输出(二)----输出平行四边形图案:(难度系数:小于半颗星)
  14. Eclipse BreakPoint断点调试技巧和基本步骤方法
  15. element-ui中el-dialog使用技巧
  16. 五点三次平滑的程序源代码
  17. 这么多嵌入式设计创意,哪个你曾想过?
  18. win7修复计算机界面,用好Windows7自修复 系统崩溃无需重做
  19. 2014年11月3日至2014年12月29日
  20. 数学模型用matlab表示,数学模型的MATLAB描述.ppt

热门文章

  1. 汽车行业SAP性能分析解决方案
  2. Mac OS删除文件夹和文件的命令
  3. unity二叉树_Unity3D面试总结(续)
  4. #学习笔记#(58)中文标点符号转英文标点符号,及全角转半角js
  5. 视频号超过抖音是迟早的事
  6. python -aliyun
  7. Google Play详情页优化——评论真的会影响转化吗?
  8. COMSOL等离子体错误记录
  9. 省国税局关于营改增相关问题的解答(一)
  10. spring集成邮箱