0, "numAlarmPlaca" => 0, "numCanalDahdi" => 0, "numAlarmCanal" => 0, "numDgvGsm" => 0, "numAlarmGsm" => 0, "numDgvE1" => 0, "numAlarmE1" => 0, "numCanalDGV" => 0, "numAlarmDGV" => 0); /* * Ancoras para canais com alarme. */ $canaisDgvA = ''; $canaisDahdiA = ''; /* * Lista informações sobre placas dahdi instaladas no servidor. */ $resultados = DahdiShowStatus($socket); if (count($resultados) > 1) { $ret = DisplayShowStatus($resultados) . "
"; } /* * Monitora os canais dahdi */ $resultados = DahdiShowChannels($socket); if (count($resultados) > 1) { $ret .= DisplayShowChannels($resultados) . "
"; } /* * Reseta as estatisticas dgv */ if (isset($_POST['btEstatDgv'])) { DgvResetStatistics($socket); } $resultados = DgvShowChannels($socket); if (count($resultados) > 1) { $ret .= DisplayDgvShowChannels($resultados) . "
"; } $resultados = DgvShowAlarmsAll($socket); if (count($resultados) > 1) { $ret .= DisplayDgvShowAlarms($socket, $resultados); } $numPlacaDahdi = $totaliza["numPlacaDahdi"]; $numAlarmPlaca = $totaliza["numAlarmPlaca"]; $numCanalDahdi = $totaliza["numCanalDahdi"]; $numAlarmCanal = $totaliza["numAlarmCanal"]; $numDgvGsm = $totaliza["numDgvGsm"]; $numAlarmGsm = $totaliza["numAlarmGsm"]; $numDgvE1 = $totaliza["numDgvE1"]; $numAlarmE1 = $totaliza["numAlarmE1"]; $numCanalDGV = $totaliza["numCanalDGV"]; $numAlarmDGV = $totaliza["numAlarmDGV"]; $ultAtu = date("H:i:s"); $ret .= str_repeat("
", 110); if (IsAjax()) { $ret = "$ret@$numPlacaDahdi@$numAlarmPlaca@$numCanalDahdi@$numAlarmCanal@$numDgvGsm@$numAlarmGsm@$numDgvE1@$numAlarmE1@$numCanalDGV@$numAlarmDGV@$ultAtu"; echo $ret; exit; } else { $jsStartup[] = "var idSet = window.setInterval(\"MoitorE1()\",10000);"; $jsStartup[] = "SetAncorAlarmsDahdi('$canaisDahdiA');"; $jsStartup[] = "SetAncorAlarmsDgv('$canaisDgvA');"; $smarty->assign('resultados', $ret); $smarty->assign('numPlacaDahdi', $numPlacaDahdi); $smarty->assign('numCanalDahdi', $numCanalDahdi); $smarty->assign('numAlarmPlaca', $numAlarmPlaca); $smarty->assign('numAlarmCanal', $numAlarmCanal); $smarty->assign('numCanalDGV', $numCanalDGV); $smarty->assign('numAlarmDGV', $numAlarmDGV); $smarty->assign('numDgvGsm', $numDgvGsm); $smarty->assign('numAlarmGsm', $numAlarmGsm); $smarty->assign('numDgvE1', $numDgvE1); $smarty->assign('numAlarmE1', $numAlarmE1); $smarty->assign('ultAtu', $ultAtu); $smarty->display("monitorE1.tpl"); } /* * functions */ function DisplayShowStatus($tabela) { $start = 0; $result = "\n"; $titulo = "Placas Dadhi Instaladas"; $colspan = count($tabela[0]) + 1; $numPlaca = 0; $numAlars = 0; $result .= "\n"; foreach ($tabela as $linha) { $result .= ""; foreach ($linha as $coluna) { $result .= !$start ? "" : ""; } $status = trim(strtoupper($linha[1])); if (($status != 'OK') && ($start)) { $statusDisp = ""; $numAlars++; } else { $statusDisp = ""; } $result .= !$start ? "" : ""; if ($start) $numPlaca++; $result .= "\n"; $start++; } $result .= "
$titulo
$coluna$colunaStatus$statusDisp
\n"; $GLOBALS["totaliza"]["numPlacaDahdi"] = $numPlaca; $GLOBALS["totaliza"]["numAlarmPlaca"] = $numAlars; return $result; } function DisplayShowChannels($tabela) { $start = 0; $result = "\n"; $titulo = "Canais Dadhi"; $colspan = count($tabela[0]) + 1; $result .= "\n"; $numCanal = 0; $numAlars = 0; $alarmasA = ''; foreach ($tabela as $linha) { $idLinha = $linha[0]; $result .= ""; foreach ($linha as $coluna) { $result .= !$start ? "" : ""; } $status = trim(strtoupper($linha[7])); if (($status == 'BLOCK') && ($start)) { $statusDisp = ""; $alarmasA .= !$alarmasA ? $idLinha : ";$idLinha"; $numAlars++; } else { $statusDisp = ""; } $result .= !$start ? "" : ""; $result .= ""; if ($start) $numCanal++; $start++; } $result .= "
$titulo
$coluna$colunaStatus$statusDisp
"; $GLOBALS["totaliza"]["numCanalDahdi"] = $numCanal; $GLOBALS["totaliza"]["numAlarmCanal"] = $numAlars; $GLOBALS["canaisDahdiA"] = $alarmasA; return $result; } function DisplayDgvShowChannels($tabela) { $start = 0; $result = "\n"; $titulo = "Canais Digivoice"; $colspan = count($tabela[0]) + 1; $result .= "\n"; $numCanalDGV = 0; $numAlarmDGV = 0; $canaisDgvA = ''; foreach ($tabela as $linha) { $result .= ""; foreach ($linha as $coluna) { $result .= !$start ? "" : ""; } $status = trim(strtoupper($linha[5])); if (($status) && ($start)) { $idCanal = $linha[0]; $statusDisp = ""; $numAlarmDGV++; $canaisDgvA .= !$canaisDgvA ? $idCanal : ";$idCanal"; } else { $statusDisp = ""; } if ($start) { $numCanalDGV++; } $result .= !$start ? "" : ""; $result .= ""; $start++; } $result .= "
$titulo
$coluna$colunaStatus$statusDisp
"; $GLOBALS["totaliza"]["numCanalDGV"] = $numCanalDGV; $GLOBALS["totaliza"]["numAlarmDGV"] = $numAlarmDGV; $GLOBALS["canaisDgvA"] = $canaisDgvA; return $result; } function DisplayDgvShowAlarms($socket, $resultados) { $resultAlarm = array(); $alarms = array(); $ret = ''; foreach ($resultados as $result) { if (array_search($result[0], $alarms) === false) { $alarms[] = $result[0]; $resultAlarm = DgvShowAlarms($socket, $result[0], $result[1]); $ret .= (($result[1] == "GSM") ? DisplayDgvShowAlarmGSM($resultAlarm) : DisplayDgvShowAlarmE1($resultAlarm)) . "
\n"; } } return $ret; } function DisplayDgvShowAlarmGSM($tabela) { $start = 0; $result = "
\n"; $result .= "\n"; $titulo = "Alarms Digivoice(GSM)"; $colspan = count($tabela[0]) + 1; $result .= "\n"; $reset = 0; $dispReset = ''; $numAlarmGsm = 0; $ultres = 0; foreach ($tabela as $linha) { $linha = trim($linha); if ((stripos($linha, 'Reset') !== false)) { $reset++; } $aln = ""; if ($reset == 1) { $dispReset = $linha; $reset++; } else if ($reset == 2) { $linha = $dispReset . ' ' . $linha; $reset = 0; $aln = " align=\"center\""; $ultres = 1; } if (!$reset) { if ($start && (stripos($linha, "Nenhum") !== false)) { $color = "#FF0000"; $numAlarmGsm++; } else { $color = $ultres ? "#000000" : "#00FF00"; } $result .= ""; $result .= !$start ? "" : "
$linha
"; $result .= "
"; } $start++; } $result .= "
$titulo
$linha
"; $GLOBALS["totaliza"]["numAlarmGsm"] = $numAlarmGsm; return $result; } function DisplayDgvShowAlarmE1($tabela) { $start = 0; $result = ""; $result .= "
\n"; $result .= "\n"; $titulo = "Alarms Digivoice(E1)"; $colspan = count($tabela[0]) + 2; $result .= "\n"; $numAlarmE1 = 0; foreach ($tabela as $linha) { if ($start > 0) { $result .= ""; if ((stripos($linha[0], 'Reset') !== false)) { break; } foreach ($linha as $coluna) { //if(!$coluna) $coluna = '-'; $result .= $start == 1 ? "" : ""; $irslip = strpos($coluna, 'ALARM_RSLIP') !== false; $str = $irslip ? "000" : "Off"; $status = (stripos($coluna, $str) !== false); //$irslip ? (stripos($coluna, $str) === false) : (stripos($coluna, $str) !== false); if (!$status) { $statusDisp = $coluna ? "" : '-'; if ($start > 1) $numAlarmE1++; } else { $statusDisp = ""; } $result .= $start == 1 ? "" : ""; } $result .= ""; } $start++; } $GLOBALS["totaliza"]["numAlarmE1"] = $numAlarmE1; $reset = 0; $coluna1 = ''; $legend = false; $colspan++; foreach ($tabela as $linha) { if ((stripos($linha[0], 'Reset') !== false)) { $reset++; } else if (($reset) && (stripos($linha[0], 'Alarm') !== false)) { $result .= "\n"; $reset = false; $legend = true; } else if ($reset) { $coluna1 = "Ultimo Reset: " . $linha[0]; $result .= ""; } else if ($legend) { $result .= ""; } } $result .= ""; $result .= "
$titulo
$coluna" . ($coluna ? $coluna : '-' ) . "Status$statusDisp
Legenda
$coluna1
$linha[0]$linha[1]
\n"; return $result; } function DahdiShowStatus($socket) { /* * Executa comandos no servidor. */ $comandos = array(); $comandos[] = "action: command"; $comandos[] = "command: dahdi show status"; ExecutaMonitorE1($socket, $comandos); $fimComando = "--END COMMAND--"; $resultado = array(); $start = 0; $Desc = ""; $Alm = ""; $IR = ""; $bpv = ""; $crc = ""; while (!feof($socket)) { $buffer = fgets($socket); /* * Encerra o loop quando identifica o fim dos commandos */ if (strpos($buffer, $fimComando) !== false) { break; } /* * Inicia a coleta das informações */ if ((stripos($buffer, 'Description') !== false) && (stripos($buffer, 'Alarms') !== false)) { $start++; } $extDados = trim($buffer); if ($start && $extDados) { $Desc = trim(substr($buffer, 0, 40)); $Alm = trim(substr($buffer, 41, 11)); $IR = trim(substr($buffer, 52, 11)); $bpv = trim(substr($buffer, 63, 11)); $crc = trim(substr($buffer, 74, 4)); $resultado[] = array($Desc, $Alm, $IR, $bpv, $crc); } /* * Garante que o socket não vai procurar para sempre */ if ($buffer === false) { break; } } return $resultado; } function DahdiShowChannels($socket) { /* * Executa comandos no servidor. */ $comandos = array(); $comandos[] = "action: command"; $comandos[] = "command: mfcr2 show channels"; ExecutaMonitorE1($socket, $comandos); $fimComando = "--END COMMAND--"; $resultado = array(); $start = 0; //Chan Variant Max ANI Max DNIS ANI First Immediate Accept Tx CAS Rx CAS $Chan = ''; $Variant = ''; $Max_ANI = ''; $Max_DNIS = ''; $ANI_First = ''; $Immediate = ''; $Tx_Cas = ''; $Rx_CAS = ''; while (!feof($socket)) { $buffer = fgets($socket); /* * Encerra o loop quando identifica o fim dos commandos */ if (strpos($buffer, $fimComando) !== false) { break; } /* * Inicia a coleta das informações */ if ((stripos($buffer, 'Chan') !== false) && (stripos($buffer, 'Variant') !== false)) { $start++; } $extDados = trim($buffer); if (($start && $extDados) || (($start > 1) && (stripos($buffer, 'Chan') === false))) { $Chan = trim(substr($buffer, 0, 5)); $Variant = trim(substr($buffer, 5, 8)); $Max_ANI = trim(substr($buffer, 13, 8)); $Max_DNIS = trim(substr($buffer, 21, 9)); $ANI_First = trim(substr($buffer, 30, 10)); $Immediate = trim(substr($buffer, 40, 17)); $Tx_Cas = trim(substr($buffer, 57, 9)); $Rx_CAS = trim(substr($buffer, 66, 9)); $resultado[] = array($Chan, $Variant, $Max_ANI, $Max_DNIS, $ANI_First, $Immediate, $Tx_Cas, $Rx_CAS); } /* * Garante que o socket não vai procurar para sempre */ if ($buffer === false) { break; } } return $resultado; } function DgvResetStatistics($socket) { /* * Executa comandos no servidor. */ $comandos = array(); $comandos[] = "action: command"; $comandos[] = "command: dgv alarms reset all all"; ExecutaMonitorE1($socket, $comandos); $fimComando = "--END COMMAND--"; while (!feof($socket)) { $buffer = fgets($socket); /* * Encerra o loop quando identifica o fim dos commandos */ if (strpos($buffer, $fimComando) !== false) { $resultado = true; break; } /* * Garante que o socket não vai procurar para sempre */ if ($buffer === false) { $resultado = false; break; } } return $resultado; } function DgvShowChannels($socket) { /* * Executa comandos no servidor. */ $comandos = array(); $comandos[] = "action: command"; $comandos[] = "command: dgv show channels"; ExecutaMonitorE1($socket, $comandos); $fimComando = "--END COMMAND--"; $resultado = array(); $Chan = ''; $Grp = ''; $Context = ''; $PortId = ''; $Rsrvd = ''; $Alrmd = ''; $Lckd = ''; $Extension = ''; $CardType = ''; $Intrf = ''; while (!feof($socket)) { $buffer = fgets($socket); /* * Encerra o loop quando identifica o fim dos commandos */ if (strpos($buffer, $fimComando) !== false) { break; } /* * Inicia a coleta das informações */ if ((stripos($buffer, 'Chan') !== false) && (stripos($buffer, 'Rsrvd') !== false)) { $start++; } $extDados = trim($buffer); if ($start && $extDados) { $Chan = trim(substr($buffer, 0, 5)); $Grp = trim(substr($buffer, 6, 3)); $Context = trim(substr($buffer, 10, 15)); $PortId = trim(substr($buffer, 27, 12)); $Rsrvd = trim(substr($buffer, 40, 5)); $Alrmd = trim(substr($buffer, 46, 5)); $Lckd = trim(substr($buffer, 52, 4)); $Extension = trim(substr($buffer, 57, 11)); $CardType = trim(substr($buffer, 69, 12)); $Intrf = trim(substr($buffer, 82, 6)); if (($start == 1) || (($start > 1) && (stripos($buffer, 'Chan') === false))) { $resultado[] = array($Chan, $Grp, $Context, $PortId, $Rsrvd, $Alrmd, $Lckd, $Extension, $CardType, $Intrf); } $start++; } /* * Garante que o socket não vai procurar para sempre */ if ($buffer === false) { break; } } return $resultado; } function DgvShowAlarmsAll($socket) { /* * Executa comandos no servidor. */ $comandos = array(); $comandos[] = "action: command"; $comandos[] = "command: dgv show alarms all"; $fimComando = "--END COMMAND--"; ExecutaMonitorE1($socket, $comandos); $resultado = []; $numCanalGsm = 0; $numCanalE1 = 0; while (!feof($socket)) { $buffer = fgets($socket); /* * Encerra o loop quando identifica o fim dos commandos */ if (strpos($buffer, $fimComando) !== false) { break; } /* * Inicia a coleta das informações */ if (stripos($buffer, 'CARD:') !== false) { $start++; } $ini = 0; $tam = 0; $extDados = trim($buffer); if ($start && $extDados) { $ini = strpos($buffer, '<') + 1; $tam = strpos($buffer, ',') - $ini; $card = substr($buffer, $ini, $tam); $card = explode(":", $card); $tipo = (stripos($buffer, 'GSM') !== false) ? "GSM" : "E1"; $resultado[] = array($card[1], $tipo); } /* * Garante que o socket não vai procurar para sempre */ if ($buffer === false) { break; } } $numcards = array(); foreach ($resultado as $rest) { if (!array_search($rest[0], $numcards)) { $numcards[] = $rest[0]; if ($rest[1] == "GSM") { $numCanalGsm++; } else { $numCanalE1++; }; } } $GLOBALS["totaliza"]["numDgvGsm"] = $numCanalGsm; $GLOBALS["totaliza"]["numDgvE1"] = $numCanalE1; return $resultado; } function DgvShowAlarms($socket, $alarm, $tipo) { /* * Executa comandos no servidor. */ $comandos = array(); $comandos[] = "action: command"; $comandos[] = "command: dgv show alarms $alarm"; ExecutaMonitorE1($socket, $comandos); $fimComando = "--END COMMAND--"; $resultado = ""; $start = 0; $span1 = ''; $span2 = ''; $startSpan = false; $startLegend = 0; while (!feof($socket)) { $buffer = fgets($socket); /* * Encerra o loop quando identifica o fim dos commandos */ if (strpos($buffer, $fimComando) !== false) { break; } /* * Inicia a coleta das informações */ if (stripos($buffer, 'DigiVoice') !== false) { $start++; } if ($tipo == "GSM") { if ((stripos($buffer, '+') !== false) && (stripos($buffer, '-') !== false)) { $buffer = str_replace("+", "", $buffer); $buffer = str_replace("-", "", $buffer); } $linha = ''; $extDados = trim($buffer); if ($start && $extDados) { $linha = trim($buffer); if (substr($linha, 0, 1) == "|") { $tam = strlen($linha) - 2; $linha = substr($linha, 1, $tam); } $extDados = trim(str_replace("|", "", $buffer)); if ($extDados) $resultado[] = $linha; } } else { $linha = ''; $extDados = trim(str_replace("|", "", $buffer)); if ($start && $extDados) { $span1 = ''; $span2 = ''; /* Linha de Cabecalio */ if (stripos($buffer, 'DigiVoice') !== false) { $span1 = trim($buffer); $span2 = 'cabecalio'; } else if (stripos($buffer, 'Span: 1') !== false) { $span1 = trim(substr($buffer, 8, 9)); $span2 = trim(substr($buffer, 39, 9)); $startSpan = true; } else if (($startSpan) && (stripos($buffer, '+') !== false)) { $startSpan = false; $startLegend++; } else if ($startSpan) { $span1 = trim(substr($buffer, 4, 29)); $span2 = trim(substr($buffer, 35, 29)); } else if ($startLegend) { if ($startLegend == 1) { $span1 = trim($buffer); $span2 = "Legenda"; } else { $span1 = trim(substr($buffer, 11, 14)); $span2 = trim(substr($buffer, 28)); } $startLegend++; } if ($span1) { $resultado[] = array($span1, $span2); } } } /* DigiVoice - Alarmes E1 - Placa E1: 2 +---[ Span: 1 ]----------------+---[ Span: 2 ]----------------+ | | | | ALARM_LOSS Off 000 | ALARM_LOSS Off 000 | | ALARM_AISS Off 000 | ALARM_AISS Off 000 | | ALARM_AIS16S Off 000 | ALARM_AIS16S Off 000 | | ALARM_SYNC Off 000 | ALARM_SYNC Off 000 | | ALARM_MFSYNC Off 000 | ALARM_MFSYNC Off 000 | | ALARM_RAIS Off 000 | ALARM_RAIS Off 000 | | ALARM_CRC4SYNC Off 000 | ALARM_CRC4SYNC Off 000 | | ALARM_RSLIP 000 | ALARM_RSLIP 000 | | | | | Ultimo Reset: | Ultimo Reset: | | 2012-11-09 00:00:01 | 2012-11-09 00:00:01 | | | | +------------------------------+------------------------------+ Descricoes dos Alarmes: | |_ ALARM_LOSS - Indicacao de Perda de Sinal. |_ ALARM_AISS - Status de Indicacao de Alarme. |_ ALARM_AIS16S - Indicacao de Alarme no Canal 16. |_ ALARM_SYNC - Perda de Sincronismo de Quadro. |_ ALARM_MFSYNC - Perda de Sincronismo de Multiquadro. |_ ALARM_RAIS - Indicacao de Alarme Remoto. |_ ALARM_CRC4SYNC - Erro de CRC-4. |_ ALARM_RSLIP - Escorregamento. */ /* * Garante que o socket não vai procurar para sempre */ if ($buffer === false) { break; } } return $resultado; } function GetResult($socket, $fimComando) { while (!feof($socket)) { $buffer = fgets($socket); //list($param, $value) = explode(':', $buffer); /* * Garante que o socket não vai procurar para sempre */ if (strpos($buffer, $fimComando) !== false) { break; } if ($buffer === false) { break; } } } function ExecutaMonitorE1($socket, $comandos) { $actionid = rand(000000000, 9999999999); foreach ($comandos as $comando) { $comando = trim($comando); fwrite($socket, "$comando\r\n"); } /* * Finaliza o comando */ fwrite($socket, "ActionID: " . $actionid . "\r\n\r\n"); return $actionid; } function GetConnection($conStr) { $ret = pg_connect($conStr); if (!$ret) { logTrb('GetConnection', "Conexao com banco de dados", "Erro ao executar conexao no banco", 'ERRO', $conStr); } return $ret; } ?>