Commit 12905195a33639e515ebbff974633ec36428e549
Exists in
master
Merge branch 'master' of https://github.com/lightbase/cacic-agente
Conflicts: cacic-daemon/cacicD/cacicd.cpp cacic-daemon/cacicD/cacictimer.cpp
Showing
6 changed files
with
24 additions
and
38 deletions
Show diff stats
cacic-daemon/cacicD/cacicd.cpp
@@ -31,16 +31,15 @@ cacicD::~cacicD() | @@ -31,16 +31,15 @@ cacicD::~cacicD() | ||
31 | 31 | ||
32 | void cacicD::start() { | 32 | void cacicD::start() { |
33 | try{ | 33 | try{ |
34 | - QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em ").append(application()->applicationDirPath()).append(".")); | ||
35 | - QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath().append("/getConfig.json")); | 34 | + QLogger::QLog_Info("Cacic Daemon", QString("Servico iniciado em " + application()->applicationDirPath() + ".")); |
35 | + QJsonObject result = ccacic->getJsonFromFile(application()->applicationDirPath() + "/getConfig.json"); | ||
36 | if(!result.contains("error") && !result.isEmpty()){ | 36 | if(!result.contains("error") && !result.isEmpty()){ |
37 | - Ocacictimer->setPeriodicidadeExecucao(result["codestatus"].toInt()); | 37 | + Ocacictimer->setPeriodicidadeExecucao(result["interval"].toInt()); |
38 | Ocacictimer->iniciarTimer(); | 38 | Ocacictimer->iniciarTimer(); |
39 | }else{ | 39 | }else{ |
40 | //TODO: deve iniciar com um timer default (4 horas é um tempo bom), pra não ficar freezado pra sempre. | 40 | //TODO: deve iniciar com um timer default (4 horas é um tempo bom), pra não ficar freezado pra sempre. |
41 | - QLogger::QLog_Error("Cacic Daemon", QString("getConfig.json não encontrado.")); | 41 | + QLogger::QLog_Error("Cacic Daemon", QString("Problemas com o arquivo getConfig.json")); |
42 | } | 42 | } |
43 | - //QLogger::QLog_Info("Cacic Daemon", "Serviço finalizado."); | ||
44 | }catch (...){ | 43 | }catch (...){ |
45 | QLogger::QLog_Error("Cacic Daemon", QString("Erro desconhecido ao iniciar o serviço.")); | 44 | QLogger::QLog_Error("Cacic Daemon", QString("Erro desconhecido ao iniciar o serviço.")); |
46 | } | 45 | } |
cacic-daemon/cacicD/cacictimer.cpp
@@ -31,7 +31,6 @@ void CacicTimer::mslot(){ | @@ -31,7 +31,6 @@ void CacicTimer::mslot(){ | ||
31 | verificarPeriodicidadeJson(); | 31 | verificarPeriodicidadeJson(); |
32 | }catch (...){ | 32 | }catch (...){ |
33 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Não foi possivel verificar a periodicidade no getConfig.json")); | 33 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Não foi possivel verificar a periodicidade no getConfig.json")); |
34 | - | ||
35 | } | 34 | } |
36 | cMutex->lock(); | 35 | cMutex->lock(); |
37 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Semáforo fechado.")); | 36 | QLogger::QLog_Info("Cacic Daemon (Timer)", QString("Semáforo fechado.")); |
@@ -42,25 +41,18 @@ void CacicTimer::mslot(){ | @@ -42,25 +41,18 @@ void CacicTimer::mslot(){ | ||
42 | QStringList nomesModulos = verificarModulos(); | 41 | QStringList nomesModulos = verificarModulos(); |
43 | 42 | ||
44 | if ( !nomesModulos.empty() ) { | 43 | if ( !nomesModulos.empty() ) { |
45 | - | ||
46 | foreach( QString nome, nomesModulos ) { | 44 | foreach( QString nome, nomesModulos ) { |
47 | - if( nome == "gercols" ) { | ||
48 | - definirDirGercols(getApplicationDirPath()); | ||
49 | - //iniciarModulo não se refere à aplicação 'gercols' | ||
50 | - iniciarModulo(); | 45 | + definirDirModulo(getApplicationDirPath(), nome); |
46 | + iniciarModulo(getDirProgram()); | ||
51 | 47 | ||
48 | + if(nome == "cacic-gercols"){ | ||
52 | //Envio do json gerado na coleta | 49 | //Envio do json gerado na coleta |
53 | bool ok; | 50 | bool ok; |
54 | QJsonObject jsonColeta = ccacic->getJsonFromFile("coleta.json"); | 51 | QJsonObject jsonColeta = ccacic->getJsonFromFile("coleta.json"); |
55 | OCacicComm->comm("/ws/neo/coleta", &ok, jsonColeta ); | 52 | OCacicComm->comm("/ws/neo/coleta", &ok, jsonColeta ); |
56 | - } else if( nome == "mapas" ) { | ||
57 | - definirDirMapas(getApplicationDirPath()); | ||
58 | - //iniciarModulo não se refere à aplicação 'mapas' | ||
59 | - iniciarModulo(); | ||
60 | } | 53 | } |
61 | } | 54 | } |
62 | } | 55 | } |
63 | - | ||
64 | }else{ | 56 | }else{ |
65 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); | 57 | qDebug() << "getConfig() failed. - " + QDateTime::currentDateTime().toLocalTime().toString(); |
66 | QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na obtenção do arquivo de configuração."); | 58 | QLogger::QLog_Error("Cacic Daemon (Timer)", "Falha na obtenção do arquivo de configuração."); |
@@ -169,13 +161,13 @@ void CacicTimer::setDirProgram(const QString &value) | @@ -169,13 +161,13 @@ void CacicTimer::setDirProgram(const QString &value) | ||
169 | } | 161 | } |
170 | 162 | ||
171 | 163 | ||
172 | -void CacicTimer::iniciarModulo() | 164 | +void CacicTimer::iniciarModulo(QString modulo) |
173 | { | 165 | { |
174 | registraInicioColeta(); | 166 | registraInicioColeta(); |
175 | QDir::setCurrent(this->applicationDirPath); | 167 | QDir::setCurrent(this->applicationDirPath); |
176 | QProcess proc; | 168 | QProcess proc; |
177 | proc.setWorkingDirectory(this->applicationDirPath); | 169 | proc.setWorkingDirectory(this->applicationDirPath); |
178 | - proc.execute(getDirProgram()); | 170 | + proc.execute(modulo); |
179 | if((proc.atEnd()) && (proc.exitStatus() == QProcess::NormalExit)){ | 171 | if((proc.atEnd()) && (proc.exitStatus() == QProcess::NormalExit)){ |
180 | registraFimColeta("SUCESSO"); | 172 | registraFimColeta("SUCESSO"); |
181 | }else{ | 173 | }else{ |
@@ -229,7 +221,7 @@ void CacicTimer::verificarPeriodicidadeJson() | @@ -229,7 +221,7 @@ void CacicTimer::verificarPeriodicidadeJson() | ||
229 | QJsonObject result = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json"); | 221 | QJsonObject result = ccacic->getJsonFromFile(this->applicationDirPath + "/getConfig.json"); |
230 | if(!result.contains("error") && !result.isEmpty()){ | 222 | if(!result.contains("error") && !result.isEmpty()){ |
231 | if(getPeriodicidadeExecucao() != result["nu_intervalo_exec"].toInt()){ | 223 | if(getPeriodicidadeExecucao() != result["nu_intervalo_exec"].toInt()){ |
232 | - setPeriodicidadeExecucao(result["nu_intervalo_exec"].toInt()); | 224 | + setPeriodicidadeExecucao(result["nu_intervalo_exec"].toInt()); //segundo alteração do eduardo, o nome da variável ficou o mesmo de antes. me corrijam se estiver errado |
233 | reiniciarTimer(); | 225 | reiniciarTimer(); |
234 | } | 226 | } |
235 | }else{ | 227 | }else{ |
@@ -238,19 +230,11 @@ void CacicTimer::verificarPeriodicidadeJson() | @@ -238,19 +230,11 @@ void CacicTimer::verificarPeriodicidadeJson() | ||
238 | } | 230 | } |
239 | 231 | ||
240 | 232 | ||
241 | -void CacicTimer::definirDirGercols(QString appDirPath){ | ||
242 | -#if defined (Q_OS_WIN) | ||
243 | - setDirProgram(appDirPath + "\\cacic-gercols.exe"); | ||
244 | -#elif defined (Q_OS_LINUX) | ||
245 | - setDirProgram(appDirPath + "/cacic-gercols"); | ||
246 | -#endif | ||
247 | -} | ||
248 | - | ||
249 | -void CacicTimer::definirDirMapas(QString appDirPath){ | 233 | +void CacicTimer::definirDirModulo(QString appDirPath, QString nome){ |
250 | #if defined (Q_OS_WIN) | 234 | #if defined (Q_OS_WIN) |
251 | - setDirProgram(appDirPath + "\\cacic-mapas.exe"); | 235 | + setDirProgram(appDirPath + "\\" + nome + ".exe"); |
252 | #elif defined (Q_OS_LINUX) | 236 | #elif defined (Q_OS_LINUX) |
253 | - setDirProgram(appDirPath + "/cacic-mapas"); | 237 | + setDirProgram(appDirPath + "/"+ nome); |
254 | #endif | 238 | #endif |
255 | } | 239 | } |
256 | 240 |
cacic-daemon/cacicD/cacictimer.h
@@ -42,12 +42,11 @@ private: | @@ -42,12 +42,11 @@ private: | ||
42 | QString dirProgram; | 42 | QString dirProgram; |
43 | QString applicationDirPath; | 43 | QString applicationDirPath; |
44 | QString getDirProgram() const; | 44 | QString getDirProgram() const; |
45 | - void iniciarModulo(); | 45 | + void iniciarModulo(QString modulo); |
46 | void iniciarInstancias(); | 46 | void iniciarInstancias(); |
47 | void verificarPeriodicidadeJson(); | 47 | void verificarPeriodicidadeJson(); |
48 | void lerArquivoConfig( const QJsonObject &jsonConfig); | 48 | void lerArquivoConfig( const QJsonObject &jsonConfig); |
49 | - void definirDirGercols(QString appDirPath); | ||
50 | - void definirDirMapas(QString appDirPath); | 49 | + void definirDirModulo(QString appDirPath, QString nome); |
51 | QJsonObject jsonConfig; | 50 | QJsonObject jsonConfig; |
52 | int periodicidadeExecucao; | 51 | int periodicidadeExecucao; |
53 | int getPeriodicidadeExecucao() const; | 52 | int getPeriodicidadeExecucao() const; |
install-cacic/install-cacic.pro
@@ -25,6 +25,7 @@ TEMPLATE = app | @@ -25,6 +25,7 @@ TEMPLATE = app | ||
25 | SOURCES += main.cpp \ | 25 | SOURCES += main.cpp \ |
26 | installcacic.cpp \ | 26 | installcacic.cpp \ |
27 | ../src/ccacic.cpp \ | 27 | ../src/ccacic.cpp \ |
28 | + ../src/cacic_comm.cpp \ | ||
28 | ../src/cacic_computer.cpp \ | 29 | ../src/cacic_computer.cpp \ |
29 | ../src/operatingsystem.cpp \ | 30 | ../src/operatingsystem.cpp \ |
30 | ../src/wmi.cpp \ | 31 | ../src/wmi.cpp \ |
install-cacic/installcacic.cpp
@@ -10,15 +10,18 @@ InstallCacic::InstallCacic(QObject *parent) : | @@ -10,15 +10,18 @@ InstallCacic::InstallCacic(QObject *parent) : | ||
10 | void InstallCacic::run(QStringList argv, int argc) { | 10 | void InstallCacic::run(QStringList argv, int argc) { |
11 | 11 | ||
12 | QLogger::QLog_Debug("Install", "Inicio de instalacao"); | 12 | QLogger::QLog_Debug("Install", "Inicio de instalacao"); |
13 | + | ||
14 | + oCacicComm = new CacicComm(); | ||
15 | + | ||
13 | bool ok; | 16 | bool ok; |
14 | //valida os parametros repassados | 17 | //valida os parametros repassados |
15 | QMap<QString, QString> param = validaParametros(argv, argc, &ok); | 18 | QMap<QString, QString> param = validaParametros(argv, argc, &ok); |
16 | //se tiver usuario, senha e url | 19 | //se tiver usuario, senha e url |
17 | if (ok){ | 20 | if (ok){ |
18 | - oCacicComm.setUrlGerente(this->argumentos["host"]); | ||
19 | - oCacicComm.setUsuario(this->argumentos["user"]); | ||
20 | - oCacicComm.setPassword(this->argumentos["password"]); | ||
21 | - QJsonObject jsonLogin = oCacicComm.login(&ok); | 21 | + oCacicComm->setUrlGerente(this->argumentos["host"]); |
22 | + oCacicComm->setUsuario(this->argumentos["user"]); | ||
23 | + oCacicComm->setPassword(this->argumentos["password"]); | ||
24 | + QJsonObject jsonLogin = oCacicComm->login(&ok); | ||
22 | if (ok){ | 25 | if (ok){ |
23 | //conectado, grava a chave na classe; | 26 | //conectado, grava a chave na classe; |
24 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); | 27 | oCacic.setChaveCrypt(jsonLogin["reply"].toObject()["chavecrip"].toString()); |
install-cacic/installcacic.h
@@ -23,7 +23,7 @@ public: | @@ -23,7 +23,7 @@ public: | ||
23 | void registro(); | 23 | void registro(); |
24 | private: | 24 | private: |
25 | QMap<QString, QString> argumentos; | 25 | QMap<QString, QString> argumentos; |
26 | - CacicComm oCacicComm; | 26 | + CacicComm *oCacicComm; |
27 | CACIC_Computer oCacicComputer; | 27 | CACIC_Computer oCacicComputer; |
28 | CCacic oCacic; | 28 | CCacic oCacic; |
29 | QLogger::QLoggerManager *logManager; | 29 | QLogger::QLoggerManager *logManager; |