mirror of
https://github.com/lucaspalomodevelop/core.git
synced 2026-03-15 17:14:46 +00:00
python3: replace subprocess.call in src/opnsense/scripts/system/* for https://github.com/opnsense/core/issues/3574
This commit is contained in:
parent
cf3b447275
commit
9a4be6f2e3
@ -28,38 +28,32 @@
|
||||
--------------------------------------------------------------------------------------
|
||||
list device interrupts stats
|
||||
"""
|
||||
import tempfile
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
import ujson
|
||||
|
||||
if __name__ == '__main__':
|
||||
result = dict()
|
||||
with tempfile.NamedTemporaryFile() as output_stream:
|
||||
subprocess.call(['/usr/bin/vmstat', '-i'], stdout=output_stream, stderr=open(os.devnull, 'wb'))
|
||||
output_stream.seek(0)
|
||||
|
||||
intf = None
|
||||
interrupts = dict()
|
||||
interrupt_map = dict()
|
||||
for line in output_stream:
|
||||
line = line.decode()
|
||||
if line.find(':') > -1:
|
||||
intrp = line.split(':')[0].strip()
|
||||
parts = ':'.join(line.split(':')[1:]).split()
|
||||
interrupts[intrp] = {'devices': [], 'total': None, 'rate': None}
|
||||
for part in parts:
|
||||
if not part.isdigit():
|
||||
interrupts[intrp]['devices'].append(part)
|
||||
devnm = part.split(':')[0]
|
||||
if devnm not in interrupt_map:
|
||||
interrupt_map[devnm] = list()
|
||||
interrupt_map[devnm].append(intrp)
|
||||
elif interrupts[intrp]['total'] is None:
|
||||
interrupts[intrp]['total'] = int(part)
|
||||
else:
|
||||
interrupts[intrp]['rate'] = int(part)
|
||||
sp = subprocess.run(['/usr/bin/vmstat', '-i'], capture_output=True, text=True)
|
||||
intf = None
|
||||
interrupts = dict()
|
||||
interrupt_map = dict()
|
||||
for line in sp.stdout.split("\n"):
|
||||
if line.find(':') > -1:
|
||||
intrp = line.split(':')[0].strip()
|
||||
parts = ':'.join(line.split(':')[1:]).split()
|
||||
interrupts[intrp] = {'devices': [], 'total': None, 'rate': None}
|
||||
for part in parts:
|
||||
if not part.isdigit():
|
||||
interrupts[intrp]['devices'].append(part)
|
||||
devnm = part.split(':')[0]
|
||||
if devnm not in interrupt_map:
|
||||
interrupt_map[devnm] = list()
|
||||
interrupt_map[devnm].append(intrp)
|
||||
elif interrupts[intrp]['total'] is None:
|
||||
interrupts[intrp]['total'] = int(part)
|
||||
else:
|
||||
interrupts[intrp]['rate'] = int(part)
|
||||
result['interrupts'] = interrupts # interrupts as reported by vmstat
|
||||
result['interrupt_map'] = interrupt_map # link device to interrupt
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@
|
||||
--------------------------------------------------------------------------------------
|
||||
return all available ciphers
|
||||
"""
|
||||
import tempfile
|
||||
import subprocess
|
||||
import os
|
||||
import sys
|
||||
@ -45,18 +44,16 @@ if __name__ == '__main__':
|
||||
rfc5246[row[0]] = {'description': row[1]}
|
||||
|
||||
result = {}
|
||||
with tempfile.NamedTemporaryFile() as output_stream:
|
||||
subprocess.call(['/usr/local/bin/openssl', 'ciphers', '-V'], stdout=output_stream, stderr=open(os.devnull, 'wb'))
|
||||
output_stream.seek(0)
|
||||
for line in output_stream:
|
||||
parts = line.decode().strip().split()
|
||||
if len(parts) > 1:
|
||||
cipher_id = parts[0]
|
||||
cipher_key = parts[2]
|
||||
item = {'version': parts[3], 'id': cipher_id, 'description': ''}
|
||||
for part in parts[4:]:
|
||||
item[part.split('=')[0]] = part.split('=')[-1]
|
||||
if cipher_id in rfc5246:
|
||||
item['description'] = rfc5246[cipher_id]['description']
|
||||
result[cipher_key] = item
|
||||
sp = subprocess.run(['/usr/local/bin/openssl', 'ciphers', '-V'], capture_output=True, text=True)
|
||||
for line in sp.stdout.split("\n"):
|
||||
parts = line.strip().split()
|
||||
if len(parts) > 1:
|
||||
cipher_id = parts[0]
|
||||
cipher_key = parts[2]
|
||||
item = {'version': parts[3], 'id': cipher_id, 'description': ''}
|
||||
for part in parts[4:]:
|
||||
item[part.split('=')[0]] = part.split('=')[-1]
|
||||
if cipher_id in rfc5246:
|
||||
item['description'] = rfc5246[cipher_id]['description']
|
||||
result[cipher_key] = item
|
||||
print (ujson.dumps(result))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user