|
| 1 | +import sys |
| 2 | +import login.login_api as login_api |
| 3 | +import config.hosts_api as hosts_api |
| 4 | +import admin.processes_api as processes_api |
| 5 | + |
| 6 | +nbmaster = "" |
| 7 | +username = "" |
| 8 | +password = "" |
| 9 | +domainName = "" |
| 10 | +domainType = "" |
| 11 | +hostName = "" |
| 12 | + |
| 13 | +def print_disclaimer(): |
| 14 | + print("\n-------------------------------------------------------------------------------------------------") |
| 15 | + print("-- This script requires Python3.5 or higher. --") |
| 16 | + print("-- The system where this script is run should have Python 3.5 or higher version installed. --") |
| 17 | + print("-------------------------------------------------------------------------------------------------") |
| 18 | + print("The script requires 'requests' library to make the API calls.") |
| 19 | + print("You can install the library using the command: pip install requests") |
| 20 | + print("-------------------------------------------------------------------------------------------------") |
| 21 | + |
| 22 | +def print_usage(): |
| 23 | + print("\nCommand-line usage (should be run from the parent directory of the 'admin' directory):") |
| 24 | + print("\tpython -Wignore -m admin.list_nb_processes -hostName <hostName> -nbmaster <masterServer> -username <username> -password <password> [-domainName <domainName>] [-domainType <domainType>]") |
| 25 | + print("Note: hostName is the name of the NetBackup host to get the list of processes.\n") |
| 26 | + print("-------------------------------------------------------------------------------------------------") |
| 27 | + |
| 28 | +def read_command_line_arguments(): |
| 29 | + if len(sys.argv)%2 == 0: |
| 30 | + print("\nInvalid command!") |
| 31 | + print_usage() |
| 32 | + exit() |
| 33 | + |
| 34 | + global nbmaster |
| 35 | + global username |
| 36 | + global password |
| 37 | + global domainName |
| 38 | + global domainType |
| 39 | + global hostName |
| 40 | + |
| 41 | + for i in range(1, len(sys.argv), 2): |
| 42 | + if sys.argv[i] == "-nbmaster": |
| 43 | + nbmaster = sys.argv[i + 1] |
| 44 | + elif sys.argv[i] == "-username": |
| 45 | + username = sys.argv[i + 1] |
| 46 | + elif sys.argv[i] == "-password": |
| 47 | + password = sys.argv[i + 1] |
| 48 | + elif sys.argv[i] == "-domainName": |
| 49 | + domainName = sys.argv[i + 1] |
| 50 | + elif sys.argv[i] == "-domainType": |
| 51 | + domainType = sys.argv[i + 1] |
| 52 | + elif sys.argv[i] == "-hostName": |
| 53 | + hostName = sys.argv[i + 1] |
| 54 | + else: |
| 55 | + print("\nInvalid command!") |
| 56 | + print_usage() |
| 57 | + exit() |
| 58 | + |
| 59 | + if nbmaster == "": |
| 60 | + print("Please provide the value for 'nbmaster'\n") |
| 61 | + exit() |
| 62 | + elif username == "": |
| 63 | + print("Please provide the value for 'username'\n") |
| 64 | + exit() |
| 65 | + elif password == "": |
| 66 | + print("Please provide the value for 'password'\n") |
| 67 | + exit() |
| 68 | + elif domainName == "": |
| 69 | + print("Please provide the value for 'domainName'\n") |
| 70 | + exit() |
| 71 | + elif domainType == "": |
| 72 | + print("Please provide the value for 'domainType'\n") |
| 73 | + exit() |
| 74 | + elif hostName == "": |
| 75 | + print("Please provide the value for 'hostName'\n") |
| 76 | + exit() |
| 77 | + |
| 78 | +def print_nbprocesses_details(processes): |
| 79 | + print("NB PROCESS NAME".rjust(20), end = "\t") |
| 80 | + print("PID".rjust(10), end = "\t") |
| 81 | + print("MEMORY USAGE (MB)".rjust(10), end = "\t\t") |
| 82 | + print("START TIME".rjust(10), end = "\t\t") |
| 83 | + print("ELAPSED TIME".rjust(10), end = "\t") |
| 84 | + print("PRIORITY".rjust(10)) |
| 85 | + print("-----------------------------------------"*3) |
| 86 | + for process in processes: |
| 87 | + process_attributes = process['attributes'] |
| 88 | + print(process_attributes['processName'].rjust(20), end = "\t") |
| 89 | + print(str(process_attributes['pid']).rjust(10), end = "\t") |
| 90 | + print(str(process_attributes['memoryUsageMB']).rjust(10), end = "\t\t") |
| 91 | + print(process_attributes['startTime'].rjust(10), end = "\t\t") |
| 92 | + print(process_attributes['elapsedTime'].rjust(10), end = "\t") |
| 93 | + print(str(process_attributes['priority']).rjust(10)) |
| 94 | + print() |
| 95 | + |
| 96 | +print_disclaimer() |
| 97 | + |
| 98 | +print_usage() |
| 99 | + |
| 100 | +read_command_line_arguments() |
| 101 | + |
| 102 | +base_url = "https://" + nbmaster + "/netbackup" |
| 103 | + |
| 104 | +jwt = login_api.perform_login(base_url, username, password, domainName, domainType) |
| 105 | + |
| 106 | +host_uuid = hosts_api.get_host_uuid(base_url, jwt, nbmaster) |
| 107 | + |
| 108 | +processes = processes_api.get_all_nb_processes(base_url, jwt, host_uuid) |
| 109 | + |
| 110 | +processes_data = processes['data'] |
| 111 | + |
| 112 | +if len(processes_data) > 0: |
| 113 | + print_nbprocesses_details(processes_data) |
| 114 | +else: |
| 115 | + print("\nNo NB processes exist on the specified host!") |
| 116 | + |
0 commit comments