------------------------------------------------------------------------ @package Plugin Monitoring for GLPI @author David Durieux @co-author @comment @copyright Copyright (c) 2011-2014 Plugin Monitoring for GLPI team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link https://forge.indepnet.net/projects/monitoring/ @since 2014 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; Session::checkRight("plugin_monitoring_servicescatalog", READ); Html::header(__('Monitoring', 'monitoring'), $_SERVER["PHP_SELF"], "plugins", "monitoring", "businessrules"); $pmBusinessrule_component = new PluginMonitoringBusinessrule_component(); $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); if (isset($_POST['add'])) { if (!isset($_POST['plugin_monitoring_components_id']) || $_POST['plugin_monitoring_components_id'] < 1) { Html::back(); } $a_data = current($pmComponentscatalog_Component->find("`plugin_monitoring_componentscalalog_id`='" . $_POST['plugin_monitoring_componentscatalogs_id'] . "'\n AND `plugin_monitoring_components_id`='" . $_POST['plugin_monitoring_components_id'] . "'", '', 1)); $_POST['plugin_monitoring_componentscatalogs_components_id'] = $a_data['id']; $pmBusinessrule_component->add($_POST); $pmBusinessrule_component->replayDynamicServices($_POST['plugin_monitoring_businessrulegroups_id']); } Html::back(); Html::footer();
public function testPHPlogs() { global $CFG_GLPI, $PLUGIN_HOOKS; $_SESSION['glpi_use_mode'] = 2; $_SESSION["glpiID"] = 2; $_SESSION["glpiactiveentities_string"] = 0; $PLUGIN_HOOKS = plugin_init_monitoring(); plugin::load("monitoring"); $CFG_GLPI['root_doc'] = "http://127.0.0.1/fusion0.80/"; loadLanguage("en_GB"); $pmComponent = new PluginMonitoringComponent(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmService = new PluginMonitoringService(); $computer = new Computer(); // Add components $input = array(); $input['name'] = 'Host alive'; $input['plugin_monitoring_commands_id '] = '21'; $input['plugin_monitoring_checks_id'] = '1'; $input['calendars_id'] = '1'; $components_id = $pmComponent->add($input); // Add components catalog $input = array(); $input['name'] = 'linux servers'; $catalogs_id = $pmComponentscatalog->add($input); $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $catalogs_id; $input['plugin_monitoring_components_id'] = $components_id; $pmComponentscatalog_Component->add($input); // Add Computer $input = array(); $input['name'] = 'pc1'; $input['entities_id'] = 0; $pc1 = $computer->add($input); // Check computer pc1 not added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '0', '[f1] Computer in component cataglog and may not be'); $input = array(); $input['plugin_monitoring_componentscalalog_id'] = $catalogs_id; $input['name'] = 'all have name'; $input['itemtype'] = 'Computer'; $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["pc"],"itemtype":"Computer","start":"0"}'; $rules_id = $pmComponentscatalog_rule->add($input); // Check computer pc1 not added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '1', '[f2] Computer may be in component catalog'); // Check service of this computer created $a_services = $pmService->find(); $this->assertEquals(count($a_services), '1', '[s2] One service may be created'); // Add Computer $input = array(); $input['name'] = 'pc2'; $input['entities_id'] = 0; $pc2 = $computer->add($input); // Check computer pc1 not added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '2', '[f3] 2 computers may be in component catalog'); // Check service of this computer created $a_services = $pmService->find(); $this->assertEquals(count($a_services), '2', '[s3] 2 services may be created'); // Remove pc2 $computer->delete(array('id' => $pc2), 1); // Check computer pc1 added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '1', '[f4] Computer may be unique in component catalog'); // Check service of this computer created $a_services = $pmService->find(); $this->assertEquals(count($a_services), '1', '[s4] One service may be created'); // Modify rule $input['id'] = $rules_id; $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["tc"],"itemtype":"Computer","start":"0"}'; $pmComponentscatalog_rule->update($input); // Check no computer in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '0', '[f5] Computer may be deleted on rule update'); // Check service $a_services = $pmService->find(); $this->assertEquals(count($a_services), '0', '[s5] No service may be created'); // Modify rule $input['id'] = $rules_id; $input['condition'] = '{"field":["1"],"searchtype":["contains"],"contains":["pc"],"itemtype":"Computer","start":"0"}'; $pmComponentscatalog_rule->update($input); // Check computer pc1 added in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '1', '[f6] Computer may be unique in component catalog'); // Delete rule $pmComponentscatalog_rule->delete(array('id' => $rules_id), 1); // Check not have computer in ressources $a_hosts = $pmComponentscatalog_Host->find("`plugin_monitoring_componentscalalog_id`='" . $catalogs_id . "'"); $this->assertEquals(count($a_hosts), '0', '[f7] must have no computer in component catalog'); // Check service $a_services = $pmService->find(); $this->assertEquals(count($a_services), '0', '[s7] No service may be created'); }
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') . " :"; 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 " "; 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') . " :"; 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'> "; 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; }
function showSyntheseReport($componentscatalogs_id) { global $CFG_GLPI; if (!isset($_SESSION['glpi_plugin_monitoring']['synthese'])) { $_SESSION['glpi_plugin_monitoring']['synthese'] = array(); } if (!isset($_SESSION['glpi_plugin_monitoring']['synthese'][$componentscatalogs_id])) { $_SESSION['glpi_plugin_monitoring']['synthese'][$componentscatalogs_id] = array(); } $sess = $_SESSION['glpi_plugin_monitoring']['synthese'][$componentscatalogs_id]; $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponent = new PluginMonitoringComponent(); $a_options = array(); $this->getFromDB($componentscatalogs_id); echo "<form name='form' method='post' action='".$CFG_GLPI['root_doc']."/plugins/monitoring/front/report_componentscatalog.form.php'>"; echo "<table class='tab_cadre_fixe'>"; echo '<tr class="tab_bg_1">'; echo '<th colspan="5">'; echo __('Report'); echo "<input type='hidden' name='componentscatalogs_id' value='".$componentscatalogs_id."' />"; echo "<input type='hidden' name='reporttype' value='synthese' />"; $a_options['componentscatalogs_id'] = $componentscatalogs_id; echo '</th>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<td>'; echo '</td>'; echo '<td colspan="2">'; $default_value = 12; if (isset($sess['synthesenumber'])) { $default_value = $sess['synthesenumber']; } Dropdown::showNumber("synthesenumber", array( 'value' => $default_value, 'min' => 2, 'max' => 30) ); $a_options['synthesenumber'] = $default_value; echo " "; $a_time = array('week' => __('Week'), 'month' => __('Month'), 'year' => __('Year')); $default_value = 'week'; if (isset($sess['synthesenumber'])) { $default_value = $sess['synthesenumber']; } Dropdown::showFromArray("syntheseperiod", $a_time, array('value' => $default_value)); $a_options['syntheseperiod'] = $default_value; echo '</td>'; echo "<td>".__('End date')." :</td>"; echo "<td>"; $default_value = date('Y-m-d'); if (isset($sess['synthesedate_end'])) { $default_value = $sess['synthesedate_end']; } Html::showDateFormItem("synthesedate_end", $default_value); $a_options['synthesedate_end'] = $default_value; echo "</td>"; echo '</tr>'; echo "</table>"; echo "<table class='tab_cadre_fixe'>"; $a_composants = $pmComponentscatalog_Component->find("`plugin_monitoring_componentscalalog_id`='".$componentscatalogs_id."'"); foreach ($a_composants as $comp_data) { $pmComponent->getFromDB($comp_data['plugin_monitoring_components_id']); echo "<tr class='tab_bg_1'>"; echo "<td width='10'>"; //echo "<input type='checkbox' name='components_id[]' value='".$pmComponent->getID()."' checked />"; echo "<input type='hidden' name='components_id[]' value='".$pmComponent->getID()."' />"; $a_options['components_id'][] = $pmComponent->getID(); echo "</td>"; echo "<td>"; echo $pmComponent->getLink(); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td width='10'>"; echo "</td>"; echo "<td>"; PluginMonitoringToolbox::loadPreferences($pmComponent->getID()); $a_perfnames = PluginMonitoringServicegraph::getperfdataNames($pmComponent->fields['graph_template']); echo "<table class='tab_cadre_fixe'>"; echo "<tr class='tab_bg_3'>"; echo "<td rowspan='".count($a_perfnames)."' width='90'>"; echo __('Use for report', 'monitoring')." :"; echo "</td>"; $i = 0; $j = 0; if (!isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()])) { foreach ($a_perfnames as $name) { $_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()][$name] = 'checked'; } } foreach ($a_perfnames as $name) { if ($i > 0) { echo "<tr class='tab_bg_3'>"; } echo "<td>"; $checked = "checked"; if (isset($sess['perfname']) && isset($sess['perfname'][$pmComponent->getID()])) { if (isset($sess['perfname'][$pmComponent->getID()])) { $checked = ""; } if (isset($sess['perfname'][$pmComponent->getID()][$name])) { $checked = "checked"; } } else { if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()])) { $checked = ""; } if (isset($_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()][$name])) { $checked = $_SESSION['glpi_plugin_monitoring']['perfname'][$pmComponent->getID()][$name]; } } echo "<input type='checkbox' name='perfname[".$pmComponent->getID()."][".$name."]' value='".$name."' ".$checked."/> ".$name; if ($checked == 'checked') { $a_options['perfname'][$pmComponent->getID()][] = $name; } echo "</td>"; echo "<td>"; echo __('Best is high value', 'monitoring').' :'; echo "</td>"; echo "<td>"; $default_value = 1; if (isset($sess['perfname_val']) && isset($sess['perfname_val'][$pmComponent->getID()])) { if (isset($sess['perfname_val'][$pmComponent->getID()][$name])) { $default_value = $sess['perfname_val'][$pmComponent->getID()][$name]; } } Dropdown::showYesNo('perfname_val['.$pmComponent->getID().']['.$name.']', $default_value); if ($checked == 'checked') { $a_options['perfname_val'][$pmComponent->getID()][$name] = $default_value; } echo "</td>"; echo "</tr>"; $i++; } echo "</table>"; echo "</td>"; echo "</tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' align='center'>"; echo "<input type='submit' class='submit' name='update' value='".__('Save')."'/>"; echo " <input type='submit' class='submit' name='generatepdf' value='".__('Generate PDF', 'monitoring')."'/>"; echo "</td>"; echo "</tr>"; echo "</table>"; Html::closeForm(); if (isset($_SESSION['plugin_monitoring_report'])) { // $a_options = $_SESSION['plugin_monitoring_report']; } $this->generateSyntheseReport( $_SESSION['glpi_plugin_monitoring']['synthese'][$componentscatalogs_id], FALSE); }
function showReport($componentscatalogs_id) { global $CFG_GLPI; $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponent = new PluginMonitoringComponent(); $this->getFromDB($componentscatalogs_id); echo "<form name='form' method='post' \n action='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/report_componentscatalog.form.php'>"; echo "<table class='tab_cadre_fixe'>"; echo '<tr class="tab_bg_1">'; echo '<th colspan="5">'; echo __('Report'); echo "<input type='hidden' name='componentscatalogs_id' value='" . $componentscatalogs_id . "' />"; echo '</th>'; echo '</tr>'; // ** simple report echo '<tr class="tab_bg_1">'; echo '<tr class="tab_bg_1">'; echo '<td>'; echo '<input type="radio" name="reporttype" value="simplereport" checked />'; echo '</td>'; echo '<td colspan="4">'; echo '<strong>' . __('Simple report', "monitoring") . '</strong>'; echo '</td>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<td>'; echo '</td>'; echo "<td>" . __('Start date') . " :</td>"; echo "<td>"; Html::showDateFormItem("date_start", date('Y-m-d H:i:s', date('U') - 24 * 3600 * 7)); echo "</td>"; echo "<td>" . __('End date') . " :</td>"; echo "<td>"; Html::showDateFormItem("date_end", date('Y-m-d')); echo "</td>"; echo "</tr>"; // ** synthese echo '<tr class="tab_bg_1">'; echo '<td>'; echo '<input type="radio" name="reporttype" value="synthese" />'; echo '</td>'; echo '<td colspan="4">'; echo '<strong>' . __('Synthese', "monitoring") . '</strong>'; echo '</td>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<td>'; echo '</td>'; echo '<td colspan="2">'; Dropdown::showNumber("synthesenumber", array('value' => 12, 'min' => 2, 'max' => 30)); echo " "; $a_time = array('week' => __('Week'), 'month' => __('Month'), 'year' => __('Year')); Dropdown::showFromArray("syntheseperiod", $a_time); echo '</td>'; echo "<td>" . __('End date') . " :</td>"; echo "<td>"; Html::showDateFormItem("synthesedate_end", date('Y-m-d')); echo "</td>"; echo '</tr>'; // ** synthese ++ echo '<tr class="tab_bg_1">'; echo '<td>'; echo '<input type="radio" name="reporttype" value="syntheseplus" />'; echo '</td>'; echo '<td colspan="4">'; echo '<strong>' . __('Synthese detail', "monitoring") . '</strong>'; echo '</td>'; echo '</tr>'; echo '<tr class="tab_bg_1">'; echo '<td>'; echo '</td>'; echo '<td colspan="2">'; Dropdown::showNumber("syntheseplusnumber", array('value' => 12, 'min' => 2, 'max' => 30)); echo " "; $a_time = array('week' => __('Week'), 'month' => __('Month'), 'year' => __('Year')); Dropdown::showFromArray("syntheseplusperiod", $a_time); echo '</td>'; echo "<td>" . __('End date') . " :</td>"; echo "<td>"; Html::showDateFormItem("syntheseplusdate_end", date('Y-m-d')); echo "</td>"; echo '</tr>'; echo "</table>"; echo "<table class='tab_cadre_fixe'>"; $a_composants = $pmComponentscatalog_Component->find("`plugin_monitoring_componentscalalog_id`='" . $componentscatalogs_id . "'"); foreach ($a_composants as $comp_data) { $pmComponent->getFromDB($comp_data['plugin_monitoring_components_id']); echo "<tr class='tab_bg_1'>"; echo "<td width='10'>"; echo "<input type='checkbox' name='components_id[]' value='" . $pmComponent->getID() . "' checked />"; echo "</td>"; echo "<td>"; echo $pmComponent->getLink(); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td width='10'>"; echo "</td>"; echo "<td>"; PluginMonitoringServicegraph::preferences($pmComponent->getID(), 1, 1); echo "</td>"; echo "</tr>"; } echo "<tr class='tab_bg_1'>"; echo "<td colspan='2' align='center'>"; echo "<input type='submit' class='submit' name='generate' value='" . __('Generate the report', 'monitoring') . "'/>"; echo "</td>"; echo "</tr>"; Html::closeForm(); }
/** * Display content of tab * * @param CommonGLPI $item * @param integer $tabnum * @param interger $withtemplate * * @return boolean true */ static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) { if ($item->getType() == 'PluginMonitoringComponent') { if ($tabnum == '0') { $item->copyItem($item->getID()); } else { if ($tabnum == '1') { PluginMonitoringComponentscatalog_Component::listForComponents($item->getID()); } else { if ($tabnum == '2') { $item->preferences($item->getID()); } } } } return true; }
function replayDynamicServices($plugin_monitoring_businessrulegroups_id) { global $DB; if ($plugin_monitoring_businessrulegroups_id == 0) { return; } // Get entity and if recursif $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup(); $pmServicescatalog = new PluginMonitoringServicescatalog(); $pmBusinessrulegroup->getFromDB($plugin_monitoring_businessrulegroups_id); $pmServicescatalog->getFromDB($pmBusinessrulegroup->fields['plugin_monitoring_servicescatalogs_id']); if ($pmServicescatalog->fields['is_recursive']) { $a_sons = getSonsOf("glpi_entities", $pmServicescatalog->fields['entities_id']); $restrict_entities = "AND ( `glpi_plugin_monitoring_services`.`entities_id` IN ('" . implode("','", $a_sons) . "') )"; } else { $restrict_entities = "AND ( `glpi_plugin_monitoring_services`.`entities_id` = '" . $pmServicescatalog->fields['entities_id'] . "' )"; } $a_brcomponents = $this->find("`plugin_monitoring_businessrulegroups_id`='" . $plugin_monitoring_businessrulegroups_id . "'"); $a_services = array(); foreach ($a_brcomponents as $a_brcomponent) { $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponentscatalog_Component->getFromDB($a_brcomponent['plugin_monitoring_componentscatalogs_components_id']); // Get all services of component of component catalog $query = "SELECT `glpi_plugin_monitoring_services`.`id` FROM `glpi_plugin_monitoring_services`" . " LEFT JOIN `glpi_plugin_monitoring_componentscatalogs_hosts`" . " ON plugin_monitoring_componentscatalogs_hosts_id=" . " `glpi_plugin_monitoring_componentscatalogs_hosts`.`id`" . " WHERE `glpi_plugin_monitoring_services`.`plugin_monitoring_components_id`" . " = '" . $pmComponentscatalog_Component->fields['plugin_monitoring_components_id'] . "' " . $restrict_entities; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { $a_services[$data['id']] = $data['id']; } } // get static services of the group (so not add dynamic if yet in static) $pmBusinessrule_component = new PluginMonitoringBusinessrule_component(); $pmBusinessrule = new PluginMonitoringBusinessrule(); $a_static = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $plugin_monitoring_businessrulegroups_id . "'" . " AND `is_dynamic`=0"); foreach ($a_static as $data) { if (isset($a_services[$data['plugin_monitoring_services_id']])) { unset($a_services[$data['plugin_monitoring_services_id']]); // Update generic status $pmBusinessrule->getFromDB($data['id']); $input = array('id' => $data['id'], 'is_generic' => $pmServicescatalog->fields['is_generic']); $pmBusinessrule->update($input); } } // update services + is_dynamic=1 $query = "SELECT * FROM `glpi_plugin_monitoring_businessrules`" . " WHERE `plugin_monitoring_businessrulegroups_id`='" . $plugin_monitoring_businessrulegroups_id . "'" . " AND `is_dynamic`=1"; $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { // Update if yet in DB if (isset($a_services[$data['plugin_monitoring_services_id']])) { unset($a_services[$data['plugin_monitoring_services_id']]); // Update generic status $pmBusinessrule->getFromDB($data['id']); $input = array('id' => $data['id'], 'is_generic' => $pmServicescatalog->fields['is_generic']); $pmBusinessrule->update($input); } else { // delete if not exist $pmBusinessrule->delete($data); } } // Add new foreach ($a_services as $services_id) { $input = array('plugin_monitoring_businessrulegroups_id' => $plugin_monitoring_businessrulegroups_id, 'plugin_monitoring_services_id' => $services_id, 'is_dynamic' => '1', 'is_generic' => $pmServicescatalog->fields['is_generic']); $pmBusinessrule->add($input); } }
if (!isset($_POST["sort"])) { $_POST["sort"] = ""; } if (!isset($_POST["order"])) { $_POST["order"] = ""; } if (!isset($_POST["withtemplate"])) { $_POST["withtemplate"] = ""; } $pmComponentscatalog = new PluginMonitoringComponentscatalog(); if ($_POST["id"] > 0 && $pmComponentscatalog->can($_POST["id"], 'r')) { switch ($_POST['glpi_tab']) { case -1: break; case 1: $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); $pmComponentscatalog_Component->showComponents($_POST['id']); break; case 2: $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog_Host->showHosts($_POST['id'], 1); break; case 3: $pmComponentscatalog_rule = new PluginMonitoringComponentscatalog_rule(); $pmComponentscatalog_rule->showRules($_POST['id']); break; case 4: $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmComponentscatalog_Host->showHosts($_POST['id'], 0); break; case 5:
@package Plugin Monitoring for GLPI @author David Durieux @co-author @comment @copyright Copyright (c) 2011-2014 Plugin Monitoring for GLPI team @license AGPL License 3.0 or (at your option) any later version http://www.gnu.org/licenses/agpl-3.0-standalone.html @link https://forge.indepnet.net/projects/monitoring/ @since 2011 ------------------------------------------------------------------------ */ include "../../../inc/includes.php"; Session::checkRight("plugin_monitoring_componentscatalog", READ); $pmComponentscatalog_Component = new PluginMonitoringComponentscatalog_Component(); if (isset($_POST["add"])) { $pmComponentscatalog_Component->add($_POST); $pmComponentscatalog_Component->addComponentToItems($_POST['plugin_monitoring_componentscalalog_id'], $_POST['plugin_monitoring_components_id']); Html::back(); } else { if (isset($_POST["deleteitem"])) { foreach ($_POST["item"] as $id => $num) { $fields = array(); $pmComponentscatalog_Component->getFromDB($id); $fields = $pmComponentscatalog_Component->fields; $pmComponentscatalog_Component->delete(array('id' => $id)); $pmComponentscatalog_Component->removeComponentToItems($fields['plugin_monitoring_componentscalalog_id'], $fields['plugin_monitoring_components_id']); } Html::back(); }