-1
import paramiko

cmd = 'asadm -U admin -P password -e "enable; asinfo -v get-stats:context=xdr;dc=A"'

def get_aerospike_hs():
    ssh = paramiko.SSHClient()
    ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
    try:
        ssh.connect('ip_address', username='username', key_filename=r'local_file_location/keyfile.pem')
        command = f'sudo su -c "{cmd}"'  # Use f-string for command
        _, stdout, stderr = ssh.exec_command(command)
        
        errors = stderr.read().decode('utf-8')
        if errors:
            print(f"Error: {errors}")
        status = stdout.read().decode('utf-8')
        return status
    except Exception as e:
        print(f"Exception occurred: {e}")
    finally:
        ssh.close()

if __name__ == '__main__':
    aerospike_status = get_aerospike_hs()
    if aerospike_status:
        print(aerospike_status)
    else:
        print("No Status Returned")

Please check and review the above code so that it can return the health check status of Aerospike Cluster

The above code was executed to get the output: No Status Returned

  • What do you get if you run `ssh username@ip_addres sudo su -c "asadm ..."` from local command-line (as *single* line)? – Martin Prikryl Aug 08 '23 at 14:51
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 08 '23 at 15:20

0 Answers0