Skip to content

Commit

Permalink
脚本优化
Browse files Browse the repository at this point in the history
  • Loading branch information
guohongze committed Mar 15, 2017
1 parent 0e97540 commit acf79cb
Show file tree
Hide file tree
Showing 16 changed files with 20 additions and 315 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
.svn/

.idea
2 changes: 1 addition & 1 deletion adminset.conf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ password =
database = adminset

[token]
token =
token = HPcWR7l4NJNJ


Binary file removed db.sqlite3
Binary file not shown.
Empty file removed readme.md
Empty file.
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -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
2 changes: 0 additions & 2 deletions scripts/__init__.py

This file was deleted.

20 changes: 18 additions & 2 deletions post_info.py → scripts/agent_post_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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]
Expand All @@ -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}')
Expand All @@ -72,6 +82,8 @@ def getDiskInfo():
p = n.communicate()
ret[dk] = p
return ret


def parserDiskInfo(diskdata):
pd = {}
disknum = diskdata.keys()
Expand All @@ -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()
Expand All @@ -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

Expand Down
34 changes: 0 additions & 34 deletions scripts/get_DMI_info.py

This file was deleted.

34 changes: 0 additions & 34 deletions scripts/get_cpu_info.py

This file was deleted.

42 changes: 0 additions & 42 deletions scripts/get_disk_info.py

This file was deleted.

18 changes: 0 additions & 18 deletions scripts/get_host_info.py

This file was deleted.

42 changes: 0 additions & 42 deletions scripts/get_ip.py

This file was deleted.

43 changes: 0 additions & 43 deletions scripts/get_memory_info.py

This file was deleted.

46 changes: 0 additions & 46 deletions scripts/ipbackup.py

This file was deleted.

Loading

0 comments on commit acf79cb

Please sign in to comment.