Exemplo n.º 1
0
   function showForm($items_id, $options=array(), $services_id='') {
      $pMonitoringCommand = new PluginMonitoringCommand();
      $pMonitoringServicedef = new PluginMonitoringServicedef();

      if (isset($_GET['withtemplate']) AND ($_GET['withtemplate'] == '1')) {
         $options['withtemplate'] = 1;
      } else {
         $options['withtemplate'] = 0;
      }

      if ($services_id!='') {
         $this->getEmpty();
      } else {
         $this->getFromDB($items_id);
      }
      $this->showTabs($options);
      $this->showFormHeader($options);
      if (!isset($this->fields['plugin_monitoring_servicedefs_id'])
              OR empty($this->fields['plugin_monitoring_servicedefs_id'])) {
         $pMonitoringServicedef->getEmpty();
      } else {
         $pMonitoringServicedef->getFromDB($this->fields['plugin_monitoring_servicedefs_id']);
      }
      $template = false;


      echo "<tr>";
      echo "<td>";
      if ($services_id!='') {
         echo "<input type='hidden' name='plugin_monitoring_services_id' value='".$services_id."' />";
      }
      echo __('Name')."&nbsp;:";
      echo "</td>";
      echo "<td>";
      $objectName = autoName($this->fields["name"], "name", ($template === "newcomp"),
                             $this->getType());
      Html::autocompletionTextField($this, 'name', array('value' => $objectName));
      echo "</td>";
      echo "<td>";
      echo __('Template')."&nbsp;:";
      echo "</td>";
      echo "<td>";
      if ($items_id != '0') {
         echo "<input type='hidden' name='update' value='update'>\n";
      }
      echo "<input type='hidden' name='plugin_monitoring_servicedefs_id_s' value='".$this->fields['plugin_monitoring_servicedefs_id']."'>\n";
      if ($pMonitoringServicedef->fields['is_template'] == '0') {
         $this->fields['plugin_monitoring_servicedefs_id'] = 0;
      }
      Dropdown::show("PluginMonitoringServicetemplate", array(
            'name' => 'plugin_monitoring_servicetemplates_id',
            'value' => $this->fields['plugin_monitoring_servicetemplates_id'],
            'auto_submit' => true
      ));
      echo "</td>";
      echo "<td>";
      if ($this->fields["items_id"] == '') {

      } else {
         echo "<input type='hidden' name='items_id' value='".$this->fields["items_id"]."'>\n";
         echo "<input type='hidden' name='itemtype' value='".$this->fields["itemtype"]."'>\n";
      }
      echo "</td>";
      echo "</tr>";

      echo "<tr>";
      echo "<th colspan='4'>&nbsp;</th>";
      echo "</tr>";

      echo "<tr>";
      // * itemtype link
      if ($this->fields['itemtype'] != '') {
         $itemtype = $this->fields['itemtype'];
         $item = new $itemtype();
         $item->getFromDB($this->fields['items_id']);
         echo "<td>";
         echo __('Item Type')." <i>".$item->getTypeName()."</i>";
         echo "&nbsp;:</td>";
         echo "<td>";
         echo $item->getLink(1);
         echo "</td>";
      } else {
         echo "<td colspan='2' align='center'>";
         echo __('No type associated', 'monitoring');
         echo "</td>";
      }
      // * command
      echo "<td>";
      echo __('Command', 'monitoring')."&nbsp;:";
      echo "</td>";
      echo "<td align='center'>";
      if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
         $pMonitoringServicetemplate = new PluginMonitoringServicetemplate();
         $pMonitoringServicetemplate->getFromDB($this->fields['plugin_monitoring_servicetemplates_id']);
         $pMonitoringCommand->getFromDB($pMonitoringServicetemplate->fields['plugin_monitoring_commands_id']);
         echo $pMonitoringCommand->getLink(1);
      } else {
         $pMonitoringCommand->getFromDB($pMonitoringServicedef->fields['plugin_monitoring_commands_id']);
         Dropdown::show("PluginMonitoringCommand", array(
                              'name' =>'plugin_monitoring_commands_id',
                              'value'=>$pMonitoringServicedef->fields['plugin_monitoring_commands_id']
                              ));
      }
      echo "</td>";
      echo "</tr>";

      echo "<tr>";
      // * checks
      echo "<td>".__('Check definition', 'monitoring')."&nbsp;:</td>";
      echo "<td align='center'>";
      if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
         $pMonitoringCheck = new PluginMonitoringCheck();
         $pMonitoringCheck->getFromDB($pMonitoringServicetemplate->fields['plugin_monitoring_checks_id']);
         echo $pMonitoringCheck->getLink(1);
      } else {
         Dropdown::show("PluginMonitoringCheck",
                        array('name'=>'plugin_monitoring_checks_id',
                              'value'=>$pMonitoringServicedef->fields['plugin_monitoring_checks_id']));
      }
      echo "</td>";
      // * active check
      echo "<td>";
      echo __('Active check', 'monitoring')."&nbsp;:";
      echo "</td>";
      echo "<td align='center'>";
      if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
         echo Dropdown::getYesNo($pMonitoringServicetemplate->fields['active_checks_enabled']);
      } else {
         Dropdown::showYesNo("active_checks_enabled", $pMonitoringServicedef->fields['active_checks_enabled']);
      }
      echo "</td>";
      echo "</tr>";

      echo "<tr>";
      // * passive check
      echo "<td>";
      echo __('Passive check', 'monitoring')."&nbsp;:";
      echo "</td>";
      echo "<td align='center'>";
      if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
         echo Dropdown::getYesNo($pMonitoringServicetemplate->fields['passive_checks_enabled']);
      } else {
         Dropdown::showYesNo("passive_checks_enabled", $pMonitoringServicedef->fields['passive_checks_enabled']);
      }
      echo "</td>";
      // * calendar
      echo "<td>".__('Check period', 'monitoring')."&nbsp;:</td>";
      echo "<td align='center'>";
      if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
         $calendar = new Calendar();
         $calendar->getFromDB($pMonitoringServicetemplate->fields['calendars_id']);
         echo $calendar->getLink(1);
      } else {
         dropdown::show("Calendar", array('name'=>'calendars_id',
                                 'value'=>$pMonitoringServicedef->fields['calendars_id']));
      }
      echo "</td>";
      echo "</tr>";

      if (!($this->fields['plugin_monitoring_servicetemplates_id'] > 0
              AND $pMonitoringServicetemplate->fields['remotesystem'] == '')) {

         echo "<tr>";
         echo "<th colspan='4'>".__('Remote check', 'monitoring')."</th>";
         echo "</tr>";

         echo "<tr>";
         // * remotesystem
         echo "<td>";
         echo __('Utility used for remote check', 'monitoring')."&nbsp;:";
         echo "</td>";
         echo "<td>";
         $input = array();
         $input[''] = '------';
         $input['byssh'] = 'byssh';
         $input['nrpe'] = 'nrpe';
         $input['nsca'] = 'nsca';
         if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
            echo $input[$pMonitoringServicetemplate->fields['remotesystem']];
         } else {
            Dropdown::showFromArray("remotesystem",
                                 $input,
                                 array('value'=>$pMonitoringServicedef->fields['remotesystem']));
         }
         echo "</td>";
         // * is_argument
         echo "<td>";
         echo __('Use arguments (NRPE only)', 'monitoring')."&nbsp;:";
         echo "</td>";
         echo "<td>";
         if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
            echo Dropdown::getYesNo($pMonitoringServicetemplate->fields['is_arguments']);
         } else {
            Dropdown::showYesNo("is_arguments", $pMonitoringServicedef->fields['is_arguments']);
         }
         echo "</td>";
         echo "</tr>";

         echo "<tr>";
         // alias command
         echo "<td>";
         echo __('Alias command if required (NRPE only)', 'monitoring')."&nbsp;:";
         echo "</td>";
         echo "<td>";
         if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
            echo "<input type='text' name='alias_commandservice' value='".$this->fields['alias_command']."' />";
         } else {
            echo "<input type='text' name='alias_command' value='".$pMonitoringServicedef->fields['alias_command']."' />";
         }
         echo "</td>";

         echo "<td>";
         echo __('Template (for graphs generation)', 'monitoring')."&nbsp;:GHJKL";
         echo "</td>";
         echo "<td>";
         if ($this->fields['plugin_monitoring_servicetemplates_id'] > 0) {
            $pMonitoringCommand->getEmpty();
            $pMonitoringCommand->getFromDB($pMonitoringServicetemplate->fields['aliasperfdata_commands_id']);
            echo $pMonitoringCommand->getLink(1);
         } else {
            $pMonitoringCommand->getFromDB($pMonitoringServicedef->fields['aliasperfdata_commands_id']);
            Dropdown::show("PluginMonitoringCommand", array(
                                 'name' =>'aliasperfdata_commands_id',
                                 'value'=>$pMonitoringServicedef->fields['aliasperfdata_commands_id']
                                 ));
         }
         echo "</td>";
         echo "</tr>";
      }

      // * Manage arguments
      $array = array();
      $a_displayarg = array();
      if (isset($pMonitoringCommand->fields['command_line'])) {
         preg_match_all("/\\$(ARG\d+)\\$/", $pMonitoringCommand->fields['command_line'], $array);
         $a_arguments = importArrayFromDB($this->fields['arguments']);
         foreach ($array[0] as $arg) {
            if (strstr($arg, "ARG")) {
               $arg = str_replace('$', '', $arg);
               if (!isset($a_arguments[$arg])) {
                  $a_arguments[$arg] = '';
               }
               $a_displayarg[$arg] = $a_arguments[$arg];

            }
         }
      }
      if (count($a_displayarg) > 0) {
         $a_argtext = importArrayFromDB($pMonitoringCommand->fields['arguments']);
         echo "<tr>";
         echo "<th colspan='4'>".__('Argument ([text:text] is used to get values dynamically)', 'monitoring')."&nbsp;</th>";
         echo "</tr>";

         foreach ($a_displayarg as $key=>$value) {
         echo "<tr>";
         echo "<th>".$key."</th>";
         echo "<td colspan='2'>";
            if (isset($a_argtext[$key])) {
               echo nl2br($a_argtext[$key])."&nbsp;:";
            } else {
               echo __('Argument', 'monitoring')."&nbsp;:";
            }

            if ($value == '') {
               $matches = array();
               preg_match('/(\[\w+\:\w+\])/',
                              nl2br($a_argtext[$key]), $matches);
               if (isset($matches[0])) {
                  $value = $matches[0];
               }
            }

            echo "</td>";
            echo "<td>";
            echo "<input type='text' name='arg[".$key."]' value='".$value."'/><br/>";
            echo "</td>";
            echo "</tr>";
         }
      }

      $this->showFormButtons($options);
      return true;
   }
 function showComponents($componentscatalogs_id)
 {
     global $DB, $LANG, $CFG_GLPI;
     $this->addComponent($componentscatalogs_id);
     $rand = mt_rand();
     $pmComponent = new PluginMonitoringComponent();
     $pmCommand = new PluginMonitoringCommand();
     $pmCheck = new PluginMonitoringCheck();
     $calendar = new Calendar();
     echo "<form method='post' name='componentscatalog_component_form{$rand}' id='componentscatalog_component_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/front/componentscatalog_component.form.php\">";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>";
     echo $LANG['plugin_monitoring']['component'][2];
     echo "</th>";
     echo "</tr>";
     echo "</table>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th width='10'>&nbsp;</th>";
     echo "<th>" . $LANG['common'][16] . "</th>";
     echo "<th>" . $LANG['plugin_monitoring']['command'][2] . "</th>";
     echo "<th>" . $LANG['plugin_monitoring']['check'][0] . "</th>";
     echo "<th>" . $LANG['plugin_monitoring']['host'][9] . "</th>";
     echo "<th>" . $LANG['plugin_monitoring']['service'][8] . "</th>";
     echo "</tr>";
     $used = array();
     $query = "SELECT * FROM `" . $this->getTable() . "`\n         WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $used[] = $data['plugin_monitoring_components_id'];
         $pmComponent->getFromDB($data['plugin_monitoring_components_id']);
         echo "<tr>";
         echo "<td>";
         echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'>";
         echo "</td>";
         echo "<td class='center'>";
         echo $pmComponent->getLink(1);
         echo "</td>";
         echo "<td class='center'>";
         $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']);
         echo $pmCommand->getLink();
         echo "</td>";
         echo "<td class='center'>";
         $pmCheck->getFromDB($pmComponent->fields['plugin_monitoring_checks_id']);
         echo $pmCheck->getLink();
         echo "</td>";
         echo "<td class='center'>";
         $calendar->getFromDB($pmComponent->fields['calendars_id']);
         echo $calendar->getLink();
         echo "</td>";
         echo "<td class='center'>";
         if ($pmComponent->fields['remotesystem'] == '') {
             echo "-";
         } else {
             echo $pmComponent->fields['remotesystem'];
         }
         echo "</td>";
         echo "</tr>";
     }
     openArrowMassive("componentscatalog_host_form{$rand}", true);
     closeArrowMassive('deleteitem', $LANG['buttons'][6]);
     echo "</table>";
 }
 /**
  * Display form for service configuration
  *
  * @param $items_id integer ID
  * @param $options array
  *
  *@return bool true if form is ok
  *
  **/
 function showForm($items_id, $options = array())
 {
     $pMonitoringCommand = new PluginMonitoringCommand();
     if ($items_id == '0') {
         $this->getEmpty();
     } else {
         $this->getFromDB($items_id);
     }
     $this->showFormHeader($options);
     echo "<tr>";
     echo "<td>";
     echo __('Template name') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     echo "<input type='hidden' name='is_template' value='1' />";
     $objectName = autoName($this->fields["name"], "name", 1, $this->getType());
     Html::autocompletionTextField($this, 'name', array('value' => $objectName));
     echo "</td>";
     // * commande
     echo "<td>";
     echo __('Command', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td align='center'>";
     if ($this->fields['is_template'] == '1') {
         $pMonitoringCommand->getFromDB($this->fields['plugin_monitoring_commands_id']);
         echo $pMonitoringCommand->getLink(1);
     } else {
         $pMonitoringCommand->getFromDB($this->fields['plugin_monitoring_commands_id']);
         Dropdown::show("PluginMonitoringCommand", array('name' => 'plugin_monitoring_commands_id', 'value' => $this->fields['plugin_monitoring_commands_id']));
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     // * checks
     echo "<td>" . __('Check definition', 'monitoring') . "&nbsp;:</td>";
     echo "<td align='center'>";
     if ($this->fields['is_template'] == '1') {
         $pMonitoringCheck = new PluginMonitoringCheck();
         $pMonitoringCheck->getFromDB($this->fields['plugin_monitoring_checks_id']);
         echo $pMonitoringCheck->getLink(1);
     } else {
         Dropdown::show("PluginMonitoringCheck", array('name' => 'plugin_monitoring_checks_id', 'value' => $this->fields['plugin_monitoring_checks_id']));
     }
     echo "</td>";
     // * active check
     echo "<td>";
     echo __('Active checks enable', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td align='center'>";
     if ($this->fields['is_template'] == '1') {
         echo Dropdown::getYesNo($this->fields['active_checks_enabled']);
     } else {
         Dropdown::showYesNo("active_checks_enabled", $this->fields['active_checks_enabled']);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     // * passive check
     echo "<td>";
     echo __('Passive checks enable', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td align='center'>";
     if ($this->fields['is_template'] == '1') {
         echo Dropdown::getYesNo($this->fields['passive_checks_enabled']);
     } else {
         Dropdown::showYesNo("passive_checks_enabled", $this->fields['passive_checks_enabled']);
     }
     echo "</td>";
     // * calendar
     echo "<td>" . __('Check period', 'monitoring') . "&nbsp;:</td>";
     echo "<td align='center'>";
     if ($this->fields['is_template'] == '1') {
         $calendar = new Calendar();
         $calendar->getFromDB($this->fields['calendars_id']);
         echo $calendar->getLink(1);
     } else {
         dropdown::show("Calendar", array('name' => 'calendars_id', 'value' => $this->fields['calendars_id']));
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<th colspan='4'>" . __('Remote check', 'monitoring') . "</th>";
     echo "</tr>";
     echo "<tr>";
     // * remotesystem
     echo "<td>";
     echo __('Utility used for remote check', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     $input = array();
     $input[''] = '------';
     $input['byssh'] = __('By ssh', 'monitoring');
     $input['nrpe'] = 'nrpe';
     $input['nsca'] = 'nsca';
     if ($this->fields['is_template'] == '1') {
         echo $input[$this->fields['remotesystem']];
     } else {
         Dropdown::showFromArray("remotesystem", $input, array('value' => $this->fields['remotesystem']));
     }
     echo "</td>";
     // * is_argument
     echo "<td>";
     echo __('Use arguments (Only for NRPE)', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     if ($this->fields['is_template'] == '1') {
         echo Dropdown::getYesNo($this->fields['is_arguments']);
     } else {
         Dropdown::showYesNo("is_arguments", $this->fields['is_arguments']);
     }
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     // alias command
     echo "<td>";
     echo __('Alias command if required (Only for NRPE)', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     if ($this->fields['is_template'] == '1') {
         echo "<input type='text' name='alias_commandservice' value='" . $this->fields['alias_command'] . "' />";
     } else {
         echo "<input type='text' name='alias_command' value='" . $this->fields['alias_command'] . "' />";
     }
     echo "</td>";
     echo "<td>";
     echo __('Command link (used for graphs generation)', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     if ($this->fields['is_template'] == '1') {
         $pMonitoringCommand->getFromDB($this->fields['aliasperfdata_commands_id']);
         echo $pMonitoringCommand->getLink(1);
     } else {
         $pMonitoringCommand->getFromDB($this->fields['aliasperfdata_commands_id']);
         Dropdown::show("PluginMonitoringCommand", array('name' => 'aliasperfdata_commands_id', 'value' => $this->fields['aliasperfdata_commands_id']));
     }
     echo "</td>";
     echo "</tr>";
     // * Manage arguments
     $array = array();
     $a_displayarg = array();
     if (isset($pMonitoringCommand->fields['command_line'])) {
         preg_match_all("/\\\$(ARG\\d+)\\\$/", $pMonitoringCommand->fields['command_line'], $array);
         $a_arguments = importArrayFromDB($this->fields['arguments']);
         foreach ($array[0] as $arg) {
             if (strstr($arg, "ARG")) {
                 $arg = str_replace('$', '', $arg);
                 if (!isset($a_arguments[$arg])) {
                     $a_arguments[$arg] = '';
                 }
                 $a_displayarg[$arg] = $a_arguments[$arg];
             }
         }
     }
     if (count($a_displayarg) > 0) {
         $a_argtext = importArrayFromDB($pMonitoringCommand->fields['arguments']);
         echo "<tr>";
         echo "<th colspan='4'>" . __('Arguments', 'monitoring') . "&nbsp;</th>";
         echo "</tr>";
         foreach ($a_displayarg as $key => $value) {
             echo "<tr>";
             echo "<th>" . $key . "</th>";
             echo "<td colspan='2'>";
             if (isset($a_argtext[$key])) {
                 echo nl2br($a_argtext[$key]) . "&nbsp;:";
             } else {
                 echo __('Argument', 'monitoring') . "&nbsp;:";
             }
             echo "</td>";
             echo "<td>";
             echo "<input type='text' name='arg[" . $key . "]' value='" . $value . "'/><br/>";
             echo "</td>";
             echo "</tr>";
         }
     }
     $this->showFormButtons($options);
     return true;
 }
 function showComponents($componentscatalogs_id)
 {
     global $DB, $CFG_GLPI;
     $this->addComponent($componentscatalogs_id);
     $rand = mt_rand();
     $pmComponent = new PluginMonitoringComponent();
     $pmCommand = new PluginMonitoringCommand();
     $pmCheck = new PluginMonitoringCheck();
     $calendar = new Calendar();
     echo "<form method='post' name='componentscatalog_component_form{$rand}' id='componentscatalog_component_form{$rand}' action=\"" . $CFG_GLPI["root_doc"] . "/plugins/monitoring/front/componentscatalog_component.form.php\">";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th>";
     echo __('Associated components', 'monitoring');
     echo "</th>";
     echo "</tr>";
     echo "</table>";
     echo "<table class='tab_cadre_fixe'>";
     echo "<tr>";
     echo "<th width='10'>&nbsp;</th>";
     echo "<th>" . __('Name') . "</th>";
     echo "<th>" . __('Command name', 'monitoring') . "</th>";
     echo "<th>" . __('Check definition', 'monitoring') . "</th>";
     echo "<th>" . __('Check period', 'monitoring') . "</th>";
     echo "<th>" . __('Remote check', 'monitoring') . "</th>";
     echo "</tr>";
     $used = array();
     $query = "SELECT * FROM `" . $this->getTable() . "`\n         WHERE `plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'";
     $result = $DB->query($query);
     while ($data = $DB->fetch_array($result)) {
         $used[] = $data['plugin_monitoring_components_id'];
         $pmComponent->getFromDB($data['plugin_monitoring_components_id']);
         echo "<tr>";
         echo "<td>";
         echo "<input type='checkbox' name='item[" . $data["id"] . "]' value='1'>";
         echo "</td>";
         echo "<td class='center'>";
         echo $pmComponent->getLink(1);
         echo "</td>";
         echo "<td class='center'>";
         $pmCommand->getFromDB($pmComponent->fields['plugin_monitoring_commands_id']);
         echo $pmCommand->getLink();
         echo "</td>";
         echo "<td class='center'>";
         $pmCheck->getFromDB($pmComponent->fields['plugin_monitoring_checks_id']);
         echo $pmCheck->getLink();
         echo "</td>";
         echo "<td class='center'>";
         $calendar->getFromDB($pmComponent->fields['calendars_id']);
         echo $calendar->getLink();
         echo "</td>";
         echo "<td class='center'>";
         if ($pmComponent->fields['remotesystem'] == '') {
             echo "-";
         } else {
             echo $pmComponent->fields['remotesystem'];
         }
         echo "</td>";
         echo "</tr>";
     }
     Html::openArrowMassives("componentscatalog_host_form{$rand}", true);
     Html::closeArrowMassives(array('deleteitem' => _sx('button', 'Delete permanently')));
     Html::closeForm();
     echo "</table>";
 }