示例#1
0
 /**
  * Get snmp version for a specific host
  *
  * @method get
  * @route /host/[i:id]/snmp-version
  */
 public function snmpVersionForHostAction()
 {
     $di = Di::getDefault();
     $router = $di->get('router');
     $requestParam = $this->getParams('named');
     $snmpVersionParam = Host::getParameters($requestParam['id'], 'host_snmp_version');
     $snmpVersion = array();
     if (isset($snmpVersionParam['host_snmp_version'])) {
         $snmpVersion = array("id" => $snmpVersionParam['host_snmp_version'], "text" => $snmpVersionParam['host_snmp_version']);
     }
     $router->response()->json($snmpVersion);
 }
示例#2
0
 public function testGetParametersBadColumns()
 {
     $this->setExpectedException('PDOException', '', '42S22');
     Host::getParameters(1, 'test_error');
     Connector::getParameters(1, array('name', 'test_error'));
 }
示例#3
0
 /**
  * Get the value from template
  *
  * @param int $hostId The host template Id
  * @return array
  */
 public static function getInheritanceValues($hostId, $withHostValues = false, $columns = array())
 {
     $values = array();
     $templates = static::getTemplateChain($hostId, array(), -1);
     if ($withHostValues) {
         array_unshift($templates, array('id' => $hostId));
     }
     foreach ($templates as $template) {
         if (count($columns) > 0) {
             $inheritanceValues = HostTemplateRepository::getInheritanceValues($template['id'], false, $columns);
             $tmplValues = Host::getParameters($template['id'], $columns);
         } else {
             $inheritanceValues = HostTemplateRepository::getInheritanceValues($template['id']);
             $tmplValues = Host::getParameters($template['id'], self::$inheritanceColumns);
         }
         $tmplValues = array_filter($tmplValues, function ($value) {
             return !is_null($value);
         });
         $tmplValues = array_merge($inheritanceValues, $tmplValues);
         $values = array_merge($tmplValues, $values);
     }
     return $values;
 }
示例#4
0
文件: Unique.php 项目: rk4an/centreon
 /**
  * 
  * @param type $value
  * @param array $params
  * @return boolean
  */
 public function validate($value, $params = array(), $sContext = 'server')
 {
     $db = Di::getDefault()->get('db_centreon');
     $bSuccess = true;
     $resultError = _("Object already exists");
     $sMessage = '';
     $aParams = array();
     $aHost = array();
     $sLabel = '';
     $iId = '';
     $return = '';
     if (isset($params['object']) && $params['object'] == 'service') {
         $objClass = "CentreonConfiguration\\Repository\\" . ucfirst($params['object'] . "Repository");
         if (isset($params['extraParams']['service_description'])) {
             $sLabel = $params['extraParams']['service_description'];
         }
         if (isset($params['extraParams']['service_id'])) {
             $iId = $params['extraParams']['service_id'];
         }
         if (isset($params['extraParams']['service_hosts'])) {
             $aHosts = explode(",", $params['extraParams']['service_hosts']);
             $aHosts = array_diff($aHosts, array(''));
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             foreach ($aHosts as $iIdHost) {
                 $sHostName = "";
                 $aHostName = Host::getParameters($iIdHost, 'host_name');
                 if (is_array($aHostName) && isset($aHostName['host_name']) & !empty($aHostName['host_name'])) {
                     $sHostName = $aHostName['host_name'];
                 }
                 $aParams['host'] = $sHostName;
                 $aParams['service'] = $sLabel;
                 try {
                     $idReturned = $objClass::getIdFromUnicity($aParams);
                     $return[] = self::compareResponse($iObjectId, $idReturned);
                 } catch (MissingParameterException $e) {
                     $return[] = 0;
                 }
             }
         }
     } elseif (isset($params['object']) && $params['object'] == 'servicetemplate') {
         $objClass = "CentreonConfiguration\\Repository\\" . ucfirst($params['object'] . "Repository");
         if (isset($params['extraParams']['service_description'])) {
             $sLabel = $params['extraParams']['service_description'];
         }
         $aParams['servicetemplate'] = $sLabel;
         try {
             $idReturned = $objClass::getIdFromUnicity($aParams);
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             $return[] = self::compareResponse($iObjectId, $idReturned);
         } catch (MissingParameterException $e) {
             $return[] = 0;
         }
     } elseif (isset($params['object']) && $params['object'] == 'host') {
         $objClass = "CentreonConfiguration\\Repository\\" . ucfirst($params['object'] . "Repository");
         if (isset($params['extraParams']['host_name'])) {
             $sLabel = $params['extraParams']['host_name'];
         }
         $aParams['host'] = $sLabel;
         try {
             $idReturned = $objClass::getIdFromUnicity($aParams);
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             $return[] = self::compareResponse($iObjectId, $idReturned);
         } catch (MissingParameterException $e) {
             $return[] = 0;
         }
     } elseif (isset($params['object']) && $params['object'] == 'hosttemplate') {
         $objClass = "CentreonConfiguration\\Repository\\HostTemplateRepository";
         if (isset($params['extraParams']['host_name'])) {
             $sLabel = $params['extraParams']['host_name'];
         }
         $aParams['hosttemplate'] = $sLabel;
         try {
             $idReturned = $objClass::getIdFromUnicity($aParams);
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             $return[] = self::compareResponse($iObjectId, $idReturned);
         } catch (MissingParameterException $e) {
             $return[] = 0;
         }
     } elseif (isset($params['object']) && $params['object'] == 'command') {
         $objClass = "CentreonConfiguration\\Repository\\" . ucfirst($params['object'] . "Repository");
         if (isset($params['extraParams']['command_name'])) {
             $sLabel = $params['extraParams']['command_name'];
         }
         $aParams['command'] = $sLabel;
         try {
             $idReturned = $objClass::getIdFromUnicity($aParams);
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             $return[] = self::compareResponse($iObjectId, $idReturned);
         } catch (MissingParameterException $e) {
             $return[] = 0;
         }
     } elseif (isset($params['object']) && $params['object'] == 'contact') {
         $objClass = "CentreonAdministration\\Repository\\" . ucfirst($params['object'] . "Repository");
         if (isset($params['extraParams']['description'])) {
             $sLabel = $params['extraParams']['description'];
         }
         $aParams['contact'] = $sLabel;
         try {
             $idReturned = $objClass::getIdFromUnicity($aParams);
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             $return[] = self::compareResponse($iObjectId, $idReturned);
         } catch (MissingParameterException $e) {
             $return[] = 0;
         }
     } elseif (isset($params['object']) && $params['object'] == 'user') {
         $objClass = "CentreonAdministration\\Repository\\" . ucfirst($params['object'] . "Repository");
         if (isset($params['extraParams']['login'])) {
             $sLabel = $params['extraParams']['login'];
         }
         $aParams['user'] = $sLabel;
         try {
             $idReturned = $objClass::getIdFromUnicity($aParams);
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             $return[] = self::compareResponse($iObjectId, $idReturned);
         } catch (MissingParameterException $e) {
             $return[] = 0;
         }
     } elseif (isset($params['object']) && $params['object'] == 'businessactivity') {
         $objClass = "CentreonBam\\Repository\\" . ucfirst($params['object'] . "Repository");
         if (isset($params['extraParams']['name'])) {
             $sLabel = $params['extraParams']['name'];
         }
         $aParams['bam'] = $sLabel;
         try {
             $idReturned = $objClass::getIdFromUnicity($aParams);
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             $return[] = self::compareResponse($iObjectId, $idReturned);
         } catch (MissingParameterException $e) {
             $return[] = 0;
         }
     } elseif (isset($params['object']) && $params['object'] == 'connector') {
         $objClass = "CentreonConfiguration\\Repository\\" . ucfirst($params['object'] . "Repository");
         if (isset($params['extraParams']['name'])) {
             $sLabel = $params['extraParams']['name'];
         }
         $aParams['connector'] = $sLabel;
         try {
             $idReturned = $objClass::getIdFromUnicity($aParams);
             $iObjectId = '';
             if (isset($params['extraParams']['object_id']) && !empty($params['extraParams']['object_id'])) {
                 $iObjectId = $params['extraParams']['object_id'];
             }
             $return[] = self::compareResponse($iObjectId, $idReturned);
         } catch (MissingParameterException $e) {
             $return[] = 0;
         }
     }
     if (is_array($return)) {
         foreach ($return as $valeur) {
             if ($valeur > 0) {
                 $bSuccess = false;
                 $sMessage = $resultError;
                 break;
             }
         }
     } else {
         if ($return > 0) {
             $bSuccess = false;
             $sMessage = $resultError;
         }
     }
     if ($sContext == 'client') {
         $reponse = $bSuccess;
     } else {
         $reponse = array('success' => $bSuccess, 'error' => $sMessage);
     }
     return $reponse;
 }
示例#5
0
 /**
  * Get service for a specific kpi
  *
  *
  * @method get
  * @route /indicator/[i:id]/service
  */
 public function serviceForIndicatorAction()
 {
     $di = Di::getDefault();
     $router = $di->get('router');
     $requestParam = $this->getParams('named');
     $relObj = static::$relationMap['indicator_service'];
     $listOfServices = $relObj::getHostIdServiceIdFromKpiId($requestParam['id']);
     $finalList = array();
     if (isset($listOfServices[0]) && !empty($listOfServices[0]['service_id']) && !empty($listOfServices[0]['host_id'])) {
         $serviceDescription = Service::getParameters($listOfServices[0]['service_id'], 'service_description');
         $hostName = Host::getParameters($listOfServices[0]['host_id'], 'host_name');
         $finalList = array("id" => $listOfServices[0]['service_id'] . '_' . $listOfServices[0]['host_id'], "text" => $hostName['host_name'] . ' ' . $serviceDescription['service_description']);
     }
     $router->response()->json($finalList);
 }
示例#6
0
文件: Unique.php 项目: rk4an/centreon
 /**
  * 
  * @param type $sModule
  * @param type $sNameObject
  * @param array $aDatas
  */
 public static function validateDataService($sModule, $sNameObject, $aDatas)
 {
     $iObjectId = '';
     $return = '';
     $oRepository = $sModule . "\\Repository\\" . ucfirst($sNameObject . "Repository");
     $oModel = $sModule . "\\Models\\" . ucfirst($sNameObject);
     $sChampUnique = $oModel::getUniqueLabelField();
     $sChampPk = $oModel::getPrimaryKey();
     if (isset($aDatas['extraParams'][$sChampUnique])) {
         $sLabel = $aDatas['extraParams'][$sChampUnique];
     }
     if (isset($aDatas['extraParams'][$sChampPk])) {
         $iId = $aDatas['extraParams'][$sChampPk];
     }
     if (isset($aDatas['extraParams']['service_hosts'])) {
         $aHosts = explode(",", $aDatas['extraParams']['service_hosts']);
         $aHosts = array_diff($aHosts, array(''));
         if (isset($aDatas['extraParams']['object_id']) && !empty($aDatas['extraParams']['object_id'])) {
             $iObjectId = $aDatas['extraParams']['object_id'];
         }
         foreach ($aHosts as $iIdHost) {
             $sHostName = "";
             $aHostName = Host::getParameters($iIdHost, 'host_name');
             if (is_array($aHostName) && isset($aHostName['host_name']) & !empty($aHostName['host_name'])) {
                 $sHostName = $aHostName['host_name'];
             }
             $aParams['host'] = $sHostName;
             $aParams['service'] = $sLabel;
             try {
                 $idReturned = $oRepository::getIdFromUnicity($aParams);
                 $return[] = self::compareResponse($iObjectId, $idReturned);
             } catch (MissingParameterException $e) {
                 $return[] = 0;
             }
         }
     }
     return $return;
 }