GithubHelp home page GithubHelp logo

autocmdb's Introduction

说明

CMDB管理系统,基于Ansible最新版开发,采用前后端分离架构

项目主要结构

./
├── ansible_client  # ansible_client客户端
│   └── monitor
│       ├── cpu.py  # 监控cpu
│       └── memory.py  # 监控内存
├── api  # api部分
│   ├── api_urls.py  # api相关的url
│   ├── serializers  # 序列化相关
│   │   ├── ansible.py  # ansible
│   │   ├── disk.py  # 磁盘
│   │   ├── hostinfo.py  # 主机详细信息
│   │   ├── host.py  # 主机信息
│   │   └── network.py  # 网络信息
│   ├── utils
│   │   ├── ansible  # ansible相关
│   │   │   ├── check_ip.py  # 检测ip可用性
│   │   │   ├── exec_ansible.py  # ansible的API,用来执行ansible命令
│   │   │   ├── extract_setup.py  # 检测硬件信息
│   │   │   ├── hosts_fm.py  # ansible的hosts文件写入
│   │   │   ├── login_host.py  # 远程登录主机
│   │   │   └── remotExect.sh  # 输入密码
│   │   ├── auth.py  # 认证
│   │   ├── response.py  # 统一code返回值
│   │   └── serialization_general.py  # 标准序列化返回值
│   └── views
│       ├── ansible.py  # ansible相关
│       ├── disk.py  # 磁盘相关
│       ├── hostinfo.py  # 主机详情
│       ├── host.py  # 主机
│       ├── monit  # 监控相关
│       │   ├── cpu.py
│       │   └── memory.py
│       └── network.py  # 网卡相关
├── AutoCmdb
│   ├── settings.py  # 项目配置文件
│   ├── urls.py  # 总入口
├── cron
│   └── test_orm.py  # 测试脚本
├── db.sqlite3  # 数据库
├── manage.py  # 启动文件
├── README.md
├── repository
│   └── models.py  # 数据库文件
└── web  # 前端展示部分
    ├── static  # 静态目录
    │   ├── css
    │   ├── img
    │   ├── js
    │   └── plugins
    │       ├── bootstrap-3.3.7  # bootstrap
    │       ├── font-awesome-4.7.0  # 图标库插件
    │       ├── Highcharts-6.1.2  # 图表插件
    │       └── sweetalert  # 弹框插件
    ├── templates  # 模板相关
    │   ├── ansible_add_host.html  # 添加ansible主机
    │   ├── ansible_add.html  # 添加ansible组
    │   ├── ansible_list.html  # ansible列表
    │   ├── base.html  # 母版
    │   ├── default.html  # 默认首页的右侧部分
    │   ├── host_info.html  # 主机详情
    │   ├── host_list.html  # 主机列表
    │   ├── index.html  # 首页主体部分,包含左侧边栏和头部
    │   └── monitor  # 监控图表相关
    │       ├── cpu.html
    │       └── memory.html
    ├── views
    │   ├── ansible.py  # ansible相关
    │   ├── host.py  # 主机相关
    │   └── index.py
    └── web_urls.py  # web页面相关路由

运行环境

Project version Description
python 3.6.5
django 1.11.15 必须此版本
djangorestframework 3.8.2
ansible 2.7.0 不能低于此版本

功能说明

以下功能,都是用python来完成的
1.  使用django rest framework开发api
2.  优雅获取本机IP
3.  判断ip地址是否有效
4.  判断ssh端口是否开放
5.  自动使用yum安装软件
6.  自动完成ssh免密码登录
7.  根据数据库记录的变化,自动写入文件/etc/ansible/hosts
8.  使用ansible 2.x API收集客户端硬件信息
9.  根据返回的硬件信息,使用事务写入数据库中
10. 使用psutil模块获取cpu和内存使用情况,并发送给后端API,统一入库.
11. 使用Highcharts插件来展示监控图表,比如: cpu和内存.

效果

首页:

Image text

ansible管理:

Image text

ansible主机:

Image text

主机详情:

Image text

运行方式

ansible主控端

首先需要编译安装python3,请参考链接:
http://www.py3study.com/Article/details/id/320.html
做到添加豆瓣源为止,请务必按照本教程操作,否则会出现没有pip3的问题!!!

安装2个系统软件
yum install -y ansible expect


安装python相关模块
pip3 install django==1.11.15
pip3 install djangorestframework
pip3 install ansible
或者使用requirements.txt文件安装相关模块
pip3 install -r requirements.txt

最后切换到项目目录,使用以下命令运行
python3 manage.py runserver 0.0.0.0:8000

ansible被控端

编译安装python3,参考上面的操作!
注意:被控端不需要安装ansible!!!

安装python相关模块
pip3 install requests psutil

将项目中的ansible_client拷贝到opt目录中
注意:务必修改cpu.py和memory.py中的ip地址

设置linux任务计划:

# 监控cpu和内存
* * * * * python3 /opt/ansible_client/monitor/cpu.py
* * * * * python3 /opt/ansible_client/monitor/memory.py

网页操作

请务必安装以下操作进行:
访问页面: http://ip地址/web/  
注意:必须使用谷歌浏览器访问,360浏览器可能某些数据无法加载!

1. 进入首页,点击左侧ansible管理。必须先添加组
2. 添加组之后,再点击添加主机
3. 最后点击左侧ansible主机,就可以查看主机详情和监控图表了

备注

本项目只是一个demo,请勿直接用于生产环境!

Copyright (c) 2018-present, xiao You

autocmdb's People

Contributors

py3study avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.