diff --git a/.gitignore b/.gitignore index e405594f..581d4cf9 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,2 @@ .svn/ - .idea diff --git a/adminset.conf b/adminset.conf index d8dde748..80c764c8 100644 --- a/adminset.conf +++ b/adminset.conf @@ -13,6 +13,6 @@ password = database = adminset [token] -token = +token = HPcWR7l4NJNJ diff --git a/db.sqlite3 b/db.sqlite3 deleted file mode 100644 index 3689eb05..00000000 Binary files a/db.sqlite3 and /dev/null differ diff --git a/readme.md b/readme.md deleted file mode 100644 index e69de29b..00000000 diff --git a/requirements.txt b/requirements.txt index 92d86903..eac4eabe 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ django==1.9.8 sh==1.12.9 -Celery==4.0.2 mysql-python==1.2.5 +ansible==2.2.1.0 diff --git a/scripts/__init__.py b/scripts/__init__.py deleted file mode 100644 index 8bc2184f..00000000 --- a/scripts/__init__.py +++ /dev/null @@ -1,2 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- \ No newline at end of file diff --git a/post_info.py b/scripts/agent_post_info.py similarity index 95% rename from post_info.py rename to scripts/agent_post_info.py index dc1dffda..b7d7386e 100644 --- a/post_info.py +++ b/scripts/agent_post_info.py @@ -10,16 +10,22 @@ import platform import socket +token = 'HPcWR7l4NJNJ' +server_url = 'http://192.168.47.130:8000/cmdb/collect' + + def get_ip(): hostname = socket.getfqdn(socket.gethostname()) ipaddr = socket.gethostbyname(hostname) return ipaddr + def getDMI(): p = Popen('dmidecode', stdout=PIPE, shell=True) stdout, stderr = p.communicate() return stdout - + + def parserDMI(dmidata): pd = {} line_in = False @@ -34,6 +40,7 @@ def parserDMI(dmidata): line_in = False return pd + def getMemTotal(): cmd = "grep MemTotal /proc/meminfo" p = Popen(cmd, stdout = PIPE, shell = True) @@ -42,12 +49,14 @@ def getMemTotal(): memtotal = int(round(int(mem_total)/1024.0/1024.0, 0)) return memtotal + def getCpu(): cmd = "cat /proc/cpuinfo" p = Popen(cmd, stdout = PIPE, stderr = PIPE, shell = True) stdout, stderr = p.communicate() return stdout + def parserCpu(stdout): groups = [i for i in stdout.split('\n\n')] group = groups[-2] @@ -58,6 +67,7 @@ def parserCpu(stdout): cpu_info[k] = v return cpu_info + def getDiskInfo(): ret = {} disk_dev = re.compile(r'Disk\s/dev/sd[a-z]{1}') @@ -72,6 +82,8 @@ def getDiskInfo(): p = n.communicate() ret[dk] = p return ret + + def parserDiskInfo(diskdata): pd = {} disknum = diskdata.keys() @@ -90,12 +102,14 @@ def parserDiskInfo(diskdata): pd[num] = endnum + 'G' return pd + def postData(data): postdata = urllib.urlencode(data) - req = urllib2.urlopen('http://192.168.47.130:8000/cmdb/collect',postdata) + req = urllib2.urlopen(server_url, postdata) req.read() return True + def main(): data_info = {} data_info['memory'] = getMemTotal() @@ -116,6 +130,8 @@ def main(): os_ver = os_ver.rstrip() data_info['osver'] = os_ver data_info['hostname'] = platform.uname()[1] + data_info['token'] = token + return data_info diff --git a/scripts/get_DMI_info.py b/scripts/get_DMI_info.py deleted file mode 100644 index 3baf6d20..00000000 --- a/scripts/get_DMI_info.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/python -# -*- coding:utf-8 -*- - -from subprocess import PIPE,Popen -import urllib, urllib2 - -def getDMI(): - p = Popen('dmidecode',shell=True,stdout=PIPE) - stdout, stderr = p.communicate() - return stdout - -def parserDMI(dmidata): - pd = {} - fd = {} - line_in = False - for line in dmidata.split('\n'): - if line.startswith('System Information'): - line_in = True - continue - if line.startswith('\t') and line_in: - k, v = [i.strip() for i in line.split(':')] - pd[k] = v - else: - line_in = False - name = "Manufacturer:%s ; Serial_Number:%s ; Product_Name:%s" % (pd['Manufacturer'],pd['Serial Number'],pd['Product Name']) - for i in name.split(';'): - k, v = [j.strip() for j in i.split(':')] - fd[k] = v - return fd - -if __name__ == '__main__': - dmidata = getDMI() - postdata = parserDMI(dmidata) - print postdata diff --git a/scripts/get_cpu_info.py b/scripts/get_cpu_info.py deleted file mode 100644 index aa5fdb8b..00000000 --- a/scripts/get_cpu_info.py +++ /dev/null @@ -1,34 +0,0 @@ -#!/usr/bin/python -#-*- coding:utf-8 -*- - -from subprocess import PIPE,Popen -import re - -def getCpuInfo(): - p = Popen(['cat','/proc/cpuinfo'],shell=False,stdout=PIPE) - stdout, stderr = p.communicate() - return stdout.strip() - -def parserCpuInfo(cpudata): - pd = {} - model_name = re.compile(r'.*model name\s+:\s(.*)') - vendor_id = re.compile(r'vendor_id\s+:(.*)') - cpu_cores = re.compile(r'cpu cores\s+:\s([\d]+)') - lines = [line for line in cpudata.split('\n')] - for line in lines: - model = re.match(model_name,line) - vendor = re.match(vendor_id,line) - cores = re.match(cpu_cores,line) - if model: - pd['Model_Name'] = model.groups()[0].strip() - if vendor: - pd['Vendor_Id'] = vendor.groups()[0].strip() - if cores: - pd['Cpu_Cores'] = cores.groups()[0] - else: - pd['Cpu_Cores'] = int('1') - return pd - -if __name__ == '__main__': - cpudata = getCpuInfo() - print parserCpuInfo(cpudata) diff --git a/scripts/get_disk_info.py b/scripts/get_disk_info.py deleted file mode 100644 index ae0df4b2..00000000 --- a/scripts/get_disk_info.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python -#-*- coding:utf-8 -*- - -from subprocess import PIPE,Popen -import re -import json - - -def getDiskInfo(): - ret = {} - disk_dev = re.compile(r'Disk\s/dev/sd[a-z]{1}') - disk_name = re.compile(r'/dev/sd[a-z]{1}') - pcmd = Popen(['fdisk','-l'],shell=False,stdout=PIPE) - stdout, stderr = pcmd.communicate() - for i in stdout.split('\n'): - disk = re.match(disk_dev,i) - if disk: - dk = re.search(disk_name,disk.group()).group() - n = Popen('smartctl -i %s' % dk,shell=True,stdout=PIPE) - p = n.communicate() - ret[dk] = p - return ret -def parserDiskInfo(diskdata): - pd = {} - disknum = diskdata.keys() - device_model = re.compile(r'(Device Model):(\s+.*)') - serial_number = re.compile(r'(Serial Number):(\s+[\d\w]{1,30})') - firmware_version = re.compile(r'(Firmware Version):(\s+[\w]{1,20})') - user_capacity = re.compile(r'(User Capacity):(\s+[\d,]{1,50})') - for num in disknum: - t = str(diskdata[num]) - for line in t.split('\n'): - user = re.search(user_capacity,line) - if user: - diskvo = user.groups()[1].strip() - nums = int(diskvo.replace(',','')) - pd[num] = nums/1000/1000/1000 - return json.dumps(pd) - -if __name__ == '__main__': - diskdata = getDiskInfo() - print parserDiskInfo(diskdata) diff --git a/scripts/get_host_info.py b/scripts/get_host_info.py deleted file mode 100644 index 2c3ead46..00000000 --- a/scripts/get_host_info.py +++ /dev/null @@ -1,18 +0,0 @@ -#!/usr/bin/python -#-*- coding:utf-8 -*- - -import platform - -def getHostInfo(): - pd ={} - version = platform.dist() - os_name = platform.node() - os_release = platform.release() - os_version = '%s %s' % (version[0],version[1]) - pd['os_name'] = os_name - pd['os_release'] = os_release - pd['os_version'] = os_version - return pd - -if __name__ == '__main__': - print getHostInfo() diff --git a/scripts/get_ip.py b/scripts/get_ip.py deleted file mode 100644 index dd4dcddd..00000000 --- a/scripts/get_ip.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/python -#-*- coding:utf-8 -*- - -from subprocess import PIPE,Popen -import re - - -def getIpaddr(): - p = Popen(['ifconfig'],shell=False,stdout=PIPE) - stdout, stderr = p.communicate() - return stdout.strip() - - -def parserIpaddr(ipdata): - try: - device = re.compile(r'^(eth\d{0,9})') - except ImportError,e: - device = re.compile(r'^(eno\d{0,9})') - mac = re.compile(r'(ether\s[0-9A-Fa-f:]{17})') - ip = re.compile(r'inet ([\d.]{7,15})') - for lines in ipdata.split('\n\n'): - pd = {} - eth_device = re.search(device,lines) - hw = re.search(mac,lines) - ips = re.search(ip,lines) - if eth_device: - if eth_device: - Device = eth_device.groups()[0] - if hw: - Mac = hw.groups()[0].split()[1] - if ips: - Ip = ips.groups()[0] - pd['Device'] = Device - pd['Mac'] = Mac - pd['Ip'] = Ip - yield pd - -if __name__ == '__main__': - ipdata = getIpaddr() - foo = parserIpaddr(ipdata) - for i in foo: - print i diff --git a/scripts/get_memory_info.py b/scripts/get_memory_info.py deleted file mode 100644 index f1a18e5f..00000000 --- a/scripts/get_memory_info.py +++ /dev/null @@ -1,43 +0,0 @@ -#!/usr/bin/python -#-*- coding:utf-8 -*- - -from subprocess import PIPE,Popen -import re -import sys - -def getMemInfo(): - p = Popen(['dmidecode'],shell=False,stdout=PIPE) - stdout, stderr = p.communicate() - return stdout.strip() - -def parserMemInfo(memdata): - line_in = False - mem_str = '' - pd = {} - fd = {} - for line in memdata.split('\n'): - if line.startswith('Memory Device') and line.endswith('Memory Device'): - line_in = True - mem_str+='\n' - continue - if line.startswith('\t') and line_in: - mem_str+=line - else: - line_in = False - for i in mem_str.split('\n')[1:]: - lines = i.replace('\t','\n').strip() - for ln in lines.split('\n'): - k, v = [i for i in ln.split(':')] - pd[k.strip()] = v.strip() - if pd['Size'] != 'No Module Installed': - mem_info = 'Size:%s ; Part_Number:%s ; Manufacturer:%s' % (pd['Size'],pd['Part Number'],pd['Manufacturer']) - for line in mem_info.split('\n'): - for word in line.split(';'): - k, v = [i.strip() for i in word.split(':')] - fd[k] = v.strip() - yield fd - -if __name__ == '__main__': - memdata = getMemInfo() - for i in parserMemInfo(memdata): - print i diff --git a/scripts/ipbackup.py b/scripts/ipbackup.py deleted file mode 100644 index f3e48d19..00000000 --- a/scripts/ipbackup.py +++ /dev/null @@ -1,46 +0,0 @@ -#!/usr/bin/python -#-*- coding:utf-8 -*- - -from subprocess import PIPE,Popen -import re - -def getIpaddr(): - p = Popen(['ifconfig'],shell=False,stdout=PIPE) - stdout, stderr = p.communicate() - return stdout.strip() - -def parserIpaddr(ipdata): - device = re.compile(r'(wlan\d)') - ipaddr = re.compile(r'(inet addr:[\d.]{7,15})') - mac = re.compile(r'(HWaddr\s[0-9A-Fa-f:]{17})') - link = re.compile(r'(Link encap:[\w]{3,14})') - mask = re.compile(r'(Mask:[\d.]{9,15})') - for lines in ipdata.split('\n\n'): - pd = {} - eth_device = re.search(device,lines) - inet_ip = re.search(ipaddr,lines) - hw = re.search(mac,lines) - link_encap = re.search(link,lines) - _mask = re.search(mask,lines) - if eth_device: - if eth_device: - Device = eth_device.groups()[0] - if inet_ip: - Ipaddr = inet_ip.groups()[0].split(':')[1] - if hw: - Mac = hw.groups()[0].split()[1] - if link_encap: - Link = link_encap.groups()[0].split(':')[1] - if _mask: - Mask = _mask.groups()[0].split(':')[1] - pd['Device'] = Device - pd['Ipaddr'] = Ipaddr - pd['Mac'] = Mac - pd['Link'] = Link - pd['Mask'] = Mask - yield pd - -if __name__ == '__main__': - ipdata = getIpaddr() - for i in parserIpaddr(ipdata): - print i diff --git a/scripts/test.py b/scripts/test.py deleted file mode 100644 index 12e04885..00000000 --- a/scripts/test.py +++ /dev/null @@ -1,49 +0,0 @@ -#! /usr/bin/env python -# -*- coding: utf-8 -*- - -from subprocess import PIPE,Popen -import re - - -def getip(): - p = Popen(['ip','addr'],shell=False,stdout=PIPE) - stdout, stderr = p.communicate() - return stdout.strip() - - -def pgetip(ipdata): - pd = {} - device = re.compile(r'(eno\d{0,9})') - ip = re.compile(r'inet ([\d.]{7,15})') - for lines in ipdata.split('\n'): - eth_device = re.search(device,lines) - ips = re.search(ip,lines) - if eth_device: - Device = eth_device.groups() - Ip = ips.groups()[0] - pd['Device'] = Device - pd['Ip'] = Ip - yield pd - -def pgetip(ipdata): - device = re.compile(r'^(eno\d{0,9})') - mac = re.compile(r'(ether\s[0-9A-Fa-f:]{17})') - ip = re.compile(r'inet ([\d.]{7,15})') - for lines in ipdata.split('\n'): - pd = {} - eth_device = re.search(device,lines) - hw = re.search(mac,lines) - ips = re.search(ip,lines) - if eth_device: - if eth_device: - Device = eth_device.groups()[0] - if hw: - Mac = hw.groups()[0].split()[1] - if ips: - Ip = ips.groups()[0] - pd['Device'] = Device - pd['Mac'] = Mac - pd['Ip'] = Ip - yield pd - -pgetip(getip()) \ No newline at end of file diff --git a/static/dist/img/demo.png b/static/dist/img/demo.png new file mode 100644 index 00000000..554a49e2 Binary files /dev/null and b/static/dist/img/demo.png differ