def do_work(*args, **kwargs):
	for x in args:
		if '=' in x:
			k, v = x.split('=', 1)
			kwargs[k] = v
		else:
			print "ignoring option", x
	
	SERVER=SETTINGS.get('server', "http://www.openproximity.com/stats")
	SITEID=SETTINGS.get('site', "")
	CUSTID=SETTINGS.get('customer', "")
	
	if kwargs.get('server', None):
		SERVER=kwargs.get('server')
	
	if kwargs.get('site_id', None):
		SITEID=kwargs.get('site_id')
	
	if kwargs.get('customer_id', None):
		CUSTID=kwargs.get('customer_id')

	post_data = {'site-id': SITEID, 'customer-id': CUSTID}
		
	print time.time(), "posting to", SERVER
	reply = do_post(SERVER, post_data, 'remote-commands-get')
	print time.time(), "got-reply"

	reply = json.loads(reply)
	print time.time(), "got json"
	print time.time(), reply
	
	dry_run = kwargs.get('dry_run', 'false').lower()=='false'
	
	if 'commands' in reply:
		output = do_commands(reply['commands'], dry_run)
	
	do_post(SERVER, {'result': json.dumps(output)}, 'remote-commands-result')
예제 #2
0
def do_work(*args, **kwargs):
    for x in args:
        if '=' in x:
            k, v = x.split('=', 1)
            kwargs[k] = v
        else:
            print "ignoring option", x

    SERVER = SETTINGS.get('server', "http://www.openproximity.com/stats")
    SITEID = SETTINGS.get('site', "")
    CUSTID = SETTINGS.get('customer', "")

    if kwargs.get('server', None):
        SERVER = kwargs.get('server')

    if kwargs.get('site_id', None):
        SITEID = kwargs.get('site_id')

    if kwargs.get('customer_id', None):
        CUSTID = kwargs.get('customer_id')

    post_data = {'site-id': SITEID, 'customer-id': CUSTID}

    print time.time(), "posting to", SERVER
    reply = do_post(SERVER, post_data, 'remote-commands-get')
    print time.time(), "got-reply"

    reply = json.loads(reply)
    print time.time(), "got json"
    print time.time(), reply

    dry_run = kwargs.get('dry_run', 'false').lower() == 'false'

    if 'commands' in reply:
        output = do_commands(reply['commands'], dry_run)

    do_post(SERVER, {'result': json.dumps(output)}, 'remote-commands-result')
예제 #3
0
def do_data_upload(*args, **kwargs):
    for x in args:
        if '=' in x:
            k, v = x.split('=', 1)
            kwargs[k] = v
        else:
            print "ignoring option", x

    SERVER = SETTINGS.get('server', "http://www.openproximity.com/stats")
    SITEID = SETTINGS.get('site', "")
    CUSTID = SETTINGS.get('customer', "")

    if kwargs.get('server', None):
        SERVER = kwargs.get('server')

    if kwargs.get('site_id', None):
        SITEID = kwargs.get('site_id')

    if kwargs.get('customer_id', None):
        CUSTID = kwargs.get('customer_id')

    post_data = generate_data(SITEID, CUSTID)

    if kwargs.get('debug', None):
        for key, val in post_data.items():
            if key in ['site-id', 'customer-id']:
                print val
            else:
                print json.loads(val)
        return

    print time.time(), "dumping"
    post_data = json.dumps(post_data)
    print time.time(), "data-generated"

    compress = compress_data(post_data)

    print time.time(), 'uncompressed', len(post_data)

    print time.time(), "posting to", SERVER
    reply = do_post(SERVER, compress)
    print time.time(), "got-reply"

    reply = json.loads(reply)
    print time.time(), "got json"

    reply_process_agent_records(reply.get('agent-records', list()))
    transaction.commit()

    reply_process_device_records(reply.get('device-records', list()))
    transaction.commit()

    print reply['customer-id'], reply['site-id']

    if 'error' in reply:
        raise Exception(reply['error'])

    if 'available-campaigns' in reply:
        new_camps = list()
        date = AgentMarketingCampaign._meta.get_field('last_modification')
        for hash_, last_mod in reply['available-campaigns']:
            if AgentMarketingCampaign.objects.filter(
                    hash_id=hash_, last_modification=last_mod).count() == 0:
                new_camps.append(hash_)

        print "new camps available, I need to get %s camps" % len(new_camps)

    print time.time(), "dumping"
    post_data = json.dumps({'campaigns': new_camps})
    print time.time(), "data-generated"

    compress = compress_data(post_data)

    print time.time(), 'uncompressed', len(post_data)

    print time.time(), "posting to", SERVER
    camps = json.loads(do_post(SERVER, compress, 'get-campaigns'))
    print time.time(), "got-reply"
    print camps
    do_campaing_sync(camps, SERVER)
    transaction.commit()

    if kwargs.get('save_settings', 'false').lower() == 'true':
        SETTINGS['customer'] = reply['customer-id']
        SETTINGS['site'] = reply['site-id']
        op = settings.OPENPROXIMITY.getDict('/')
        op['agent'] = SETTINGS
        settings.OPENPROXIMITY.saveSettings(op)
def do_data_upload(*args, **kwargs):
	for x in args:
		if '=' in x:
			k, v = x.split('=', 1)
			kwargs[k] = v
		else:
			print "ignoring option", x
	
	SERVER=SETTINGS.get('server', "http://www.openproximity.com/stats")
	SITEID=SETTINGS.get('site', "")
	CUSTID=SETTINGS.get('customer', "")
	
	if kwargs.get('server', None):
		SERVER=kwargs.get('server')
	
	if kwargs.get('site_id', None):
		SITEID=kwargs.get('site_id')
	
	if kwargs.get('customer_id', None):
		CUSTID=kwargs.get('customer_id')

	post_data = generate_data(SITEID, CUSTID)
	
	if kwargs.get('debug', None):
		for key, val in post_data.items():
			if key in ['site-id','customer-id']:
				print val
			else:
				print json.loads(val)
		return
	
	print time.time(), "dumping"
	post_data = json.dumps(post_data)
	print time.time(), "data-generated"
	
	compress = compress_data(post_data)

	print time.time(), 'uncompressed', len(post_data)
	
	print time.time(), "posting to", SERVER
	reply = do_post(SERVER, compress)
	print time.time(), "got-reply"

	reply = json.loads(reply)
	print time.time(), "got json"

	reply_process_agent_records(reply.get('agent-records',list()))
	transaction.commit()
	
	reply_process_device_records(reply.get('device-records',list()))
	transaction.commit()
	
	print reply['customer-id'], reply['site-id']
	
	if 'error' in reply:
		raise Exception(reply['error'])
	
	if 'available-campaigns' in reply:
		new_camps = list()
		date = AgentMarketingCampaign._meta.get_field('last_modification')
		for hash_, last_mod in reply['available-campaigns']:
			if AgentMarketingCampaign.objects.filter(hash_id=hash_, last_modification=last_mod).count() == 0:
				new_camps.append(hash_)
	
		print "new camps available, I need to get %s camps" % len(new_camps)
	
	print time.time(), "dumping"
	post_data = json.dumps({'campaigns': new_camps})
	print time.time(), "data-generated"
	
	compress = compress_data(post_data)

	print time.time(), 'uncompressed', len(post_data)
	
	print time.time(), "posting to", SERVER
	camps = json.loads(do_post(SERVER, compress, 'get-campaigns'))
	print time.time(), "got-reply"
	print camps
	do_campaing_sync(camps, SERVER)
	transaction.commit()

	
	if kwargs.get('save_settings', 'false').lower()=='true':
		SETTINGS['customer']=reply['customer-id']
		SETTINGS['site']=reply['site-id']
		op = settings.OPENPROXIMITY.getDict('/')
		op['agent'] = SETTINGS
		settings.OPENPROXIMITY.saveSettings(op)