Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 63 additions & 0 deletions examples/pull_device_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
'''
Script: Poll Unhealthy Devices
Version: 1.0

Usage:
python poll_device_health.py

'''

import time
import argparse
import sys
import getpass

from datetime import datetime
from datetime import timedelta
from pyexclient import WorkbenchClient
from pyexclient.workbench import neq
from pyexclient.workbench import gt
from pyexclient.workbench import flag
import json

import pdb


def authenticate():
'''
Prompt user for authentication info
'''
username = input("Enter Username: ")
password = getpass.getpass("Enter Password: ")
code = input("2FA Code: ")
xc = WorkbenchClient('https://workbench.expel.io', username=username, password=password, mfa_code=code)
return xc


def main():
xc = authenticate()

device_list = []

via_siem_config_inventory = {}
hail_mary_dict = {}
for device in device_list:
try:
config = xc.secrets.get(id=f'security_device-{device}') #I assumed the docs had a typo for a while, but the URL *actually* looks like this lol
defined_secrets = config._data['attributes']['secret'].keys() # the .keys() returns only which secrets *are defined*, not the values. Be very careful when copypasting if you delete this
key_list = ','.join(defined_secrets)
csv_str = f"{device},{key_list},"
print(csv_str)
hail_mary_dict[device] = key_list
except:
csv_str = f"{device},ERROR,"
print(csv_str)
hail_mary_dict[device] = "ERROR"
time.sleep(60) # Yes, you *actually* have to wait this long per device, my deepest condolences

print(json.dumps(hail_mary_dict, indent=4))



if __name__ == '__main__':
sys.exit(main())
Loading