Ejemplo n.º 1
0
function submitLogs(callback) {
	QB.init(status_app.app_id, status_app.auth_key, status_app.auth_secret, false);
	QB.service.qbInst.config.endpoints.api = status_app.endpoint;
	QB.createSession({login: "******", password: "******"}, function(error, response){
	    if(!error) {
	        
	        var currentLogsInstance = 0,
	        	numberOfInstances = instances.length,
	        	sendLogs;
	        
	        sendLogs = function() {
		        var errors = null;
                if(error_log[instances[currentLogsInstance].name] !== "undefined" && error_log[instances[currentLogsInstance].name] !== null)
                errors = JSON.stringify(error_log[instances[currentLogsInstance].name]);
                
                var log = {
                    logs: JSON.stringify(latency[instances[currentLogsInstance].name]),
                    errors: errors,
                    total_latency: latency.total[instances[currentLogsInstance].name],
                    hours: moment().format("HH"),
                    minutes: moment().format("mm")
                }
                
                QB.data.create(instances[currentLogsInstance].name, log, function(error,response){
                    if (!error) {
                    	console.log("Sent logs for " + instances[currentLogsInstance].name);
                        currentLogsInstance++;
                        if( currentLogsInstance === numberOfInstances) {
                            console.log("Sent all logs (x"+currentLogsInstance+")");
                            callback();
                            return;
                        } else {
							sendLogs();
							return;
						}
                    } else {
	                    setTimeout(function() {
		                    sendLogs();
		                    return;
	                    }, 5000)
                    }
                });
                
	        };
	        
	        sendLogs();

	    } else {
    	    console.log("Could not create new session. Will try again in 10 seconds.");
    	    setTimeout(function() {submitLogs()}, 10000)    	    
	    }
	});
}
Ejemplo n.º 2
0
function createNewSession() {
    var my = {
		begin: startTime(),
		name: "Create new session" };
    
    QB.createSession(config.masterLogin, function(error, response){
	    if(error) {
	        failed(my.name, error);
	        my = null;
	    } else {
	    	setTemp("session", { token: response.token });
	        next(my.name);
	        my = null;
	    }
	});
}
Ejemplo n.º 3
0
function createSession() {
	var my = {
		begin: startTime(),
		name: "Create session" };

	QB.createSession(function(error, response){
	    if(error) {
	        failed(my.name, error);
	        my = null;
	    } else {
	        timeTo(my.name, getLatency(my.begin));
	        next(my.name);
	        my = null;
	    }
	});
}
Ejemplo n.º 4
0
function createUserSession() {
	var my = {
		begin: startTime(),
		name: "Create user session",
		module: "user" };
	
	QB.createSession({ login: getTemp(my.module, "login"), password: "******" }, function(error, response){
	    if(error) {
	        failed(my.name, error);
	        my = null;
	    } else {
	        timeTo(my.name, getLatency(my.begin));
	        next(my.name);
	        my = null;
	    }
	});
}
Ejemplo n.º 5
0
QB.createSession({
	login: CONFIG.user.login,
	password: CONFIG.user.password
}, (createSessionError, res) => {
	if(createSessionError) {
		console.error('[QB] createSession is failed', JSON.stringify(createSessionError));
		process.exit(1);
	}

	// Connect to Real-Time Chat
	QB.chat.connect({
		userId: CONFIG.user.id,
		password: CONFIG.user.password
	}, (chatConnectError) => {
		if (chatConnectError) {
			console.log('[QB] chat.connect is failed', JSON.stringify(chatConnectError));
			process.exit(1);
		}

		console.log('[QB] bot is up and running');

		// Retireve all group chats where bot is in occupants list.
		QB.chat.dialog.list({type: 2}, (dialogListError, dialogList) => {
			if(dialogListError){
				console.log('[QB] dialog.list is failed', JSON.stringify(dialogListError));
				process.exit(1);
			}

			// Join bot's group chats
			dialogList.items.forEach((dialog) => {
				QB.chat.muc.join(dialog.xmpp_room_jid);
			});
		});

		// Add listeners
		QB.chat.onMessageListener = qbListeners.onMessageListener;
		QB.chat.onSubscribeListener = qbListeners.onSubscribeListener;
		QB.chat.onSystemMessageListener = qbListeners.onSystemMessageListener;
	});
}
);