Example #1
0
   /**
    * Display services associated with host
    *
    * @param $itemtype value type of item
    * @param $items_id integer id of the object
    *
    **/
   function listByHost($itemtype, $items_id) {
      global $CFG_GLPI,$DB;

      $params = Search::manageParams("PluginMonitoringService", array(), false);
      $num = 20; // Computer
      if ($itemtype == 'Printer') {
         $num = 21;
      } else if ($itemtype == 'NetworkEquipment') {
         $num = 22;
      }
      $params['criteria'][0] = array(
         'field'      => $num,
         'searchtype' => 'is',
         'value'      => $items_id
      );
      $col_to_display = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11);

      $data = Search::prepareDatasForSearch('PluginMonitoringService', $params, $col_to_display);
      $data['tocompute'] = $data['toview'];
      Search::constructSQL($data);
      Search::constructDatas($data);

      $pmComponentscatalog = new PluginMonitoringComponentscatalog();

      $services_id = array();
      foreach ($data['data']['rows'] as $row) {
         $services_id[] = $row['id'];
      }
      $oldvalue = current(getAllDatasFromTable(
              'glpi_plugin_monitoring_serviceevents',
              "`plugin_monitoring_services_id` IN ('".implode("', '", $services_id)."')",
              false,
              'date ASC LIMIT 1'));
      $date = new DateTime($oldvalue['date']);
      $start = time();
      if ($date->getTimestamp() < $start) {
         $start = $date->getTimestamp();
      }

      $nbdays = round((date('U') - $start) / 86400);
      echo "<script type=\"text/javascript\">
      $(function() {
          $( \"#custom_date\" ).datepicker({ minDate: -".$nbdays.", maxDate: \"+0D\", dateFormat:'mm/dd/yy' });
          $( \"#custom_time\" ).timepicker();

      });
      </script>";

      echo '<center><input type="text" id="custom_date" value="'.date('m/d/Y').'"> '
              . ' <input type="text" id="custom_time" value="'.date('H:i').'"></center>';

      echo '<div id="custom_date" style="display:none"></div>';
      echo '<div id="custom_time" style="display:none"></div>';

      echo "<table class='tab_cadre_fixe'>";

      echo "<tr class='tab_bg_1'>";
      echo "<th colspan='5'>";
      echo __('Resources', 'monitoring');
      $item = new $itemtype();
      $item->getFromDB($items_id);
      echo " - ".$item->getTypeName();
      echo " - ".$item->getName();
      echo "</th>";
      echo "</tr>";

      echo "<table class='tab_cadre_fixe'>";

      foreach ($data['data']['rows'] as $row) {
         $pmComponentscatalog->getFromDB($row[8][0]['id']);

         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='14'>".$pmComponentscatalog->getTypeName()."&nbsp;:&nbsp;".$pmComponentscatalog->getLink()."</th>";
         echo "</tr>";

         echo "<tr class='tab_bg_1'>";
         // echo "<th>";
         // echo __('Show counters', 'monitoring');
         // echo "</th>";
         echo "<th>";
         echo __('Show graphics', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Component', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Resource state', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Last check', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Result details', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Check period', 'monitoring');
         echo "</th>";
         echo "<th>".__('Current month', 'monitoring')." ".Html::showToolTip(__('Availability', 'monitoring'), array('display'=>false))."</th>";
         echo "<th>".__('Last month', 'monitoring')." ".Html::showToolTip(__('Availability', 'monitoring'), array('display'=>false))."</th>";
         echo "<th>".__('Current year', 'monitoring')." ".Html::showToolTip(__('Availability', 'monitoring'), array('display'=>false))."</th>";
         echo "<th>".__('Detail', 'monitoring')."</th>";
         echo '<th>'.__('Acknowledge', 'monitoring').'</th>';
         echo "<th>".__('Arguments', 'monitoring')."</th>";
         echo "</tr>";

//         $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`
//            LEFT JOIN `glpi_plugin_monitoring_components`
//               on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`
//            WHERE `plugin_monitoring_componentscatalogs_hosts_id`='".$row['id']."'
//               ORDER BY `name`";
//         $results = $DB->query($querys);
//         while ($datas=$DB->fetch_array($results)) {
//            $this->getFromDB($datas['id']);

            echo "<tr class='tab_bg_1'>";
            PluginMonitoringDisplay::displayLine($row, 0);
            echo "</tr>";

//         }

         echo "<tr style='border:1px solid #ccc;background-color:#ffffff'>";
         echo "<td colspan='14' height='5'></td>";
         echo "</tr>";
      }

      echo "</table>";

      Html::closeForm();
   }
 /**
  * Display services associated with host
  *
  * @param $itemtype value type of item
  * @param $items_id integer id of the object
  *
  **/
 function listByHost($itemtype, $items_id)
 {
     global $LANG, $CFG_GLPI, $DB;
     $pmComponentscatalog = new PluginMonitoringComponentscatalog();
     $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n         WHERE `items_id`='" . $items_id . "'\n            AND `itemtype`='" . $itemtype . "'";
     $result = $DB->query($query);
     //      echo "<form name='form' method='post'
     //         action='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th colspan='5'>";
     echo $LANG['plugin_monitoring']['service'][0];
     //      echo "&nbsp;<a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php?services_id=".$a_hosts['id']."'>
     //         <img src='".$CFG_GLPI['root_doc']."/pics/menu_add.png' /></a>";
     //
     //      echo "&nbsp;<a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/servicedef.form.php?add_template=1'>
     //         <img src='".$CFG_GLPI['root_doc']."/pics/menu_addtemplate.png' /></a>";
     echo "</th>";
     echo "</tr>";
     echo "<table>";
     while ($data = $DB->fetch_array($result)) {
         $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']);
         echo "<table class='tab_cadre_fixe'>";
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='12'>" . $pmComponentscatalog->getTypeName() . "&nbsp;:&nbsp;" . $pmComponentscatalog->getLink() . "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<th>";
         echo $LANG['joblist'][0];
         echo "</th>";
         echo "<th>";
         echo $LANG['entity'][0];
         echo "</th>";
         echo "<th>";
         echo $LANG['stats'][7];
         echo "</th>";
         echo "<th>";
         echo $LANG['plugin_monitoring']['component'][0];
         echo "</th>";
         echo "<th>";
         echo $LANG['state'][0];
         echo "</th>";
         echo "<th>";
         echo $LANG['plugin_monitoring']['service'][18];
         echo "</th>";
         echo "<th>";
         echo $LANG['rulesengine'][82];
         echo "</th>";
         echo "<th>";
         echo $LANG['plugin_monitoring']['host'][9];
         echo "</th>";
         echo "<th>" . $LANG['plugin_monitoring']['availability'][1] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>";
         echo "<th>" . $LANG['plugin_monitoring']['availability'][2] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>";
         echo "<th>" . $LANG['plugin_monitoring']['availability'][3] . " " . showToolTip($LANG['plugin_monitoring']['availability'][0], array('display' => false)) . "</th>";
         echo "<th>";
         echo $LANG['plugin_monitoring']['service'][4];
         echo "</th>";
         echo "</tr>";
         $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`\n            LEFT JOIN `glpi_plugin_monitoring_components`\n               on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n            WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data['id'] . "'\n               ORDER BY `name`";
         $results = $DB->query($querys);
         while ($datas = $DB->fetch_array($results)) {
             $this->getFromDB($datas['id']);
             echo "<tr class='tab_bg_1'>";
             PluginMonitoringDisplay::displayLine($datas, 0);
             echo "</tr>";
         }
         echo "</table>";
     }
     //      echo "<tr class='tab_bg_1'>";
     //      echo "<td colspan='8' align='center'>";
     //      echo "<input type='submit' class='submit' name='update' value='".$LANG['buttons'][7]."'>";
     //      echo "</td>";
     //      echo "</tr>";
     echo "</table>";
     echo "</form>";
 }
 function showForm($items_id, $servicescatalogs_id, $options = array())
 {
     global $CFG_GLPI;
     if ($items_id != '') {
         $this->getFromDB($items_id);
     } else {
         $this->getEmpty();
     }
     $this->showFormHeader($options);
     $pmBusinessrule_component = new PluginMonitoringBusinessrule_component();
     $pmBusinessrule_component->replayDynamicServices($items_id);
     $pmSC = new PluginMonitoringServicescatalog();
     $pmSC->getFromDB($servicescatalogs_id);
     $rand = mt_rand();
     echo "<tr class='tab_bg_1'>";
     echo "<td>";
     echo "<input type='hidden' name='plugin_monitoring_servicescatalogs_id' value='" . $servicescatalogs_id . "'/>";
     echo __('Name') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     echo "<input type='text' name='name' value='" . $this->fields["name"] . "' size='30'/>";
     echo "</td>";
     if ($items_id != '') {
         if (Session::haveRight("plugin_monitoring_servicescatalog", CREATE)) {
             echo "<th colspan='2' width='60%'>";
             echo __('Resources', 'monitoring');
             echo "&nbsp;";
             echo "<img onClick=\"Ext.get('ressources" . $rand . "').setDisplayed('block')\"\n                       title=\"" . __('add') . "\" alt=\"" . __('add') . "\"\n                       class='pointer'  src='" . $CFG_GLPI["root_doc"] . "/pics/add_dropdown.png'>";
             echo "</th>";
         }
     }
     echo "</tr>";
     echo "<tr>";
     echo "<td valign='top'>";
     echo __('Logical operator') . "&nbsp;:";
     echo "</td>";
     echo "<td valign='top'>";
     $first_operator = array();
     $first_operator['and'] = "and";
     $first_operator['or'] = "or";
     $first_operator['2 of:'] = __('2 of', 'monitoring');
     $first_operator['3 of:'] = __('3 of', 'monitoring');
     $first_operator['4 of:'] = __('4 of', 'monitoring');
     $first_operator['5 of:'] = __('5 of', 'monitoring');
     $first_operator['6 of:'] = __('6 of', 'monitoring');
     $first_operator['7 of:'] = __('7 of', 'monitoring');
     $first_operator['8 of:'] = __('8 of', 'monitoring');
     $first_operator['9 of:'] = __('9 of', 'monitoring');
     $first_operator['10 of:'] = __('10 of', 'monitoring');
     Dropdown::showFromArray('operator', $first_operator, array("value" => $this->fields['operator']));
     echo "</td>";
     if ($items_id != '') {
         echo "<td colspan='2'>";
         if (Session::haveRight("plugin_monitoring_servicescatalog", CREATE)) {
             // ** Dropdown to display
             echo "<div style='display:none' id='ressources" . $rand . "' >";
             // Static (a service for an host)
             echo "<table>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>";
             echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/businessrule.form.php'>";
             echo "<input type='hidden' name='plugin_monitoring_businessrulegroups_id' value='" . $items_id . "' />";
             echo "<input type='hidden' name='is_generic' value='" . $pmSC->getField('is_generic') . "' />";
             PluginMonitoringBusinessrule::dropdownService(0, array('name' => 'type'));
             echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
             Html::closeForm();
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             echo "<hr>";
             // Dynamique (all service of component of component catalog)
             echo "<table>";
             echo "<tr class='tab_bg_1'>";
             echo "<td><strong>";
             echo __('Components catalog', 'monitoring');
             echo ' + ';
             echo __('Component', 'monitoring');
             echo " (" . __('Dynamic', 'monitoring') . ")";
             echo " :</strong></td>";
             echo "</tr>";
             echo "<tr class='tab_bg_1'>";
             echo "<td>";
             echo "<form name='form' method='post' action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/businessrule_component.form.php'>";
             echo "<input type='hidden' name='plugin_monitoring_businessrulegroups_id' value='" . $items_id . "' />";
             $options = array('toupdate' => array('value_fieldname' => 'plugin_monitoring_componentscalalog_id', 'to_update' => "componentdropdown" . $rand, 'url' => $CFG_GLPI["root_doc"] . "/plugins/monitoring/ajax/dropdownComponent.php", 'moreparams' => array()));
             Dropdown::show('PluginMonitoringComponentscatalog', $options);
             echo '<div id="componentdropdown' . $rand . '"></div>';
             //PluginMonitoringBusinessrule::dropdownService(0, array('name' => 'type'));
             echo "<input type='submit' name='add' value=\"" . __('Add') . "\" class='submit'>";
             Html::closeForm();
             echo "</td>";
             echo "</tr>";
             echo "</table>";
             echo "<hr>";
             echo "</div>";
         }
         $pmBusinessrule = new PluginMonitoringBusinessrule();
         $pmService = new PluginMonitoringService();
         $a_services = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'" . " AND `is_dynamic`='0'");
         if (count($a_services) > 0) {
             echo "<strong>" . __('Static hosts', 'monitoring') . " :</strong>";
             echo "<table width='100%'>";
             foreach ($a_services as $gdata) {
                 if ($pmService->getFromDB($gdata['plugin_monitoring_services_id'])) {
                     $shortstate = $pmService->getShortState();
                     echo "<tr class='tab_bg_1'>";
                     echo "<td>";
                     echo "<img src='" . $pmService->getShortState(array('image' => '32')) . "'/>";
                     echo "</td>";
                     echo "<td>";
                     echo $pmService->getLink();
                     echo "</td>";
                     echo "<td>";
                     echo "<input type='submit' name='deletebusinessrules-" . $gdata['id'] . "' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>";
                     echo "</td>";
                     echo "</tr>";
                 } else {
                     // resource deleted
                     echo "<tr class='tab_bg_1'>";
                     echo "<td colspan='2' bgcolor='#ff0000'>";
                     echo __('Resource deleted', 'monitoring');
                     echo "</td>";
                     echo "<td>";
                     echo "<input type='submit' name='deletebusinessrules-" . $gdata['id'] . "' value=\"" . __('Clean') . "\" class='submit'>";
                     echo "</td>";
                     echo "</tr>";
                 }
             }
             echo "</table>";
             echo "<hr/>";
         }
         $a_br_components = $pmBusinessrule_component->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'");
         $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component();
         $pmComponentscatalog = new PluginMonitoringComponentscatalog();
         $pmComponent = new PluginMonitoringComponent();
         if (count($a_br_components) > 0) {
             echo "<strong>" . __('Dynamic hosts', 'monitoring') . " :</strong>";
             echo "<table width='100%'>";
             foreach ($a_br_components as $a_br_component) {
                 echo "<tr class='tab_bg_1'>";
                 echo "<td>";
                 $pmComponentscatalog_Component->getFromDB($a_br_component['plugin_monitoring_componentscatalogs_components_id']);
                 $pmComponentscatalog->getFromDB($pmComponentscatalog_Component->fields['plugin_monitoring_componentscalalog_id']);
                 echo $pmComponentscatalog->getLink();
                 echo ' > ';
                 $pmComponent->getFromDB($pmComponentscatalog_Component->fields['plugin_monitoring_components_id']);
                 echo $pmComponent->getLink();
                 echo "</td>";
                 echo "<td>";
                 echo "<input type='submit' name='deletebrcomponents-" . $a_br_component['id'] . "' value=\"" . _sx('button', 'Delete permanently') . "\" class='submit'>";
                 echo "</td>";
                 echo "</tr>";
             }
             echo "</table>";
         }
         if (!($pmSC->fields['is_generic'] && $pmSC->fields['is_recursive'])) {
             echo "<table width='100%'>";
             $a_services = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $items_id . "'" . " AND `is_dynamic`='1'");
             foreach ($a_services as $gdata) {
                 $pmService->getFromDB($gdata["plugin_monitoring_services_id"]);
                 $shortstate = $pmService->getShortState();
                 echo "<tr class='tab_bg_1'>";
                 echo "<td width='130'>&nbsp;";
                 echo "</td>";
                 echo "<td>";
                 echo "<img src='" . $pmService->getShortState(array('image' => '32')) . "'/>";
                 echo "</td>";
                 echo "<td>";
                 $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host();
                 $pmComponentscatalog_Host->getFromDB($pmService->fields['plugin_monitoring_componentscatalogs_hosts_id']);
                 echo $pmService->getLink();
                 echo "</td>";
                 echo "</tr>";
             }
             echo "</table>";
         } else {
             echo "<strong>" . __('Dynamic hosts list will be defined during Shinken configuration build.', 'monitoring') . "</strong>";
         }
     }
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     return true;
 }
 static function listForComponents($components_id)
 {
     global $DB;
     $pmComponentscatalog = new PluginMonitoringComponentscatalog();
     echo "<table class='tab_cadre' width='400'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th>" . __('Components catalog', 'monitoring') . "</th>";
     echo "</tr>";
     $query = "SELECT `glpi_plugin_monitoring_componentscatalogs`.* FROM `glpi_plugin_monitoring_componentscatalogs_components`\n         LEFT JOIN `glpi_plugin_monitoring_componentscatalogs`\n            ON `plugin_monitoring_componentscalalog_id` =\n               `glpi_plugin_monitoring_componentscatalogs`.`id`\n         WHERE `plugin_monitoring_components_id`='" . $components_id . "'\n         ORDER BY `glpi_plugin_monitoring_componentscatalogs`.`name`";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         echo "<tr class='tab_bg_1'>";
         echo "<td>";
         $pmComponentscatalog->getFromDB($data['id']);
         echo $pmComponentscatalog->getLink(1);
         echo "</td>";
         echo "</tr>";
     }
     echo "</table>";
 }
Example #5
0
 /**
  * Display services associated with host
  *
  * @param $itemtype value type of item
  * @param $items_id integer id of the object
  *
  **/
 function listByHost($itemtype, $items_id)
 {
     global $CFG_GLPI, $DB;
     $pmComponentscatalog = new PluginMonitoringComponentscatalog();
     $query = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n         WHERE `items_id`='" . $items_id . "'\n            AND `itemtype`='" . $itemtype . "'";
     $result = $DB->query($query);
     //      echo "<form name='form' method='post'
     //         action='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php'>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr class='tab_bg_1'>";
     echo "<th colspan='5'>";
     echo __('Resources', 'monitoring');
     $item = new $itemtype();
     $item->getFromDB($items_id);
     echo " - " . $item->getTypeName();
     echo " - " . $item->getName();
     //      echo "&nbsp;<a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/service.form.php?services_id=".$a_hosts['id']."'>
     //         <img src='".$CFG_GLPI['root_doc']."/pics/menu_add.png' /></a>";
     //
     //      echo "&nbsp;<a href='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/servicedef.form.php?add_template=1'>
     //         <img src='".$CFG_GLPI['root_doc']."/pics/menu_addtemplate.png' /></a>";
     echo "</th>";
     echo "</tr>";
     echo "<table class='tab_cadre_fixe'>";
     while ($data = $DB->fetch_array($result)) {
         $pmComponentscatalog->getFromDB($data['plugin_monitoring_componentscalalog_id']);
         echo "<tr class='tab_bg_1'>";
         echo "<th colspan='14'>" . $pmComponentscatalog->getTypeName() . "&nbsp;:&nbsp;" . $pmComponentscatalog->getLink() . "</th>";
         echo "</tr>";
         echo "<tr class='tab_bg_1'>";
         echo "<th>";
         echo __('Status');
         echo "</th>";
         echo "<th>";
         echo __('Entity');
         echo "</th>";
         echo "<th>";
         echo __('Components', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Components', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Status');
         echo "</th>";
         echo "<th>";
         echo __('Last check', 'monitoring');
         echo "</th>";
         echo "<th>";
         echo __('Result details');
         echo "</th>";
         echo "<th>";
         echo __('Check period', 'monitoring');
         echo "</th>";
         echo "<th>" . __('Current month', 'monitoring') . " " . Html::showToolTip(__('Availability', 'monitoring'), array('display' => false)) . "</th>";
         echo "<th>" . __('Last month', 'monitoring') . " " . Html::showToolTip(__('Availability', 'monitoring'), array('display' => false)) . "</th>";
         echo "<th>" . __('Current year', 'monitoring') . " " . Html::showToolTip(__('Availability', 'monitoring'), array('display' => false)) . "</th>";
         echo "<th>" . __('Detail', 'monitoring') . "</th>";
         echo '<th>' . __('Acknowledge', 'monitoring') . '</th>';
         echo "<th>";
         echo __('Arguments', 'monitoring');
         echo "</th>";
         echo "</tr>";
         $querys = "SELECT `glpi_plugin_monitoring_services`.* FROM `glpi_plugin_monitoring_services`\n            LEFT JOIN `glpi_plugin_monitoring_components`\n               on `plugin_monitoring_components_id` = `glpi_plugin_monitoring_components`.`id`\n            WHERE `plugin_monitoring_componentscatalogs_hosts_id`='" . $data['id'] . "'\n               ORDER BY `name`";
         $results = $DB->query($querys);
         while ($datas = $DB->fetch_array($results)) {
             $this->getFromDB($datas['id']);
             echo "<tr class='tab_bg_1'>";
             PluginMonitoringDisplay::displayLine($datas, 0);
             echo "</tr>";
         }
         echo "<tr style='border:1px solid #ccc;background-color:#ffffff'>";
         echo "<td colspan='14' height='5'></td>";
         echo "</tr>";
     }
     echo "</table>";
     Html::closeForm();
 }