static function runUnavailability($services_id = 0, $start = 0, $limit = 100000)
 {
     global $DB;
     $limit = 10000;
     $pmUnavailability = new PluginMonitoringUnavailability();
     $pmUnavailabilityState = new PluginMonitoringUnavailabilityState();
     $pmServiceevent = new PluginMonitoringServiceevent();
     $where = '';
     if ($services_id != '0') {
         $where = " WHERE `id`='" . $services_id . "' ";
     }
     $query = "SELECT `id` FROM `glpi_plugin_monitoring_services` " . $where . " ";
     $result = $DB->query($query);
     //      $nb = 0;
     //      $tttime = 0;
     while ($data = $DB->fetch_array($result)) {
         $pmUnavailability->getCurrentState($data['id']);
         //         Toolbox::logInFile('UNAV', "======= ".$data['id']." =======\n");
         $serviceevents_id = $pmUnavailabilityState->getLastID($data['id']);
         //         $loop = 0;
         while (true) {
             //            Toolbox::logInFile('UNAV', "start (loop ".$loop.")\n");
             //   $time = microtime();
             //   $time = explode(' ', $time);
             //   $time = $time[1] + $time[0];
             //   $start = $time;
             $query2 = "SELECT `id`,`state`,`date`,`event`\n               FROM `glpi_plugin_monitoring_serviceevents`\n               USE INDEX (unavailability)\n                     WHERE `unavailability` IN (0, 1)\n                        AND `state_type`='HARD'\n                        AND `plugin_monitoring_services_id`='" . $data['id'] . "'\n                        ORDER BY `id`\n                        LIMIT {$serviceevents_id}, {$limit}";
             $result2 = $DB->query($query2);
             //Toolbox::logInFile('UNAV', "LIMIT $serviceevents_id, $limit (".$DB->numrows($result2).")\n");
             $stop = False;
             if ($DB->numrows($result2) < $limit) {
                 $stop = True;
                 //             $nb += $DB->numrows($result2);
                 $serviceevents_id += $DB->numrows($result2);
             } else {
                 $serviceevents_id += $limit;
                 //               $nb += $limit;
             }
             while ($data2 = $DB->fetch_array($result2)) {
                 $pmUnavailability->checkState($data2['state'], $data2['date'], $data['id'], $DB->escape($data2['event']));
             }
             $pmUnavailabilityState->setLastID($data['id'], $serviceevents_id);
             //   $time = microtime();
             //   $time = explode(' ', $time);
             //   $time = $time[1] + $time[0];
             //   $finish = $time;
             //   $total_time = round(($finish - $start), 4);
             //   $tttime += $total_time;
             //            Toolbox::logInFile('UNAV', "end (".$total_time." seconds - ".$nb." / ".$tttime.")\n");
             //            $loop++;
             if ($stop) {
                 break;
             }
         }
     }
 }