public function createApplication() { $ems = new Monitor(); $ems->run(); $app = $ems->getApp(); $app['debug'] = true; unset($app['exception_handler']); return $app; }
public function testGetMonitorOptions() { $monitors = Monitor::model()->getMonitorOptions(); $this->assertTrue(3 === count($monitors)); $this->assertTrue(is_array($monitors)); $this->assertTrue(in_array('monitor1', $monitors)); $this->assertFalse(in_array('monitor4', $monitors)); }
/** * Updates a particular model. * @param integer $id the ID of the model to be updated */ public function actionUbah($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Server'])) { $model->attributes = $_POST['Server']; $model->save(); } $monitorListBukan = new Monitor('search'); $monitorListBukan->unsetAttributes(); $monitorListBukan->serverId = $id; $monitorList = new ServerMonitor('search'); $monitorList->unsetAttributes(); $monitorList->server_id = $id; $this->render('ubah', array('model' => $model, 'monitorListBukan' => $monitorListBukan, 'monitorList' => $monitorList)); }
public function actionSort() { $return = array('sukses' => false); if (isset($_POST['mon'])) { Monitor::model()->updateOrder($_POST['mon']); $return = array('sukses' => true); } $this->renderJSON($return); }
public static function outputToDevice($deviceID) { if ($deviceID == 1) { Monitor::drawDataToMonitor(); } if ($deviceID == 2) { Printer::sendDataToPrinter(); } }
public static function getMonitors() { $monitors = array(); $mrows = $GLOBALS['PW_DB']->executeSelect('*', 'monitors', ''); foreach ($mrows as $m) { $monitors[] = Monitor::fetch($m); } return $monitors; }
public function actionMonitorDetail($id, $serverId) { $namaTabel = "{$serverId}_{$id}"; $model = new MonitorDetail($namaTabel); $model->scenario = 'search'; $monitor = Monitor::model()->findByPk($id); $server = Server::model()->findByPk($serverId); $this->render('monitor_detail', ['model' => $model, 'server' => $server, 'monitor' => $monitor]); }
public static function checkAll() { $monitors = $GLOBALS['PW_DB']->executeSelect('*', 'monitors', ''); foreach ($monitors as $mrow) { $monitor = Monitor::fetch($mrow); $up = $monitor->poll(); echo $monitor->getAlias(), $up; $monitor->saveToDb(); } }
/** * @param string $func_name * @param string $desc * @return array */ private function runTestFunction($func_name, $desc) { $start_mem_usage = memory_get_usage(); $start_time = Monitor::getMicroTime(); for ($i = $this->num_runs; $i > 0; $i--) { $this->{$func_name}(); } $memory = memory_get_usage() - $start_mem_usage; return array('function' => $func_name, 'description' => $desc, 'mem_usage' => round($memory / 1024 / 1024, 4), 'time' => bcsub(Monitor::getMicroTime(), $start_time, 4)); }
public function processDelete($data) { $this->customProcessDelete(); $mons = $GLOBALS['PW_DB']->executeSelect('*', 'monitors', 'WHERE ' . intval($this->id) . ' IN (notification_channels)'); foreach ($mons as $mon) { $mhandle = Monitor::fetch($mon); $mhandle->deleteChannel($mhandle); $mhandle->saveToDb(); } $GLOBALS['PW_DB']->executeDelete('channels', 'WHERE id=' . intval($this->id)); }
public function pushError($error) { $di = \Phalcon\DI::getDefault(); if (isset($di['request'])) { $error['url'] = $di['request']->getHttpHost() . $di['request']->getUri(); } if (isset($di['local']->rawData['service'])) { $error['callinfo'] = json_encode($di['local']->rawData); if ($di['local']->rawData['service'] == 'Api\\Services\\Monitor') { return; } } $error['app'] = Monitor::getProject(); $error['serverip'] = sprintf("%u\n", ip2long(Monitor::getLocalip())); $di['remote']->swooleCall(array('service' => 'Api\\Services\\Monitor', 'method' => 'addlog', 'args' => array($error))); }
public function run() { $servers = ServerMonitor::model()->ambilServers($this->monitorId); $monitor = Monitor::model()->findByPk($this->monitorId); $tipeOutput = $monitor->outputType->nama; $tipeView = $monitor->viewType->nama; switch ($tipeView) { case 'linechart': $view = 'boxMonitorLineChart'; break; case 'onoffstatus': $view = 'boxMonitorOnOffStatus'; break; case 'text': $view = 'boxMonitorText'; break; } $this->render($view, array('title' => $this->title, 'monitorId' => $this->monitorId, 'servers' => $servers, 'tipeOutput' => $tipeOutput)); }
/** * test file writing stops at max size. max size is set to 10 in setUp, so there is only space for 1 log * @todo doesn't work as fileSize always returns the same value as at first read. So test manually instead. */ public function disabletestMaxSize() { AmfphpMonitor::addTime('test time 0 '); $this->object->filterSerializedResponse(null); AmfphpMonitor::addTime('should not log'); $this->object->filterSerializedResponse(null); $this->object->filterSerializedResponse(null); $this->object->filterSerializedResponse(null); $this->object->filterSerializedResponse(null); $log = file_get_contents($this->logPath); //echo $log; //echo "ertert " . filesize($this->logPath); $this->assertTrue(strpos($log, 'should not log') === false); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer $id the ID of the model to be loaded * @return Monitor the loaded model * @throws CHttpException */ public function loadModel($id) { $model = Monitor::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }
/** Generate bigdump : generate items for an entity * * @param $ID_entity entity ID **/ function generate_entity($ID_entity) { global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK, $DOCUMENTS, $NET_PORT, $NET_LOC; regenerateTreeCompleteName("glpi_entities"); $current_year = date("Y"); // DOMAIN $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine"); $dp = new Domain(); $FIRST["domain"] = getMaxItem("glpi_domains")+1; for ($i=0 ; $i<$MAX['domain'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "domain $ID_entity '$i"; } $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); } $LAST["domain"] = getMaxItem("glpi_domains"); // STATUS $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'"); $dp = new State(); $FIRST["state"] = getMaxItem("glpi_states")+1; for ($i=0 ; $i<$MAX['state'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "State $ID_entity '$i"; } $state_id = $dp->add(toolbox::addslashes_deep(array('name' => $val, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'comment' => "comment $val"))); // generate sub status for ($j=0 ; $j<$MAX['state'] ; $j++) { $val2 = "Sub $val $j"; $dp->add(toolbox::addslashes_deep(array('name' => $val2, 'entities_id' => $ID_entity, 'is_recursive' => 1, 'states_id' => $state_id, 'comment' => "comment $val"))); } } $LAST["state"] = getMaxItem("glpi_states"); // glpi_groups $FIRST["groups"] = getMaxItem("glpi_groups")+1; $group = new Group(); for ($i=0 ; $i<$MAX['groups'] ; $i++) { $gID = $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "group d'$i", 'comment' => "comment group d'$i", 'is_assign' => 0))); // Generate sub group for ($j=0 ; $j<$MAX['groups'] ; $j++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "subgroup d'$j", 'comment' => "comment subgroup d'$j of group $i", 'groups_id' => $gID, 'is_assign' => 0))); } } $LAST["groups"] = getMaxItem("glpi_groups"); $FIRST["techgroups"] = $LAST["groups"]+1; for ($i=0 ; $i<$MAX['groups'] ; $i++) { $group->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "tech group d'$i", 'comment' => "comment tech group d'$i"))); } $LAST["techgroups"] = getMaxItem("glpi_groups"); regenerateTreeCompleteName("glpi_groups"); // glpi_users $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1; $user = new User(); $gu = new Group_User(); for ($i=0 ; $i<$MAX['users_sadmin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "sadmin$i-$ID_entity", 'password' => "sadmin'$i", 'password2' => "sadmin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "sadmin '$i name", 'firstname' => "sadmin '$i firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 4, '_entities_id' => $ID_entity, '_is_recursive' => 1 ))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_sadmin"] = getMaxItem("glpi_users"); $FIRST["users_admin"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_admin'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "admin$i-$ID_entity", 'password' => "admin'$i", 'password2' => "admin'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "admin$i 'name", 'firstname' => "admin$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 3, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']), 'is_manager' => 1, 'is_delegate' => 1)); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'is_manager' => 1, 'is_delegate' => 1)); } $LAST["users_admin"] = getMaxItem("glpi_users"); $FIRST["users_normal"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_normal'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "normal$i-$ID_entity", 'password' => "normal'$i", 'password2' => "normal'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "normal$i 'name", 'firstname' => "normal$i 'firstname", 'comment' => "comment '$i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 2, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']))); } $LAST["users_normal"] = getMaxItem("glpi_users"); $FIRST["users_postonly"] = getMaxItem("glpi_users")+1; for ($i=0 ; $i<$MAX['users_postonly'] ; $i++) { $users_id = $user->add(toolbox::addslashes_deep( array('name' => "postonly$i-$ID_entity", 'password' => "postonly'$i", 'password2' => "postonly'$i", 'phone' => "tel $i", 'phone2' => "tel2 $i", 'mobile' => "mobile $i", 'realname' => "postonly$i 'name", 'firstname' => "postonly$i 'firstname", 'comment' => "comment' $i", 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'usercategories_id' => mt_rand(0,$MAX['user_type']), '_profiles_id' => 1, '_entities_id' => $ID_entity, '_is_recursive' => 1))); $gu->add(array('users_id' => $users_id, 'groups_id' => mt_rand($FIRST['groups'], $LAST['groups']))); } $LAST["users_postonly"] = getMaxItem("glpi_users"); $FIRST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories")+1; $kbc = new KnowbaseItemCategory(); for ($i=0 ; $i<max(1,pow($MAX['kbcategories'],1/3)) ; $i++) { $newID = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ' categorie $i", 'comment' => "comment ' categorie $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $j++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity s-categorie '$j", 'comment' => "comment s-categorie '$j", 'knowbaseitemcategories_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['kbcategories'],1/2)) ; $k++) { $newID2 = $kbc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "entity ss-categorie' $k", 'comment' => "comment ss-categorie' $k", 'knowbaseitemcategories_id' => $newID2))); } } } $query = "OPTIMIZE TABLE `glpi_knowbaseitemcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_knowbaseitemcategories"); $LAST["kbcategories"] = getMaxItem("glpi_knowbaseitemcategories"); // LOCATIONS $added = 0; $FIRST["locations"] = getMaxItem("glpi_locations")+1; $loc = new Location(); for ($i=0 ; $i<pow($MAX['locations'],1/5)&&$added<$MAX['locations'] ; $i++) { $added++; $newID = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "location' $i", 'comment' => "comment 'location $i", 'building' => "building $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $added++; $newID2 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "s-location '$j", 'comment' => "comment s-location '$j", 'building' => "building $i", 'room' => "stage '$j", 'locations_id' => $newID))); for ($k=0 ; $k<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $k++) { $added++; $newID3 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ss-location '$k", 'comment' => "comment ss-location' $k", 'building' => "building $i", 'room' => "part' $k", 'locations_id' => $newID2))); for ($l=0 ; $l<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $l++) { $added++; $newID4 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "sss-location' $l", 'comment' => "comment sss-location' $l", 'building' => "building $i", 'room' => "room' $l", 'locations_id' => $newID3))); for ($m=0 ; $m<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $m++) { $added++; $newID5 = $loc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ssss-location' $m", 'comment' => "comment ssss-location' $m", 'building' => "building $i", 'room' => "room' $l-$m", 'locations_id' => $newID4))); } } } } } $query = "OPTIMIZE TABLE `glpi_locations`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_locations"); $LAST["locations"]=getMaxItem("glpi_locations"); // Task categories $added = 0; $FIRST["taskcategory"] = getMaxItem("glpi_taskcategories")+1; $tc = new TaskCategory(); for ($i=0 ; $i<pow($MAX['taskcategory'],1/5)&&$added<$MAX['taskcategory'] ; $i++) { $added++; $newID = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i"))); for ($j=0 ; $j<mt_rand(0,pow($MAX['locations'],1/4))&&$added<$MAX['locations'] ; $j++) { $newID2 = $tc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "ent$ID_entity taskcategory' $i", 'comment' => "comment ent$ID_entity taskcategory' $i", 'taskcategories_id' => $newID))); $added++; } } $query = "OPTIMIZE TABLE `glpi_taskcategories`"; $DB->query($query) or die("PB REQUETE ".$query); regenerateTreeCompleteName("glpi_taskcategories"); $LAST["taskcategory"] = getMaxItem("glpi_taskcategories"); $ic = new ItilCategory(); // Specific ticket categories $newID = $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "category for entity' $ID_entity", 'comment' => "comment category for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'],$LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'],$LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1))); for ($i=0 ; $i<max(1,pow($MAX['tracking_category'],1/3)) ; $i++) { $ic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "scategory for entity' $ID_entity", 'comment' => "comment scategory for entity' $ID_entity", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST['techgroups'], $LAST['techgroups']), 'tickettemplates_id_incident' => 1, 'tickettemplates_id_demand' => 1, 'itilcategories_id' => $newID))); } regenerateTreeCompleteName("glpi_itilcategories"); $FIRST["solutiontypes"] = getMaxItem("glpi_solutiontypes")+1; $items = array("d'après KB"); $st = new SolutionType(); for ($i=0 ; $i<$MAX['solutiontypes'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "type de solution ' $i"; } $st->add(toolbox::addslashes_deep(array('name' => $val, 'comment' => "comment $val", 'entities_id' => $ID_entity, 'is_recursive' => 1))); } $LAST["solutiontypes"] = getMaxItem("glpi_solutiontypes"); $FIRST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates")+1; $nb_items = mt_rand(0,$MAX['solutiontemplates']); $st = new SolutionTemplate(); for ($i=0 ; $i<$nb_items ; $i++) { $st-> add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "solution' $i-$ID_entity", 'content' => "content solution' $i-$ID_entity", 'solutiontypes_id' => mt_rand(0,$MAX['solutiontypes']), 'comment' => "comment solution' $i-$ID_entity"))); } $LAST["solutiontemplates"] = getMaxItem("glpi_solutiontemplates"); // Add Specific questions $k = 0; $FIRST["kbitems"] = getMaxItem("glpi_knowbaseitems")+1; $ki = new KnowbaseItem(); $eki = new Entity_KnowbaseItem(); for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 0)); } } // Add global questions for ($i=$FIRST['kbcategories'] ; $i<=$LAST['kbcategories'] ; $i++) { $nb = mt_rand(0,$MAX_KBITEMS_BY_CAT); for ($j=0 ; $j<$nb ; $j++) { $k++; $newID = $ki->add(toolbox::addslashes_deep( array('knowbaseitemcategories_id' => $i, 'name' => "Entity' $ID_entity Recursive Question $k", 'answer' => "Answer' $k".Toolbox::getRandomString(50), 'is_faq' => mt_rand(0,1), 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin'])))); $eki->add(array('entities_id' => $ID_entity, 'knowbaseitems_id' => $newID, 'is_recursive' => 1)); } } $LAST["kbitems"] = getMaxItem("glpi_knowbaseitems"); // Ajout documents specific $FIRST["document"] = getMaxItem("glpi_documents")+1; $doc = new Document(); for ($i=0 ; $i<$MAX['document'] ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "commen't $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-0"; } // Global ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $link = ""; if (mt_rand(0,100)<50) { $link = "http://linktodoc/doc$i"; } $docID = $doc->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive document' $i-$ID_entity", 'documentcategories_id' => mt_rand(1,$MAX['rubdocs']), 'comment' => "comment' $i", 'link' => $link, 'notepad' => "notes document' $i"))); $DOCUMENTS[$docID] = $ID_entity."-1"; } $LAST["document"] = getMaxItem("glpi_documents"); // Ajout budgets specific $FIRST["budget"] = getMaxItem("glpi_budgets")+1; $b = new Budget(); for ($i=0 ; $i<$MAX['budget'] ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 0, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["budget"] = getMaxItem("glpi_budgets"); // GLobal ones for ($i=0 ; $i<$MAX['document']/2 ; $i++) { $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = $date1+MONTH_TIMESTAMP*12*mt_rand(1,4); // + entre 1 et 4 ans $b->add(toolbox::addslashes_deep( array('name' => "Recursive budget' $i-$ID_entity", 'entities_id' => $ID_entity, 'is_recusive' => 1, 'comment' => "comment' $i-$ID_entity", 'begin_date' => date("Y-m-d",intval($date1)), 'end_date' => date("Y-m-d",intval($date2))))); } $LAST["document"] = getMaxItem("glpi_documents"); // glpi_suppliers $items = array("DELL", "IBM", "ACER", "Microsoft", "Epson", "Xerox", "Hewlett Packard", "Nikon", "Targus", "LG", "Samsung", "Lexmark"); $FIRST["enterprises"] = getMaxItem("glpi_suppliers")+1; $ent = new Supplier(); // Global ones for ($i=0 ; $i<$MAX['enterprises']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive' $val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes enterprises' $i"))); addDocuments('Supplier', $entID); } // Specific ones for ($i=0 ; $i<$MAX['enterprises'] ; $i++) { if (isset($items[$i])) { $val = $items[$i]; } else { $val = "enterprise_".$i."_ID_entity"; } $entID = $ent->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "'$val-$ID_entity", 'suppliertypes_id' => mt_rand(1,$MAX['enttype']), 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'website' => "http://www.$val.com/", 'fax' => "fax $i", 'email' => "info@ent$i.com", 'notepad' => "notes supplier' $i", 'comment' => "comment supplier' $i"))); addDocuments('Supplier', $entID); } $LAST["enterprises"] = getMaxItem("glpi_suppliers"); // Ajout contracts $FIRST["contract"] = getMaxItem("glpi_contracts")+1; $c = new Contract(); $cs = new Contract_Supplier(); $cc = new ContractCost(); // Specific for ($i=0 ; $i<$MAX['contract'] ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "contract' $i-$ID_entity", 'num' => "num' $i", 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); // Add a cost $cc->add(toolbox::addslashes_deep( array('contracts_id' => $contractID, 'cost' => mt_rand(100,10000), 'name' => "Initial 'cost", 'begin_date' => $date, 'budgets_id' => mt_rand($FIRST['budget'], $LAST['budget'])))); } for ($i=0 ; $i<$MAX['contract']/2 ; $i++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $contractID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 1, 'name' => "Recursive contract' $i-$ID_entity", 'num' => "num' $i", 'cost' => mt_rand(100,10000), 'contracttypes_id' => mt_rand(1,$MAX['contract_type']), 'begin_date' => $date, 'duration' => mt_rand(1,36), 'notice' => mt_rand(1,3), 'periodicity' => mt_rand(1,36), 'billing' => mt_rand(1,36), 'comment' => "comment' $i", 'accounting_number' => "compta num' $i", 'renewal' => 1))); addDocuments('Contract', $contractID); // Add an enterprise $cs->add(array('contracts_id' => $contractID, 'suppliers_id' => mt_rand($FIRST["enterprises"], $LAST["enterprises"]))); } $LAST["contract"] = getMaxItem("glpi_contracts"); // Ajout contacts $prenoms = array("Jean", "John", "Louis", "Pierre", "Auguste", "Albert", "Julien", "Guillaume", "Bruno", "Maurice", "Francois", "Laurent", "Richard", "Henri", "Clement", "d'avy"); $noms = array("Dupont", "Smith", "Durand", "Martin", "Dubois", "Dufour", "Dupin", "Duval", "Petit", "Grange", "Bernard", "Bonnet", "Richard", "Leroy", "Dumont", "Fontaine", "d'orleans"); $FIRST["contacts"] = getMaxItem("glpi_contacts")+1; $c = new Contact(); $cs = new Contact_Supplier(); for ($i=0 ; $i<$MAX['contacts'] ; $i++) { if (isset($noms[$i])) { $val = $noms[$i]; } else { $val = "name $i"; } if (isset($prenoms[$i])) { $val2 = $prenoms[$i]; } else { $val2 = "firstname $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val-$ID_entity", 'firstname' => $val2, 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } for ($i=0 ; $i<$MAX['contacts']/2 ; $i++) { if (isset($items[$i])) { $val = "Recursive ".$items[$i]; } else { $val = "Recursive contact $i"; } $contactID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => 0, 'name' => "$val'-$ID_entity", 'contacttypes_id' => mt_rand(1,$MAX['contact_type']), 'usertitles_id' => mt_rand(0,$MAX['user_title']), 'phone' => "phone $i", 'phone2' => "phone2 $i", 'mobile' => "mobile $i", 'fax' => "fax $i", 'email' => "email $i", 'address' => "address' $i", 'postcode' => "postcode $i", 'town' => "town' $i", 'state' => "state' $i", 'country' => "country $i", 'comment' => "Comment' $i"))); // Link with enterprise $cs->add(array('contacts_id' => $contactID, 'suppliers_id' => mt_rand($FIRST['enterprises'],$LAST['enterprises']))); } $LAST["contacts"] = getMaxItem("glpi_contacts"); // TYPE DE CONSOMMABLES $FIRST["type_of_consumables"] = getMaxItem("glpi_consumableitems")+1; $ci = new Consumableitem(); for ($i=0 ; $i<$MAX['type_of_consumables'] ; $i++) { $consID = $ci->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "consumable type' $i", 'ref' => "ref d' $i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'consumableitemtypes_id' => mt_rand(0,$MAX['consumable_type']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment' $i", 'notepad' => "notes consumableitem' $i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('ConsumableItem', $consID); // AJOUT INFOCOMS addInfocoms('ConsumableItem', $consID, $ID_entity); // Ajout consommable en stock $c = new Consumable(); for ($j=0 ; $j<mt_rand(0,$MAX['consumables_stock']) ; $j++) { $date = mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } // Ajout consommable donne for ($j=0 ; $j<mt_rand(0,$MAX['consumables_given']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'consumableitems_id' => $consID, 'date_in' => $date, 'date_out' => date("Y-m-d"))); // AJOUT INFOCOMS addInfocoms('Consumable', $ID, $ID_entity); } } $LAST["type_of_consumables"] = getMaxItem("glpi_consumableitems"); // TYPE DE CARTOUCHES $FIRST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems")+1; $ct = new CartridgeItem(); for ($i=0 ; $i<$MAX['type_of_cartridges'] ; $i++) { $cartID = $ct->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => mt_rand(0,1), 'name' => "cartridge ' type $i", 'ref' => "ref '$i", 'locations_id' => mt_rand($FIRST["locations"], $LAST['locations']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'users_id_tech' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id_tech' => mt_rand($FIRST["groups"], $LAST["groups"]), 'comment' => "comment '$i", 'notepad' => "notes cartridgeitem '$i", 'alarm_threshold' => mt_rand(0,10)))); addDocuments('CartridgeItem', $cartID); // AJOUT INFOCOMS addInfocoms('CartridgeItem', $cartID, $ID_entity); $c = new Cartridge(); $cipm = new CartridgeItem_PrinterModel(); // Ajout cartouche en stock for ($j=0 ; $j<mt_rand(0,$MAX['cartridges_stock']) ; $j++) { $date = mt_rand(2000,$current_year-1)."-".mt_rand(1,12)."-".mt_rand(1,28); $ID = $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $cartID, 'date_in' => $date)); // AJOUT INFOCOMS addInfocoms('Cartridge', $ID, $ID_entity); } // Assoc printer type to cartridge type $cipm->add(array('cartridgeitems_id' => $cartID, 'printermodels_id' => mt_rand(1,$MAX['type_printers']), )); } $LAST["type_of_cartridges"] = getMaxItem("glpi_cartridgeitems"); // Networking $NET_LOC = array(); $FIRST["networking"] = getMaxItem("glpi_networkequipments")+1; $FIRST["printers"] = getMaxItem("glpi_printers")+1; $ne = new NetworkEquipment(); $p = new Printer(); $np = new Netpoint(); $c = new Cartridge(); foreach ($DB->request('glpi_locations') as $data) { $i = $data["id"]; $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $infoIP = getNextIP(); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); // insert networking $netwID = $ne->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "networking '$i-$ID_entity", 'ram' => mt_rand(32,256), 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num '$i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment '$i", 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'networkequipmenttypes_id' => mt_rand(1,$MAX['type_networking']), 'networkequipmentmodels_id' => mt_rand(1,$MAX['model_networking']), 'networkequipmentfirmwares_id' => mt_rand(1,$MAX['firmware']), 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'mac' => getNextMAC(), 'ip' => $infoIP["ip"], 'notepad' => "notes networking '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); $NET_LOC[$data['id']] = $netwID; addDocuments('NetworkEquipment', $netwID); addContracts('NetworkEquipment', $netwID); // AJOUT INFOCOMS addInfocoms('NetworkEquipment', $netwID, $ID_entity); // Link with father addNetworkEthernetPort('NetworkEquipment', $netwID, $ID_entity, $i); // Ajout imprimantes reseaux : 1 par loc + connexion d un matos reseau + ajout de cartouches // Add trackings addTracking('NetworkEquipment', $netwID, $ID_entity); $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $recur = mt_rand(0,1); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recur, 'name' => "printer of loc '$i", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact '$i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $i, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['enterprises']), 'is_global' => 1, 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_sadmin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity, $recur); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result2 = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result2)>0) { $ctypeID = $DB->result($result2,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = abs(round(($date2-$date1)/$oldnb)); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $c->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => $date, 'date_use' => date("Y-m-d",$date2))); } $iface = mt_rand(1,$MAX['iface']); // Add networking ports addNetworkEthernetPort('Printer', $printID, $ID_entity, $i); } unset($NET_LOC); $LAST["networking"] = getMaxItem("glpi_networkequipments"); //////////// INVENTORY // glpi_computers $FIRST["computers"] = getMaxItem("glpi_computers")+1; $FIRST["monitors"] = getMaxItem("glpi_monitors")+1; $FIRST["phones"] = getMaxItem("glpi_phones")+1; $FIRST["peripherals"] = getMaxItem("glpi_peripherals")+1; $c = new Computer(); $mon = new Monitor(); $cdevmb = new Item_DeviceMotherBoard(); $cdevproc = new Item_DeviceProcessor(); $cdevmem = new Item_DeviceMemory(); $cdevhd = new Item_DeviceHardDrive(); $cdevnc = new Item_DeviceNetworkCard(); $cdevdr = new Item_DeviceDrive(); $cdevcon = new Item_DeviceControl(); $cdevgc = new Item_DeviceGraphicCard(); $cdevsc = new Item_DeviceSoundCard(); $cdevpci = new Item_DevicePci(); $cdevcase = new Item_DeviceCase(); $cdevps = new Item_DevicePowerSupply(); $cdisk = new ComputerDisk(); $np = new Netpoint(); $ci = new Computer_Item(); $phone = new Phone(); $print = new Printer(); $periph = new Peripheral(); $cart = new Cartridge(); for ($i=0 ; $i<$MAX['computers'] ; $i++) { $loc = mt_rand($FIRST["locations"],$LAST['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $userID = mt_rand($FIRST['users_normal'],$LAST['users_postonly']); $groupID = mt_rand($FIRST["groups"],$LAST["groups"]); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $domainID = mt_rand($FIRST['domain'],$LAST['domain']); $networkID = mt_rand(1,$MAX['network']); $compID = $c->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "computer ' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'operatingsystems_id' => mt_rand(1,$MAX['os']), 'operatingsystemversions_id' => mt_rand(1,$MAX['os_version']), 'operatingsystemservicepacks_id' => mt_rand(1,$MAX['os_sp']), 'os_license_number' => "os sn $i", 'os_licenseid' => "os id $i", 'autoupdatesystems_id' => mt_rand(1,$MAX['os_sp']), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'computertypes_id' => mt_rand(1,$MAX['type_computers']), 'computermodels_id' => mt_rand(1,$MAX['model']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes computer '$i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'uuid' => Toolbox::getRandomString(30) ))); addDocuments('Computer', $compID); addContracts('Computer', $compID); $NET_PORT['Computer'][$compID] = 0; // Add trackings addTracking('Computer', $compID, $ID_entity); // Add reservation addReservation('Computer', $compID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Computer', $compID, $ID_entity); // ADD DEVICE $cdevmb->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevproc->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,4); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevmem->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevhd->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } $cdevnc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15), 'mac' => getNextMAC())); $cdevdr->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevcon->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevgc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $cdevsc->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); $max = mt_rand(1,4); for($nb = 0; $nb<$max; $nb++) { $cdevpci->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial' => Toolbox::getRandomString(15))); } $cdevcase->addDevices(1, 'Computer', $compID, mt_rand(1,$MAX['device']), array('serial'=> Toolbox::getRandomString(15))); $max = mt_rand(1,2); $devid = mt_rand(1,$MAX['device']); for($nb = 0; $nb<$max; $nb++) { $cdevps->addDevices(1, 'Computer', $compID, $devid, array('serial' => Toolbox::getRandomString(15))); } // insert disk $nb_disk = mt_rand(1,$MAX_DISK); for ($j=1 ; $j<=$nb_disk ; $j++) { $totalsize = mt_rand(10000,1000000); $freesize = mt_rand(0,$totalsize); $cdisk->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'computers_id' => $compID, 'name' => "disk '$j", 'device' => "/dev/disk$j", 'mountpoint' => "/mnt/disk$j", 'filesystems_id' => mt_rand(1,10), 'totalsize' => $totalsize, 'freesize' => $freesize))); } // Add networking ports addNetworkEthernetPort('Computer', $compID, $ID_entity, $loc); // Ajout d'un ecran sur l'ordi $monID = $mon->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "monitor' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'size' => mt_rand(14,22), 'have_micro' => mt_rand(0,1), 'have_speaker' => mt_rand(0,1), 'have_subd' => mt_rand(0,1), 'have_bnc' => mt_rand(0,1), 'have_dvi' => mt_rand(0,1), 'have_pivot' => mt_rand(0,1), 'have_hdmi' => mt_rand(0,1), 'have_displayport' => mt_rand(0,1), 'locations_id' => $loc, 'monitortypes_id' => mt_rand(1,$MAX['type_monitors']), 'monitormodels_id' => mt_rand(1,$MAX['model_monitors']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes monitor' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Monitor', $monID); addContracts('Monitor', $monID); // Add trackings addTracking('Monitor', $monID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Monitor', $monID, $ID_entity); $ci->add(array('itemtype' => 'Monitor', 'items_id' => $monID, 'computers_id' => $compID, )); // Ajout d'un telephhone avec l'ordi $telID = $phone->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "phone' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'firmware' => Toolbox::getRandomString(10), 'brand' => "brand' $i", 'phonepowersupplies_id' => mt_rand(0,$MAX['phone_power']), 'number_line' => Toolbox::getRandomString(10), 'have_headset' => mt_rand(0,1), 'have_hp' => mt_rand(0,1), 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_phones']), 'phonemodels_id' => mt_rand(1,$MAX['model_phones']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes phone' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Phone', $telID); addContracts('Phone', $telID); // Add trackings addTracking('Phone', $telID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Phone', $telID, $ID_entity); $ci->add(array('itemtype' => 'Phone', 'items_id' => $telID, 'computers_id' => $compID)); // Ajout des periphs externes en connection directe while (mt_rand(0,100)<$percent['peripherals']) { $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes peripheral' $i", 'users_id' => $userID, 'groups_id' => $groupID, 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => $compID)); } // Ajout d'une imprimante connection directe pour X% des computers + ajout de cartouches if (mt_rand(0,100)<=$percent['printer']) { // Add printer $typeID = mt_rand(1,$MAX['type_printers']); $modelID = mt_rand(1,$MAX['model_printers']); $printID = $p->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "printer of comp' $i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'have_serial' => mt_rand(0,1), 'have_parallel' => mt_rand(0,1), 'have_usb' => mt_rand(0,1), 'have_wifi' => mt_rand(0,1), 'have_ethernet' => mt_rand(0,1), 'comment' => "comment' $i", 'memory_size' => mt_rand(0,128), 'locations_id' => $loc, 'domains_id' => $domainID, 'networks_id' => $networkID, 'printertypes_id' => $typeID, 'printermodels_id' => $modelID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes printers '$i", 'users_id' => mt_rand($FIRST['users_postonly'], $LAST['users_postonly']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Printer', $printID); addContracts('Printer', $printID); // Add trackings addTracking('Printer', $printID, $ID_entity); // Add connection $ci->add(array('itemtype' => 'Printer', 'items_id' => $printID, 'computers_id' => $compID)); // AJOUT INFOCOMS addInfocoms('Printer', $printID, $ID_entity); // Add Cartouches // Get compatible cartridge $query = "SELECT `cartridgeitems_id` FROM `glpi_cartridgeitems_printermodels` WHERE `printermodels_id` = '$typeID'"; $result = $DB->query($query) or die("PB REQUETE ".$query); if ($DB->numrows($result)>0) { $ctypeID = $DB->result($result,0,0) or die (" PB RESULT ".$query); $printed = 0; $oldnb = mt_rand(1,$MAX['cartridges_by_printer']); $date1 = strtotime(mt_rand(2000,$current_year)."-".mt_rand(1,12)."-".mt_rand(1,28)); $date2 = time(); $inter = round(($date2-$date1)/$oldnb); // Add old cartridges for ($j=0 ; $j<$oldnb ; $j++) { $printed += mt_rand(0,5000); $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date1+$j*$inter), 'date_out' => date("Y-m-d",$date1+($j+1)*$inter), 'pages' => $printed)); } // Add current cartridges $cart->add(array('entities_id' => $ID_entity, 'cartridgeitems_id' => $ctypeID, 'printers_id' => $printID, 'date_in' => date("Y-m-d",$date1), 'date_use' => date("Y-m-d",$date2))); } } } $LAST["computers"] = getMaxItem("glpi_computers"); $LAST["monitors"] = getMaxItem("glpi_monitors"); $LAST["phones"] = getMaxItem("glpi_phones"); // Add global peripherals $periph = new Peripheral(); $ci = new Computer_Item(); for ($i=0 ; $i<$MAX['global_peripherals'] ; $i++) { $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $periphID = $periph->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'name' => "periph '$i-$ID_entity", 'serial' => Toolbox::getRandomString(10), 'otherserial' => Toolbox::getRandomString(10), 'contact' => "contact' $i", 'contact_num' => "num' $i", 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'comment' => "comment' $i", 'brand' => "brand' $i", 'locations_id' => $loc, 'phonetypes_id' => mt_rand(1,$MAX['type_peripherals']), 'phonemodels_id' => mt_rand(1,$MAX['model_peripherals']), 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'is_global' => 1, 'notepad' => "notes peripheral' $i", 'users_id' => mt_rand($FIRST['users_normal'], $LAST['users_normal']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0) ))); addDocuments('Peripheral', $periphID); addContracts('Peripheral', $periphID); // Add trackings addTracking('Peripheral', $periphID, $ID_entity); // Add reservation addReservation('Peripheral', $periphID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Peripheral', $periphID, $ID_entity); // Add connections $val = mt_rand(1,$MAX['connect_for_peripherals']); for ($j=1 ; $j<$val ; $j++) { $ci->add(array('itemtype' => 'Peripheral', 'items_id' => $periphID, 'computers_id' => mt_rand($FIRST["computers"],$LAST['computers']))); } } $LAST["peripherals"] = getMaxItem("glpi_peripherals"); $FIRST["software"] = getMaxItem("glpi_softwares")+1; // Ajout logiciels + licences associees a divers PCs $items = array(array("Open'Office", "1.1.4", "2.0", "2.0.1"), array("Microsoft Office", "95", "97", "XP", "2000", "2003", "2007"), array("Acrobat Reader", "6.0", "7.0", "7.04"), array("Gimp", "2.0", "2.2"), array("InkScape", "0.4")); $soft = new Software(); $softvers = new SoftwareVersion(); $softlic = new SoftwareLicense(); $csv = new Computer_SoftwareVersion(); $csl = new Computer_SoftwareLicense(); for ($i=0 ; $i<$MAX['software'] ; $i++) { if (isset($items[$i])) { $name = $items[$i][0]; } else { $name = "software '$i"; } $loc = mt_rand(1,$MAX['locations']); $techID = mt_rand($FIRST['users_sadmin'],$LAST['users_admin']); $gtechID = mt_rand($FIRST["techgroups"],$LAST["techgroups"]); $recursive = mt_rand(0,1); $softID = $soft->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'name' => $name, 'comment' => "comment '$i", 'locations_id' => $loc, 'users_id_tech' => $techID, 'groups_id_tech' => $gtechID, 'manufacturers_id' => mt_rand(1,$MAX['manufacturer']), 'notepad' => "notes software '$i", 'users_id' => mt_rand($FIRST['users_admin'], $LAST['users_admin']), 'groups_id' => mt_rand($FIRST["groups"], $LAST["groups"]), 'is_helpdesk_visible' => 1, 'softwarecategories_id' => mt_rand(1,$MAX['softwarecategory']) ))); addDocuments('Software', $softID); addContracts('Software', $softID); // Add trackings addTracking('Software', $softID, $ID_entity); // AJOUT INFOCOMS addInfocoms('Software', $softID, $ID_entity); // Add versions $FIRST["version"] = getMaxItem("glpi_softwareversions")+1; if (isset($items[$i])) { $val2 = count($items[$i]); } else { $val2 = mt_rand(1,$MAX['softwareversions']+1); } for ($j=1 ; $j<=$val2 ; $j++) { if (isset($items[$i])) { $version = $items[$i][mt_rand(1,count($items[$i])-1)]; } else { $version = "$j.0"; } $os = mt_rand(1,$MAX['os']); $versID = $softvers->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'name' => $version, 'comment' => "comment '$version", 'states_id' => (mt_rand(0,100)<$percent['state'] ?mt_rand($FIRST['state'],$LAST['state']):0), 'operatingsystems_id' => $os))); $val3 = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$val3 ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csv->add(array('computers_id' => $comp_id, 'softwareversions_id' => $versID)); } } $LAST["version"] = getMaxItem("glpi_softwareversions"); // Add licenses $val2 = mt_rand(1,$MAX['softwarelicenses']); for ($j=0 ; $j<$val2 ; $j++) { $softwareversions_id_buy = mt_rand($FIRST["version"],$LAST["version"]); $softwareversions_id_use = mt_rand($softwareversions_id_buy,$LAST["version"]); $nbused = min($LAST["computers"]-$FIRST['computers'], mt_rand(1,$MAX['softwareinstall'])); $licID = $softlic->add(toolbox::addslashes_deep( array('entities_id' => $ID_entity, 'is_recursive' => $recursive, 'softwares_id' => $softID, 'number' => $nbused, 'softwarelicensetypes_id' => mt_rand(1,$MAX['licensetype']), 'name' => "license '$j", 'serial' => "serial $j", 'otherserial' => "otherserial $j", 'comment' => "comment license '$j", 'softwareversions_id_buy' => $softwareversions_id_buy, 'softwareversions_id_use' => $softwareversions_id_use))); $comp_id = mt_rand($FIRST["computers"], $LAST['computers']); for ($k=0 ; $k<$nbused ; $k++) { $comp_id++; if ($comp_id>$LAST["computers"]) { $comp_id = $FIRST["computers"]; } $csl->add(array('computers_id' => $comp_id, 'softwarelicenses_id' => $licID)); } } } $LAST["software"] = getMaxItem("glpi_softwares"); }
<?php include "../includes/Monitor.php"; $monitor = array(); $client = new Monitor(); //cantidad total de filas capturadas o encuestas ods2_mayo_14 mongodb $monitor['totalEncuestas'] = $client->totalEncuestas(); // ultimos datos del log $monitor['log'] = $client->getLog(); echo json_encode($monitor); exit;
/** * * Import monitors from OCS * @since 1.0 * @param $cfg_ocs OCSNG mode configuration * @param $computers_id computer's id in GLPI * @param $ocsservers_id OCS server id * @param $ocsid computer's id in OCS * @param entity the entity in which the monitor will be created * @param dohistory record in history link between monitor and computer */ static function importMonitor($cfg_ocs, $computers_id, $ocsservers_id, $ocsid, $entity, $dohistory) { global $PluginOcsinventoryngDBocs, $DB; self::checkOCSconnection($ocsservers_id); if ($cfg_ocs["import_monitor"]) { $already_processed = array(); $do_clean = true; $m = new Monitor(); $conn = new Computer_Item(); $query = "SELECT DISTINCT `CAPTION`, `MANUFACTURER`, `DESCRIPTION`, `SERIAL`, `TYPE`\n FROM `monitors`\n WHERE `HARDWARE_ID` = '{$ocsid}'"; // Config says import monitor with serial number only // Restrict SQL query ony for monitors with serial present if ($cfg_ocs["import_monitor"] == 4) { $query = $query . " AND `SERIAL` NOT LIKE ''"; } $result = $PluginOcsinventoryngDBocs->query($query); $lines = array(); $checkserial = true; // First pass - check if all serial present if ($PluginOcsinventoryngDBocs->numrows($result) > 0) { while ($line = $PluginOcsinventoryngDBocs->fetch_array($result)) { if (empty($line["SERIAL"])) { $checkserial = false; } $lines[] = Toolbox::clean_cross_side_scripting_deep(Toolbox::addslashes_deep($line)); } } if (count($lines) > 0 && ($cfg_ocs["import_monitor"] <= 2 || $checkserial)) { foreach ($lines as $line) { $mon = array(); $mon["name"] = $line["CAPTION"]; if (empty($line["CAPTION"]) && !empty($line["MANUFACTURER"])) { $mon["name"] = $line["MANUFACTURER"]; } if (empty($line["CAPTION"]) && !empty($line["TYPE"])) { if (!empty($line["MANUFACTURER"])) { $mon["name"] .= " "; } $mon["name"] .= $line["TYPE"]; } $mon["serial"] = $line["SERIAL"]; //Look for a monitor with the same name (and serial if possible) already connected //to this computer $query = "SELECT `m`.`id`, `gci`.`is_deleted`\n FROM `glpi_monitors` as `m`, `glpi_computers_items` as `gci`\n WHERE `m`.`id` = `gci`.`items_id`\n AND `gci`.`is_dynamic`='1'\n AND `computers_id`='{$computers_id}'\n AND `itemtype`='Monitor'\n AND `m`.`name`='" . $mon["name"] . "'"; if (!empty($mon["serial"])) { $query .= " AND `m`.`serial`='" . $mon["serial"] . "'"; } $results = $DB->query($query); $id = false; $lock = false; if ($DB->numrows($results) == 1) { $id = $DB->result($results, 0, 'id'); $lock = $DB->result($results, 0, 'is_deleted'); } if ($id == false) { // Clean monitor object $m->reset(); $mon["manufacturers_id"] = Dropdown::importExternal('Manufacturer', $line["MANUFACTURER"]); if ($cfg_ocs["import_monitor_comment"]) { $mon["comment"] = $line["DESCRIPTION"]; } $id_monitor = 0; if ($cfg_ocs["import_monitor"] == 1) { //Config says : manage monitors as global //check if monitors already exists in GLPI $mon["is_global"] = 1; $query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `name` = '" . $mon["name"] . "'\n AND `is_global` = '1'\n AND `entities_id` = '{$entity}'"; $result_search = $DB->query($query); if ($DB->numrows($result_search) > 0) { //Periph is already in GLPI //Do not import anything just get periph ID for link $id_monitor = $DB->result($result_search, 0, "id"); } else { $input = $mon; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $id_monitor = $m->add($input); } } else { if ($cfg_ocs["import_monitor"] >= 2) { //Config says : manage monitors as single units //Import all monitors as non global. $mon["is_global"] = 0; // Try to find a monitor with the same serial. if (!empty($mon["serial"])) { $query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `serial` LIKE '%" . $mon["serial"] . "%'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'"; $result_search = $DB->query($query); if ($DB->numrows($result_search) == 1) { //Monitor founded $id_monitor = $DB->result($result_search, 0, "id"); } } //Search by serial failed, search by name if ($cfg_ocs["import_monitor"] == 2 && !$id_monitor) { //Try to find a monitor with no serial, the same name and not already connected. if (!empty($mon["name"])) { $query = "SELECT `glpi_monitors`.`id`\n FROM `glpi_monitors`\n LEFT JOIN `glpi_computers_items`\n ON (`glpi_computers_items`.`itemtype`='Monitor'\n AND `glpi_computers_items`.`items_id`\n =`glpi_monitors`.`id`)\n WHERE `serial` = ''\n AND `name` = '" . $mon["name"] . "'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'\n AND `glpi_computers_items`.`computers_id` IS NULL"; $result_search = $DB->query($query); if ($DB->numrows($result_search) == 1) { $id_monitor = $DB->result($result_search, 0, "id"); } } } if (!$id_monitor) { $input = $mon; if ($cfg_ocs["states_id_default"] > 0) { $input["states_id"] = $cfg_ocs["states_id_default"]; } $input["entities_id"] = $entity; $id_monitor = $m->add($input); } } } // ($cfg_ocs["import_monitor"] >= 2) if ($id_monitor) { //Import unique : Disconnect monitor on other computer done in Connect function $connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Monitor', 'items_id' => $id_monitor, '_no_history' => !$dohistory, 'is_dynamic' => 1, 'is_deleted' => 0)); $already_processed[] = $id_monitor; //Update column "is_deleted" set value to 0 and set status to default $input = array(); $old = new Monitor(); if ($old->getFromDB($id_monitor)) { if ($old->fields["is_deleted"]) { $input["is_deleted"] = 0; } if ($cfg_ocs["states_id_default"] > 0 && $old->fields["states_id"] != $cfg_ocs["states_id_default"]) { $input["states_id"] = $cfg_ocs["states_id_default"]; } if (empty($old->fields["name"]) && !empty($mon["name"])) { $input["name"] = $mon["name"]; } if (empty($old->fields["serial"]) && !empty($mon["serial"])) { $input["serial"] = $mon["serial"]; } if (count($input)) { $input["id"] = $id_monitor; $input['entities_id'] = $entity; $m->update($input); } } } } else { $already_processed[] = $id; } } // end foreach if ($cfg_ocs["import_monitor"] <= 2 || $checkserial) { //Look for all monitors, not locked, not linked to the computer anymore $query = "SELECT `id`\n FROM `glpi_computers_items`\n WHERE `itemtype`='Monitor'\n AND `computers_id`='{$computers_id}'\n AND `is_dynamic`='1'\n AND `is_deleted`='0'"; if (!empty($already_processed)) { $query .= "AND `items_id` NOT IN (" . implode(',', $already_processed) . ")"; } foreach ($DB->request($query) as $data) { //Delete all connexions $conn->delete(array('id' => $data['id'], '_ocsservers_id' => $ocsservers_id), true); } } } } }
<?php $monitor = Monitor::fetch(intval($_GET['id'])); if (FormHelpers::donePOST()) { $monitor->processDelete($_GET); ?> <div class="message"> The monitor has been deleted. <br /> <a href="?page=monitors">Return to monitors</a> </div> <? } else { ?> <div class="form-field"> </div> <?php FormHelpers::startForm('POST', '?page=monitor-delete&id=' . $monitor->getId()); FormHelpers::createHidden('confirmed', '1'); ?> <center> Are you sure you want to delete this monitor?<br /> <?php FormHelpers::createSubmit('Yes'); ?> </center> <?php FormHelpers::endForm(); }
/** * Monitor constructor */ function tracker_monitor($name = '', $monitorId = '', $metadata = '', $store = '') { parent::Monitor($name, $monitorId, $metadata, $store); }
if (empty($_POST["id"])) { exit; } if (!isset($_REQUEST['glpi_tab'])) { exit; } if (!isset($_POST["sort"])) { $_POST["sort"] = ""; } if (!isset($_POST["order"])) { $_POST["order"] = ""; } if (!isset($_POST["withtemplate"])) { $_POST["withtemplate"] = ""; } $monitor = new Monitor(); if ($_POST["id"] > 0 && $monitor->can($_POST["id"], 'r')) { if (!empty($_POST["withtemplate"])) { switch ($_REQUEST['glpi_tab']) { case 4: Infocom::showForItem($monitor, $_POST["withtemplate"]); Contract::showAssociated($monitor, $_POST["withtemplate"]); break; case 5: Document::showAssociated($monitor, $_POST["withtemplate"]); break; default: Plugin::displayAction($monitor, $_REQUEST['glpi_tab'], $_POST["withtemplate"]); } } else { switch ($_REQUEST['glpi_tab']) {
$monitor->restore($_POST); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"])); $monitor->redirectToList(); } else { if (isset($_POST["purge"])) { $monitor->check($_POST["id"], 'd'); $monitor->delete($_POST, 1); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"])); $monitor->redirectToList(); } else { if (isset($_POST["update"])) { $monitor->check($_POST["id"], 'w'); $monitor->update($_POST); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s updates an item'), $_SESSION["glpiname"])); Html::back(); } else { if (isset($_POST["unglobalize"])) { $monitor->check($_POST["id"], 'w'); Computer_Item::unglobalizeItem($monitor); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s sets unitary management'), $_SESSION["glpiname"])); Html::redirect($CFG_GLPI["root_doc"] . "/front/monitor.form.php?id=" . $_POST["id"]); } else { Html::header(Monitor::getTypeName(2), $_SERVER['PHP_SELF'], "inventory", "monitor"); $monitor->showForm($_GET["id"], array('withtemplate' => $_GET["withtemplate"])); Html::footer(); } } } } } }
private function _getMonitor($name = '', $monitorId = '', $metadata = '', $store = '') { $class = strtolower($name . '_monitor'); $monitor = null; if (file_exists('custom/modules/Trackers/monitor/' . $class . '.php')) { require_once 'custom/modules/Trackers/monitor/' . $class . '.php'; if (class_exists($class)) { $monitor = new $class($name, $monitorId, $metadata, $store); } } elseif (file_exists('modules/Trackers/monitor/' . $class . '.php')) { require_once 'modules/Trackers/monitor/' . $class . '.php'; if (class_exists($class)) { $monitor = new $class($name, $monitorId, $metadata, $store); } } else { $monitor = new Monitor($name, $monitorId, $metadata, $store); } $monitor->setEnabled(empty($this->disabledMonitors[$monitor->name])); return $monitor; }
/** * Show report title **/ static function title() { global $PLUGIN_HOOKS, $CFG_GLPI; // Report generation // Default Report included $report_list["default"]["name"] = __('Default report'); $report_list["default"]["file"] = "report.default.php"; if (Contract::canView()) { // Rapport ajoute par GLPI V0.2 $report_list["Contrats"]["name"] = __('By contract'); $report_list["Contrats"]["file"] = "report.contract.php"; } if (Infocom::canView()) { $report_list["Par_annee"]["name"] = __('By year'); $report_list["Par_annee"]["file"] = "report.year.php"; $report_list["Infocoms"]["name"] = __('Hardware financial and administrative information'); $report_list["Infocoms"]["file"] = "report.infocom.php"; $report_list["Infocoms2"]["name"] = __('Other financial and administrative information (licenses, cartridges, consumables)'); $report_list["Infocoms2"]["file"] = "report.infocom.conso.php"; } if (Session::haveRight("networking", READ)) { $report_list["Rapport prises reseau"]["name"] = __('Network report'); $report_list["Rapport prises reseau"]["file"] = "report.networking.php"; } if (Session::haveRight("reservation", READ)) { $report_list["reservation"]["name"] = __('Loan'); $report_list["reservation"]["file"] = "report.reservation.php"; } if (Computer::canView() || Monitor::canView() || Session::haveRight("networking", READ) || Peripheral::canView() || Printer::canView() || Phone::canView()) { $report_list["state"]["name"] = _n('Status', 'Statuses', Session::getPluralNumber()); $report_list["state"]["file"] = "report.state.php"; } //Affichage du tableau de presentation des stats echo "<table class='tab_cadre_fixe'>"; echo "<tr><th colspan='2'>" . __('Select the report you want to generate') . "</th></tr>"; echo "<tr class='tab_bg_1'><td class='center'>"; $count = count($report_list); $selected = -1; $values = array($CFG_GLPI["root_doc"] . '/front/report.php' => Dropdown::EMPTY_VALUE); while ($data = each($report_list)) { $val = $data[0]; $name = $report_list["{$val}"]["name"]; $file = $report_list["{$val}"]["file"]; $key = $CFG_GLPI["root_doc"] . "/front/" . $file; $values[$key] = $name; if (stripos($_SERVER['REQUEST_URI'], $key) !== false) { $selected = $key; } } $names = array(); $optgroup = array(); if (isset($PLUGIN_HOOKS["reports"]) && is_array($PLUGIN_HOOKS["reports"])) { foreach ($PLUGIN_HOOKS["reports"] as $plug => $pages) { if (is_array($pages) && count($pages)) { foreach ($pages as $page => $name) { $names[$plug . '/' . $page] = array("name" => $name, "plug" => $plug); $optgroup[$plug] = Plugin::getInfo($plug, 'name'); } } } asort($names); } foreach ($optgroup as $opt => $title) { $group = $title; foreach ($names as $key => $val) { if ($opt == $val["plug"]) { $file = $CFG_GLPI["root_doc"] . "/plugins/" . $key; $values[$group][$file] = $val["name"]; if (stripos($_SERVER['REQUEST_URI'], $file) !== false) { $selected = $file; } } } } Dropdown::showFromArray('statmenu', $values, array('on_change' => "window.location.href=this.options[this.selectedIndex].value", 'value' => $selected)); echo "</td>"; echo "</tr>"; echo "</table>"; }
<?php include 'src/php/files.php'; include 'src/php/monitor.php'; try { if ($_FILES) { $file = new Files("./files/", $_FILES); $monitor = new Monitor($file->getFileName(), "files/"); } } catch (Exception $e) { echo 'Exception: ', $e->getMessage(), "\n"; } ?> <!DOCTYPE html> <html> <head> <title>Station Monitor</title> <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.min.css"> <link rel="stylesheet" href="src/css/default.css"> </head> <body role="document"> <nav class="navbar navbar-inverse navbar-fixed-top"> <div class="container"> <div class="navbar-header"> <button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar" aria-expanded="false" aria-controls="navbar"> <span class="sr-only">Toggle navigation</span> <span class="icon-bar"></span> <span class="icon-bar"></span> <span class="icon-bar"></span> </button> <a class="navbar-brand" href="#">Station Monitor</a>
if (!isset($SESSION->lang)) { $SESSION->lang = DEFAULT_LANGUAGE; } \Locale::setDefault($SESSION->lang); $l10n->setLanguage($SESSION->lang); //============================================================================================ // Model //============================================================================================ require 'models/grouping.php'; require 'models/cpu.php'; require 'models/mon.php'; require 'models/per.php'; require 'models/key.php'; require 'models/furniture.php'; $cpu = new Cpu(); $mon = new Monitor(); $per = new Peripheral(); $key = new Key(); $furniture = new Furniture(); $equip = new Grouping(); //============================================================================================ // Load the page requested by the user //============================================================================================ if (!isset($_GET['page'])) { $data = $equip->listItems(); for ($i = 0; $i < count($data); $i++) { $z = $equip->countItems($data[$i]['group_id']); $data[$i]['noi'] = $z[0]['count']; } $employees = $equip->listEmployees(); $allCpu = $equip->listcpuUG();
$monitor->restore($_POST); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s restores an item'), $_SESSION["glpiname"])); $monitor->redirectToList(); } else { if (isset($_POST["purge"])) { $monitor->check($_POST["id"], PURGE); $monitor->delete($_POST, 1); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s purges an item'), $_SESSION["glpiname"])); $monitor->redirectToList(); } else { if (isset($_POST["update"])) { $monitor->check($_POST["id"], UPDATE); $monitor->update($_POST); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s updates an item'), $_SESSION["glpiname"])); Html::back(); } else { if (isset($_POST["unglobalize"])) { $monitor->check($_POST["id"], UPDATE); Computer_Item::unglobalizeItem($monitor); Event::log($_POST["id"], "monitors", 4, "inventory", sprintf(__('%s sets unitary management'), $_SESSION["glpiname"])); Html::redirect($CFG_GLPI["root_doc"] . "/front/monitor.form.php?id=" . $_POST["id"]); } else { Html::header(Monitor::getTypeName(Session::getPluralNumber()), $_SERVER['PHP_SELF'], "assets", "monitor"); $monitor->display(array('id' => $_GET["id"], 'withtemplate' => $_GET["withtemplate"])); Html::footer(); } } } } } }
<?php require_once dirname(__FILE__) . "/../lib/class_Monitor.php"; require_once dirname(__FILE__) . "/../http/classes/class_mb_exception.php"; /* * incoming parameters from command line */ if ($_SERVER["argc"] != 3) { echo _mb("Insufficient arguments! Monitoring aborted."); $e = new mb_exception("Insufficient arguments! Monitoring aborted."); die; } $reportFile = $_SERVER["argv"][1]; $autoUpdate = intval($_SERVER["argv"][2]); $monitor = new Monitor($reportFile, $autoUpdate, dirname(__FILE__) . "/tmp/"); $monitor->updateInXMLReport();
// ---------------------------------------------------------------------- define('GLPI_ROOT', '..'); include GLPI_ROOT . "/inc/includes.php"; if (empty($_GET["id"])) { $_GET["id"] = ""; } if (!isset($_GET["sort"])) { $_GET["sort"] = ""; } if (!isset($_GET["order"])) { $_GET["order"] = ""; } if (!isset($_GET["withtemplate"])) { $_GET["withtemplate"] = ""; } $monitor = new Monitor(); if (isset($_POST["add"])) { $monitor->check(-1, 'w', $_POST); $newID = $monitor->add($_POST); Event::log($newID, "monitors", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][20] . " " . $_POST["name"] . "."); glpi_header($_SERVER['HTTP_REFERER']); } else { if (isset($_POST["delete"])) { $monitor->check($_POST["id"], 'd'); $monitor->delete($_POST); Event::log($_POST["id"], "monitors", 4, "inventory", $_SESSION["glpiname"] . " " . $LANG['log'][22]); $monitor->redirectToList(); } else { if (isset($_POST["restore"])) { $monitor->check($_POST["id"], 'd'); $monitor->restore($_POST);
/** * Monitor constructor */ public function __construct($name = '', $monitorId = '', $metadata = '', $store = '') { parent::__construct($name, $monitorId, $metadata, $store); }
/** * @test */ public function ComputerMonitor() { global $DB; $DB->connect(); $a_dataMonit = getAllDatasFromTable("glpi_monitors"); $this->assertEquals(1, count($a_dataMonit), "Must have 1 monitor created"); $a_dataLink = getAllDatasFromTable("glpi_computers_items", "`itemtype`='Monitor'\n AND `computers_id`='1'"); $this->assertEquals(1, count($a_dataLink), "Number of monitors not right"); $a_dataLink = current($a_dataLink); $monitor = new Monitor(); $monitor->getFromDB($a_dataLink['items_id']); unset($monitor->fields['date_mod']); $a_reference = array('id' => '1', 'entities_id' => '0', 'name' => 'ThinkPad Display 1280x800', 'contact' => 'ddurieux', 'contact_num' => NULL, 'users_id_tech' => '0', 'groups_id_tech' => '0', 'comment' => '', 'serial' => 'UBYVUTFYEIUI', 'otherserial' => NULL, 'size' => '0', 'have_micro' => '0', 'have_speaker' => '0', 'have_subd' => '0', 'have_bnc' => '0', 'have_dvi' => '0', 'have_pivot' => '0', 'have_hdmi' => '0', 'have_displayport' => '0', 'locations_id' => '0', 'monitortypes_id' => '0', 'monitormodels_id' => '0', 'manufacturers_id' => '2', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'template_name' => NULL, 'users_id' => '0', 'groups_id' => '0', 'states_id' => '0', 'ticket_tco' => '0.0000', 'is_dynamic' => '0'); $this->assertEquals($a_reference, $monitor->fields); }