Created on 2017年6月6日python
第1課 上節做業 10minutes數據庫
顯示頁面時,只有登陸了才能顯示,沒登陸會彈出一個登陸框,就是一個遮擋層
第2課 自動化之路和CMBD地位 22minutesdjango
CMDB:
自動安裝
配置管理系統
CMDB運維資產管理系統(全部系統都須要調用這裏的信息)---核心所在
圖表工具
highchats
echats
CMDB:
採集硬件數據
API彙報----開放給全部外部,收集信息,經過API寫入到數據庫
頁面管理
大概流程:Client Agent經過URL向API彙報====>API接收後存到數據庫中====>後臺管理經過調用數據庫,對數據進行增刪改查
json
第3課 CMDB之puppet採集數據方式 21minutes
採集puppet去操做
puppet:
factor ==> 結果以Key/value方式存在 (Saltstack ===> grains)
report ==> 只要master/slive鏈接一次,就執行report process函數
master(保存配置信息,和slive半小時鏈接一次,可更改)
slive(從Master獲取配置,用此配置獲得本地硬件信息)
可經過puppet採集硬件信息,嚴重依賴puppet
後端
第4課 CMDB之自定義python插件採集數據方式 11minutesapi
經過Python程序來調用Shell收集硬件信息
新建了個day15_pj的程序,代碼不完整,需補充
第5課 CMDB之django實現API 35minutes
每一個Agang裏獲得都是字典,包含設備的硬件信息
經過對視頻裏的腳本的複製,部分未看到
能夠經過httplib 的方式將數據發送到一個函數裏
markdown
Created on 2017年6月7日
第6課 CMDB之數據流執行過程回顧 18minutesapp
def RequestUrl(host,port,source,params,timeout): headers = {'Content-type':'applicaton/','Accept':'text/plain'} try: conn = httplib.HTTPConnection(host,port,timeout) conn.request('POST',source,params,headers) response = conn.getresponse() original = response.read() except Exception,e: raise e return original server_info = {'cpu':'idle'} if __name__ == '__main': while True: #經過Plugin獲取硬件信息 #將所的得到的信息組合成一個字典,將字典發送到一個API #API保存信息到數據庫 RequestData = urllib.urlencode({'data':server_info}) result = RequestUrl('127.0.0.1','8888','/recelve_server_info',RequestData,30) print '========result: %s =========='%(result,) time.sleep(50)
第7課 CMDB之rest_framework開始API一 31minutes運維
能夠測試Httplib程序 ----------------------------------------------------------------- # -*- coding: utf-8 -*- ''' Created on 2017年6月7日 @author: louts ''' import os import httplib import time import json import urllib from plugins import DiskPlugin from plugins import MemoryPlugin class Program(): def __init__(self): hostname = os.environ['HOSTNAME'] self.server_info = '' def execute(self): big_dict = {} #對每一個插件得到的數據直接拉過來,放大一個大字典裏 ram = MemoryPlugin.MemoryPlugin ram_dict = ram.execute() big_dict = { 'ram':ram_dict, } RequestData = {'data':big_dict} #格式化數據 RequestData = urllib.urlencode({'data':server_info}) #發送數據 self.requestUrl('127.0.0.1','8000','/api/',RequestData,30) #經過httplib向URL發送請求 (代碼已完整) #http://127.0.0.1:8000/index/ #host:127.0.0.1 port:8000 source:/index/ params:data def requestUrl(self,host,port,source,params,timeout): headers = {'Content-type':'applicaton/','Accept':'text/plain'} try: conn = httplib.HTTPConnection(host,port,timeout) conn.request('POST',source,params,headers) response = conn.getresponse() original = response.read() except Exception,e: raise e return original if __name__ == '__main__': times = 0 while True: objProgram = Program() objProgram.execute() times += 1 time.sleep(30000) ----------------------------------------------------------------- Python開放接口,其實就是寫一個函數,將信息進行返回 def install_os(request): #從數據庫取數據 #用Json進行封裝 #返回給用戶 pass #REST是Representational State Transfer的簡稱,中文翻譯爲「表徵狀態轉移」 def server(request): #REST裏的函數用名詞來定義 #可用行業的規則來操做,增刪改查 method = post,delete,put,get if post: Add if delete: del if put: update if get: Select Django REST framework pip install djangorestframework pip install markdown # Markdown support for the browsable API. pip install django-filter # Filtering support
Created on 2017年6月10日
第8課 CMDB之rest_framework開始API二 32minuteside
這裏有點問題,須要學習,在URL裏不能有兩個URL,將原來的URL併到新的當中就能夠看到了 還不知道如何增刪改查 #------rest-framework------------------ from django.conf.urls import url, include from django.contrib.auth.models import User from app01.models import Book #這裏導入有問題 from rest_framework import routers, serializers, viewsets # Serializers define the API representation. #這個類直接序列化queryset獲得的數據 class UserSerializer(serializers.HyperlinkedModelSerializer): class Meta: #這裏是定義的數據庫類 model = User fields = ('url', 'username', 'email', 'is_staff') # ViewSets define the view behavior. class UserViewSet(viewsets.ModelViewSet): queryset = User.objects.all() serializer_class = UserSerializer class BookSerializer(serializers.HyperlinkedModelSerializer): class Meta: #這裏是定義的數據庫類 model = Book fields = ('url', 'name', 'auth') # ViewSets define the view behavior. class BookViewSet(viewsets.ModelViewSet): queryset = Book.objects.all() serializer_class = BookSerializer # Routers provide an easy way of automatically determining the URL conf. router = routers.DefaultRouter() router.register(r'users', UserViewSet) router.register(r'books', BookViewSet) urlpatterns = [ url(r'^', include(router.urls)), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), url(r'^recevie_server_info/', views.recevie_server_info), url(r'^admin/', admin.site.urls), ]
#----------------------------------
視頻中的URL有POST,實際操做中沒有這個功能
Chrome插件POSTMAN能夠對頁面進行操做。
Created on 2017年6月11日
第9課 CMDB之表結構設計 41minutes
能夠經過rest_framework的裝飾器來限制增刪改查,但實驗未成功 --------------------------------------------------- from rest_framework.decorators import api_view from rest_framework.response import Response #rest_framework裝飾器 @api_view(['GET','PUT','POST','DELETE']) def servers(request): #REST是Representational State Transfer的簡稱,中文翻譯爲「表徵狀態轉移」 #REST裏的函數用名詞來定義 #可用行業的規則來操做,增刪改查 #method = post,delete,put,get method = request.method if method == 'POST': return Response('ddd') ------------------------------------------------------- 建立數據庫,一個Asset表對應一大堆的後端設備及CPU和內存信息
Created on 2017年6月18日
第10課 CMDB之表結構設計 41minutes