Closed zepernick03 closed 4 years ago
I'm gonna need more to work off of than that.
It was a Visual Studio Code Error; never mind thanks
I have re-instated your previous comment as there are a few things I wanted to bring up in this thread, however you had edited your original comment instead of adding new comments.
Tying this all together, you should end up with something that looks more like this:
from tenable.sc import TenableSC
from csv import DictWriter
import arrow, click
@click.command()
@click.option('--filename', '-f', type=click.File('w'), default='user_report.csv', help='CSV Report FIle')
@click.option('--address', '-a', envvar='TSC_ADDRESS', prompt=True, help='Tenable.sc Address')
@click.option('--username', '-u', envvar='TSC_USERNAME', prompt=True, help='Tenable.sc Username')
@click.option('--password', '-p', envvar='TSC_PASSWORD', prompt=True, hide_input=True, help='Tenable.sc Password')
def get_users(filename, address, username, password):
with TenableSC(address, username=username, password=password) as sc:
fields = ['Group Name', 'User Lastname', 'User Firstname', 'Username', 'Last Logged In']
csv = DictWriter(filename, fields, extrasaction='ignore')
csv.writeheader()
# refer to field list available here:
# https://docs.tenable.com/sccv/api/Group.html
for group in sc.groups.list(fields=['id', 'name', 'users']):
for u in group['users']:
user = sc.users.details(u['id'])
if int(user['lastLogin']) > 0:
last_log = arrow.get(int(user['lastLogin'])).strftime('%Y-%m-%d %H:%M:%S')
else:
last_log = 'Never'
csv.writerow({
'Group Name': group.get('name'),
'User Lastname': user.get('lastname'),
'User Firstname': user.get('firstname'),
'Username': user.get('username'),
'Last Logged In': last_log,
})
if __name__ == '__main__':
get_users()
Thank you for the response I will try this.
When I am entering my password I get a NameError saying that my password is not defined