コード例 #1
0
 /**
  * Agrupar las paradas programadas para aquellos hosts que tengan mas de X servicios programados.
  *
  * @return array Con los eventos programados
  */
 public function getScheduledDowntimesGroupped()
 {
     $groupCount = 5;
     $hosts = array();
     $out = array();
     $downtimes = Util::arraySortByProperty($this->getScheduledDowntimes(), 'start_time', false);
     // Recorrer el array de eventos y contabilizar el número de veces que aparece cada host
     foreach ($downtimes as $downtime) {
         /** @var $downtime DowntimeInterface */
         // Incrementar el contador y silenciar avisos
         @$hosts[$downtime->getHostHash()]['count']++;
     }
     // Recorrer el array de eventos y agrupar aquellos eventos de un host que se repitan más de $groupCount.
     // Se utiliza un nuevo array con la clave el nombre del host
     foreach ($downtimes as $downtime) {
         /** @var $downtime DowntimeInterface */
         $hash = $downtime->getHostHash();
         $hostCounter = $hosts[$hash]['count'];
         if ($hostCounter > $groupCount) {
             $downtime->setServiceDisplayName(sprintf(Language::t('Programado para %d servicios'), $hostCounter));
             $out[$hash] = $downtime;
         } elseif (!isset($out[$hash])) {
             $out[$hash] = $downtime;
         }
     }
     return $out;
 }
コード例 #2
0
 /**
  * Devuelve el nombre del estado
  *
  * @param EventInterface $item
  * @param null $state
  * @return bool|string
  */
 public static function getStateName(EventInterface $item, $state = null)
 {
     $state = is_null($state) ? $item->getState() : intval($state);
     switch ($item->getType()) {
         case Event::TYPE_HOST:
             return Language::t(EventStateHost::getStateName($state));
         case Event::TYPE_SERVICE:
             return Language::t(EventStateService::getStateName($state));
         case Event::TYPE_TRIGGER:
             return Language::t(EventStateTrigger::getStateName($state));
     }
     return false;
 }
コード例 #3
0
ファイル: SMD.class.php プロジェクト: nuxsmin/sysMonDash
 /**
  * Obtener los datos remotos desde la API de sysMonDash con CURL
  *
  * Devuelve los datos deserializados
  *
  * @param $url
  * @return mixed
  * @throws \Exception
  */
 protected function getRemoteData($url)
 {
     $data = json_decode(Util::getDataFromUrl($url));
     if (is_object($data) && isset($data->status) && $data->status === 1) {
         $msg = sprintf('%s (%s): %s', $this->getBackend()->getAlias(), 'SMD', $data->description);
         error_log($msg);
         throw new BackendException($msg);
     } elseif (!is_object($data)) {
         $msg = sprintf('%s (%s): %s', $this->getBackend()->getAlias(), 'SMD', Language::t('Error al acceder a la API'));
         error_log($msg);
         throw new BackendException($msg);
     }
     return unserialize(base64_decode($data->data));
 }
コード例 #4
0
ファイル: Response.class.php プロジェクト: nuxsmin/sysMonDash
 /**
  * Devuelve una respuesta en formato JSON con el estado y el mensaje.
  *
  * @param string|array $data   mensaje a devolver
  * @param int          $status devuelve el estado
  * @param string       $action con la accion a realizar
  * @return bool
  */
 public static function printJSON($data, $status = 1, $action = '')
 {
     if (!is_string($data) && !is_array($data)) {
         return false;
     }
     if (!is_array($data)) {
         $json = array('status' => $status, 'description' => Language::t(Json::safeJsonString($data)), 'action' => $action);
     } else {
         $data['status'] = $status;
         $data['action'] = $action;
         $json = Json::safeJson($data);
     }
     header('Content-type: application/json');
     exit(json_encode($json));
 }
コード例 #5
0
ファイル: saveConfig.php プロジェクト: nuxsmin/sysMonDash
$showColService = Request::analyze('col_service', false, false, true);
$showColInfo = Request::analyze('col_info', false, false, true);
$showColBackend = Request::analyze('col_backend', false, false, true);
$showScheduled = Request::analyze('hide_scheduled', false, false, true);
$regexHostShow = Request::analyze('regex_host_show');
$regexServicesNoShow = Request::analyze('regex_services_no_show');
$criticalItems = Request::analyze('critical_items');
$specialClientURL = Request::analyze('special_client_url');
$specialRemoteServerURL = Request::analyze('special_remote_server_url');
$specialMonitorServerUrl = Request::analyze('special_monitor_server_url');
$specialAPIToken = Request::analyze('special_api_token');
$specialConfigPass = Request::analyze('special_config_pass');
try {
    $Backends = Html::processFormBackends(Request::analyze('backend'));
} catch (Exception $e) {
    Response::printJSON(\SMD\Core\Language::t($e->getMessage()));
}
$ConfigData = new ConfigData();
$ConfigData->setLanguage($siteLanguage);
$ConfigData->setPageTitle($siteTitle);
$ConfigData->setRefreshValue($eventRefresh);
$ConfigData->setNewItemTime($eventNewItemTime);
$ConfigData->setMaxDisplayItems($eventMaxItems);
$ConfigData->setNewItemAudioEnabled($eventNewItemAudio);
$ConfigData->setColLastcheck($showColLastCheck);
$ConfigData->setColHost($showColHost);
$ConfigData->setColService($showColService);
$ConfigData->setColStatusInfo($showColInfo);
$ConfigData->setColBackend($showColBackend);
$ConfigData->setShowScheduled($showScheduled);
$ConfigData->setRegexHostShow($regexHostShow);
コード例 #6
0
ファイル: Util.class.php プロジェクト: nuxsmin/sysMonDash
 /**
  * Info de la aplicación
  *
  * @param $index
  * @return array
  */
 public static function getAppInfo($index)
 {
     $appInfo = array('appupdates' => 'https://api.github.com/repos/nuxsmin/sysMonDash/releases/latest', 'appVersion' => 'v' . implode('.', self::getVersion()), 'appCode' => '<a href="https://github.com/nuxsmin/sysMonDash" target="_blank" title="sysMonDash - GitHub">sysMonDash</a>', 'appWiki' => '<a href="https://github.com/nuxsmin/sysMonDash/wiki" target="_blank" title="sysMonDash Wiki - GitHub">sysMonDash Wiki</a>', 'appAuthor' => '<a href="http://cygnux.org" target="_blank" title="' . Language::t('Un proyecto de cygnux.org') . '">cygnux.org</a>');
     return isset($appInfo[$index]) ? $appInfo[$index] : '';
 }
コード例 #7
0
 /**
  * Función para mostrar los elementos del Dashboard
  *
  * @param EventInterface $item El elemento que contiene los datos.
  * @param bool $newItem Si es un nuevo elemento
  * @param bool $newItemUp Si es un nuevo elemento recuperado
  * @return EventInterface
  */
 private function getHtmlItems(EventInterface $item, $newItem = false, $newItemUp = false)
 {
     $lastStateTime = date("m-d-Y H:i:s", $item->getLastHardStateChange());
     $lastStateDuration = Util::timeElapsed(time() - $item->getLastHardStateChange());
     $lastCheckDuration = Util::timeElapsed(time() - $item->getLastCheck());
     $serviceDesc = $item->getDisplayName() ? $item->getDisplayName() : $item->getCheckCommand();
     $hostname = $item->getHostDisplayName() ? $item->getHostDisplayName() : $item->getDisplayName();
     $hostAlias = $item->getHostAlias() ? $item->getHostAlias() : ($item->getAlias() ? $item->getAlias() : $hostname);
     $scheduled = $item->getScheduledDowntimeDepth() >= 1 || $item->getHostScheduledDowntimeDepth() >= 1;
     $tdClass = '';
     $trClass = EventState::getStateClass($item);
     $statusName = EventState::getStateName($item);
     $link = null;
     if ($item->getHostLastTimeUnreachable() > $item->getHostLastTimeUp() && !$newItemUp || $item->getLastTimeUnreachable() > $item->getLastCheck() && $item->getStateType() === 1) {
         $trClass = EventState::getStateClass($item, EventStateInterface::STATE_UNREACHABLE);
         $statusName = EventState::getStateName($item, EventStateInterface::STATE_UNREACHABLE);
     }
     if ($scheduled) {
         $trClass = EventState::getStateClass($item, EventStateInterface::STATE_SCHEDULED);
         $statusName = EventState::getStateName($item, EventStateInterface::STATE_SCHEDULED);
     }
     if ($newItem && !$item->isAcknowledged() && !$scheduled && !$newItemUp) {
         $tdClass = "new";
     } elseif ($newItemUp && time() - $item->getLastHardStateChange() <= Config::getConfig()->getNewItemTime() / 2) {
         $trClass = EventState::getStateClass($item, EventStateInterface::STATE_RECOVER);
         $statusName = EventState::getStateName($item, EventStateInterface::STATE_RECOVER);
     } elseif ($item->isFlapping()) {
         $trClass = EventState::getStateClass($item, EventStateInterface::STATE_FLAPPING);
         $statusName = EventState::getStateName($item, EventStateInterface::STATE_FLAPPING);
     } elseif ($item->isAcknowledged()) {
         $trClass = EventState::getStateClass($item, EventStateInterface::STATE_ACKNOWLEDGED);
         $statusName = EventState::getStateName($item, EventStateInterface::STATE_ACKNOWLEDGED);
     }
     $line = '<tr class="item-data ' . $trClass . '" title="' . sprintf(Language::t('Estado %s desde %s'), $statusName, $lastStateTime) . '">' . PHP_EOL;
     $line .= '<td class="center">' . $statusName . '</td>';
     if (Config::getConfig()->isColLastcheck()) {
         $line .= '<td title="' . sprintf('%s : %s', Language::t('Último check'), $lastCheckDuration) . '" class="center ' . $tdClass . '">' . $lastStateDuration . '</td>' . PHP_EOL;
     }
     if (Config::getConfig()->isColHost()) {
         if (!is_null($link)) {
             $line .= '<td><a href="' . $link . '" target="blank" title="' . $hostname . '">' . $hostAlias . '</a></td>' . PHP_EOL;
         } else {
             $line .= '<td>' . $hostAlias . '</td>' . PHP_EOL;
         }
     }
     if (Config::getConfig()->isColStatusInfo()) {
         if ($item->getFilterStatus() === '' || $newItem) {
             $line .= '<td class="statusinfo">' . $item->getPluginOutput() . '</td>' . PHP_EOL;
         } else {
             $line .= '<td class="statusinfo">' . $item->getPluginOutput() . '<br>Filter: ' . $item->getFilterStatus() . '</td>' . PHP_EOL;
         }
     }
     if (Config::getConfig()->isColService()) {
         $line .= '<td class="center">' . $serviceDesc . '</td>' . PHP_EOL;
     }
     if (Config::getConfig()->isColBackend()) {
         $line .= '<td class="center">' . $item->getBackendAlias() . '</td>' . PHP_EOL;
     }
     $line .= '</tr>' . PHP_EOL;
     return $line;
 }
コード例 #8
0
ファイル: getData.php プロジェクト: nuxsmin/sysMonDash
}
?>

<?php 
if (count($SMD->getErrors()) > 0) {
    ?>
    <div class="title"><?php 
    echo Language::t('Errores');
    ?>
</div>
    <?php 
    foreach ($SMD->getErrors() as $error) {
        ?>
        <div id="nomessages" class="full error">
            <?php 
        echo Language::t($error);
        ?>
        </div>
    <?php 
    }
}
?>

<?php 
ob_end_flush();
?>

<?php 
if (Util::checkRefreshSession()) {
    ?>
    <script>
コード例 #9
0
ファイル: config.php プロジェクト: nuxsmin/sysMonDash
        config.setLang('<?php 
echo Language::t('Seguro?');
?>
');
        config.setLang('<?php 
echo Language::t('Conexión correcta');
?>
');
        config.setLang('<?php 
echo Language::t('Respuesta:');
?>
');
        config.setLang('<?php 
echo Language::t('Error de conexión');
?>
');
        config.setLang('<?php 
echo Language::t('URL no indicada');
?>
');
        config.setLang('<?php 
echo Language::t('No olvide guardar la configuración');
?>
');
        smd.setConfig(config);
        smd.setConfigHooks();
    }());
</script>
</body>
</html>
コード例 #10
0
ファイル: Zabbix.class.php プロジェクト: nuxsmin/sysMonDash
 /**
  * Obtener los hosts de un mantenimiento
  *
  * @param $maintenanceId
  * @return string
  */
 private function getHostsForMaintenance($maintenanceId)
 {
     $hosts = array();
     foreach ($this->hostsMaintenance as $host) {
         if ((int) $host['maintenanceid'] === (int) $maintenanceId) {
             $hosts[] = $host['host'];
         }
     }
     return count($hosts) > 0 ? $hosts : Language::t('N/D');
 }
コード例 #11
0
ファイル: index.php プロジェクト: nuxsmin/sysMonDash
echo Config::getConfig()->getRemoteServer();
?>
');
        config.setAjaxFile('<?php 
echo $ajaxFile;
?>
');
        config.setScroll(<?php 
echo $scroll ? 'true' : 'false';
?>
);
        config.setTimeout(<?php 
echo $timeout;
?>
);
        config.setLang('<?php 
echo Language::t('Error al obtener los eventos de monitorización');
?>
');
        config.setAudioEnabled(<?php 
echo Config::getConfig()->isNewItemAudioEnabled() ? 'true' : 'false';
?>
);

        smd.setConfig(config);
        smd.startSMD();
        smd.getUpdates();
    }());
</script>
</body>
</html>
コード例 #12
0
ファイル: getUpdates.php プロジェクト: nuxsmin/sysMonDash
 * (at your option) any later version.
 *
 * sysMonDash is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with sysMonDash.  If not, see <http://www.gnu.org/licenses/>.
 */
use SMD\Core\Init;
use SMD\Core\Language;
use SMD\Util\Util;
define('APP_ROOT', '..');
require APP_ROOT . DIRECTORY_SEPARATOR . 'inc' . DIRECTORY_SEPARATOR . 'Base.php';
Init::start();
$updates = Util::checkUpdates();
if (is_array($updates)) {
    ?>
    <a href="<?php 
    echo $updates['url'];
    ?>
" target="_blank"
       title="<?php 
    printf(Language::t('Nueva Versión %s'), $updates['version']);
    ?>
">
        <i class="fa fa-cloud-download"></i>
    </a>
<?php 
}
コード例 #13
0
ファイル: Init.class.php プロジェクト: nuxsmin/sysMonDash
 /**
  * @param \Exception $e
  * @return string
  */
 public static function showError(\Exception $e)
 {
     error_log(Language::t($e->getMessage()));
     return '<div id="result" class="error">' . Language::t($e->getMessage()) . '</div>';
 }