Add password_cmd parameter
This commit is contained in:
parent
5a95b4ecdc
commit
9ddb8a4eb9
2 changed files with 18 additions and 12 deletions
28
client.py
28
client.py
|
@ -5,6 +5,7 @@ import yaml
|
||||||
import argparse
|
import argparse
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
|
||||||
config = os.path.join(os.path.dirname(os.path.realpath(__file__)),"config.yml")
|
config = os.path.join(os.path.dirname(os.path.realpath(__file__)),"config.yml")
|
||||||
|
|
||||||
|
@ -16,8 +17,12 @@ term_cols = getattr(shutil.get_terminal_size((80, 20)), 'columns')
|
||||||
def call_api(params, path):
|
def call_api(params, path):
|
||||||
url = '/'.join((params['base_url'],params['api_path'],path))
|
url = '/'.join((params['base_url'],params['api_path'],path))
|
||||||
try:
|
try:
|
||||||
response = requests.get(url, auth=(params['username'],
|
if 'password_cmd' in params:
|
||||||
params['password']))
|
result = subprocess.run(params['password_cmd'].split(), stdout=subprocess.PIPE)
|
||||||
|
password = result.stdout.decode('utf-8')
|
||||||
|
else:
|
||||||
|
password = params['password']
|
||||||
|
response = requests.get(url, auth=(params['username'],password))
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -49,15 +54,6 @@ def sizeof_fmt(num, suffix='B', binary=True):
|
||||||
num /= base
|
num /= base
|
||||||
return "%.1f %s%s" % (num, 'Y', suffix)
|
return "%.1f %s%s" % (num, 'Y', suffix)
|
||||||
|
|
||||||
# Test instances
|
|
||||||
for instance in list(cfg['instances']):
|
|
||||||
test = call_api(cfg['instances'][instance], 'devices')
|
|
||||||
if test is None:
|
|
||||||
if cfg['debug']: print("Instance %s is not working, disabling" % instance)
|
|
||||||
cfg['instances'].pop(instance)
|
|
||||||
else:
|
|
||||||
if cfg['debug']: print("Instance %s is working" % instance)
|
|
||||||
|
|
||||||
def search_ports(args):
|
def search_ports(args):
|
||||||
for instance, params in cfg['instances'].items():
|
for instance, params in cfg['instances'].items():
|
||||||
if args.instance is not None and instance not in args.instance.split(','):
|
if args.instance is not None and instance not in args.instance.split(','):
|
||||||
|
@ -198,6 +194,16 @@ def search_devices(args):
|
||||||
print("(0m" + "q" * 27 + "v" + "q" * 28 + "v" + "q" * 28 + "v" + "q" * (term_cols - 88) + "j(B")
|
print("(0m" + "q" * 27 + "v" + "q" * 28 + "v" + "q" * 28 + "v" + "q" * (term_cols - 88) + "j(B")
|
||||||
|
|
||||||
|
|
||||||
|
# Test instances
|
||||||
|
for instance in list(cfg['instances']):
|
||||||
|
test = call_api(cfg['instances'][instance], 'devices')
|
||||||
|
if test is None:
|
||||||
|
if cfg['debug']: print("Instance %s is not working, disabling" % instance)
|
||||||
|
cfg['instances'].pop(instance)
|
||||||
|
else:
|
||||||
|
if cfg['debug']: print("Instance %s is working" % instance)
|
||||||
|
|
||||||
|
|
||||||
# Argument parsing
|
# Argument parsing
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument('-i','--instance', type=str, help="Comma-separated list of Observium instances to use",nargs='?', default=None)
|
parser.add_argument('-i','--instance', type=str, help="Comma-separated list of Observium instances to use",nargs='?', default=None)
|
||||||
|
|
|
@ -4,7 +4,7 @@ instances:
|
||||||
base_url: 'https://observium1'
|
base_url: 'https://observium1'
|
||||||
api_path: 'api/v0'
|
api_path: 'api/v0'
|
||||||
username: ''
|
username: ''
|
||||||
password: ''
|
password_cmd: ''
|
||||||
observium2:
|
observium2:
|
||||||
base_url: 'http://observium2'
|
base_url: 'http://observium2'
|
||||||
api_path: 'api/v0'
|
api_path: 'api/v0'
|
||||||
|
|
Loading…
Reference in a new issue