How to use get_connected_clients method in Slash

Best Python code snippet using slash

bareos-incoming-connect

Source:bareos-incoming-connect Github

copy

Full Screen

...14def get_job_names(director):15 result = director.call('.jobs')['jobs']16 jobs = [ job['name'] for job in result ]17 return jobs18def get_connected_clients(director):19 result = director.call('status director')['client-connection']20 clients = [ client['name'] for client in result ]21 return clients22def trigger(director, jobnames, clients, hours_cycle):23 for client in clients:24 jobname = 'backup-{}'.format(client)25 if not jobname in jobnames:26 print('{} skipped, no matching job ({}) found'.format(client, jobname))27 else:28 jobs = director.call('list jobs client={0} hours={1}'.format(client, hours_cycle))['jobs']29 if jobs:30 job = director.call('list jobs client={0} hours={1} last'.format(client, hours_cycle))['jobs'][0]31 jobinfo = '{starttime}: jobid={jobid}, level={level}, status={jobstatus}'.format(**job)32 print('{}: skipped, recent backups available ({})'.format(jobname, jobinfo))33 else:34 # TODO: check type=backup and failed35 jobid = director.call('run {} yes'.format(jobname))['run']['jobid']36 print('{}: backup triggered, jobid={}'.format(jobname, jobid))37def getArguments():38 parser = argparse.ArgumentParser(description='Python script to replace the standard RunOnIncomingConnectInterval mechanism for performing backups for laptops, etc. (the devices is not constantly working)')39 parser.add_argument('--debug', action='store_true', help="enable debugging output")40 parser.add_argument('--dirname', dest="dirname", default="bareos-dir", help="Bareos Director name (default bareos-dir)")41 args = parser.parse_args()42 return args43if os.path.exists(dir_conf) == False:44 sys.exit("Directory not found: " + dir_conf)45if os.path.isfile(dir_conf + file_conf) == False:46 sys.exit("Configuration file does not exist: " + dir_conf + file_conf)47if __name__ == '__main__':48 logging.basicConfig(format='%(levelname)s %(module)s.%(funcName)s: %(message)s', level = logging.INFO)49 logger = logging.getLogger()50 args = getArguments()51 config = configparser.ConfigParser()52 config.read(dir_conf + file_conf)53 dirname = args.dirname54 parameter = {}55 try:56 address = config.get(dirname, 'address')57 port = config.get(dirname, 'port')58 password = config.get(dirname, 'password')59 name = config.get(dirname, 'name')60 hours_cycle = config.get(dirname, 'hours_cycle')61 enable = config.get(dirname, 'enable')62 except Exception as e :63 print('The following issue was found in the config file: ' + str(e))64 sys.exit(1)65 if str(enable) == "False":66 print("Director " + dirname + " has state = False")67 sys.exit(0)68 if args.debug:69 logger.setLevel(logging.DEBUG)70 try:71 parameter['dirname'] = dirname72 parameter['name'] = name73 password = bareos.bsock.Password(password)74 parameter['password'] = password75 parameter['address'] = address76 parameter['port'] = port77 logger.debug('Options passed to bareos.bsock.DirectorConsoleJson: %s' % (parameter))78 try:79 director = bareos.bsock.DirectorConsoleJson(**parameter)80 except Exception as e :81 print(str(e))82 sys.exit(1)83 except RuntimeError as e:84 print(str(e))85 sys.exit(1)86 logger.debug( "authentication successful" )87 jobs = get_job_names(director)88 clients = get_connected_clients(director)...

Full Screen

Full Screen

bareos-triggerjob.py

Source:bareos-triggerjob.py Github

copy

Full Screen

...7def get_job_names(director):8 result = director.call(".jobs")["jobs"]9 jobs = [job["name"] for job in result]10 return jobs11def get_connected_clients(director):12 result = director.call("status director")["client-connection"]13 clients = [client["name"] for client in result]14 return clients15def trigger(director, jobnames, clients, hours):16 for client in clients:17 jobname = "backup-{}".format(client)18 if not jobname in jobnames:19 print("{} skipped, no matching job ({}) found".format(client, jobname))20 else:21 jobs = director.call(22 ("list jobs client={} hours={}").format(client, hours)23 )["jobs"]24 if jobs:25 job = director.call(26 ("list jobs client={} hours={} last").format(client, hours)27 )["jobs"][0]28 jobinfo = "{starttime}: jobid={jobid}, level={level}, status={jobstatus}".format(29 **job30 )31 print(32 "{}: skipped, recent backups available ({})".format(33 jobname, jobinfo34 )35 )36 else:37 jobid = director.call("run {} yes".format(jobname))["run"]["jobid"]38 print("{}: backup triggered, jobid={}".format(jobname, jobid))39def getArguments():40 epilog = """41 bareos-triggerjob is a Python script that allows you to perform a backup for a connected client if a definable time has passed since the last backup.42 It will look for all clients connected to the Director. If it finds a job named "backup-{clientname}" that did not successfully run during the specified time period, it will trigger this job. This way, clients that are not regularly connected to the director, such as notebooks, can be reliably backed up.43 bareos-triggerjob should be executed regularly to detect newly connected clients. To do so, a cronjob should run the script repeatedly.44 Note: bareos-triggerjob requires a connection between director and client. Therefore, activate Client Initiated Connections (https://docs.bareos.org/TasksAndConcepts/NetworkSetup.html#client-initiated-connection) to automatically establish a connection whenever possible. Otherwise no jobs will be started.45 """46 argparser = argparse.ArgumentParser(47 description=u"Trigger Bareos jobs.", epilog=epilog48 )49 argparser.add_argument(50 "-d", "--debug", action="store_true", help="enable debugging output"51 )52 bareos.bsock.DirectorConsole.argparser_add_default_command_line_arguments(argparser)53 args = argparser.parse_args()54 return args55if __name__ == "__main__":56 logging.basicConfig(57 format="%(levelname)s %(module)s.%(funcName)s: %(message)s", level=logging.INFO58 )59 logger = logging.getLogger()60 args = getArguments()61 if args.debug:62 logger.setLevel(logging.DEBUG)63 try:64 options = ["address", "port", "dirname", "name"]65 parameter = {}66 for i in options:67 if hasattr(args, i) and getattr(args, i) != None:68 logger.debug("%s: %s" % (i, getattr(args, i)))69 parameter[i] = getattr(args, i)70 else:71 logger.debug('%s: ""' % (i))72 logger.debug("options: %s" % (parameter))73 password = bareos.bsock.Password(args.password)74 parameter["password"] = password75 director = bareos.bsock.DirectorConsoleJson(**parameter)76 except RuntimeError as e:77 print(str(e))78 sys.exit(1)79 logger.debug("authentication successful")80 hours = str(args.hours)81 jobs = get_job_names(director)82 clients = get_connected_clients(director)...

Full Screen

Full Screen

app.py

Source:app.py Github

copy

Full Screen

...14 device_name = request.form.get("platform", None)15 new_client = {"platform": device_name, "ip": device_ip}16 if device_name and device_ip:17 connect_client(new_client)18 print(get_connected_clients())19 return jsonify(new_client)20 else: 21 return {error: "Could not connect client, no valid platform"}22@app.route("/remove_client", methods=['POST'])23def remove_client():24 device_name = request.form.get("platform", None)25 if device_name:26 remove_connected_client(device_name)27 print(get_connected_clients())28 return jsonify({"platform": device_name})29 else:30 return {error: "Client does not exist"}31@app.route("/get")32def get_clients():33 clients = get_connected_clients()34 print(clients)35 return jsonify(clients)36if __name__ == "__main__":...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Slash automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful