// ------------------------------------- // PRIVATE FUNCTIONS // ------------------------------------- void LPWatcher::readLogFile(bool quiet){ QStringList reppools = listReplicatedPools(); QTextStream in(logfile); while(!LFSTREAM->atEnd()){ QString log = LFSTREAM->readLine(); //Divide up the log into it's sections QString timestamp = log.section(":",0,2).simplified(); QString time = timestamp.section(" ",3,3).simplified(); QString message = log.section(":",3,3).toLower().simplified(); QString dev = log.section(":",4,4).simplified(); //dataset/snapshot/nothing //Now decide what to do/show because of the log message //qDebug() << "New Log Message:" << log; if(message.contains("creating snapshot")){ dev = message.section(" ",-1).simplified(); //Setup the status of the message LOGS.insert(10,"SNAPCREATED"); LOGS.insert(11,dev); //dataset LOGS.insert(12, QString(tr("New snapshot of %1")).arg(dev) ); //summary LOGS.insert(13, QString(tr("Creating snapshot for %1")).arg(dev) ); LOGS.insert(14, timestamp); //full timestamp LOGS.insert(15, time); // time only if(!quiet){ emit MessageAvailable("message"); } }else if(message.contains("starting replication")){ //Setup the file watcher for this new log file FILE_REPLICATION = dev; dev = message.section(" ",5,5,QString::SectionSkipEmpty); //Make sure the device is currently setup for replication if( !reppools.contains(dev) ){ FILE_REPLICATION.clear(); continue; } //Try to start the replication watcher if( startRepFileWatcher() ){ //Set the appropriate status variables LOGS.insert(20,"STARTED"); LOGS.insert(21, dev); //zpool LOGS.insert(22, tr("Replication Starting") ); //summary LOGS.insert(23, QString(tr("Starting replication for %1")).arg(dev) ); //Full message LOGS.insert(24, timestamp); //full timestamp LOGS.insert(25, time); // time only LOGS.insert(26,tr("Replication Log")+" <"+FILE_REPLICATION+">"); //log file if(!quiet){ emit MessageAvailable("replication"); } } }else if(message.contains("finished replication")){ stopRepFileWatcher(); dev = message.section(" ",-1).simplified(); //Make sure the device is currently setup for replication if( reppools.contains(dev) ){ //Now set the status of the process LOGS.insert(20,"FINISHED"); LOGS.insert(21,dev); //dataset LOGS.insert(22, tr("Finished Replication") ); //summary LOGS.insert(23, QString(tr("Finished replication for %1")).arg(dev) ); LOGS.insert(24, timestamp); //full timestamp LOGS.insert(25, time); // time only LOGS.insert(26, ""); //clear the log file entry if(!quiet){ emit MessageAvailable("replication"); } }else if( !reppools.contains( LOGS.value(21) ) ){ //Clear the current replication log, device was removed from replication LOGS.remove(20); LOGS.remove(21); LOGS.remove(22); LOGS.remove(23); LOGS.remove(24); LOGS.remove(25); LOGS.remove(26); if(!quiet){ emit MessageAvailable(""); } } }else if( message.contains("failed replication") ){ stopRepFileWatcher(); //Now set the status of the process dev = message.section(" ",-1).simplified(); //Make sure the device is currently setup for replication if( reppools.contains(dev) ){ //Update the logs QString file = log.section("LOGFILE:",1,1).simplified(); QString tt = QString(tr("Replication Failed for %1")).arg(dev) +"\n"+ QString(tr("Logfile available at: %1")).arg(file); LOGS.insert(20,"ERROR"); LOGS.insert(21,dev); //dataset LOGS.insert(22, tr("Replication Failed") ); //summary LOGS.insert(23, tt ); LOGS.insert(24, timestamp); //full timestamp LOGS.insert(25, time); // time only LOGS.insert(26, tr("Replication Error Log")+" <"+file+">" ); if(!quiet){ emit MessageAvailable("replication"); } }else if( !reppools.contains( LOGS.value(21) ) ){ //Clear the current replication log, device was removed from replication LOGS.remove(20); LOGS.remove(21); LOGS.remove(22); LOGS.remove(23); LOGS.remove(24); LOGS.remove(25); LOGS.remove(26); if(!quiet){ emit MessageAvailable(""); } } } } }
// ------------------------------------- // PRIVATE FUNCTIONS // ------------------------------------- void LPWatcher::readLogFile(bool quiet){ QTextStream in(logfile); while(!LFSTREAM->atEnd()){ QString log = LFSTREAM->readLine(); //Divide up the log into it's sections QString timestamp = log.section(":",0,2).simplified(); QString time = timestamp.section(" ",3,3).simplified(); QString message = log.section(":",3,3).toLower().simplified(); QString dev = log.section(":",4,4).simplified(); //dataset/snapshot/nothing //Now decide what to do/show because of the log message //qDebug() << "New Log Message:" << log; if(message.contains("creating snapshot")){ dev = message.section(" ",-1).simplified(); //Setup the status of the message LOGS.insert(10,"SNAPCREATED"); LOGS.insert(11,dev); //dataset LOGS.insert(12, QString(tr("New snapshot of %1")).arg(dev) ); //summary LOGS.insert(13, QString(tr("Creating snapshot for %1")).arg(dev) ); LOGS.insert(14, timestamp); //full timestamp LOGS.insert(15, time); // time only if(!quiet){ emit MessageAvailable("message"); } }else if(message.contains("starting replication")){ //Setup the file watcher for this new log file FILE_REPLICATION = dev; startRepFileWatcher(); //Set the appropriate status variables LOGS.insert(20,"REPSTARTED"); // 21 - dataset set on update ping LOGS.insert(22, tr("Replication Started") ); //summary // 23 - Full message set on update ping LOGS.insert(24, timestamp); //full timestamp LOGS.insert(25, time); // time only if(!quiet){ emit MessageAvailable("replication"); } }else if(message.contains("finished replication")){ stopRepFileWatcher(); dev = message.section(" ",-1).simplified(); //Now set the status of the process LOGS.insert(20,"REPFINISHED"); LOGS.insert(21,dev); //dataset LOGS.insert(22, tr("Finished Replication") ); //summary LOGS.insert(23, QString(tr("Finished replication for %1")).arg(dev) ); LOGS.insert(24, timestamp); //full timestamp LOGS.insert(25, time); // time only if(!quiet){ emit MessageAvailable("replication"); } }else if( message.contains("FAILED replication") ){ stopRepFileWatcher(); //Now set the status of the process dev = message.section(" ",-1).simplified(); QString file = log.section("LOGFILE:",1,1).simplified(); QString tt = QString(tr("Replication Failed for %1")).arg(dev) +"\n"+ QString(tr("Logfile available at: %1")).arg(file); LOGS.insert(20,"REPERROR"); LOGS.insert(21,dev); //dataset LOGS.insert(22, tr("Replication Failed") ); //summary LOGS.insert(23, tt ); LOGS.insert(24, timestamp); //full timestamp LOGS.insert(25, time); // time only if(!quiet){ emit MessageAvailable("replication"); } } } }