Finished reworking sc200-pull; removed db code.
This commit is contained in:
117
sc200-pull.py
117
sc200-pull.py
@@ -91,6 +91,9 @@ Settings = [
|
|||||||
] + \
|
] + \
|
||||||
['Alarm-Name:' + repr(x) for x in range(59)] + \
|
['Alarm-Name:' + repr(x) for x in range(59)] + \
|
||||||
['Alarm-Severity:' + repr(x) for x in range(59)]
|
['Alarm-Severity:' + repr(x) for x in range(59)]
|
||||||
|
#Settings = [
|
||||||
|
#'Site-Name'
|
||||||
|
#]
|
||||||
|
|
||||||
|
|
||||||
def Setup():
|
def Setup():
|
||||||
@@ -177,21 +180,14 @@ class Worker(threading.Thread):
|
|||||||
def run(self):
|
def run(self):
|
||||||
retry = False
|
retry = False
|
||||||
socket.setdefaulttimeout(5)
|
socket.setdefaulttimeout(5)
|
||||||
#print ('Started')
|
|
||||||
while 1:
|
while 1:
|
||||||
IP = self.__IPs.get()
|
IP = self.__IPs.get()
|
||||||
#print((self.getName()))
|
|
||||||
if IP is None:
|
if IP is None:
|
||||||
self.__Results.put(None)
|
self.__Results.put(None)
|
||||||
#print('Exiting')
|
|
||||||
break
|
break
|
||||||
|
|
||||||
#s = socket.socket()
|
|
||||||
#if s.connect_ex((str(IP), 80)) == 0:
|
|
||||||
if GetStatusCode(str(IP), "/languages") == 200:
|
if GetStatusCode(str(IP), "/languages") == 200:
|
||||||
print((self.getName() + ' processing: ' + str(IP)))
|
print((self.getName() + ' processing: ' + str(IP)))
|
||||||
#print(('Socket OK: %s' % IP))
|
|
||||||
#print(('%s' % IP))
|
|
||||||
while True:
|
while True:
|
||||||
proxy = ServerProxy('http://%s/xmlrpc' % IP)
|
proxy = ServerProxy('http://%s/xmlrpc' % IP)
|
||||||
try:
|
try:
|
||||||
@@ -207,69 +203,15 @@ class Worker(threading.Thread):
|
|||||||
|
|
||||||
if len(Values) > 0:
|
if len(Values) > 0:
|
||||||
Values.insert(0, str(IP))
|
Values.insert(0, str(IP))
|
||||||
self.__Results.put(['SC200', Values])
|
self.__Results.put(Values)
|
||||||
|
|
||||||
#AlarmNames = ['Alarm-Name:' + repr(x) for x in range(59)]
|
|
||||||
#while True:
|
|
||||||
#try:
|
|
||||||
#Values = proxy.db.get(AlarmNames)
|
|
||||||
#except socket.timeout:
|
|
||||||
#retry = True
|
|
||||||
#continue
|
|
||||||
|
|
||||||
#if retry:
|
|
||||||
#retry = False
|
|
||||||
#else:
|
|
||||||
#break
|
|
||||||
|
|
||||||
#Values.insert(0, str(IP))
|
|
||||||
|
|
||||||
#self.__Results.put(['AlarmNames', Values])
|
|
||||||
|
|
||||||
#AlarmSeverities = ['Alarm-Severity:' + repr(x)
|
|
||||||
#for x in range(59)]
|
|
||||||
#Values = proxy.db.get(AlarmSeverities)
|
|
||||||
|
|
||||||
#Values.insert(0, str(IP))
|
|
||||||
|
|
||||||
#self.__Results.put(['AlarmSeverities', Values])
|
|
||||||
#s.close()
|
|
||||||
else:
|
else:
|
||||||
print((self.getName() + ' skipping: ' + str(IP)))
|
print((self.getName() + ' skipping: ' + str(IP)))
|
||||||
|
|
||||||
|
|
||||||
def Loader():
|
|
||||||
Count = WORKERS
|
|
||||||
c = db.cursor()
|
|
||||||
|
|
||||||
while 1:
|
|
||||||
Row = Results.get()
|
|
||||||
if Row is None:
|
|
||||||
if Count > 1:
|
|
||||||
Count -= 1
|
|
||||||
print(Count)
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
#print(('Loading: %s %s' % (Row[1][0], Row[0])))
|
|
||||||
#SQL = 'INSERT INTO %s VALUES (' % Row[0]
|
|
||||||
#for i in Row[1]:
|
|
||||||
#SQL += '?,'
|
|
||||||
#SQL = SQL[:-1]
|
|
||||||
#SQL += ')'
|
|
||||||
|
|
||||||
#c.execute(SQL, Row[1])
|
|
||||||
#print((list(zip(Settings, Row[1][1:]))))
|
|
||||||
c.executemany('INSERT INTO SettingsValues VALUES ( \'%s\', ?, ?)'
|
|
||||||
% Row[1][0],
|
|
||||||
list(zip(Settings, Row[1][1:])))
|
|
||||||
|
|
||||||
db.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def Output():
|
def Output():
|
||||||
c = db.cursor()
|
Count = WORKERS
|
||||||
fieldNames = ['IP'] + Settings
|
fieldNames = ['IP'] + Settings
|
||||||
|
|
||||||
with open('/tmp/sc200.csv', 'w', newline='') as outFile:
|
with open('/tmp/sc200.csv', 'w', newline='') as outFile:
|
||||||
csvWriter = csv.DictWriter(outFile, fieldnames=fieldNames,
|
csvWriter = csv.DictWriter(outFile, fieldnames=fieldNames,
|
||||||
delimiter=',', quotechar='"',
|
delimiter=',', quotechar='"',
|
||||||
@@ -277,45 +219,20 @@ def Output():
|
|||||||
|
|
||||||
csvWriter.writeheader()
|
csvWriter.writeheader()
|
||||||
|
|
||||||
c.execute('''SELECT DISTINCT IP FROM SettingsValues ORDER BY IP''')
|
while 1:
|
||||||
for Device in c:
|
Row = Results.get()
|
||||||
IP = Device
|
if Row is None:
|
||||||
print((('''SELECT SettingsID, Value
|
if Count > 1:
|
||||||
FROM SettingsValues WHERE IP = \'%s\'''' % IP)))
|
Count -= 1
|
||||||
row = c.execute('''SELECT SettingsID, Value
|
#print(Count)
|
||||||
FROM SettingsValues WHERE IP = \'%s\'''' % IP)
|
else:
|
||||||
print(((row)))
|
break
|
||||||
|
else:
|
||||||
|
csvWriter.writerow(dict(list(zip(fieldNames, Row))))
|
||||||
|
|
||||||
outFile.close()
|
outFile.close()
|
||||||
|
|
||||||
|
|
||||||
#csvWriter.writerow()
|
|
||||||
|
|
||||||
#c = db.cursor()
|
|
||||||
#with open('/tmp/sc200.csv', 'w', newline='') as outFile:
|
|
||||||
#csvWriter = csv.writer(outFile, delimiter=',', quotechar='"',
|
|
||||||
#quoting=csv.QUOTE_MINIMAL)
|
|
||||||
#c.execute('''SELECT * FROM SettingsValues ORDER BY IP''')
|
|
||||||
#csvWriter.writerow([col[0] for col in c.description])
|
|
||||||
#for row in c:
|
|
||||||
#csvWriter.writerow(row)
|
|
||||||
#outFile.close()
|
|
||||||
|
|
||||||
#with open('/tmp/sc200-alarms.csv', 'w', newline='') as outFile:
|
|
||||||
#csvWriter = csv.writer(outFile, delimiter=',', quotechar='"',
|
|
||||||
#quoting=csv.QUOTE_MINIMAL)
|
|
||||||
#c.execute('''SELECT * FROM AlarmNames LIMIT 1''')
|
|
||||||
#for row in c:
|
|
||||||
#csvWriter.writerow(row)
|
|
||||||
#c.execute('''SELECT * FROM AlarmSeverities''')
|
|
||||||
#for row in c:
|
|
||||||
#csvWriter.writerow(row)
|
|
||||||
#outFile.close()
|
|
||||||
|
|
||||||
db = sqlite3.connect(':memory:')
|
|
||||||
#db = sqlite3.connect('/tmp/sc200.db')
|
|
||||||
|
|
||||||
Setup()
|
|
||||||
IPs = queue.Queue(0)
|
IPs = queue.Queue(0)
|
||||||
Results = queue.Queue(0)
|
Results = queue.Queue(0)
|
||||||
|
|
||||||
@@ -328,7 +245,6 @@ for SubNet in Nets:
|
|||||||
for IP in Net:
|
for IP in Net:
|
||||||
if ((IP != Net.network and IP != Net.broadcast) or
|
if ((IP != Net.network and IP != Net.broadcast) or
|
||||||
Net.broadcast is None):
|
Net.broadcast is None):
|
||||||
#print(('Queued: ' + str(IP)))
|
|
||||||
IPs.put(IP)
|
IPs.put(IP)
|
||||||
|
|
||||||
for i in range(WORKERS):
|
for i in range(WORKERS):
|
||||||
@@ -337,7 +253,6 @@ for i in range(WORKERS):
|
|||||||
if threading.current_thread() is not threading.main_thread():
|
if threading.current_thread() is not threading.main_thread():
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
Loader()
|
|
||||||
Output()
|
Output()
|
||||||
|
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|||||||
Reference in New Issue
Block a user