Commit 5472f8063e295dd2a411598a784a236c3a679b39

Authored by Starlone Passos
1 parent 8128f434

Autenticando no webservice. Simplificando os logs

README.md
... ... @@ -26,7 +26,7 @@ Ainda editando o arquivo *sei/sei/config/ConfiguracaoSEI.php* adicione uma nova
26 26 'Modulos' => array('MdEstatisticas' => 'mod-sei-estatisticas')),
27 27 ...
28 28 'MdEstatisticas' => array(
29   - 'url' => 'http://estatisticas.planejamento.gov.br/estatisticas',
  29 + 'url' => 'http://estatisticas.planejamento.gov.br',
30 30 'sigla' => 'MPOG',
31 31 'chave' => '123456'),
32 32  
... ...
dto/IndicadoresDTO.php
... ... @@ -1,23 +0,0 @@
1   -<?php
2   -
3   -require_once dirname(__FILE__).'/../../../SEI.php';
4   -
5   -class IndicadoresDTO extends InfraDTO {
6   -
7   - public function getStrNomeTabela() {
8   - return "md_estatísticas_indicadores";
9   - }
10   -
11   - public function montar() {
12   -
13   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_STR, 'VersaoSEI', 'versao_sei');
14   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_STR, 'VersaoPHP', 'versao_php');
15   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_NUM, 'TamanhoFileSystem', 'tamanho_file_system');
16   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_STR, 'Plugins', 'plugins');
17   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_NUM, 'QuantidadeUnidades', 'quantidade_unidades');
18   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_NUM, 'TamanhoDocumentosExternos', 'tamanho_docs_externos');
19   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_STR, 'Protocolo', 'protocolo');
20   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_NUM, 'QuantidadeProcedimentos', 'quantidade_procedimentos');
21   - $this->adicionarAtributoTabela(InfraDTO::$PREFIXO_STR, 'Navegadores', 'navegadores');
22   - }
23   -}
rn/MdEstatisticasAgendamentoRN.php
... ... @@ -15,40 +15,67 @@ class MdEstatisticasAgendamentoRN extends InfraRN
15 15 InfraDebug::getInstance()->limpar();
16 16  
17 17 try {
  18 + $enviar = new MdEstatisticasEnviarRN();
  19 +
  20 + $this->gravarLog('Autenticar no WebService');
  21 + if (!$enviar->autenticar()) {
  22 + throw new InfraException('Problemas com a autenticação.');
  23 + }
  24 +
  25 + $this->gravarLog('Autenticado. Coletando indicadores');
  26 +
18 27 $coletor = new MdEstatisticasColetarRN();
19 28 $indicadores = $coletor->coletarIndicadores();
20   - InfraDebug::getInstance()->gravar('JSON: ' . json_encode($indicadores), InfraLog::$INFORMACAO);
21   -
22   - $enviar = new MdEstatisticasEnviarRN();
23   -
  29 +
  30 + $this->gravarLog('Indicadores coletados, enviando');
  31 +
24 32 $saida = $enviar->enviarIndicadores($indicadores);
25   - InfraDebug::getInstance()->gravar('Retorno: ' . json_encode($saida), InfraLog::$INFORMACAO);
26   -
  33 +
27 34 $id = $saida['id'];
  35 +
  36 + if (!$id) {
  37 + throw new InfraException('Erro no envio dos indicadores.');
  38 + }
28 39  
29   - if ($id) {
30   - $data = $enviar->obterUltimoAcesso();
31   - InfraDebug::getInstance()->gravar('Data: ' . $data, InfraLog::$INFORMACAO);
32   -
33   - $acessos = $coletor->obterAcessosUsuarios($data);
34   - $enviar->enviarAcessos($acessos, $id);
35   -
36   - $velocidades = $coletor->obterVelocidadePorCidade();
37   - $enviar->enviarVelocidades($velocidades, $id);
38   -
39   - $sistemasOperacionaisUsuarios = $coletor->obterSistemasOperacionaisUsuarios();
40   - $enviar->enviarSistemasUsuarios($sistemasOperacionaisUsuarios, $id);
41   -
42   - $navegadores = $coletor->obterNavegadores();
43   - $enviar->enviarNavegadores($navegadores, $id);
  40 + $this->gravarLog('Indicadores recebidos. Coletar indicadores do tipo lista');
  41 +
  42 + $this->gravarLog('Obter a data do último envio das quantidades de acessos ');
  43 + $data = $enviar->obterUltimoAcesso();
  44 + $this->gravarLog('Ultima data das quantidades de acessos: ' . $data . '. Coletar quantidade de acessos');
44 45  
45   - $logs = $coletor->obterQuantidadeLogErro();
46   - $enviar->enviarLogsErro($logs, $id);
47   -
48   - $dataultimorecurso = $enviar->obterUltimoRecurso();
49   - $recursos = $coletor->obterQuantidadeRecursos($dataultimorecurso);
50   - $enviar->enviarRecursos($recursos, $id);
51   - }
  46 + $acessos = $coletor->obterAcessosUsuarios($data);
  47 + $this->gravarLog('Coletado. Enviar quantidade de acessos: ');
  48 + $enviar->enviarAcessos($acessos, $id);
  49 +
  50 + $this->gravarLog('Enviado. Coletar velocidades por cidade: ');
  51 + $velocidades = $coletor->obterVelocidadePorCidade();
  52 + $this->gravarLog('Coletado. Enviar: ');
  53 + $enviar->enviarVelocidades($velocidades, $id);
  54 +
  55 + $this->gravarLog('Enviado. Coletar os sistemas operacionais dos usuários: ');
  56 + $sistemasOperacionaisUsuarios = $coletor->obterSistemasOperacionaisUsuarios();
  57 + $this->gravarLog('Coletado. Enviar: ');
  58 + $enviar->enviarSistemasUsuarios($sistemasOperacionaisUsuarios, $id);
  59 +
  60 + $this->gravarLog('Enviado. Coletar os navegadores: ');
  61 + $navegadores = $coletor->obterNavegadores();
  62 + $this->gravarLog('Coletado. Enviar: ');
  63 + $enviar->enviarNavegadores($navegadores, $id);
  64 +
  65 + $this->gravarLog('Enviado. Coletar a quantidade de logs de erro: ');
  66 + $logs = $coletor->obterQuantidadeLogErro();
  67 + $this->gravarLog('Coletado. Enviar: ');
  68 + $enviar->enviarLogsErro($logs, $id);
  69 +
  70 + $this->gravarLog('Enviado. Obter a ultima data que foi enviado a quantidade de recursos ');
  71 + $dataultimorecurso = $enviar->obterUltimoRecurso();
  72 + $this->gravarLog('Ultima data das quantidades de recursos: ' . $dataultimorecurso . '. Coletar quantidade de recursos');
  73 + $recursos = $coletor->obterQuantidadeRecursos($dataultimorecurso);
  74 + $this->gravarLog('Coletado. Enviar: ');
  75 + $enviar->enviarRecursos($recursos, $id);
  76 + $this->gravarLog('Enviado: ');
  77 +
  78 + $this->gravarLog('Finalizado');
52 79  
53 80 LogSEI::getInstance()->gravar(InfraDebug::getInstance()->getStrDebug(), InfraLog::$INFORMACAO);
54 81 } catch (Exception $e) {
... ... @@ -57,6 +84,11 @@ class MdEstatisticasAgendamentoRN extends InfraRN
57 84 InfraDebug::getInstance()->setBolEcho(false);
58 85 throw new InfraException('Erro processando estatísticas do sistema.', $e);
59 86 }
  87 +
  88 + }
  89 +
  90 + private function gravarLog($texto) {
  91 + InfraDebug::getInstance()->gravar($texto, InfraLog::$INFORMACAO);
60 92 }
61 93 }
62 94 ?>
... ...
rn/MdEstatisticasColetarRN.php
... ... @@ -48,8 +48,6 @@ class MdEstatisticasColetarRN extends InfraRN
48 48 $ind['extensoes'] = $this->obterQuantidadeDocumentosExternosPorExtensao();
49 49 $ind['anexosTamanhos'] = $this->obterTamanhoDocumentosExternos();
50 50  
51   - InfraDebug::getInstance()->gravar('Ind: ' . json_encode($ind), InfraLog::$INFORMACAO);
52   -
53 51 return $ind;
54 52 } catch (Exception $e) {
55 53 InfraDebug::getInstance()->setBolLigado(false);
... ... @@ -98,24 +96,18 @@ class MdEstatisticasColetarRN extends InfraRN
98 96 array_push($lista, $result);
99 97 }
100 98  
101   - InfraDebug::getInstance()->gravar('SEI03 - Plugins: ' . json_encode($lista), InfraLog::$INFORMACAO);
102 99 return $lista;
103 100 }
104 101  
105 102 private function obterQuantidadeUnidades() {
106 103 $objUnidadeRN = new UnidadeRN();
107   - $numQuantidadeUnidades = $objUnidadeRN->contarRN0128(new UnidadeDTO());
108   -
109   - InfraDebug::getInstance()->gravar('SEI11 - Quantidade Unidades: ' . $numQuantidadeUnidades, InfraLog::$INFORMACAO);
110   - return $numQuantidadeUnidades;
  104 + return $objUnidadeRN->contarRN0128(new UnidadeDTO());
111 105 }
112 106  
113 107 private function obterTamanhoTotalDocumentosExternos() {
114 108 $query = "select sum(tamanho) as tamanho from anexo where sin_ativo = 'S'";
115 109 $rs = BancoSEI::getInstance()->consultarSql($query);
116 110 $tamanho = (count($rs) && isset($rs[0]['tamanho'])) ? $rs[0]['tamanho'] : 0;
117   -
118   - InfraDebug::getInstance()->gravar('SEI12 - Tamanho Documentos Externos: ' . $tamanho, InfraLog::$INFORMACAO);
119 111 return $tamanho;
120 112 }
121 113  
... ... @@ -123,8 +115,6 @@ class MdEstatisticasColetarRN extends InfraRN
123 115 $query = "SELECT COUNT(*) as quantidade FROM usuario WHERE sin_ativo = 'S'";
124 116 $rs = BancoSEI::getInstance()->consultarSql($query);
125 117 $quantidade = (count($rs) && isset($rs[0]['quantidade'])) ? $rs[0]['quantidade'] : 0;
126   -
127   - InfraDebug::getInstance()->gravar('SEI09 - Quantidade de usuários: ' . $quantidade, InfraLog::$INFORMACAO);
128 118 return $quantidade;
129 119 }
130 120  
... ... @@ -136,7 +126,6 @@ class MdEstatisticasColetarRN extends InfraRN
136 126 if ($temHTTPS) {
137 127 $protocolo = 'HTTPS';
138 128 }
139   - InfraDebug::getInstance()->gravar('SEI12 - Protocolo: ' . $protocolo, InfraLog::$INFORMACAO);
140 129 return $protocolo;
141 130 }
142 131 }
... ... @@ -145,24 +134,18 @@ class MdEstatisticasColetarRN extends InfraRN
145 134 $query = "select count(*) as quantidade from procedimento";
146 135 $rs = BancoSEI::getInstance()->consultarSql($query);
147 136 $quantidade = (count($rs) && isset($rs[0]['quantidade'])) ? $rs[0]['quantidade'] : 0;
148   -
149   - InfraDebug::getInstance()->gravar('SEI06 - Quantidade de Processos Administrativos: ' . $quantidade, InfraLog::$INFORMACAO);
150 137 return $quantidade;
151 138 }
152 139  
153 140 private function obterTipoSGBD() {
154 141 $objConfiguracaoSEI = ConfiguracaoSEI::getInstance();
155   - $sgbd = $objConfiguracaoSEI->getValor('BancoSEI', 'Tipo', false, '');
156   - InfraDebug::getInstance()->gravar('SEI02 - SGBD: ' . $sgbd, InfraLog::$INFORMACAO);
157   - return $sgbd;
  142 + return $objConfiguracaoSEI->getValor('BancoSEI', 'Tipo', false, '');
158 143 }
159 144  
160 145 private function obterQuantidadeDocumentosInternos() {
161 146 $query = "SELECT COUNT(*) as quantidade FROM documento WHERE STA_DOCUMENTO = 'I'";
162 147 $rs = BancoSEI::getInstance()->consultarSql($query);
163 148 $quantidade = (count($rs) && isset($rs[0]['quantidade'])) ? $rs[0]['quantidade'] : 0;
164   -
165   - InfraDebug::getInstance()->gravar('SEI05 - Quantidade de documentos internos: ' . $quantidade, InfraLog::$INFORMACAO);
166 149 return $quantidade;
167 150 }
168 151  
... ... @@ -170,8 +153,6 @@ class MdEstatisticasColetarRN extends InfraRN
170 153 $query = "SELECT COUNT(*) as quantidade FROM documento WHERE STA_DOCUMENTO = 'X'";
171 154 $rs = BancoSEI::getInstance()->consultarSql($query);
172 155 $quantidade = (count($rs) && isset($rs[0]['quantidade'])) ? $rs[0]['quantidade'] : 0;
173   -
174   - InfraDebug::getInstance()->gravar('SEI05 - Quantidade de documentos externos: ' . $quantidade, InfraLog::$INFORMACAO);
175 156 return $quantidade;
176 157 }
177 158  
... ... @@ -196,13 +177,10 @@ class MdEstatisticasColetarRN extends InfraRN
196 177 );
197 178 array_push($lista, $result);
198 179 }
199   -
200   - InfraDebug::getInstance()->gravar('SEI07 - Quantidade de extensoes de documentos externos: ' . json_encode($lista), InfraLog::$INFORMACAO);
201 180 return $lista;
202 181 }
203 182  
204 183 private function obterEstrategiaCessao() {
205   - InfraDebug::getInstance()->gravar('SEI24 - Estrategia de armazenamento de cessao: ' . ini_get('session.save_handler'), InfraLog::$INFORMACAO);
206 184 return ini_get('session.save_handler');
207 185 }
208 186  
... ... @@ -215,7 +193,6 @@ class MdEstatisticasColetarRN extends InfraRN
215 193 $memcache->connect($host, $porta);
216 194 $versao = $memcache->getVersion();
217 195  
218   - InfraDebug::getInstance()->gravar('SEI23 - Versão memcached: ' . $versao, InfraLog::$INFORMACAO);
219 196 return $versao;
220 197 }
221 198  
... ... @@ -234,8 +211,6 @@ class MdEstatisticasColetarRN extends InfraRN
234 211 $rs = BancoSEI::getInstance()->consultarSql($query);
235 212 }
236 213 $tamanho = (count($rs) && isset($rs[0]['tamanho'])) ? $rs[0]['tamanho'] : 0;
237   -
238   - InfraDebug::getInstance()->gravar('SEI03 - Tamanho do SGBD: ' . $tamanho, InfraLog::$INFORMACAO);
239 214 return $tamanho;
240 215 }
241 216  
... ... @@ -253,8 +228,6 @@ class MdEstatisticasColetarRN extends InfraRN
253 228 if ($query) {
254 229 $tabelas = BancoSEI::getInstance()->consultarSql($query);
255 230 }
256   -
257   - InfraDebug::getInstance()->gravar('SEI15 - Tamanho das tabelas: ' . json_encode($tabelas), InfraLog::$INFORMACAO);
258 231 return $tabelas;
259 232 }
260 233  
... ... @@ -268,33 +241,23 @@ class MdEstatisticasColetarRN extends InfraRN
268 241 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
269 242 $output = curl_exec($ch);
270 243 $json = json_decode($output, true);
271   - $versao = $json['lucene']['lucene-spec-version'];
272   - InfraDebug::getInstance()->gravar('SEI22 - Versao Solr: ' . $versao, InfraLog::$INFORMACAO);
273   - return $versao;
  244 + return $json['lucene']['lucene-spec-version'];
274 245 }
275 246  
276 247 private function obterServidorAplicacao() {
277   - $versao = $_SERVER['SERVER_SOFTWARE'];
278   - InfraDebug::getInstance()->gravar('SEI20 - Quantidade de servidores de aplicação e suas versões: ' . $versao, InfraLog::$INFORMACAO);
279   - return $versao;
  248 + return $_SERVER['SERVER_SOFTWARE'];
280 249 }
281 250  
282 251 private function obterSistemaOperacional() {
283   - $so = PHP_OS;
284   - InfraDebug::getInstance()->gravar('SEI17 - Quantidade de Sistemas Operacionais: ' . $so, InfraLog::$INFORMACAO);
285   - return $so;
  252 + return PHP_OS;
286 253 }
287 254  
288 255 private function obterSistemaOperacionalDetalhado() {
289   - $so = php_uname();
290   - InfraDebug::getInstance()->gravar('SEI17 - Quantidade de Sistemas Operacionais (Detalhado): ' . $so, InfraLog::$INFORMACAO);
291   - return $so;
  256 + return php_uname();
292 257 }
293 258  
294 259 private function obterDataColeta() {
295   - $dataColeta = date(DATE_ATOM);
296   - InfraDebug::getInstance()->gravar('SEI29 - Periodicidade do envio - Data da coleta: ' . $dataColeta, InfraLog::$INFORMACAO);
297   - return $dataColeta;
  260 + return date(DATE_ATOM);
298 261 }
299 262  
300 263 private function obterTamanhoDocumentosExternos() {
... ... @@ -330,15 +293,11 @@ class MdEstatisticasColetarRN extends InfraRN
330 293 'tamanho' => 'Maior que 100MB',
331 294 'quantidade' => (count($rs) && isset($rs[0]['quantidade'])) ? $rs[0]['quantidade'] : 0
332 295 );
333   -
334   - InfraDebug::getInstance()->gravar('SEI11 - Tamanho dos documentos externos: ' . json_encode($resultado), InfraLog::$INFORMACAO);
335 296 return $resultado;
336 297 }
337 298  
338 299 private function obterUsoMemoria() {
339   - $memoria = memory_get_usage();
340   - InfraDebug::getInstance()->gravar('SEI18 - Quantidade de byte de uso de memoria: ' . json_encode($memoria), InfraLog::$INFORMACAO);
341   - return $memoria;
  300 + return memory_get_usage();
342 301 }
343 302  
344 303 private function obterUsoCPU() {
... ... @@ -347,12 +306,10 @@ class MdEstatisticasColetarRN extends InfraRN
347 306 if ($load) {
348 307 $uso = $load[0];
349 308 }
350   - InfraDebug::getInstance()->gravar('SEI18 - Porcentagem de uso de CPU: ' . json_encode($uso), InfraLog::$INFORMACAO);
351 309 return $uso;
352 310 }
353 311  
354 312 private function obterEspacoDisco() {
355   - $ds = null;
356 313 if (php_uname('s') == 'Windows NT') {
357 314 $unidade = substr($_SERVER['DOCUMENT_ROOT'], 0, 2);
358 315 if (! $unidade) {
... ... @@ -363,9 +320,7 @@ class MdEstatisticasColetarRN extends InfraRN
363 320 }
364 321 $total = disk_total_space($unidade);
365 322 $free = disk_free_space($unidade);
366   - $ds = $total - $free;
367   - InfraDebug::getInstance()->gravar('SEI18 - Espaco utilizado do disco: ' . json_encode($ds), InfraLog::$INFORMACAO);
368   - return $ds;
  323 + return $total - $free;
369 324 }
370 325  
371 326 private function obterBancoVersao() {
... ... @@ -383,7 +338,6 @@ class MdEstatisticasColetarRN extends InfraRN
383 338 $rs = BancoSEI::getInstance()->consultarSql($query);
384 339 }
385 340 $versao = (count($rs) && isset($rs[0]['versao'])) ? $rs[0]['versao'] : null;
386   - InfraDebug::getInstance()->gravar('SEI02 - Versao do SGBD: ' . $versao, InfraLog::$INFORMACAO);
387 341 return $versao;
388 342 }
389 343  
... ... @@ -409,7 +363,6 @@ class MdEstatisticasColetarRN extends InfraRN
409 363  
410 364 array_push($lista, $result);
411 365 }
412   - InfraDebug::getInstance()->gravar('SEI14 - Quantidade de bytes de transferência: ' . json_encode($lista), InfraLog::$INFORMACAO);
413 366 return $lista;
414 367 }
415 368  
... ... @@ -432,7 +385,6 @@ class MdEstatisticasColetarRN extends InfraRN
432 385 $query = sprintf($query, $ultimadata);
433 386 $rs = BancoSEI::getInstance()->consultarSql($query);
434 387 }
435   - InfraDebug::getInstance()->gravar('SEI27 - Quantidade de acessos por dia: ' . json_encode($rs), InfraLog::$INFORMACAO);
436 388 return $rs;
437 389 }
438 390  
... ... @@ -464,8 +416,6 @@ class MdEstatisticasColetarRN extends InfraRN
464 416 );
465 417 array_push($sistemas, $result);
466 418 }
467   -
468   - InfraDebug::getInstance()->gravar('SEI26 - Sistemas Operacionais dos Clientes: ' . json_encode($sistemas), InfraLog::$INFORMACAO);
469 419 return $sistemas;
470 420 }
471 421  
... ... @@ -481,8 +431,6 @@ class MdEstatisticasColetarRN extends InfraRN
481 431 );
482 432 array_push($lista, $result);
483 433 }
484   -
485   - InfraDebug::getInstance()->gravar('SEI13 - Quantidade de Navegadores: ' . json_encode($lista), InfraLog::$INFORMACAO);
486 434 return $lista;
487 435 }
488 436  
... ... @@ -501,7 +449,6 @@ class MdEstatisticasColetarRN extends InfraRN
501 449 }
502 450 if ($query) {
503 451 $query = sprintf($query, $dataultimorecurso, $current_month);
504   - InfraDebug::getInstance()->gravar('Query: ' . $query, InfraLog::$INFORMACAO);
505 452 return BancoSEI::getInstance()->consultarSql($query);
506 453 }
507 454 }
... ...
rn/MdEstatisticasEnviarRN.php
... ... @@ -8,8 +8,12 @@ class MdEstatisticasEnviarRN extends InfraRN
8 8 parent::__construct();
9 9  
10 10 $objConfiguracaoSEI = ConfiguracaoSEI::getInstance();
11   - $this->url = $objConfiguracaoSEI->getValor('MdEstatisticas', 'url', false, 'http://estatisticas.planejamento.gov.br');
  11 + $url = $objConfiguracaoSEI->getValor('MdEstatisticas', 'url', false, 'http://estatisticas.planejamento.gov.br');
  12 + $this->url = $url . '/api/estatisticas';
  13 + $this->urllogin = $url . '/login';
12 14 $this->orgaoSigla = $objConfiguracaoSEI->getValor('MdEstatisticas', 'sigla', false, '');
  15 + $this->orgaoSenha = $objConfiguracaoSEI->getValor('MdEstatisticas', 'chave', false, '');
  16 + $this->header = array('Content-Type: application/json');
13 17 }
14 18  
15 19 protected function inicializarObjInfraIBanco() {
... ... @@ -32,69 +36,85 @@ class MdEstatisticasEnviarRN extends InfraRN
32 36  
33 37 public function enviarAcessos($acessos, $id) {
34 38 $url = $this->url . '/acessos';
35   - InfraDebug::getInstance()->gravar('URL: ' . $url, InfraLog::$INFORMACAO);
36 39 $obj = array(
37 40 id => $id,
38 41 acessosUsuarios => $acessos
39 42 );
40   - InfraDebug::getInstance()->gravar('URL: ' . json_encode($obj), InfraLog::$INFORMACAO);
41 43 return $this->doPost($url, $obj, false);
42 44 }
43 45  
44 46 public function enviarVelocidades($velocidades, $id) {
45 47 $url = $this->url . '/velocidades';
46   - InfraDebug::getInstance()->gravar('URL: ' . $url, InfraLog::$INFORMACAO);
47 48 $obj = array(
48 49 id => $id,
49 50 velocidades => $velocidades
50 51 );
51   - InfraDebug::getInstance()->gravar('URL: ' . json_encode($obj), InfraLog::$INFORMACAO);
52 52 return $this->doPost($url, $obj, false);
53 53 }
54 54  
55 55 public function enviarSistemasUsuarios($sistemasOperacionaisUsuarios, $id) {
56 56 $url = $this->url . '/sistemasoperacionais';
57   - InfraDebug::getInstance()->gravar('URL: ' . $url, InfraLog::$INFORMACAO);
58 57 $obj = array(
59 58 id => $id,
60 59 sistemasOperacionaisUsuarios => $sistemasOperacionaisUsuarios
61 60 );
62   - InfraDebug::getInstance()->gravar('URL: ' . json_encode($obj), InfraLog::$INFORMACAO);
63 61 return $this->doPost($url, $obj, false);
64 62 }
65 63  
66 64 public function enviarNavegadores($navegadores, $id) {
67 65 $url = $this->url . '/navegadores';
68   - InfraDebug::getInstance()->gravar('URL: ' . $url, InfraLog::$INFORMACAO);
69 66 $obj = array(
70 67 id => $id,
71 68 navegadores => $navegadores
72 69 );
73   - InfraDebug::getInstance()->gravar('URL: ' . json_encode($obj), InfraLog::$INFORMACAO);
74 70 return $this->doPost($url, $obj, false);
75 71 }
76 72  
77 73 public function enviarLogsErro($logs, $id) {
78 74 $url = $this->url . '/logserro';
79   - InfraDebug::getInstance()->gravar('URL: ' . $url, InfraLog::$INFORMACAO);
80 75 $obj = array(
81 76 id => $id,
82 77 logsErro => $logs
83 78 );
84   - InfraDebug::getInstance()->gravar('URL: ' . json_encode($obj), InfraLog::$INFORMACAO);
85 79 return $this->doPost($url, $obj, false);
86 80 }
87 81  
88 82 public function enviarRecursos($recursos, $id) {
89 83 $url = $this->url . '/recursos';
90   - InfraDebug::getInstance()->gravar('URL: ' . $url, InfraLog::$INFORMACAO);
91 84 $obj = array(
92 85 id => $id,
93 86 recursos => $recursos
94 87 );
95   - InfraDebug::getInstance()->gravar('URL: ' . json_encode($obj), InfraLog::$INFORMACAO);
96 88 return $this->doPost($url, $obj, false);
97 89 }
  90 +
  91 + public function autenticar() {
  92 + $json = array(
  93 + username => $this->orgaoSigla,
  94 + password => $this->orgaoSenha
  95 + );
  96 + $data = json_encode($json);
  97 + $ch = curl_init();
  98 + curl_setopt($ch, CURLOPT_URL, $this->urllogin);
  99 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  100 + curl_setopt($ch, CURLOPT_POST, true);
  101 + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
  102 + curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  103 + curl_setopt($ch, CURLOPT_HEADER, true);
  104 + $output = curl_exec($ch);
  105 + $info = curl_getinfo($ch);
  106 + curl_close($ch);
  107 + if ($info['http_code'] == 200) {
  108 + $output = explode("\r\n", $output);
  109 + foreach ($output as $value) {
  110 + if (strpos($value, 'Authorization') !== false) {
  111 + $this->header[] = $value;
  112 + return true;
  113 + }
  114 + }
  115 + }
  116 + return false;
  117 + }
98 118  
99 119 private function doPost($url, $json, $isjson = true) {
100 120 $data = json_encode($json);
... ... @@ -102,9 +122,7 @@ class MdEstatisticasEnviarRN extends InfraRN
102 122 curl_setopt($ch, CURLOPT_URL, $url);
103 123 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
104 124 curl_setopt($ch, CURLOPT_POST, true);
105   - curl_setopt($ch, CURLOPT_HTTPHEADER, array(
106   - 'Content-Type: application/json'
107   - ));
  125 + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
108 126 curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
109 127 $output = curl_exec($ch);
110 128 curl_close($ch);
... ... @@ -118,6 +136,7 @@ class MdEstatisticasEnviarRN extends InfraRN
118 136 private function doGet($url, $isjson = true) {
119 137 $ch = curl_init();
120 138 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  139 + curl_setopt($ch, CURLOPT_HTTPHEADER, $this->header);
121 140 curl_setopt($ch, CURLOPT_URL, $url);
122 141 $output = curl_exec($ch);
123 142 curl_close($ch);
... ...