示例#1
0
 /**
  * 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(), $copy = array())
 {
     global $DB, $CFG_GLPI;
     $pMonitoringCommand = new PluginMonitoringCommand();
     if ($items_id == '0') {
         $this->getEmpty();
         $this->fields['active_checks_enabled'] = 1;
         $this->fields['passive_checks_enabled'] = 1;
     } else {
         $this->getFromDB($items_id);
     }
     if (count($copy) > 0) {
         foreach ($copy as $key => $value) {
             $this->fields[$key] = stripslashes($value);
         }
     }
     $this->showTabs($options);
     $this->showFormHeader($options);
     if (isset($_SESSION['plugin_monitoring_components'])) {
         $this->fields = $_SESSION['plugin_monitoring_components'];
         if (!isset($this->fields["id"])) {
             $this->fields["id"] = '';
         }
         if (!isset($this->fields["arguments"])) {
             $this->fields["arguments"] = '';
         }
         unset($_SESSION['plugin_monitoring_components']);
     }
     echo "<tr>";
     echo "<td>";
     echo __('Name') . "<font class='red'>*</font>&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>";
     // * checks
     echo "<td>" . __('Check definition', 'monitoring') . "<font class='red'>*</font>&nbsp;:</td>";
     echo "<td>";
     Dropdown::show("PluginMonitoringCheck", array('name' => 'plugin_monitoring_checks_id', 'value' => $this->fields['plugin_monitoring_checks_id']));
     echo "</td>";
     echo "</tr>";
     // * Link
     echo "<tr>";
     echo "<td>";
     //      echo "Type of template&nbsp;:";
     echo "</td>";
     echo "<td>";
     //      $a_types = array();
     //      $a_types[''] = Dropdown::EMPTY_VALUE;
     //      $a_types['partition'] = "Partition";
     //      $a_types['processor'] = "Processor";
     //      Dropdown::showFromArray("link", $a_types, array('value'=>$this->fields['link']));
     echo "</td>";
     // * active check
     echo "<td>";
     echo __('Active checks', 'monitoring') . "<font class='red'>*</font>&nbsp;:";
     echo "</td>";
     echo "<td>";
     Dropdown::showYesNo("active_checks_enabled", $this->fields['active_checks_enabled']);
     echo "</td>";
     echo "</tr>";
     // * command
     echo "<tr>";
     echo "<td>";
     echo __('Command', 'monitoring') . "<font class='red'>*</font>&nbsp;:";
     echo "</td>";
     echo "<td>";
     $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>";
     // * passive check
     echo "<td>";
     echo __('Passive check', 'monitoring') . "<font class='red'>*</font>&nbsp;:";
     echo "</td>";
     echo "<td>";
     Dropdown::showYesNo("passive_checks_enabled", $this->fields['passive_checks_enabled']);
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>";
     echo __('Template (for graphs generation)', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     Dropdown::showFromArray("graph_template", PluginMonitoringPerfdata::listPerfdata(), array('value' => $this->fields['graph_template']));
     echo "</td>";
     // * calendar
     echo "<td>" . __('Check period', 'monitoring') . "<font class='red'>*</font>&nbsp;:</td>";
     echo "<td>";
     dropdown::show("Calendar", array('name' => 'calendars_id', 'value' => $this->fields['calendars_id']));
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>";
     echo __('Event handler', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     dropdown::show("PluginMonitoringEventhandler", array('name' => 'plugin_monitoring_eventhandlers_id', 'value' => $this->fields['plugin_monitoring_eventhandlers_id']));
     echo "</td>";
     echo "<td colspan='2'>";
     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'] = 'byssh';
     $input['nrpe'] = 'nrpe';
     $input['nsca'] = 'nsca';
     Dropdown::showFromArray("remotesystem", $input, array('value' => $this->fields['remotesystem']));
     echo "</td>";
     // * is_argument
     echo "<td>";
     echo __('Use arguments (NRPE only)', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     Dropdown::showYesNo("is_arguments", $this->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>";
     echo "<input type='text' name='alias_command' value='" . $this->fields['alias_command'] . "' />";
     echo "</td>";
     echo "<td colspan='2'></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_tags = $this->tagsAvailable();
         $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 "<td>";
             if (isset($a_argtext[$key]) and $a_argtext[$key] != '') {
                 echo nl2br($a_argtext[$key]) . "&nbsp;:";
             } else {
                 echo __('Argument', 'monitoring') . " (" . $key . ")&nbsp;:";
             }
             echo "</td>";
             echo "<td>";
             echo "<input type='text' name='arg[" . $key . "]' value='" . $value . "'/><br/>";
             echo "</td>";
             if (count($a_tags) > 0) {
                 foreach ($a_tags as $key => $value) {
                     echo "<td class='tab_bg_3'>";
                     echo "<strong>" . $key . "</strong>&nbsp;:";
                     echo "</td>";
                     echo "<td class='tab_bg_3'>";
                     echo $value;
                     echo "</td>";
                     unset($a_tags[$key]);
                     break;
                 }
             } else {
                 echo "<td colspan='2'></td>";
             }
             echo "</tr>";
         }
         foreach ($a_tags as $key => $value) {
             echo "<tr>";
             echo "<td colspan='2'></td>";
             echo "<td class='tab_bg_3'>";
             echo "<strong>" . $key . "</strong>&nbsp;:";
             echo "</td>";
             echo "<td class='tab_bg_3'>";
             echo $value;
             echo "</td>";
             echo "</tr>";
         }
     }
     echo "<tr>";
     echo "<th colspan='4'>" . __('Weathermap', 'monitoring') . "&nbsp;</th>";
     echo "</tr>";
     echo "<tr>";
     echo "<td>";
     echo __('Use this component for Weathermap', 'monitoring') . "&nbsp;:";
     echo "</td>";
     echo "<td>";
     Dropdown::showYesNo("is_weathermap", $this->fields['is_weathermap']);
     echo "</td>";
     echo "<td>";
     $tooltip = __('Example', 'monitoring') . " :<br/><br/>";
     $tooltip .= "perfdata : <i>inUsage=0.00%;85;98 outUsage=0.00%;85;98 inBandwidth=<strong>789944</strong>.00bps outBandwidth=486006.00bps inAbsolut=0 outAbsolut=12665653</i><br/><br/>";
     $tooltip .= __('Regex bandwidth input', 'monitoring') . " : <i><strong>(?:.*)inBandwidth=(\\d+)(?:.*)</strong></i><br/><br/>";
     $tooltip .= __('Assign the value from regular expression') . " : <strong>789944</strong>";
     echo __('Regex bandwidth input', 'monitoring') . "&nbsp;";
     Html::showToolTip($tooltip, array('autoclose' => false));
     echo "&nbsp;:";
     echo "</td>";
     echo "<td>";
     echo "<input type='text' name='weathermap_regex_in' value='" . $this->fields['weathermap_regex_in'] . "' size='40' />";
     echo "</td>";
     echo "</tr>";
     echo "<tr>";
     echo "<td colspan='2'>";
     echo "</td>";
     echo "<td>";
     $tooltip = __('Example', 'monitoring') . " :<br/><br/>";
     $tooltip .= "perfdata : <i>inUsage=0.00%;85;98 outUsage=0.00%;85;98 inBandwidth=789944.00bps outBandwidth=<strong>486006</strong>.00bps inAbsolut=0 outAbsolut=12665653</i><br/><br/>";
     $tooltip .= __('Regex bandwidth output', 'monitoring') . " : <i><strong>(?:.*)outBandwidth=(\\d+)(?:.*)</strong></i><br/><br/>";
     $tooltip .= __('Assign the value from regular expression') . " : <strong>789944</strong>";
     echo __('Regex bandwidth output', 'monitoring') . "&nbsp;";
     Html::showToolTip($tooltip, array('autoclose' => false));
     echo "&nbsp;:";
     echo "</td>";
     echo "<td>";
     echo "<input type='text' name='weathermap_regex_out' value='" . $this->fields['weathermap_regex_out'] . "' size='40' />";
     echo "</td>";
     echo "</tr>";
     $this->showFormButtons($options);
     $this->addDivForTabs();
     return true;
 }