sc200-push working.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
from netaddr import IPNetwork
|
from netaddr import IPNetwork
|
||||||
#from netaddr import IPAddress
|
#from netaddr import IPAddress
|
||||||
from xmlrpc.client import ServerProxy
|
from xmlrpc.client import ServerProxy
|
||||||
import sqlite3
|
#import sqlite3
|
||||||
import socket
|
import socket
|
||||||
import csv
|
import csv
|
||||||
import queue
|
import queue
|
||||||
@@ -56,10 +56,10 @@ else:
|
|||||||
|
|
||||||
Settings = [
|
Settings = [
|
||||||
'Site-Name',
|
'Site-Name',
|
||||||
|
'Site-Address',
|
||||||
|
'System-Location',
|
||||||
'Site-Notes',
|
'Site-Notes',
|
||||||
'Serial-Number',
|
|
||||||
'Float-Voltage',
|
'Float-Voltage',
|
||||||
'Operating-Voltage',
|
|
||||||
'Battery-Capacity',
|
'Battery-Capacity',
|
||||||
'AC-Rectifier-Current-Limit',
|
'AC-Rectifier-Current-Limit',
|
||||||
'High-Float-Threshold',
|
'High-Float-Threshold',
|
||||||
@@ -85,79 +85,12 @@ Settings = [
|
|||||||
'Battery-Test-Duration',
|
'Battery-Test-Duration',
|
||||||
'Battery-Test-Termination-Voltage',
|
'Battery-Test-Termination-Voltage',
|
||||||
'LVD-Disconnect-Voltage:1',
|
'LVD-Disconnect-Voltage:1',
|
||||||
'LVD-Reconnect-Voltage:1',
|
'LVD-Reconnect-Voltage:1'
|
||||||
'Number-Of-Registered-Rectifiers',
|
|
||||||
'Number-Of-Rectifiers-Failed'
|
|
||||||
] + \
|
] + \
|
||||||
['Alarm-Name:' + repr(x) for x in range(59)] + \
|
['Alarm-Name'] + \
|
||||||
['Alarm-Severity:' + repr(x) for x in range(59)]
|
['Alarm-Name:' + repr(x) for x in range(1, 59)] + \
|
||||||
#Settings = [
|
['Alarm-Severity'] + \
|
||||||
#'Site-Name'
|
['Alarm-Severity:' + repr(x) for x in range(1, 59)]
|
||||||
#]
|
|
||||||
|
|
||||||
|
|
||||||
def Setup():
|
|
||||||
db.execute('''CREATE TABLE SettingsValues (
|
|
||||||
IP TEXT,
|
|
||||||
SettingsID TEXT,
|
|
||||||
Value TEXT)''')
|
|
||||||
|
|
||||||
#db.execute('''CREATE TABLE Settings (
|
|
||||||
#ID INTEGER PRIMARY KEY,
|
|
||||||
#Name TEXT UNIQUE)''')
|
|
||||||
|
|
||||||
#db.execute('''CREATE TABLE SC200 (
|
|
||||||
#IP text PRIMARY KEY,
|
|
||||||
#SiteName text,
|
|
||||||
#SiteNotes text,
|
|
||||||
#SerialNumber text,
|
|
||||||
#FloatVoltage float,
|
|
||||||
#OperatingVoltage float,
|
|
||||||
#BatteryCapacity int,
|
|
||||||
#ACRectifierCurrentLimit int,
|
|
||||||
#HighFloatThreshold float,
|
|
||||||
#EnableActiveVoltageControl bool,
|
|
||||||
#EnableTemperatureCompensation bool,
|
|
||||||
#TemperatureCompensationSlope float,
|
|
||||||
#TemperatureCompensationReferenceTemperature float,
|
|
||||||
#TemperatureCompensationUpperLimit float,
|
|
||||||
#TemperatureCompensationLowerLimit float,
|
|
||||||
#EnableEqualize bool,
|
|
||||||
#EqualizeVoltage float,
|
|
||||||
#EqualizeDuration int,
|
|
||||||
#EnableFastCharge bool,
|
|
||||||
#FastChargeVoltage float,
|
|
||||||
#FastChargeVoltageThreshold float,
|
|
||||||
#FastChargeAmpereHourThreshold int,
|
|
||||||
#FastChargeRechargePercentage int,
|
|
||||||
#FastChargeMaximumDuration int,
|
|
||||||
#FastChargeAmpereHourStopThreshold int,
|
|
||||||
#EnableBatterCurrentLimit bool,
|
|
||||||
#BCLLimit int,
|
|
||||||
#EnableBatterTest bool,
|
|
||||||
#BatteryTestDuration int,
|
|
||||||
#BatteryTestTerminationVoltage float,
|
|
||||||
#LVDDisconnectVoltage float,
|
|
||||||
#LVDReconnectVoltage float,
|
|
||||||
#NumberOfRegisteredRectifiers int,
|
|
||||||
#NumberOfRectifiersFailed int
|
|
||||||
#)''')
|
|
||||||
|
|
||||||
#SQL = '''CREATE TABLE AlarmNames (
|
|
||||||
#SiteIP text primary key'''
|
|
||||||
#for x in range(59):
|
|
||||||
#SQL = SQL + ', Alarm' + repr(x) + ' text'
|
|
||||||
#SQL = SQL + ')'
|
|
||||||
|
|
||||||
#db.execute(SQL)
|
|
||||||
|
|
||||||
#SQL = '''CREATE TABLE AlarmSeverities (
|
|
||||||
#SiteIP text primary key'''
|
|
||||||
#for x in range(59):
|
|
||||||
#SQL = SQL + ', Alarm' + repr(x) + ' int'
|
|
||||||
#SQL = SQL + ')'
|
|
||||||
|
|
||||||
#db.execute(SQL)
|
|
||||||
|
|
||||||
|
|
||||||
def GetStatusCode(host, path="/"):
|
def GetStatusCode(host, path="/"):
|
||||||
|
|||||||
263
sc200-push.py
263
sc200-push.py
@@ -1,8 +1,8 @@
|
|||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from netaddr import IPNetwork
|
#from netaddr import IPNetwork
|
||||||
#from netaddr import IPAddress
|
#from netaddr import IPAddress
|
||||||
from xmlrpc.client import ServerProxy
|
from xmlrpc.client import ServerProxy
|
||||||
import sqlite3
|
#import sqlite3
|
||||||
import socket
|
import socket
|
||||||
import csv
|
import csv
|
||||||
import queue
|
import queue
|
||||||
@@ -12,102 +12,7 @@ import http.client
|
|||||||
|
|
||||||
WORKERS = 10
|
WORKERS = 10
|
||||||
|
|
||||||
if len(sys.argv) == 1:
|
inFilePath = sys.argv[1]
|
||||||
Nets = [
|
|
||||||
'10.250.48.0/27',
|
|
||||||
'10.250.48.32/27',
|
|
||||||
'10.250.48.64/27',
|
|
||||||
'10.250.48.96/27',
|
|
||||||
'10.250.48.128/27',
|
|
||||||
'10.250.48.160/27',
|
|
||||||
'10.250.49.0/27',
|
|
||||||
'10.250.49.32/27',
|
|
||||||
'10.250.49.64/27',
|
|
||||||
'10.250.49.128/27',
|
|
||||||
'10.250.49.160/27',
|
|
||||||
'10.250.50.0/27',
|
|
||||||
'10.250.50.32/27',
|
|
||||||
'10.250.50.65/27',
|
|
||||||
'10.250.50.96/27',
|
|
||||||
'10.250.50.128/27',
|
|
||||||
'10.250.50.160/27',
|
|
||||||
'10.250.50.192/27',
|
|
||||||
'10.250.50.224/27',
|
|
||||||
'10.250.51.0/27',
|
|
||||||
'10.250.51.32/27',
|
|
||||||
'10.250.51.64/27',
|
|
||||||
'10.250.51.96/27',
|
|
||||||
'10.250.51.128/27',
|
|
||||||
'10.250.52.0/27',
|
|
||||||
'10.250.52.32/27',
|
|
||||||
'10.250.52.64/27',
|
|
||||||
'10.250.52.96/27',
|
|
||||||
'10.250.52.128/27',
|
|
||||||
'10.250.52.160/27',
|
|
||||||
'10.250.52.192/27'
|
|
||||||
]
|
|
||||||
else:
|
|
||||||
Nets = sys.argv[1:]
|
|
||||||
|
|
||||||
#Nets = [
|
|
||||||
#'10.250.48.0/27']
|
|
||||||
|
|
||||||
#print((Nets))
|
|
||||||
|
|
||||||
|
|
||||||
def Setup():
|
|
||||||
db.execute('''CREATE TABLE SC200 (
|
|
||||||
IP text PRIMARY KEY,
|
|
||||||
SiteName text,
|
|
||||||
SiteNotes text,
|
|
||||||
SerialNumber text,
|
|
||||||
FloatVoltage float,
|
|
||||||
OperatingVoltage float,
|
|
||||||
BatteryCapacity int,
|
|
||||||
ACRectifierCurrentLimit int,
|
|
||||||
HighFloatThreshold float,
|
|
||||||
EnableActiveVoltageControl bool,
|
|
||||||
EnableTemperatureCompensation bool,
|
|
||||||
TemperatureCompensationSlope float,
|
|
||||||
TemperatureCompensationReferenceTemperature float,
|
|
||||||
TemperatureCompensationUpperLimit float,
|
|
||||||
TemperatureCompensationLowerLimit float,
|
|
||||||
EnableEqualize bool,
|
|
||||||
EqualizeVoltage float,
|
|
||||||
EqualizeDuration int,
|
|
||||||
EnableFastCharge bool,
|
|
||||||
FastChargeVoltage float,
|
|
||||||
FastChargeVoltageThreshold float,
|
|
||||||
FastChargeAmpereHourThreshold int,
|
|
||||||
FastChargeRechargePercentage int,
|
|
||||||
FastChargeMaximumDuration int,
|
|
||||||
FastChargeAmpereHourStopThreshold int,
|
|
||||||
EnableBatterCurrentLimit bool,
|
|
||||||
BCLLimit int,
|
|
||||||
EnableBatterTest bool,
|
|
||||||
BatteryTestDuration int,
|
|
||||||
BatteryTestTerminationVoltage float,
|
|
||||||
LVDDisconnectVoltage float,
|
|
||||||
LVDReconnectVoltage float,
|
|
||||||
NumberOfRegisteredRectifiers int,
|
|
||||||
NumberOfRectifiersFailed int
|
|
||||||
)''')
|
|
||||||
|
|
||||||
SQL = '''CREATE TABLE AlarmNames (
|
|
||||||
SiteIP text primary key'''
|
|
||||||
for x in range(59):
|
|
||||||
SQL = SQL + ', Alarm' + repr(x) + ' text'
|
|
||||||
SQL = SQL + ')'
|
|
||||||
|
|
||||||
db.execute(SQL)
|
|
||||||
|
|
||||||
SQL = '''CREATE TABLE AlarmSeverities (
|
|
||||||
SiteIP text primary key'''
|
|
||||||
for x in range(59):
|
|
||||||
SQL = SQL + ', Alarm' + repr(x) + ' int'
|
|
||||||
SQL = SQL + ')'
|
|
||||||
|
|
||||||
db.execute(SQL)
|
|
||||||
|
|
||||||
|
|
||||||
def GetStatusCode(host, path="/"):
|
def GetStatusCode(host, path="/"):
|
||||||
@@ -121,8 +26,8 @@ def GetStatusCode(host, path="/"):
|
|||||||
|
|
||||||
class Worker(threading.Thread):
|
class Worker(threading.Thread):
|
||||||
|
|
||||||
def __init__(self, IPs, Results):
|
def __init__(self, Settings, Results):
|
||||||
self.__IPs = IPs
|
self.__Settings = Settings
|
||||||
self.__Results = Results
|
self.__Results = Results
|
||||||
self.parent = threading.current_thread()
|
self.parent = threading.current_thread()
|
||||||
threading.Thread.__init__(self)
|
threading.Thread.__init__(self)
|
||||||
@@ -130,59 +35,25 @@ 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()
|
DevSettings = self.__Settings.get()
|
||||||
#print((self.getName()))
|
if DevSettings is None:
|
||||||
if IP is None:
|
|
||||||
self.__Results.put(None)
|
self.__Results.put(None)
|
||||||
#print('Exiting')
|
|
||||||
break
|
break
|
||||||
|
|
||||||
#s = socket.socket()
|
IP = DevSettings.pop('IP', None)
|
||||||
#if s.connect_ex((str(IP), 80)) == 0:
|
|
||||||
|
for k in list(DevSettings.keys()):
|
||||||
|
if k.startswith('Alarm-Name'):
|
||||||
|
DevSettings.pop(k)
|
||||||
|
|
||||||
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:
|
||||||
Values = proxy.db.get([
|
#print(((DevSettings)))
|
||||||
'Site-Name',
|
Result = proxy.db.set(DevSettings)
|
||||||
'Site-Notes',
|
|
||||||
'Serial-Number',
|
|
||||||
'Float-Voltage',
|
|
||||||
'Operating-Voltage',
|
|
||||||
'Battery-Capacity',
|
|
||||||
'AC-Rectifier-Current-Limit',
|
|
||||||
'High-Float-Threshold',
|
|
||||||
'Enable-Active-Voltage-Control',
|
|
||||||
'Enable-Temperature-Compensation',
|
|
||||||
'Temperature-Compensation-Slope',
|
|
||||||
'Temperature-Compensation-Reference-Temperature',
|
|
||||||
'Temperature-Compensation-Upper-Limit',
|
|
||||||
'Temperature-Compensation-Lower-Limit',
|
|
||||||
'Enable-Equalize',
|
|
||||||
'Equalize-Voltage',
|
|
||||||
'Equalize-Duration',
|
|
||||||
'Enable-Fast-Charge',
|
|
||||||
'Fast-Charge-Voltage',
|
|
||||||
'Fast-Charge-Voltage-Threshold',
|
|
||||||
'Fast-Charge-Ampere-Hour-Threshold',
|
|
||||||
'Fast-Charge-Recharge-Percentage',
|
|
||||||
'Fast-Charge-Maximum-Duration',
|
|
||||||
'Fast-Charge-Ampere-Hour-Stop-Threshold',
|
|
||||||
'Enable-Battery-Current-Limit',
|
|
||||||
'BCL-Limit',
|
|
||||||
'Enable-Battery-Test',
|
|
||||||
'Battery-Test-Duration',
|
|
||||||
'Battery-Test-Termination-Voltage',
|
|
||||||
'LVD-Disconnect-Voltage:1',
|
|
||||||
'LVD-Reconnect-Voltage:1',
|
|
||||||
'Number-Of-Registered-Rectifiers',
|
|
||||||
'Number-Of-Rectifiers-Failed'
|
|
||||||
])
|
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
retry = True
|
retry = True
|
||||||
continue
|
continue
|
||||||
@@ -192,110 +63,48 @@ class Worker(threading.Thread):
|
|||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
if len(Values) > 0:
|
if len(Result) > 0:
|
||||||
Values.insert(0, str(IP))
|
Result['IP'] = str(IP)
|
||||||
self.__Results.put(['SC200', Values])
|
self.__Results.put(Result)
|
||||||
|
|
||||||
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():
|
def Input():
|
||||||
Count = WORKERS
|
with open(inFilePath, 'r', newline='') as inFile:
|
||||||
c = db.cursor()
|
csvReader = csv.DictReader(inFile)
|
||||||
|
|
||||||
|
for row in csvReader:
|
||||||
|
Settings.put(row)
|
||||||
|
inFile.close()
|
||||||
|
|
||||||
|
for i in range(WORKERS):
|
||||||
|
Settings.put(None)
|
||||||
|
|
||||||
|
|
||||||
|
def Output():
|
||||||
|
Count = WORKERS
|
||||||
while 1:
|
while 1:
|
||||||
Row = Results.get()
|
Row = Results.get()
|
||||||
if Row is None:
|
if Row is None:
|
||||||
if Count > 1:
|
if Count > 1:
|
||||||
Count -= 1
|
Count -= 1
|
||||||
print(Count)
|
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
print(('Loading: %s %s' % (Row[1][0], Row[0])))
|
print(((Row['IP'] + ':' + Row['resultString'])))
|
||||||
SQL = 'INSERT INTO %s VALUES (' % Row[0]
|
|
||||||
for i in Row[1]:
|
|
||||||
SQL += '?,'
|
|
||||||
SQL = SQL[:-1]
|
|
||||||
SQL += ')'
|
|
||||||
|
|
||||||
c.execute(SQL, Row[1])
|
Settings = queue.Queue(0)
|
||||||
db.commit()
|
|
||||||
|
|
||||||
|
|
||||||
def Output():
|
|
||||||
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 SC200 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)
|
|
||||||
Results = queue.Queue(0)
|
Results = queue.Queue(0)
|
||||||
|
|
||||||
for i in range(WORKERS):
|
Input()
|
||||||
Worker(IPs, Results).start()
|
|
||||||
|
|
||||||
for SubNet in Nets:
|
|
||||||
Net = IPNetwork(SubNet)
|
|
||||||
|
|
||||||
for IP in Net:
|
|
||||||
if IP != Net.network and IP != Net.broadcast:
|
|
||||||
#print(('Queued: ' + str(IP)))
|
|
||||||
IPs.put(IP)
|
|
||||||
|
|
||||||
for i in range(WORKERS):
|
for i in range(WORKERS):
|
||||||
IPs.put(None)
|
Worker(Settings, Results).start()
|
||||||
|
|
||||||
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