/** * Print the computer form * * @param $ID integer ID of the item * @param $options array * - target for the Form * - withtemplate template or basic computer * *@return Nothing (display) **/ function showForm($ID, $options = array()) { global $CFG_GLPI, $DB; $this->initForm($ID, $options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; //TRANS: %1$s is a string, %2$s a second one without spaces between them : to change for RTL echo "<td>" . sprintf(__('%1$s%2$s'), __('Name'), isset($options['withtemplate']) && $options['withtemplate'] ? "*" : "") . "</td>"; echo "<td>"; $objectName = autoName($this->fields["name"], "name", isset($options['withtemplate']) && $options['withtemplate'] == 2, $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, 'name', array('value' => $objectName)); echo "</td>"; echo "<td>" . __('Status') . "</td>"; echo "<td>"; State::dropdown(array('value' => $this->fields["states_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_visible_computer`")); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Location') . "</td>"; echo "<td>"; Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Type') . "</td>"; echo "<td>"; ComputerType::dropdown(array('value' => $this->fields["computertypes_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Technician in charge of the hardware') . "</td>"; echo "<td>"; User::dropdown(array('name' => 'users_id_tech', 'value' => $this->fields["users_id_tech"], 'right' => 'own_ticket', 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Manufacturer') . "</td>"; echo "<td>"; Manufacturer::dropdown(array('value' => $this->fields["manufacturers_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group in charge of the hardware') . "</td>"; echo "<td>"; Group::dropdown(array('name' => 'groups_id_tech', 'value' => $this->fields['groups_id_tech'], 'entity' => $this->fields['entities_id'], 'condition' => '`is_assign`')); echo "</td>"; echo "<td>" . __('Model') . "</td>"; echo "<td>"; ComputerModel::dropdown(array('value' => $this->fields["computermodels_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; //TRANS: Number of the alternate username echo "<td>" . __('Alternate username number') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'contact_num'); echo "</td>"; echo "<td>" . __('Serial number') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'serial'); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Alternate username') . "</td>"; echo "<td>"; Html::autocompletionTextField($this, 'contact'); echo "</td>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Inventory number'), isset($options['withtemplate']) && $options['withtemplate'] ? "*" : "") . "</td>"; echo "<td>"; $objectName = autoName($this->fields["otherserial"], "otherserial", isset($options['withtemplate']) && $options['withtemplate'] == 2, $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, 'otherserial', array('value' => $objectName)); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('User') . "</td>"; echo "<td>"; User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); echo "</td>"; echo "<td>" . __('Network') . "</td>"; echo "<td>"; Network::dropdown(array('value' => $this->fields["networks_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group') . "</td>"; echo "<td>"; Group::dropdown(array('value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"], 'condition' => '`is_itemgroup`')); echo "</td>"; // Display auto inventory informations $rowspan = 10; $inventory_show = false; if (!empty($ID) && Plugin::haveImport() && $this->fields["is_dynamic"]) { $inventory_show = true; $rowspan -= 4; } echo "<td rowspan='{$rowspan}'>" . __('Comments') . "</td>"; echo "<td rowspan='{$rowspan}' class='middle'>"; echo "<textarea cols='45' rows='" . ($rowspan + 3) . "' name='comment' >" . $this->fields["comment"]; echo "</textarea></td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Domain') . "</td>"; echo "<td >"; Domain::dropdown(array('value' => $this->fields["domains_id"], 'entity' => $this->fields["entities_id"])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Operating system') . "</td>"; echo "<td>"; OperatingSystem::dropdown(array('value' => $this->fields["operatingsystems_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Service pack') . "</td>"; echo "<td >"; OperatingSystemServicePack::dropdown(array('value' => $this->fields["operatingsystemservicepacks_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Version of the operating system') . "</td>"; echo "<td >"; OperatingSystemVersion::dropdown(array('value' => $this->fields["operatingsystemversions_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Product ID of the operating system') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'os_licenseid'); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Serial of the operating system') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'os_license_number'); echo "</td>"; if ($inventory_show) { echo "<td rowspan='4' colspan='2'>"; Plugin::doHook("autoinventory_information", $this); echo "</td>"; } echo "</tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('UUID') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'uuid'); echo "</td>"; echo "</tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>"; if ((!isset($options['withtemplate']) || $options['withtemplate'] == 0) && !empty($this->fields['template_name'])) { echo "<span class='small_space'>"; printf(__('Created from the template %s'), $this->fields['template_name']); echo "</span>"; } else { echo " "; } echo "</td><td>"; if (isset($options['withtemplate']) && $options['withtemplate']) { //TRANS: %s is the datetime of insertion printf(__('Created on %s'), Html::convDateTime($_SESSION["glpi_currenttime"])); } else { //TRANS: %s is the datetime of update printf(__('Last update on %s'), Html::convDateTime($this->fields["date_mod"])); } echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Update Source') . "</td>"; echo "<td >"; AutoUpdateSystem::dropdown(array('value' => $this->fields["autoupdatesystems_id"])); echo "</td></tr>"; $this->showFormButtons($options); return true; }
/** * Get comments for host * $id, host id * default is current host instance * */ function getComments($id=-1) { global $CFG_GLPI; if ($id == -1) { $pm_Host = $this; } else { $pm_Host = new PluginMonitoringHost(); $pm_Host->getFromDB($id); } // Toolbox::logInFile("pm", "Host getcomments : $id : ".$pm_Host->getID()."\n"); $comment = ""; $toadd = array(); // associated computer ... $item = new $pm_Host->fields['itemtype']; $item->getFromDB($pm_Host->fields['items_id']); if ($pm_Host->getField('itemtype') == 'Computer') { if ($item->isField('completename')) { $toadd[] = array('name' => __('Complete name'), 'value' => nl2br($item->getField('completename'))); } $type = new ComputerType(); if ($item->getField("computertypes_id")) { $type->getFromDB($item->getField("computertypes_id")); $type = $type->getName(); if (! empty($type)) { $toadd[] = array('name' => __('Type'), 'value' => nl2br($type)); } } else { return $comment; } $model = new ComputerModel(); if ($item->getField("computermodels_id")) { $model->getFromDB($item->getField("computermodels_id")); $model = $model->getName(); if (! empty($model)) { $toadd[] = array('name' => __('Model'), 'value' => nl2br($model)); } } $state = new State(); $state->getFromDB($item->fields["states_id"]); $state = $state->getName(); if (! empty($state)) { $toadd[] = array('name' => __('State'), 'value' => nl2br($state)); } $entity = new Entity(); $entity->getFromDB($item->fields["entities_id"]); $entity = $entity->getName(); if (! empty($entity)) { $toadd[] = array('name' => __('Entity'), 'value' => nl2br($entity)); } $location = new Location(); $location->getFromDB($item->fields["locations_id"]); $location = $location->getName(array('complete' => true)); if (! empty($location)) { $toadd[] = array('name' => __('Location'), 'value' => nl2br($location)); } if (! empty($item->fields["serial"])) { $toadd[] = array('name' => __('Serial'), 'value' => nl2br($item->fields["serial"])); } if (! empty($item->fields["otherserial"])) { $toadd[] = array('name' => __('Inventory number'), 'value' => nl2br($item->fields["otherserial"])); } if (($pm_Host instanceof CommonDropdown) && $pm_Host->isField('comment')) { $toadd[] = array('name' => __('Comments'), 'value' => nl2br($pm_Host->getField('comment'))); } if (count($toadd)) { foreach ($toadd as $data) { $comment .= sprintf(__('%1$s: %2$s')."<br>", "<span class='b'>".$data['name'], "</span>".$data['value']); } } } else { $toadd[] = array('name' => __('Host type'), 'value' => nl2br($item->getTypeName())); if ($item->isField('completename')) { $toadd[] = array('name' => __('Complete name'), 'value' => nl2br($item->getField('completename'))); } } if (!empty($comment)) { return Html::showToolTip($comment, array('display' => false)); } }
/** Generate bigdump : generate global dropdowns **/ function generateGlobalDropdowns() { global $MAX, $DB; $items = array("CD", "CD-RW", "DVD-R", "DVD+R", "DVD-RW", "DVD+RW", "ramette papier", "disk'ette", "ZIP"); $dp = new ConsumableItemType(); for ($i=0 ; $i<$MAX['consumable_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' consommable $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("phone d'power"); $dp = new PhonePowerSupply(); for ($i=0 ; $i<$MAX['phone_power'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "power ' $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Grand", "Moyen", "Mic'ro", "1U", "5U"); $dp = new DeviceCaseType(); for ($i=0 ; $i<$MAX['case_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "power ' $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Laser", "Jet d'Encre", "Encre Solide"); $dp = new CartridgeItemType(); for ($i=0 ; $i<$MAX['cartridge_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' cartouche $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Technicien", "Commercial", "Technico-Commercial", "President", "Secretaire", "Directeur d'agence"); $dp = new ContactType(); for ($i=0 ; $i<$MAX['contact_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' contact $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Maintenance", "Support", "Location", "Adhesion"); $dp = new ContractType(); for ($i=0 ; $i<$MAX['contract_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' crontact $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Fournisseur", "Transporteur", "SSII", "Revendeur d'", "Assembleur", "SSLL", "Financeur", "Assureur"); $dp = new SupplierType(); for ($i=0 ; $i<$MAX['enttype'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d'entreprise $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("H.07.02", "I.07.56", "P51", "P52", "1.60", "4.06", "43-4071299", "1.0.14", "3.0.1", "rev 1.0", "rev 1.1", "rev 1.2", "rev 1.2.1", "rev 2.0", "rev 3.0"); $dp = new NetworkEquipmentFirmware(); for ($i=0 ; $i<$MAX['firmware'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "firmware $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Fire'wire"); $dp = new InterfaceType(); for ($i=0 ; $i<$MAX['interface'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d' disque dur $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("100 Base TX", "100 Base T4", "10 base T", "1000 Base SX", "1000 Base LX", "1000 Base T", "ATM", "802.3 10 Base 2", "IEEE 803.3 10 Base 5"); $dp = new NetworkInterface(); for ($i=0 ; $i<$MAX['iface'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type carte reseau $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Non", "Oui - generique", "Oui - specifique d'entite"); $dp = new AutoUpdateSystem(); for ($i=0 ; $i<$MAX['auto_update'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de mise a jour '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Assemble", "Latitude C600", "Latitude C700", "VAIO FX601", "VAIO FX905P", "VAIO TR5MP", "L5000C", "A600K", "PowerBook G4"); $dp = new ComputerModel(); for ($i=0 ; $i<$MAX['model'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "Modele $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment' $val"))); } $items = array("4200 DTN", "4200 DN", "4200 N", "8400 ADP", "7300 ADP", "5550 DN", "PIXMA iP8500", "Stylus Color 3000", "DeskJet 5950"); $dp = new PrinterModel(); for ($i=0 ; $i<$MAX['model_printers'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele imprimante $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("LS902UTG", "MA203DT", "P97F+SB", "G220F", "10-30-75", "PLE438S-B0S", "PLE481S-W", "L1740BQ", "L1920P", "SDM-X73H"); $dp = new MonitorModel(); for ($i=0 ; $i<$MAX['model_monitors'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele moniteur $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("HP 4108GL", "HP 2524", "HP 5308", "7600", "Catalyst 4500", "Catalyst 2950", "Catalyst 3750", "Catalyst 6500"); $dp = new NetworkEquipmentModel(); for ($i=0 ; $i<$MAX['model_networking'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele materiel reseau $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("DCS-2100+", "DCS-2100G", "KD-P35B", "Optical 5000", "Cordless", "ASR 600", "ASR 375", "CS21", "MX5020", "VS4121", "T3030", "T6060"); $dp = new PeripheralModel(); for ($i=0 ; $i<$MAX['model_peripherals'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele peripherique $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Alcatel Temporis 22", "Aastra 5370ip", "Alcatel-Lucent 400 DECT Handset", "BlackBerry Curve 9300"); $dp = new PhoneModel(); for ($i=0 ; $i<$MAX['model_phones'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "modele phone $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment' $val"))); } $items = array("SIC", "LMS", "LMP", "LEA", "SP2MI", "STIC", "MATH", "ENS-MECA", "POUBELLE", "WIFI"); $dp = new Network(); for ($i=0 ; $i<$MAX['network'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "reseau $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Windows XP Pro SP2", "Linux (Debian)", "Mac OS X", "Linux (Mandriva 2006)", "Linux (Redhat)", "Windows 98", "Windows 2000", "Windows XP Pro SP1", "LINUX (Suse)", "Linux (Mandriva 10.2)"); $dp = new OperatingSystem(); for ($i=0 ; $i<$MAX['os'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "os $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("XP Pro", "XP Home", "10.0", "10.1", "10.2", "2006", "Sarge"); $dp = new operatingSystemVersion(); for ($i=0 ; $i<$MAX['os_version'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "osversion $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Service Pack 1", "Service Pack 2", "Service Pack 3", "Service Pack 4"); $dp = new OperatingSystemServicePack(); for ($i=0 ; $i<$MAX['os_sp'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "ossp $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("DDR2"); $dp = new DeviceMemoryType(); for ($i=0 ; $i<$MAX['ram_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de ram $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment' $val"))); } $items = array('Bureautique', 'Calcul', "logiciel d'antivirus", 'Multimédia'); $dp = new SoftwareCategory(); for ($i=0 ; $i<max(1,pow($MAX['softwarecategory'],1/2)) ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "category $i"; } $newID = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['softwarecategory'],1/2)) ; $j++) { $newID2 = $dp->add(toolbox::addslashes_deep(array('name' => "s-category '$j", 'comment' => "comment d' $val s-category $j", 'softwarecategories_id' => $newID))); } } $MAX['rubdocs'] = getMaxItem('glpi_softwarecategories'); $dp = new SoftwareLicenseType(); for ($i=0 ; $i<$MAX['licensetype'] ; $i++) { $val = "type ' $i"; $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("SIC", "LMS", "LMP", "LEA", "SP2MI", "STIC", "MATH", "ENS-MECA", "POUBELLE", "WIFI"); $dp = new Vlan(); for ($i=0 ; $i<$MAX['vlan'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "VLAN $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val", 'tag' => $i))); } $items = array("Portable", "Desktop", "Tour"); $dp = new ComputerType(); for ($i=0 ; $i<$MAX['type_computers'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type ordinateur $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Laser A4", "Jet d'Encre", "Laser A3", "Encre Solide A4", "Encre Solide A3"); $dp = new PrinterType(); for ($i=0 ; $i<$MAX['type_printers'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type d'imprimante $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("TFT 17", "TFT 19", "TFT 21", "CRT 17", "CRT 19", "CRT 21", "CRT 15"); $dp = new MonitorType(); for ($i=0 ; $i<$MAX['type_monitors'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type ecran $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Switch", "Routeur", "Hub", "Borne Wifi", "borne d'accueil"); $dp = new NetworkEquipmentType(); for ($i=0 ; $i<$MAX['type_networking'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de materiel reseau '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Clavier", "Souris", "Webcam", "Enceintes", "Scanner", "Clef USB", "d'autres"); $dp = new PeripheralType(); for ($i=0 ; $i<$MAX['type_peripherals'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de peripheriques '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Analogique", "IP", ); $dp = new PhoneType(); for ($i=0 ; $i<$MAX['type_phones'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de phone $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("DELL", "HP", "IIYAMA", "CANON", "EPSON", "LEXMARK", "ASUS", "MSI"); $dp = new Manufacturer(); for ($i=0 ; $i<$MAX['manufacturer'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "manufacturer $i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment '$val"))); } $items = array("Ingénieur", "Stagiaire", "Secrétaire", "ouvrier d'atelier"); $dp = new UserCategory(); for ($i=0 ; $i<$MAX['user_type'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "user type d'$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Président", "Agent Comptable", "Directeur d'agence"); $dp = new UserTitle(); for ($i=0 ; $i<$MAX['user_title'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "user type '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); } $items = array("Documentation", "Facture", "Bon Livraison", "Bon commande", "Capture d'Ecran", "Dossier Technique"); $dp = new DocumentCategory(); for ($i=0 ; $i<max(1,pow($MAX['rubdocs'],1/2)) ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "category $i"; } $newID = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['rubdocs'],1/2)) ; $j++) { $newID2 = $dp->add(toolbox::addslashes_deep( array('name' => "s-category '$j", 'comment' => "comment d' $val s-category $j", 'documentcategories_id' => $newID))); } } $MAX['rubdocs'] = getMaxItem('glpi_documentcategories'); $dp = new ItilCategory(); // GLobal ticket categories : also specific ones by entity for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) { $newID = $dp->add(toolbox::addslashes_deep( array('name' => "category '$i", 'comment' => "comment ' category $i", 'is_recursive' => 1, 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1))); for ($j=0 ; $j<mt_rand(0,pow($MAX['tracking_category'],1/2)) ; $j++) { $newID2 = $dp->add(toolbox::addslashes_deep( array('name' => "s-category '$j", 'comment' => "comment 'category $i s-category $j", 'is_recursive' => 1, 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['tracking_category'],1/2)) ; $k++) { $newID3 = $dp->add(toolbox::addslashes_deep( array('name' => "ss-category' $k", 'comment' => "comment ' category $i s-category $j ss-category $k", 'is_recursive' => 1, 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID2))); } } } $query = "OPTIMIZE TABLE `glpi_itilcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_itilcategories"); $MAX['tracking_category'] = getMaxItem('glpi_itilcategories'); // DEVICE $items = array("Textorm 6A19", "ARIA", "SLK3000B-EU", "Sonata II", "TA-212", "TA-551", "TA-581", "TAC-T01", "CS-512", "Li PC-60891", "STT-TJ02S"); $dp = new DeviceCase(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "case $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'devicecasetypes_id' => mt_rand(0,$MAX["case_type"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer'])))); } $items = array("Escalade 8006-2LP", "Escalade 8506-4LP", "2810SA", "1210SA", "DuoConnect", "DU-420", "DUB-A2", "FastTrak SX4100B", "DC-395U", "TFU-H33PI"); $dp = new DeviceControl(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "control $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment ' $val", 'interfacetypes_id' => mt_rand(0,$MAX["interface"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer'])))); } $items = array("DUW1616", "DRW-1608P", "DW1625", "GSA-4160B", "GSA-4165B", "GSA-4167RBB", "SHW-16H5S", "SOHW-1673SX", "DVR-110D", "PX-716AL", "PX-755A"); $dp = new DeviceDrive(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "drive $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'is_writer' => mt_rand(0,1), 'speed' => mt_rand(0,60), 'interfacetypes_id' => mt_rand(0,$MAX["interface"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer'])))); } $items = array("A9250/TD", "AX550/TD", "Extreme N5900", "V9520-X/TD", "All-In-Wonder X800 GT", "GV-NX66256D", "GV-RX80256DE", "Excalibur 9600XT", "X1300 IceQ", "WinFast PX6200 TD", "Millenium 750","NX6600GT"); $dp = new DeviceGraphicCard(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "gfxcard $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment ' $val", 'interfacetypes_id' => mt_rand(0,$MAX["interface"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'memory_default' => 256*mt_rand(0,8)))); } $items = array("Deskstar 7K500", "Deskstar T7K250", "Atlas 15K II", "DiamondMax Plus", "SpinPoint P - SP2514N", "Barracuda 7200.9", "WD2500JS", "WD1600JB", "WD1200JD"); $dp = new DeviceHardDrive(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "hdd $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'interfacetypes_id' => mt_rand(0,$MAX["interface"]), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'capacity_default' => mt_rand(0,300), 'rpm' => mt_rand(0,15000), 'cache' => 51200*mt_rand(0,10)))); } $items = array("DFE-530TX", "DFE-538TX", "PWLA8492MF", "PWLA8492MT", "USBVPN1", "GA311", "FA511", "TEG-PCBUSR", "3C996-SX", "3C996B-T", "3C905C-TX-M"); $dp = new DeviceNetworkCard(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "iface $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'bandwidth' => mt_rand(0,1000)))); } $items = array("AW8-MAX", "NV8", "AK86-L", "P4V88", "A8N-SLI", "A8N-VM", "K8V-MX", "K8N4-E", "P5LD2", "GA-K8NE", "GA-8I945P Pro", "D945PBLL", "SE7525GP2", "865PE Neo3-F", "K8N Neo4-F", "Thunder i7520 (S5360G2NR)", "Thunder K8SR - S2881UG2NR", "Tiger K8QS Pro - S4882UG2NR", "Tomcat i875PF (S5105G2NR)"); $dp = new DeviceMotherBoard(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "moboard $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'chipset' => 'chipset '.mt_rand(0,1000)))); } $items = array("Instant TV Cardbus", "WinTV Express", "WinTV-NOVA-S-Plus", "WinTV-NOVA-T", "WinTV-PVR-150"); $dp = new DevicePci(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "pci $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer'])))); } $items = array("DB-Killer PW335", "DB-Killer PW385", "NeoHE 380", "NeoHE 450", "Phantom 500-PEC", "TruePower 2.0 550", "Master RS-380", "EG375AX-VE-G-SFMA", "EG495AX"); $dp = new DevicePowerSupply(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "power $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'power' => mt_rand(0,500).'W', 'is_atx' => mt_rand(0,1)))); } $items = array("Athlon 64 FX-57", "Athlon 64 FX-55", "Sempron 2400+", "Sempron 2600+", "Celeron D 325", "Celeron D 330J", "Pentium 4 530J", "Pentium 4 631", "Pentium D 830", "Pentium D 920"); $dp = new DeviceProcessor(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "processor $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'frequence' => mt_rand(1000,3000), 'frequency_default' => 1000+200*mt_rand(0,10), 'nbcores_default' => mt_rand(1,8), 'nbthreads_default' => mt_rand(1,4), ))); } $items = array("CM2X256A-5400C4", "CMX1024-3200C2", "CMXP512-3200XL", "TWIN2X1024-4300C3PRO", "KTD-DM8400/1G", "KTH8348/1G", "KTD4400/256", "D6464D30A", "KTA-G5400/512", "KVR667D2N5/1G", "KVR133X64C3/256"); $dp = new DeviceMemory(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "ram $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment' $val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'frequence' => 100*mt_rand(0,10), 'size_default' => 1024*mt_rand(0,6), 'devicememorytypes_id' => mt_rand(1,$MAX['ram_type'])))); } $items = array("DDTS-100", "Audigy 2 ZS Platinum", "Audigy SE", "DJ Console Mk2", "Gamesurround Muse Pocket USB", "Phase 22", "X-Fi Platinum", "Live! 24-bit", "X-Fi Elite Pro"); $dp = new DeviceSoundCard(); for ($i=0 ; $i<$MAX['device'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "sndcard $i"; } $dp->add(toolbox::addslashes_deep( array('designation' => $val, 'is_recursive' => 1, 'comment' => "comment '$val", 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'type' => 'type '.mt_rand(0,100)))); } } // Fin generation global dropdowns
/** * Print the computer form * * @param $ID integer ID of the item * @param $options array * - target for the Form * - withtemplate template or basic computer * *@return Nothing (display) **/ function showForm($ID, $options = array()) { global $CFG_GLPI, $DB; $this->initForm($ID, $options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; //TRANS: %1$s is a string, %2$s a second one without spaces between them : to change for RTL echo "<td>" . sprintf(__('%1$s%2$s'), __('Name'), isset($options['withtemplate']) && $options['withtemplate'] ? "*" : "") . "</td>"; echo "<td>"; $objectName = autoName($this->fields["name"], "name", isset($options['withtemplate']) && $options['withtemplate'] == 2, $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, 'name', array('value' => $objectName)); echo "</td>"; echo "<td>" . __('Status') . "</td>"; echo "<td>"; State::dropdown(array('value' => $this->fields["states_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_visible_computer`")); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Location') . "</td>"; echo "<td>"; Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Type') . "</td>"; echo "<td>"; ComputerType::dropdown(array('value' => $this->fields["computertypes_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Technician in charge of the hardware') . "</td>"; echo "<td>"; User::dropdown(array('name' => 'users_id_tech', 'value' => $this->fields["users_id_tech"], 'right' => 'own_ticket', 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Manufacturer') . "</td>"; echo "<td>"; Manufacturer::dropdown(array('value' => $this->fields["manufacturers_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group in charge of the hardware') . "</td>"; echo "<td>"; Group::dropdown(array('name' => 'groups_id_tech', 'value' => $this->fields['groups_id_tech'], 'entity' => $this->fields['entities_id'], 'condition' => '`is_assign`')); echo "</td>"; echo "<td>" . __('Model') . "</td>"; echo "<td>"; ComputerModel::dropdown(array('value' => $this->fields["computermodels_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; //TRANS: Number of the alternate username echo "<td>" . __('Alternate username number') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'contact_num'); echo "</td>"; echo "<td>" . __('Serial number') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'serial'); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Alternate username') . "</td>"; echo "<td>"; Html::autocompletionTextField($this, 'contact'); echo "</td>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Inventory number'), isset($options['withtemplate']) && $options['withtemplate'] ? "*" : "") . "</td>"; echo "<td>"; $objectName = autoName($this->fields["otherserial"], "otherserial", isset($options['withtemplate']) && $options['withtemplate'] == 2, $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, 'otherserial', array('value' => $objectName)); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('User') . "</td>"; echo "<td>"; User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); echo "</td>"; echo "<td>" . __('Network') . "</td>"; echo "<td>"; Network::dropdown(array('value' => $this->fields["networks_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group') . "</td>"; echo "<td>"; Group::dropdown(array('value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"], 'condition' => '`is_itemgroup`')); echo "</td>"; // Display auto inventory informations $rowspan = 4; echo "<td rowspan='{$rowspan}'>" . __('Comments') . "</td>"; echo "<td rowspan='{$rowspan}' class='middle'>"; echo "<textarea cols='45' rows='" . ($rowspan + 3) . "' name='comment' >" . $this->fields["comment"]; echo "</textarea></td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Domain') . "</td>"; echo "<td >"; Domain::dropdown(array('value' => $this->fields["domains_id"], 'entity' => $this->fields["entities_id"])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('UUID') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'uuid'); echo "</td>"; echo "</tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Update Source') . "</td>"; echo "<td >"; AutoUpdateSystem::dropdown(array('value' => $this->fields["autoupdatesystems_id"])); echo "</td></tr>"; // Display auto inventory informations if (!empty($ID) && Plugin::haveImport() && $this->fields["is_dynamic"]) { echo "<tr class='tab_bg_1'><td colspan='4'>"; Plugin::doHook("autoinventory_information", $this); echo "</td></tr>"; } $this->showFormButtons($options); return true; }
/** * Print the computer form * * @param $ID integer ID of the item * @param $options array * - target for the Form * - withtemplate template or basic computer * *@return Nothing (display) **/ function showForm($ID, $options = array()) { global $CFG_GLPI, $DB; $this->initForm($ID, $options); $this->showFormHeader($options); echo "<tr class='tab_bg_1'>"; //TRANS: %1$s is a string, %2$s a second one without spaces between them : to change for RTL echo "<td>" . sprintf(__('%1$s%2$s'), __('Name'), isset($options['withtemplate']) && $options['withtemplate'] ? "*" : "") . "</td>"; echo "<td>"; $objectName = autoName($this->fields["name"], "name", isset($options['withtemplate']) && $options['withtemplate'] == 2, $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, 'name', array('value' => $objectName)); echo "</td>"; echo "<td>" . __('Status') . "</td>"; echo "<td>"; State::dropdown(array('value' => $this->fields["states_id"], 'entity' => $this->fields["entities_id"], 'condition' => "`is_visible_computer`")); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Location') . "</td>"; echo "<td>"; Location::dropdown(array('value' => $this->fields["locations_id"], 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Type') . "</td>"; echo "<td>"; ComputerType::dropdown(array('value' => $this->fields["computertypes_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Technician in charge of the hardware') . "</td>"; echo "<td>"; User::dropdown(array('name' => 'users_id_tech', 'value' => $this->fields["users_id_tech"], 'right' => 'own_ticket', 'entity' => $this->fields["entities_id"])); echo "</td>"; echo "<td>" . __('Manufacturer') . "</td>"; echo "<td>"; Manufacturer::dropdown(array('value' => $this->fields["manufacturers_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group in charge of the hardware') . "</td>"; echo "<td>"; Group::dropdown(array('name' => 'groups_id_tech', 'value' => $this->fields['groups_id_tech'], 'entity' => $this->fields['entities_id'], 'condition' => '`is_assign`')); echo "</td>"; echo "<td>" . __('Model') . "</td>"; echo "<td>"; ComputerModel::dropdown(array('value' => $this->fields["computermodels_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; //TRANS: Number of the alternate username echo "<td>" . __('Alternate username number') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'contact_num'); echo "</td>"; echo "<td>" . __('Serial number') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'serial'); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Alternate username') . "</td>"; echo "<td>"; Html::autocompletionTextField($this, 'contact'); echo "</td>"; echo "<td>" . sprintf(__('%1$s%2$s'), __('Inventory number'), isset($options['withtemplate']) && $options['withtemplate'] ? "*" : "") . "</td>"; echo "<td>"; $objectName = autoName($this->fields["otherserial"], "otherserial", isset($options['withtemplate']) && $options['withtemplate'] == 2, $this->getType(), $this->fields["entities_id"]); Html::autocompletionTextField($this, 'otherserial', array('value' => $objectName)); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('User') . "</td>"; echo "<td>"; User::dropdown(array('value' => $this->fields["users_id"], 'entity' => $this->fields["entities_id"], 'right' => 'all')); echo "</td>"; echo "<td>" . __('Network') . "</td>"; echo "<td>"; Network::dropdown(array('value' => $this->fields["networks_id"])); echo "</td></tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Group') . "</td>"; echo "<td>"; Group::dropdown(array('value' => $this->fields["groups_id"], 'entity' => $this->fields["entities_id"], 'condition' => '`is_itemgroup`')); echo "</td>"; // Display auto inventory informations $rowspan = 7; $inventory_show = false; if (!empty($ID) && Plugin::haveImport() && $this->fields["is_dynamic"]) { $inventory_show = true; $rowspan -= 5; } echo "<td rowspan='{$rowspan}'>" . __('Comments') . "</td>"; echo "<td rowspan='{$rowspan}' class='middle'>"; echo "<textarea cols='45' rows='" . ($rowspan + 3) . "' name='comment' >" . $this->fields["comment"]; echo "</textarea></td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Domain') . "</td>"; echo "<td >"; Domain::dropdown(array('value' => $this->fields["domains_id"], 'entity' => $this->fields["entities_id"])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Operating system') . "</td>"; echo "<td>"; OperatingSystem::dropdown(array('value' => $this->fields["operatingsystems_id"])); echo "<br /><a href='#' id='toggle_os_information'>" . __("More information") . "</a>"; echo "</td>"; if ($inventory_show) { echo "<td rowspan='4' colspan='2'>"; Plugin::doHook("autoinventory_information", $this); echo "</td>"; } echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Version of the operating system') . "</td>"; echo "<td >"; OperatingSystemVersion::dropdown(array('value' => $this->fields["operatingsystemversions_id"])); echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'><td colspan='2'>"; echo Html::scriptBlock("\n \$(document).ready(function(){\n \$('#os_information').hide();\n\n \$('#toggle_os_information').on('click',function() {\n \$('#os_information').dialog({\n width:'auto',\n resizable: false,\n appendTo: '#os_information_parent',\n position: {\n my : 'left top',\n at : 'left bottom',\n of: \$('#toggle_os_information')\n }\n })\n })\n });"); // group os advanced information in a single bloc (who can be toggled) echo "<div id='os_information_parent'>"; echo "<div id='os_information' title=\"" . __('Operating system') . "\">"; echo "<table>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Service pack') . "</td>"; echo "<td >"; OperatingSystemServicePack::dropdown(array('value' => $this->fields["operatingsystemservicepacks_id"])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Operating system architecture') . "</td>"; echo "<td >"; OperatingSystemArchitecture::dropdown(array('value' => $this->fields["operatingsystemarchitectures_id"])); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Kernel version of the operating system') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'os_kernel_version'); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Product ID of the operating system') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'os_licenseid'); echo "</td></tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Serial of the operating system') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'os_license_number'); echo "</td>"; echo "</table>"; echo "</div>"; echo "</div>"; echo "</td>"; echo "</tr>"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('UUID') . "</td>"; echo "<td >"; Html::autocompletionTextField($this, 'uuid'); echo "</td>"; echo "</tr>\n"; echo "<tr class='tab_bg_1'>"; echo "<td>" . __('Update Source') . "</td>"; echo "<td >"; AutoUpdateSystem::dropdown(array('value' => $this->fields["autoupdatesystems_id"])); echo "</td></tr>"; $this->showFormButtons($options); return true; }
function generateServicesCfg($file = 0, $tag = '') { global $DB; PluginMonitoringToolbox::logIfExtradebug('pm-shinken', "Starting generateServicesCfg services ({$tag}) ...\n"); $pMonitoringCommand = new PluginMonitoringCommand(); $pmEventhandler = new PluginMonitoringEventhandler(); $pMonitoringCheck = new PluginMonitoringCheck(); $pmComponent = new PluginMonitoringComponent(); $pmEntity = new PluginMonitoringEntity(); $pmContact_Item = new PluginMonitoringContact_Item(); $networkPort = new NetworkPort(); $pmService = new PluginMonitoringService(); $pmComponentscatalog = new PluginMonitoringComponentscatalog(); $pmHostconfig = new PluginMonitoringHostconfig(); $calendar = new Calendar(); $user = new User(); $profile_User = new Profile_User(); $pmConfig = new PluginMonitoringConfig(); $computerType = new ComputerType(); $a_services = array(); $i = 0; // Get computer type contener / VM $conteners = $computerType->find("`name`='BSDJail'"); $pmConfig->getFromDB(1); // TODO: only contacts in allowed entities ... // Prepare individual contacts $a_contacts_entities = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n AND `users_id`>0"); foreach ($a_list_contact as $data) { $contactentities = getSonsOf('glpi_entities', $data['entities_id']); if (isset($a_contacts_entities[$data['items_id']][$data['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$data['users_id']]); } $a_contacts_entities[$data['items_id']][$data['users_id']] = $contactentities; } // Prepare groups contacts $group = new Group(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n AND `groups_id`>0"); foreach ($a_list_contact as $data) { $group->getFromDB($data['groups_id']); if ($group->fields['is_recursive'] == 1) { $contactentities = getSonsOf('glpi_entities', $group->fields['entities_id']); } else { $contactentities = array($group->fields['entities_id'] => $group->fields['entities_id']); } $queryg = "SELECT * FROM `glpi_groups_users`\n WHERE `groups_id`='" . $data['groups_id'] . "'"; $resultg = $DB->query($queryg); while ($datag = $DB->fetch_array($resultg)) { if (isset($a_contacts_entities[$data['items_id']][$datag['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$datag['users_id']]); } $a_contacts_entities[$data['items_id']][$datag['users_id']] = $contactentities; } } $a_entities_allowed = $pmEntity->getEntitiesByTag($tag); // Toolbox::logInFile("pm-shinken", " Allowed entities:\n"); $a_entities_list = array(); foreach ($a_entities_allowed as $entity) { $a_entities_list = getSonsOf("glpi_entities", $entity); } $where = ''; if (!isset($a_entities_allowed['-1'])) { $where = getEntitiesRestrictRequest("WHERE", "glpi_plugin_monitoring_services", '', $a_entities_list); } // -------------------------------------------------- // "Normal" services .... $query = "SELECT * FROM `glpi_plugin_monitoring_services` {$where}"; PluginMonitoringToolbox::logIfExtradebug('pm-shinken', "Services: {$query}\n"); $result = $DB->query($query); while ($data = $DB->fetch_array($result)) { // Toolbox::logInFile("pm-shinken", " - fetch service ".$data['id']."\n"); // if (isset($a_entities_allowed['-1']) // OR isset($a_entities_allowed[$item->fields['entities_id']])) { $notadd = 0; $notadddescription = ''; $a_component = current($pmComponent->find("`id`='" . $data['plugin_monitoring_components_id'] . "'", "", 1)); if (empty($a_component)) { continue; } $a_hostname = array(); $a_hostname_single = array(); $a_hostname_type = array(); $a_hostname_id = array(); $queryh = "SELECT * FROM `glpi_plugin_monitoring_componentscatalogs_hosts`\n WHERE `id` = '" . $data['plugin_monitoring_componentscatalogs_hosts_id'] . "'\n LIMIT 1"; $resulth = $DB->query($queryh); $hostname = ''; $plugin_monitoring_componentscatalogs_id = 0; $computerTypes_id = 0; $entities_id = 0; while ($datah = $DB->fetch_array($resulth)) { $itemtype = $datah['itemtype']; $item = new $itemtype(); if ($item->getFromDB($datah['items_id'])) { // if (isset($a_entities_allowed['-1']) // OR isset($a_entities_allowed[$item->fields['entities_id']])) { // Fix if hostname is not defined ... if (!empty($item->fields['name'])) { $h = self::shinkenFilter($item->fields['name']); $a_hostname_single[] = $h; if ($pmConfig->fields['append_id_hostname'] == 1) { $h .= "-" . $datah['items_id']; } $a_hostname[] = $h; $a_hostname_type[] = $datah['itemtype']; $a_hostname_id[] = $datah['items_id']; $hostname = $item->fields['name']; $entities_id = $item->fields['entities_id']; $plugin_monitoring_componentscatalogs_id = $datah['plugin_monitoring_componentscalalog_id']; if ($itemtype == 'Computer') { $computerTypes_id = $item->fields['computertypes_id']; } } // } } } if (count($a_hostname) > 0) { if (isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) { $a_services[$i]['use'] = $_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']]; } $a_services[$i]['host_name'] = implode(",", array_unique($a_hostname)); $a_services[$i]['_HOSTITEMSID'] = implode(",", array_unique($a_hostname_id)); $a_services[$i]['_HOSTITEMTYPE'] = implode(",", array_unique($a_hostname_type)); // Define display_name / service_description $a_services[$i]['service_description'] = !empty($a_component['description']) ? $a_component['description'] : self::shinkenFilter($a_component['name']); // In case have multiple networkt port, may have description different, else be dropped by shinken if ($data['networkports_id'] > 0) { $networkPort->getFromDB($data['networkports_id']); $a_services[$i]['service_description'] .= '-' . self::shinkenFilter($networkPort->fields['name']); } $a_services[$i]['display_name'] = $a_component['name']; // $a_services[$i]['_ENTITIESID'] = $item->fields['entities_id']; // $a_services[$i]['_ITEMSID'] = $data['id']; // $a_services[$i]['_ITEMTYPE'] = 'Service'; PluginMonitoringToolbox::logIfExtradebug('pm-shinken', " - add service " . $a_services[$i]['service_description'] . " on " . $a_services[$i]['host_name'] . "\n"); if (isset(self::$shinkenParameters['glpi']['entityId'])) { $a_services[$i][self::$shinkenParameters['glpi']['entityId']] = $item->fields['entities_id']; } if (isset(self::$shinkenParameters['glpi']['itemType'])) { $a_services[$i][self::$shinkenParameters['glpi']['itemType']] = 'Service'; } if (isset(self::$shinkenParameters['glpi']['itemId'])) { $a_services[$i][self::$shinkenParameters['glpi']['itemId']] = $data['id']; } // Manage freshness if ($a_component['freshness_count'] == 0) { $a_services[$i]['check_freshness'] = '0'; $a_services[$i]['freshness_threshold'] = '3600'; } else { $multiple = 1; if ($a_component['freshness_type'] == 'seconds') { $multiple = 1; } else { if ($a_component['freshness_type'] == 'minutes') { $multiple = 60; } else { if ($a_component['freshness_type'] == 'hours') { $multiple = 3600; } else { if ($a_component['freshness_type'] == 'days') { $multiple = 86400; } } } } $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = (string) ($a_component['freshness_count'] * $multiple); } $pMonitoringCommand->getFromDB($a_component['plugin_monitoring_commands_id']); // Manage arguments $array = array(); preg_match_all("/\\\$(ARG\\d+)\\\$/", $pMonitoringCommand->fields['command_line'], $array); sort($array[0]); $a_arguments = importArrayFromDB($a_component['arguments']); $a_argumentscustom = importArrayFromDB($data['arguments']); foreach ($a_argumentscustom as $key => $value) { $a_arguments[$key] = $value; } foreach ($a_arguments as $key => $value) { $a_arguments[$key] = str_replace('!', '\\!', html_entity_decode($value)); } $args = ''; foreach ($array[0] as $arg) { if ($arg != '$PLUGINSDIR$' and $arg != '$NAGIOSPLUGINSDIR$' and $arg != '$HOSTADDRESS$' and $arg != '$MYSQLUSER$' and $arg != '$MYSQLPASSWORD$') { $arg = str_replace('$', '', $arg); if (!isset($a_arguments[$arg])) { $args .= '!'; } else { if (strstr($a_arguments[$arg], "[[HOSTNAME]]")) { $a_arguments[$arg] = str_replace("[[HOSTNAME]]", $hostname, $a_arguments[$arg]); } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTDESCR]]")) { if (class_exists("PluginFusioninventoryNetworkPort")) { $pfNetworkPort = new PluginFusioninventoryNetworkPort(); $pfNetworkPort->loadNetworkport($data['networkports_id']); $descr = $pfNetworkPort->getValue("ifdescr"); $a_arguments[$arg] = str_replace("[[NETWORKPORTDESCR]]", $descr, $a_arguments[$arg]); } } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTNUM]]")) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $logicalnum = $pfNetworkPort->fields['logical_number']; $a_arguments[$arg] = str_replace("[[NETWORKPORTNUM]]", $logicalnum, $a_arguments[$arg]); } elseif (strstr($a_arguments[$arg], "[[NETWORKPORTNAME]]")) { if (isset($data['networkports_id']) && $data['networkports_id'] > 0) { $networkPort = new NetworkPort(); $networkPort->getFromDB($data['networkports_id']); $portname = $pfNetworkPort->fields['name']; $a_arguments[$arg] = str_replace("[[NETWORKPORTNAME]]", $portname, $a_arguments[$arg]); } else { if ($a_services[$i]['_HOSTITEMTYPE'] == 'Computer') { // Get networkportname of networkcard defined $pmHostaddress = new PluginMonitoringHostaddress(); $a_hostaddresses = $pmHostaddress->find("`itemtype`='Computer'" . " AND `items_id`='" . $a_services[$i]['_HOSTITEMSID'] . "'", '', 1); if (count($a_hostaddresses) == 1) { $a_hostaddress = current($a_hostaddresses); if ($a_hostaddress['networkports_id'] > 0) { $networkPort = new NetworkPort(); $networkPort->getFromDB($a_hostaddress['networkports_id']); $a_arguments[$arg] = str_replace("[[NETWORKPORTNAME]]", $networkPort->fields['name'], $a_arguments[$arg]); } } } } } else { if (strstr($a_arguments[$arg], "[")) { $a_arguments[$arg] = PluginMonitoringService::convertArgument($data['id'], $a_arguments[$arg]); } } if ($a_arguments == '') { $notadd = 1; if ($notadddescription != '') { $notadddescription .= ", "; } $notadddescription .= "Argument " . $a_arguments[$arg] . " do not have value"; } $args .= '!' . $a_arguments[$arg]; if ($a_arguments[$arg] == '' and $a_component['alias_command'] != '') { $args .= $a_component['alias_command']; } } } } // End manage arguments if ($a_component['remotesystem'] == 'nrpe') { if ($a_component['alias_command'] != '') { $alias_command = $a_component['alias_command']; if (strstr($alias_command, '[[IP]]')) { $split = explode('-', current($a_hostname)); $ip = PluginMonitoringHostaddress::getIp($a_hostname_id[0], $a_hostname_type[0], ''); $alias_command = str_replace("[[IP]]", $ip, $alias_command); } if (current($a_hostname_type) == 'Computer') { if ($pmConfig->fields['nrpe_prefix_contener'] == 1) { if (isset($conteners[$computerTypes_id])) { // get Host of contener/VM $where = "LOWER(`uuid`)" . ComputerVirtualMachine::getUUIDRestrictRequest($item->fields['uuid']); $hosts = getAllDatasFromTable('glpi_computervirtualmachines', $where); if (!empty($hosts)) { $host = current($hosts); // $ip = PluginMonitoringHostaddress::getIp($host['computers_id'], 'Computer', ''); $alias_command = current($a_hostname_single) . "_" . $alias_command; } } } } $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . "check_nrpe!" . $alias_command; } else { $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . "check_nrpe!" . $pMonitoringCommand->fields['command_name']; } } else { $a_services[$i]['check_command'] = PluginMonitoringCommand::$command_prefix . $pMonitoringCommand->fields['command_name'] . $args; } // * Manage event handler if ($a_component['plugin_monitoring_eventhandlers_id'] > 0) { if ($pmEventhandler->getFromDB($a_component['plugin_monitoring_eventhandlers_id'])) { $a_services[$i]['event_handler'] = $pmEventhandler->fields['command_name']; } } if (!empty(self::$shinkenParameters['shinken']['services']['process_perf_data'])) { $a_services[$i]['process_perf_data'] = self::$shinkenParameters['shinken']['services']['process_perf_data']; } if (!empty(self::$shinkenParameters['shinken']['services']['notes'])) { $a_services[$i]['notes'] = self::$shinkenParameters['shinken']['services']['notes']; } if (!empty(self::$shinkenParameters['shinken']['services']['notes_url'])) { $a_services[$i]['notes_url'] = self::$shinkenParameters['shinken']['services']['notes_url']; } if (!empty(self::$shinkenParameters['shinken']['services']['action_url'])) { $a_services[$i]['action_url'] = self::$shinkenParameters['shinken']['services']['action_url']; } if (!empty(self::$shinkenParameters['shinken']['services']['icon_image'])) { $a_services[$i]['icon_image'] = self::$shinkenParameters['shinken']['services']['icon_image']; } if (!empty(self::$shinkenParameters['shinken']['services']['icon_image_alt'])) { $a_services[$i]['icon_image_alt'] = self::$shinkenParameters['shinken']['services']['icon_image_alt']; } // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringComponentscatalog'\n AND `items_id`='" . $plugin_monitoring_componentscatalogs_id . "'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else { if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users`\n WHERE `groups_id`='" . $data_contact['groups_id'] . "'"; $resultg = $DB->query($queryg); while ($datag = $DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$plugin_monitoring_componentscatalogs_id][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); // ** If shinken not use templates or template not defined : if (!isset($_SESSION['plugin_monitoring']['servicetemplates'][$a_component['id']])) { $pMonitoringCheck->getFromDB($a_component['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; $timeperiodsuffix = '-' . $pmHostconfig->getValueAncestor('jetlag', $entities_id); if ($timeperiodsuffix == '-0') { $timeperiodsuffix = ''; } if ($calendar->getFromDB($a_component['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name'] . $timeperiodsuffix; } $a_services[$i]['notification_interval'] = '30'; $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; if (isset($a_services[$i]['event_handler'])) { $a_services[$i]['event_handler_enabled'] = '1'; } else { $a_services[$i]['event_handler_enabled'] = '0'; // $a_services[$i]['event_handler_enabled'] = ''; } $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; } else { // Notification options $a_services[$i]['notification_interval'] = '30'; $pmComponentscatalog->getFromDB($plugin_monitoring_componentscatalogs_id); if ($pmComponentscatalog->fields['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $pmComponentscatalog->fields['notification_interval']; } $a_services[$i]['notification_period'] = '24x7'; $a_services[$i]['check_period'] = '24x7'; $timeperiodsuffix = '-' . $pmHostconfig->getValueAncestor('jetlag', $entities_id); if ($timeperiodsuffix == '-0') { $timeperiodsuffix = ''; } if ($calendar->getFromDB($a_component['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name'] . $timeperiodsuffix; } } // WebUI user interface ... if (isset(self::$shinkenParameters['webui']['serviceIcons']['name'])) { $a_services[$i][self::$shinkenParameters['webui']['serviceIcons']['name']] = self::$shinkenParameters['webui']['serviceIcons']['value']; } if ($notadd == '1') { unset($a_services[$i]); $input = array(); $input['id'] = $data['id']; $input['event'] = $notadddescription; $input['state'] = "CRITICAL"; $input['state_type'] = "HARD"; $pmService->update($input); } else { $i++; } } // } } PluginMonitoringToolbox::logIfExtradebug('pm-shinken', "End generateServicesCfg services\n"); PluginMonitoringToolbox::logIfExtradebug('pm-shinken', "Starting generateServicesCfg business rules ...\n"); // -------------------------------------------------- // Business rules services ... $pmService = new PluginMonitoringService(); $pmServicescatalog = new PluginMonitoringServicescatalog(); $pmBusinessrulegroup = new PluginMonitoringBusinessrulegroup(); $pmBusinessrule = new PluginMonitoringBusinessrule(); $pmComponentscatalog_Host = new PluginMonitoringComponentscatalog_Host(); $pmBusinessrule_component = new PluginMonitoringBusinessrule_component(); // Prepare individual contacts $a_contacts_entities = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog'\n AND `users_id`>0"); foreach ($a_list_contact as $data) { $contactentities = getSonsOf('glpi_entities', $data['entities_id']); if (isset($a_contacts_entities[$data['items_id']][$data['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$data['users_id']]); } $a_contacts_entities[$data['items_id']][$data['users_id']] = $contactentities; } // Prepare groups contacts $group = new Group(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog'\n AND `groups_id`>0"); foreach ($a_list_contact as $data) { $group->getFromDB($data['groups_id']); if ($group->fields['is_recursive'] == 1) { $contactentities = getSonsOf('glpi_entities', $group->fields['entities_id']); } else { $contactentities = array($group->fields['entities_id'] => $group->fields['entities_id']); } $queryg = "SELECT * FROM `glpi_groups_users`\n WHERE `groups_id`='" . $data['groups_id'] . "'"; $resultg = $DB->query($queryg); while ($datag = $DB->fetch_array($resultg)) { if (isset($a_contacts_entities[$data['items_id']][$datag['users_id']])) { $contactentities = array_merge($contactentities, $a_contacts_entities[$data['items_id']][$datag['users_id']]); } $a_contacts_entities[$data['items_id']][$datag['users_id']] = $contactentities; } } // Services catalogs $a_listBA = $pmServicescatalog->find("`is_generic`='0'"); foreach ($a_listBA as $dataBA) { if (isset($a_entities_allowed['-1']) or isset($a_entities_allowed[$dataBA['entities_id']])) { $a_grouplist = $pmBusinessrulegroup->find("`plugin_monitoring_servicescatalogs_id`='" . $dataBA['id'] . "'"); $a_group = array(); foreach ($a_grouplist as $gdata) { $pmBusinessrule_component->replayDynamicServices($gdata['id']); $a_listBR = $pmBusinessrule->find("`plugin_monitoring_businessrulegroups_id`='" . $gdata['id'] . "'"); foreach ($a_listBR as $dataBR) { if ($pmService->getFromDB($dataBR['plugin_monitoring_services_id'])) { if ($pmService->getHostName() != '') { $hostname = self::shinkenFilter($pmService->getHostName()); if ($gdata['operator'] == 'and' or $gdata['operator'] == 'or' or strstr($gdata['operator'], ' of:')) { $operator = '|'; if ($gdata['operator'] == 'and') { $operator = '&'; } if (!isset($a_group[$gdata['id']])) { $a_group[$gdata['id']] = ''; if (strstr($gdata['operator'], ' of:')) { $a_group[$gdata['id']] = $gdata['operator']; } $a_group[$gdata['id']] .= $hostname . "," . self::shinkenFilter($pmService->getName(array('shinken' => true))); } else { $a_group[$gdata['id']] .= $operator . $hostname . "," . self::shinkenFilter($pmService->getName(array('shinken' => true))); } } else { $a_group[$gdata['id']] = $gdata['operator'] . " " . $hostname . "," . self::shinkenFilter($item->getName()); } } } PluginMonitoringToolbox::logIfExtradebug('pm-shinken', " - SC group : " . $a_group[$gdata['id']] . "\n"); } } if (count($a_group) > 0) { $pMonitoringCheck->getFromDB($dataBA['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($dataBA['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['bp_host']; $a_services[$i]['business_impact'] = $dataBA['business_priority']; $a_services[$i]['service_description'] = self::shinkenFilter($dataBA['name']); $a_services[$i]['_ENTITIESID'] = $dataBA['id']; $a_services[$i]['_ITEMSID'] = $dataBA['id']; $a_services[$i]['_ITEMTYPE'] = 'ServiceCatalog'; $command = "bp_rule!"; foreach ($a_group as $key => $value) { if (!strstr($value, "&") and !strstr($value, "|")) { $a_group[$key] = trim($value); } else { $a_group[$key] = "(" . trim($value) . ")"; } } $a_services[$i]['check_command'] = $command . implode("&", $a_group); if ($dataBA['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $dataBA['notification_interval']; } else { $a_services[$i]['notification_interval'] = '30'; } $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; $a_services[$i]['event_handler_enabled'] = '0'; //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE'; $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog'\n AND `items_id`='" . $dataBA['id'] . "'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else { if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users`\n WHERE `groups_id`='" . $data_contact['groups_id'] . "'"; $resultg = $DB->query($queryg); while ($datag = $DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); $i++; } } } PluginMonitoringToolbox::logIfExtradebug('pm-shinken', "End generateServicesCfg business rules\n"); PluginMonitoringToolbox::logIfExtradebug('pm-shinken', "Starting generateServicesCfg business rules templates ...\n"); // Services catalogs templates // TODO : correctly test and improve it ! $a_listBA = $pmServicescatalog->find("`is_generic`='1'"); foreach ($a_listBA as $dataBA) { PluginMonitoringToolbox::logIfExtradebug('pm-shinken', " - SC : " . $dataBA['id'] . "\n"); if (isset($a_entities_allowed['-1']) or isset($a_entities_allowed[$dataBA['entities_id']])) { $pmServicescatalog->getFromDB($dataBA['id']); $a_entitiesServices = $pmServicescatalog->getGenericServicesEntities(); foreach ($a_entitiesServices as $idEntity => $a_entityServices) { // New entity ... so new business rule ! PluginMonitoringToolbox::logIfExtradebug('pm-shinken', " - SC templated services for an entity : " . $idEntity . "\n"); $pmDerivatedSC = new PluginMonitoringServicescatalog(); $a_derivatedSC = $pmDerivatedSC->find("`entities_id`='{$idEntity}' AND `name` LIKE '" . $dataBA['name'] . "%'"); foreach ($a_derivatedSC as $a_derivated) { PluginMonitoringToolbox::logIfExtradebug('pm-shinken', " - a_derivated : " . $a_derivated['name'] . "\n"); $a_derivatedSC = $a_derivated; } $a_group = array(); foreach ($a_entityServices as $services) { if ($pmService->getFromDB($services['serviceId'])) { // Toolbox::logInFile("pm-shinken", " - SC templated service entity : ".$services['entityId'].", service : ".$pmService->getName(true)." on ".$pmService->getHostName()."\n"); if ($pmService->getHostName() != '') { $hostname = self::shinkenFilter($pmService->getHostName()); $serviceFakeId = $services['entityId']; $pmBusinessrulegroup->getFromDB($services['BRgroupId']); $BRoperator = $pmBusinessrulegroup->getField('operator'); if ($BRoperator == 'and' or $BRoperator == 'or' or strstr($BRoperator, ' of:')) { $operator = '|'; if ($BRoperator == 'and') { $operator = '&'; } if (!isset($a_group[$serviceFakeId])) { $a_group[$serviceFakeId] = ''; if (strstr($BRoperator, ' of:')) { $a_group[$serviceFakeId] = $BRoperator; } $a_group[$serviceFakeId] .= $hostname . "," . self::shinkenFilter($pmService->getName(array('shinken' => true))); } else { $a_group[$serviceFakeId] .= $operator . $hostname . "," . self::shinkenFilter($pmService->getName(array('shinken' => true))); } } else { $a_group[$serviceFakeId] = $BRoperator . " " . $hostname . "," . self::shinkenFilter($pmService->getHostName()); } // Toolbox::logInFile("pm-shinken", " - SCT group : ".$a_group[$serviceFakeId]."\n"); } } } if (count($a_group) > 0) { $pMonitoringCheck->getFromDB($a_derivatedSC['plugin_monitoring_checks_id']); $a_services[$i]['check_interval'] = $pMonitoringCheck->fields['check_interval']; $a_services[$i]['retry_interval'] = $pMonitoringCheck->fields['retry_interval']; $a_services[$i]['max_check_attempts'] = $pMonitoringCheck->fields['max_check_attempts']; if ($calendar->getFromDB($a_derivatedSC['calendars_id'])) { $a_services[$i]['check_period'] = $calendar->fields['name']; } $a_services[$i]['host_name'] = self::shinkenFilter($a_derivatedSC['name']); $a_services[$i]['host_name'] = self::$shinkenParameters['shinken']['fake_hosts']['name_prefix'] . self::$shinkenParameters['shinken']['fake_hosts']['bp_host']; $a_services[$i]['business_impact'] = $a_derivatedSC['business_priority']; $a_services[$i]['service_description'] = self::shinkenFilter($a_derivatedSC['name']); $a_services[$i]['_ENTITIESID'] = $a_derivatedSC['entities_id']; $a_services[$i]['_ITEMSID'] = $a_derivatedSC['id']; $a_services[$i]['_ITEMTYPE'] = 'ServiceCatalog'; $command = "bp_rule!"; foreach ($a_group as $key => $value) { if (!strstr($value, "&") and !strstr($value, "|")) { $a_group[$key] = trim($value); } else { $a_group[$key] = "(" . trim($value) . ")"; } } $a_services[$i]['check_command'] = $command . implode("&", $a_group); if ($a_derivatedSC['notification_interval'] != '30') { $a_services[$i]['notification_interval'] = $a_derivatedSC['notification_interval']; } else { $a_services[$i]['notification_interval'] = '30'; } $a_services[$i]['notification_period'] = "24x7"; $a_services[$i]['notification_options'] = 'w,u,c,r,f,s'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['process_perf_data'] = '1'; $a_services[$i]['active_checks_enabled'] = '1'; $a_services[$i]['passive_checks_enabled'] = '1'; $a_services[$i]['parallelize_check'] = '1'; $a_services[$i]['obsess_over_service'] = '1'; $a_services[$i]['check_freshness'] = '1'; $a_services[$i]['freshness_threshold'] = '3600'; $a_services[$i]['notifications_enabled'] = '1'; $a_services[$i]['event_handler_enabled'] = '0'; //$a_services[$i]['event_handler'] = 'super_event_kill_everyone!DIE'; $a_services[$i]['flap_detection_enabled'] = '1'; $a_services[$i]['failure_prediction_enabled'] = '1'; $a_services[$i]['retain_status_information'] = '1'; $a_services[$i]['retain_nonstatus_information'] = '1'; $a_services[$i]['is_volatile'] = '0'; // $a_services[$i]['_httpstink'] = 'NO'; // * Contacts $a_contacts = array(); $a_list_contact = $pmContact_Item->find("`itemtype`='PluginMonitoringServicescatalog'\n AND `items_id`='" . $dataBA['id'] . "'"); foreach ($a_list_contact as $data_contact) { if ($data_contact['users_id'] > 0) { if (isset($a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$data_contact['users_id']])) { $user->getFromDB($data_contact['users_id']); $a_contacts[] = $user->fields['name']; } } } else { if ($data_contact['groups_id'] > 0) { $queryg = "SELECT * FROM `glpi_groups_users`\n WHERE `groups_id`='" . $data_contact['groups_id'] . "'"; $resultg = $DB->query($queryg); while ($datag = $DB->fetch_array($resultg)) { if (in_array($data['entities_id'], $a_contacts_entities[$dataBA['id']][$datag['users_id']])) { $user->getFromDB($datag['users_id']); $a_contacts[] = $user->fields['name']; } } } } } $a_contacts_unique = array_unique($a_contacts); $a_services[$i]['contacts'] = implode(',', $a_contacts_unique); $i++; } } } } PluginMonitoringToolbox::logIfExtradebug('pm-shinken', "End generateServicesCfg business rules templates\n"); if ($file == "1") { $config = "# Generated by plugin monitoring for GLPI\n# on " . date("Y-m-d H:i:s") . "\n\n"; foreach ($a_services as $data) { $config .= $this->writeFile("service", $data); } return array('services.cfg', $config); } else { return $a_services; } }