diff --git a/config-example.yaml b/config-example.yaml index 78c820f..7979794 100644 --- a/config-example.yaml +++ b/config-example.yaml @@ -12,4 +12,4 @@ keys: key: ssh-rsa XXXXXXXXX - name: janedoe@gmail.com description: Jane Doe - key: ssh-rsa YYYYYYYYY \ No newline at end of file + key: ssh-rsa YYYYYYYYY diff --git a/monitor.py b/monitor.py index 15ad888..aa60b7b 100755 --- a/monitor.py +++ b/monitor.py @@ -49,7 +49,7 @@ def update_keys(host, user, keys, host_length): try: client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy()) - client.connect(host, username = user) + client.connect(host, username = user, timeout = 1) stdin, stdout, stderr = client.exec_command('top -bn1 | grep "^top\\|^%Cpu\\|^.iB Mem"') stdin.close() @@ -70,6 +70,8 @@ def main(): host_length = 0 for host in config['hosts']: + if host.get('users') == None: + host['users'] = ['root'] for user in host['users']: if len(user) + len(host['host']) > host_length: host_length = len(user) + len(host['host']) @@ -81,6 +83,8 @@ def main(): print('Host'.center(host_length + 3) + ' ' + 'Load'.center(25) + ' ' + 'Ram Usage'.center(26)) for host in config['hosts']: + if host.get('users') == None: + host['users'] = ['root'] for user in host['users']: try: thread = task_thread(host['host'], user, keys, host_length) @@ -89,4 +93,4 @@ def main(): print('❌ ' + user + '@' + host['host']) if __name__ == '__main__': - main() \ No newline at end of file + main() diff --git a/sync.py b/sync.py index f5c0090..eea7305 100755 --- a/sync.py +++ b/sync.py @@ -21,7 +21,7 @@ def update_keys(host, user, keys): try: client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.MissingHostKeyPolicy()) - client.connect(host, username = user) + client.connect(host, username = user, timeout = 1) client.exec_command('echo "###\n# Warning this file has been generated and will be overwritten!\n###\n\n' + '\n'.join(keys) + '" > ~/.ssh/authorized_keys2') client.close() print('✅ ' + user + '@' + host) @@ -37,6 +37,8 @@ def main(): keys.append(key['key']) for host in config['hosts']: + if host.get('users') == None: + host['users'] = ['root'] for user in host['users']: try: thread = task_thread(host['host'], user, keys) @@ -45,4 +47,4 @@ def main(): print('❌ ' + user + '@' + host['host']) if __name__ == '__main__': - main() \ No newline at end of file + main()