def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:m:", ["host=","user="******"password="******"https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) job_data = { 'managedNetwork': netld_network, 'jobName': job_name, 'jobType': 'Script Tool Job', 'description': '', 'jobParameters': { 'tool': 'org.ziptie.tools.scripts.commandRunner', 'managedNetwork': netld_network, 'backupOnCompletion': 'false', 'ipResolutionScheme': _resolution_scheme(device), 'ipResolutionData': device, 'input.commandList': commands } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: result = _wait_for_completion(execution) _print_job_ouptut(execution, device) except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
netld_network = 'Core' ### Create a JSON-RPC proxy ### netld = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) ### use the configuration service to retrieve a page of change logs ipAddress = raw_input('Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') print "Snapshot Path Timestamp Size User" print "==============================================================================" pageData= {'offset': 0, 'pageSize': 10} while True: pageData = netld.call('Configuration.retrieveSnapshotChangeLog', netld_network, ipAddress, pageData) for changeLog in pageData['changeLogs']: snapShot = changeLog['timestamp'] firstLine = True for change in changeLog['changes']: if firstLine: sys.stdout.write(datetime.datetime.fromtimestamp(snapShot/1000).strftime('%Y-%m-%d %H:%M:%S') + " ") firstLine = False else: sys.stdout.write('{:<21}'.format('')) print '{:<15}'.format(change['path']) + " " \ + datetime.datetime.fromtimestamp(change['revisionTime']/1000).strftime('%Y-%m-%d %H:%M:%S') + " " \ + '{:>5}'.format(change['size']) + " " \
### Create a JSON-RPC proxy ### netld = JsonRpcProxy("https://{0}/rest".format(netld_host), netld_user, netld_pass) ### use the configuration service to retrieve a page of change logs ipAddress = raw_input( 'Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') archivePath = raw_input( 'Enter the configuration archive path as it appears in NetLD: ') print "Snapshot Path Timestamp Size User" print "==============================================================================" changeLog = netld.call('Configuration.retrieveArchiveChangeLog', netld_network, ipAddress, archivePath, None) snapShot = changeLog['timestamp'] firstLine = True for change in changeLog['changes']: if firstLine: sys.stdout.write( datetime.datetime.fromtimestamp(snapShot / 1000).strftime( '%Y-%m-%d %H:%M:%S') + " ") firstLine = False else: sys.stdout.write('{:<21}'.format('')) print '{:<15}'.format(change['path']) + " " \ + datetime.datetime.fromtimestamp(change['revisionTime']/1000).strftime('%Y-%m-%d %H:%M:%S') + " " \
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:s:m:w", [ "host=", "user="******"password="******"snmp-ro=", '--managed-network=', '--no-wait' ]) except getopt.GetoptError: usage_and_exit() global netld_host, netld_user, netld_pass, snmp_ro, netld_network no_wait = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-s', '--snmp-ro'): snmp_ro = arg if opt in ('-m', '--managed-network'): netld_network = arg if opt in ('-w', '--no-wait'): no_wait = True if (len(args) < 1): usage_and_exit() ip_host_file = _resolve_ipaddrs(args[0]) ### Create a JSON-RPC proxy for the inventory service ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) job_data = { 'managedNetwork': netld_network, 'jobName': 'Discovery', 'jobType': 'Discover Devices', 'description': '', 'jobParameters': { 'addresses': ip_host_file, 'managedNetwork': netld_network, 'crawl': 'false', 'boundaryNetworks': '10.0.0.0/8,192.168.0.0/16,172.16.0.0/12', 'includeInventory': 'false', 'communityStrings': snmp_ro } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: if (no_wait is None): result = _wait_for_completion(execution) print 'Job status: ' + result['status'] print 'Start time: ' + time.strftime( "%a, %d %b %Y %H:%M:%S", time.localtime(result['startTime'] / 1000)) print 'End time : ' + time.strftime( "%a, %d %b %Y %H:%M:%S", time.localtime(result['endTime'] / 1000)) print except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv,"h:u:p:m:o:", ["host=","user="******"password="******"--managed-network=","output="]) except getopt.GetoptError: usageAndExit() global netld_host, netld_user, netld_pass, netld_network outputFile = '' netld_network = 'Default' for opt, arg in opts: if opt in ('-o', '--output'): outputFile = arg if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if outputFile == '': outputFile = "HardwareReport" + strftime("%y%m%d-%H%M%S", localtime()) + ".csv" _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) job = { 'managedNetwork': netld_network, 'jobName': 'Hardware Report', 'jobType': 'Report', 'description': '', 'jobParameters': { 'tool': 'ziptie.reports.hardware', 'ipResolutionScheme': 'ipAddress', 'ipResolutionData': '', 'managedNetwork': netld_network, 'format': 'csv' }, } execution = _netld_svc.call('Scheduler.runNow', job) print "** executing job **" execution_id = execution['id'] opener = urllib2.build_opener(_netld_svc._cookie_processor, _netld_svc._https_handler) while not execution['endTime']: if execution['completionState'] == 1 or execution['completionState'] == 2: print '** execution canceled **' break time.sleep(1) execution = _netld_svc.call('Scheduler.getExecutionDataById', execution_id) url = 'https://{0}/servlet/pluginDetail?executionId={1}'.format(netld_host, str(execution_id)) response = opener.open(url) if response.headers.get('content-encoding', '') == 'deflate': resp = zlib.decompressobj(-zlib.MAX_WBITS).decompress(response.read()) else: resp = response.read() file = open(outputFile, 'w') file.write(resp) file.close() print "** Hardware Report Export execution complete **" _netld_svc.call('Security.logoutCurrentUser')
def run(host, user, password, network, csv_file, job_name, credential_config_name): with open(csv_file, 'rb') as f: reader = csv.reader(f) for row in reader: print row target_tag = '' # TODO lbayer: use user inputed values... new_password = '******' new_enable_password = '******' global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(host), user, password) job = { 'managedNetwork': network, 'jobName': job_name, 'jobType': 'Script Tool Job', 'description': '', 'jobParameters': { 'tool': 'org.ziptie.tools.scripts.changemultipassword', 'ipResolutionScheme': 'tag', 'ipResolutionData': target_tag, 'managedNetwork': network, 'backupOnCompletion': 'false', 'input.newPassword': new_password, 'input.newEnablePassword': new_enable_password, }, } execution = _netld_svc.call('Scheduler.runNow', job) print '** executing job **' execution_id = execution['id'] x = 0 # wait for completion while not execution['endTime']: if execution['completionState'] == 1 or execution[ 'completionState'] == 2: print '** execution canceled **' break x += .1 time.sleep( math.atan(x) ) # gradually increase wait time, so we don't have to wait very long for short jobs, but we don't make too many calls for long jobs execution = _netld_svc.call('Scheduler.getExecutionDataById', execution_id) ips_to_update = {} # print individual script run details... tool_run_details = _netld_svc.call('Plugins.getExecutionDetails', executionId) for detail in tool_run_details: print_details(host, executionId, detail) ips_to_update[detail.ipAddress] = True update_credentials(network, credential_config_name, ips_to_update, new_password, new_enable_password) _netld_svc.call('Security.logoutCurrentUser') print "** password change execution complete **"
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:s:m:w", ["host=","user="******"password="******"snmp-ro=",'--managed-network=','--no-wait']) except getopt.GetoptError: usage_and_exit() global netld_host, netld_user, netld_pass, snmp_ro, netld_network no_wait = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-s', '--snmp-ro'): snmp_ro = arg if opt in ('-m', '--managed-network'): netld_network = arg if opt in ('-w', '--no-wait'): no_wait = True if (len(args) < 1): usage_and_exit() ip_host_file = _resolve_ipaddrs(args[0]) ### Create a JSON-RPC proxy for the inventory service ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) job_data = { 'managedNetwork': netld_network, 'jobName': 'Discovery', 'jobType': 'Discover Devices', 'description': '', 'jobParameters': { 'addresses': ip_host_file, 'managedNetwork': netld_network, 'crawl': 'false', 'boundaryNetworks': '10.0.0.0/8,192.168.0.0/16,172.16.0.0/12', 'includeInventory': 'false', 'communityStrings': snmp_ro } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: if (no_wait is None): result = _wait_for_completion(execution) print 'Job status: ' + result['status'] print 'Start time: ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['startTime'] / 1000)) print 'End time : ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['endTime'] / 1000)) print except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
### Create a JSON-RPC proxy ### netld = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) ### use the configuration service to retrieve a page of change logs ipAddress = raw_input( 'Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') print "Snapshot Path Timestamp Size User" print "==============================================================================" pageData = {'offset': 0, 'pageSize': 10} while True: pageData = netld.call('Configuration.retrieveSnapshotChangeLog', netld_network, ipAddress, pageData) for changeLog in pageData['changeLogs']: snapShot = changeLog['timestamp'] firstLine = True for change in changeLog['changes']: if firstLine: sys.stdout.write( datetime.datetime.fromtimestamp(snapShot / 1000).strftime( '%Y-%m-%d %H:%M:%S') + " ") firstLine = False else: sys.stdout.write('{:<21}'.format('')) print '{:<15}'.format(change['path']) + " " \
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:j:m:w"), ["host=","user="******"password="******"job=",'--managed-network=','--no-wait']) except getopt.GetoptError as err: print "Error: " + str(err) usage_and_exit() global netld_host, netld_user, netld_pass, job_name, netld_network no_wait = None job_name = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-j', '--job'): job_name = arg if opt in ('-m', '--managed-network'): netld_network = (arg) if opt in ('-w', '--no-wait'): no_wait = True if (job_name is None): usage_and_exit() ### Create a JSON-RPC proxy ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = {'offset': 0, 'pageSize': 1000} try: pageData = _netld_svc.call('Scheduler.searchJobs', pageData, [netld_network], None, True) except JsonError as ex: print 'JsonError: ' + str(ex.value) jobId = -1 for job in pageData['jobData']: if (job['jobName'] == job_name): jobId = job['jobId']; break if (jobId == -1): print "No matching job found." exit(1) try: jobData = _netld_svc.call('Scheduler.getJob', jobId) if (jobData): execution = _netld_svc.call('Scheduler.runNow', jobData) else: print "Unexpected error, job with ID " + str(jobId) + " could not be retreived" exit(1) except JsonError as ex: print 'JsonError: ' + str(ex.value) exit(1) exit_code = 0; try: if (no_wait is None): result = _wait_for_completion(execution) exit_code = 0 if result['status'] == 'OK' else 1 print 'Job status: ' + result['status'] print 'Start time: ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['startTime'] / 1000)) print 'End time : ' + time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(result['endTime'] / 1000)) print except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser') return exit_code
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:m:w:c:t:", ['host=','user='******'password='******'managed-network=','--no-wait','config=','timestamp=']) except getopt.GetoptError: _usage_and_exit() global netld_host, netld_user, netld_pass, netld_network no_wait = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if opt in ('-w', '--no-wait'): no_wait = True if opt in ('-c', '--config'): configPath = arg if opt in ('-t', '--timestamp'): timestamp = arg if (len(args) > 0): device = args[0] else: _usage_and_exit() ### Create a JSON-RPC proxy for the inventory service ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = _netld_svc.call('Configuration.retrieveSnapshotChangeLog', 'Default', device, {'offset': 0, 'pageSize': 1000}) for changeLog in pageData['changeLogs']: snapShot = datetime.fromtimestamp(changeLog['timestamp'] / 1000) if (snapShot.strftime('%Y-%m-%d %H:%M:%S') > timestamp): targetTime = datetime.utcfromtimestamp(changeLog['timestamp'] / 1000) localTargetTime = snapShot else: print "Restoring configuration from snapshot: " + str(localTargetTime) break job_data = { 'managedNetwork': netld_network, 'jobName': job_name, 'jobType': 'Restore Configuration', 'description': '', 'jobParameters': { 'managedNetwork': netld_network, 'ipResolutionScheme': _resolution_scheme(device), 'ipResolutionData': device, 'configPath': configPath, 'configTimestamp': targetTime.strftime('%Y-%m-%dT%H:%M:%S') } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: if (no_wait is None): result = _wait_for_completion(execution) except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv, "h:u:p:m:w:c:t:", [ 'host=', 'user='******'password='******'managed-network=', '--no-wait', 'config=', 'timestamp=' ]) except getopt.GetoptError: _usage_and_exit() global netld_host, netld_user, netld_pass, netld_network no_wait = None for opt, arg in opts: if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if opt in ('-w', '--no-wait'): no_wait = True if opt in ('-c', '--config'): configPath = arg if opt in ('-t', '--timestamp'): timestamp = arg if (len(args) > 0): device = args[0] else: _usage_and_exit() ### Create a JSON-RPC proxy for the inventory service ### global _netld_svc _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = _netld_svc.call('Configuration.retrieveSnapshotChangeLog', 'Default', device, { 'offset': 0, 'pageSize': 1000 }) for changeLog in pageData['changeLogs']: snapShot = datetime.fromtimestamp(changeLog['timestamp'] / 1000) if (snapShot.strftime('%Y-%m-%d %H:%M:%S') > timestamp): targetTime = datetime.utcfromtimestamp(changeLog['timestamp'] / 1000) localTargetTime = snapShot else: print "Restoring configuration from snapshot: " + str( localTargetTime) break job_data = { 'managedNetwork': netld_network, 'jobName': job_name, 'jobType': 'Restore Configuration', 'description': '', 'jobParameters': { 'managedNetwork': netld_network, 'ipResolutionScheme': _resolution_scheme(device), 'ipResolutionData': device, 'configPath': configPath, 'configTimestamp': targetTime.strftime('%Y-%m-%dT%H:%M:%S') } } try: execution = _netld_svc.call('Scheduler.runNow', job_data) except JsonError as ex: print 'JsonError: ' + str(ex.value) try: if (no_wait is None): result = _wait_for_completion(execution) except JsonError as ex: print 'JsonError: ' + str(ex.value) finally: ### Logout using the security service to be nice to the server ### _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt(argv,"h:u:p:m:o:", ["host=","user="******"password="******"--managed-network=","output="]) except getopt.GetoptError: usageAndExit() global netld_host, netld_user, netld_pass, netld_network outputFile = '' netld_network = 'Default' for opt, arg in opts: if opt in ('-o', '--output'): outputFile = arg if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if outputFile == '': outputFile = "InventoryReport" + strftime("%y%m%d-%H%M%S", localtime()) + ".csv" _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = {'offset': 0, 'pageSize': 500} while True: pageData = _netld_svc.call('Inventory.search', ['Default'], 'ipAddress', "", pageData, 'ipAddress', False) csvfile = open(outputFile, 'w') cw = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) for device in pageData['devices']: cw.writerow([ noneSafe(device['backupStatus']), noneSafe(device['ipAddress']), noneSafe(device['hostname']), noneSafe(device['hardwareVendor']), noneSafe(device['model']), noneSafe(device['deviceType']), noneSafe(device['serialNumber']), noneSafe(device['adapterId']), noneSafe(device['osVersion']), noneSafe(device['softwareVendor']), noneSafe(device['backupElapsed']), noneSafe(device['memoSummary']), noneSafe(device['custom1']), noneSafe(device['custom2']), noneSafe(device['custom3']), noneSafe(device['custom4']), noneSafe(device['custom5']) ]) if pageData['offset'] + pageData['pageSize'] >= pageData['total']: break; pageData['offset'] += pageData['pageSize'] if pageData['total'] == 0: quit _netld_svc.call('Security.logoutCurrentUser')
def main(argv): try: opts, args = getopt.getopt( argv, "h:u:p:m:o:", ["host=", "user="******"password="******"--managed-network=", "output="]) except getopt.GetoptError: usageAndExit() global netld_host, netld_user, netld_pass, netld_network outputFile = '' netld_network = 'Default' for opt, arg in opts: if opt in ('-o', '--output'): outputFile = arg if opt in ('-h', '--host'): netld_host = arg if opt in ('-u', '--user'): netld_user = arg if opt in ('-p', '--password'): netld_pass = arg if opt in ('-m', '--managed-network'): netld_network = arg if outputFile == '': outputFile = "InventoryReport" + strftime("%y%m%d-%H%M%S", localtime()) + ".csv" _netld_svc = JsonRpcProxy("https://{0}/jsonrpc".format(netld_host), netld_user, netld_pass) pageData = {'offset': 0, 'pageSize': 500} while True: pageData = _netld_svc.call('Inventory.search', ['Default'], 'ipAddress', "", pageData, 'ipAddress', False) csvfile = open(outputFile, 'w') cw = csv.writer(csvfile, delimiter=',', quotechar='"', quoting=csv.QUOTE_ALL) for device in pageData['devices']: cw.writerow([ noneSafe(device['backupStatus']), noneSafe(device['ipAddress']), noneSafe(device['hostname']), noneSafe(device['hardwareVendor']), noneSafe(device['model']), noneSafe(device['deviceType']), noneSafe(device['serialNumber']), noneSafe(device['adapterId']), noneSafe(device['osVersion']), noneSafe(device['softwareVendor']), noneSafe(device['backupElapsed']), noneSafe(device['memoSummary']), noneSafe(device['custom1']), noneSafe(device['custom2']), noneSafe(device['custom3']), noneSafe(device['custom4']), noneSafe(device['custom5']) ]) if pageData['offset'] + pageData['pageSize'] >= pageData['total']: break pageData['offset'] += pageData['pageSize'] if pageData['total'] == 0: quit _netld_svc.call('Security.logoutCurrentUser')
netld_user = '******' netld_pass = '******' netld_network = 'Default' ### Create a JSON-RPC proxy ### netld = JsonRpcProxy("https://{0}/rest".format(netld_host), netld_user, netld_pass) ### use the configuration service to retrieve a page of change logs ipAddress = raw_input('Enter an individual IP address or IP/CIDR (eg. 10.0.0.0/24): ') archivePath = raw_input('Enter the configuration archive path as it appears in NetLD: ') print "Snapshot Path Timestamp Size User" print "==============================================================================" changeLog = netld.call('Configuration.retrieveArchiveChangeLog', netld_network, ipAddress, archivePath, None) snapShot = changeLog['timestamp'] firstLine = True for change in changeLog['changes']: if firstLine: sys.stdout.write(datetime.datetime.fromtimestamp(snapShot/1000).strftime('%Y-%m-%d %H:%M:%S') + " ") firstLine = False else: sys.stdout.write('{:<21}'.format('')) print '{:<15}'.format(change['path']) + " " \ + datetime.datetime.fromtimestamp(change['revisionTime']/1000).strftime('%Y-%m-%d %H:%M:%S') + " " \ + '{:>5}'.format(change['size']) + " " \ + change['author']