Exemplo n.º 1
0
 static function cronAdditionalalertsOcs($task = NULL)
 {
     global $DB, $CFG_GLPI;
     if (!$CFG_GLPI["use_mailing"]) {
         return 0;
     }
     $CronTask = new CronTask();
     if ($CronTask->getFromDBbyName("PluginAdditionalalertsOcsAlert", "AdditionalalertsOcs")) {
         if ($CronTask->fields["state"] == CronTask::STATE_DISABLE) {
             return 0;
         }
     } else {
         return 0;
     }
     $message = array();
     $cron_status = 0;
     foreach (self::getEntitiesToNotify('delay_ocs') as $entity => $delay_ocs) {
         foreach ($DB->request("glpi_plugin_ocsinventoryng_ocsservers", "`is_active` = 1") as $config) {
             $query_ocs = self::query($delay_ocs, $config, $entity);
             $ocs_infos = array();
             $ocs_messages = array();
             $type = Alert::END;
             $ocs_infos[$type] = array();
             foreach ($DB->request($query_ocs) as $data) {
                 $entity = $data['entities_id'];
                 $message = $data["name"];
                 $ocs_infos[$type][$entity][] = $data;
                 if (!isset($ocsmachines_infos[$type][$entity])) {
                     $ocs_messages[$type][$entity] = PluginAdditionalalertsOcsAlert::getTypeName(2) . "<br />";
                 }
                 $ocs_messages[$type][$entity] .= $message;
             }
             foreach ($ocs_infos[$type] as $entity => $ocsmachines) {
                 Plugin::loadLang('additionalalerts');
                 if (NotificationEvent::raiseEvent("ocs", new PluginAdditionalalertsOcsAlert(), array('entities_id' => $entity, 'ocsmachines' => $ocsmachines, 'delay_ocs' => $delay_ocs))) {
                     $message = $ocs_messages[$type][$entity];
                     $cron_status = 1;
                     if ($task) {
                         $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}\n");
                         $task->addVolume(1);
                     } else {
                         Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  {$message}");
                     }
                 } else {
                     if ($task) {
                         $task->log(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send ocsmachines alert failed\n");
                     } else {
                         Session::addMessageAfterRedirect(Dropdown::getDropdownName("glpi_entities", $entity) . ":  Send ocsmachines alert failed", false, ERROR);
                     }
                 }
             }
         }
     }
     return $cron_status;
 }
 function getTags()
 {
     $tags = array('ocsmachine.name' => __('Name'), 'ocsmachine.urlname' => __('URL') . " " . __('Name'), 'ocsmachine.operatingsystem' => __('Operating system'), 'ocsmachine.state' => __('Status'), 'ocsmachine.location' => __('Location'), 'ocsmachine.user' => __('User'), 'ocsmachine.urluser' => __('URL') . " " . __('User'), 'ocsmachine.group' => __('Group'), 'ocsmachine.urlgroup' => __('URL') . " " . __('Group'), 'ocsmachine.contact' => __('Alternate username'), 'ocsmachine.lastocsupdate' => __('Last OCSNG inventory date', 'additionalalerts'), 'ocsmachine.lastupdate' => __('Import date in GLPI', 'additionalalerts'), 'ocsmachine.ocsserver' => __('OCSNG server', 'additionalalerts'));
     foreach ($tags as $tag => $label) {
         $this->addTagToList(array('tag' => $tag, 'label' => $label, 'value' => true));
     }
     $this->addTagToList(array('tag' => 'additionalalerts', 'label' => PluginAdditionalalertsOcsAlert::getTypeName(2), 'value' => false, 'foreach' => true, 'events' => array('ocs', 'newocs')));
     asort($this->tag_descriptions);
 }