мониторинг софта в freebsd (python)
#!/usr/bin/env python
#-*- coding: windows-1251 -*-
import os
import subprocess
all = {}
rez = {}
te = {}
def devic():
data = open('data', 'r')
while 1:
da = data.readline()
all[da] = [da]
if not da: break
dmidecode = subprocess.Popen(['dmidecode -t 4'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
i = 0
while i<=50:
line = dmidecode.stdout.readline()
if not line in all:
proc = 'not register processor => '+line
rez[proc] = proc
i = i + 1
if not line: break
dmidecode = subprocess.Popen(['dmidecode -t 6'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
while 1:
line = dmidecode.stdout.readline()
if not line in all:
ram = 'not register ram => '+line
rez[ram] = ram
i = i + 1
if not line: break
dmidecode = subprocess.Popen(['dmidecode -t 10'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
while 1:
line = dmidecode.stdout.readline()
if not line in all:
media = 'not register media => '+line
rez[media] = media
if not line: break
dmidecode = subprocess.Popen(['dmidecode -t 2'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
while 1:
line = dmidecode.stdout.readline()
if not line in all:
board = 'not register mother board => '+line
rez[board] = board
if not line: break
lshw = subprocess.Popen(['lshw -C disc'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
while 1:
line = lshw.stdout.readline()
if not line in all:
disc = 'not register disc => '+line
rez[disc] = disc
if not line: break
log = open('log', 'r')
while 1:
line = log.readline()
te[line] = line
if not line: break
log.close()
log = open('log', 'a')
for x in rez:
# print rez[x]
if rez[x] not in te:
print rez[x]
log.write(rez[x])
log.close()
while 1:
devic()