Example #1
0
 function generateCommandsCfg($file = 0)
 {
     $pmCommand = new PluginMonitoringCommand();
     $pmNotificationcommand = new PluginMonitoringNotificationcommand();
     $pmEventhandler = new PluginMonitoringEventhandler();
     $a_commands = array();
     $i = 0;
     $a_list = $pmCommand->find();
     $a_listnotif = $pmNotificationcommand->find();
     $a_list = array_merge($a_list, $a_listnotif);
     foreach ($a_list as $data) {
         if ($data['command_name'] != "bp_rule") {
             $a_commands[$i]['name'] = $data['name'];
             $a_commands[$i]['command_name'] = $data['command_name'];
             $a_commands[$i]['command_line'] = $data['command_line'];
             $i++;
         }
     }
     $a_list = $pmEventhandler->find();
     foreach ($a_list as $data) {
         if ($data['command_name'] != "bp_rule") {
             $a_commands[$i]['name'] = $data['name'];
             $a_commands[$i]['command_name'] = $data['command_name'];
             $a_commands[$i]['command_line'] = $data['command_line'];
             $i++;
         }
     }
     // * Restart shinken command
     $a_commands[$i]['name'] = 'restart_shinken';
     $a_commands[$i]['command_name'] = 'restart_shinken';
     $a_commands[$i]['command_line'] = 'nohup /usr/local/shinken/bin/restart_arbiter_debug.sh &';
     if ($file == "1") {
         $config = "# Generated by plugin monitoring for GLPI\n# on " . date("Y-m-d H:i:s") . "\n\n";
         foreach ($a_commands as $data) {
             $config .= "# " . $data['name'] . "\n";
             unset($data['name']);
             $config .= $this->constructFile("command", $data);
         }
         return array('commands.cfg', $config);
     } else {
         return $a_commands;
     }
 }
Example #2
0
   function generateCommandsCfg($file=0) {

      PluginMonitoringToolbox::logIfExtradebug(
         'pm-shinken',
         "Starting generateCommandsCfg ...\n"
      );
      $pmCommand = new PluginMonitoringCommand();
      $pmNotificationcommand = new PluginMonitoringNotificationcommand();
      $pmEventhandler = new PluginMonitoringEventhandler();

      $a_commands = array();
      $i=0;

      // Only active commands and notification commands ...
      $a_list = $pmCommand->find("`is_active`='1'");
      $a_listnotif = $pmNotificationcommand->find("`is_active`='1'");
      $a_list = array_merge($a_list, $a_listnotif);

      $reload_shinken_found = false;
      $restart_shinken_found = false;
      $restart_shinken_1_4_found = false;
      foreach ($a_list as $data) {
         if ($data['command_name'] == "bp_rule") { continue; }

         // For comments ...
         $a_commands[$i]['name'] = $data['name'];

         // For Shinken ...
         $a_commands[$i]['command_name'] = PluginMonitoringCommand::$command_prefix . $data['command_name'];
         $a_commands[$i]['command_line'] = $data['command_line'];
         if (! empty($data['module_type'])) {
            $a_commands[$i]['module_type'] = $data['module_type'];
         }
         if (! empty($data['poller_tag'])) {
            $a_commands[$i]['poller_tag'] = $data['poller_tag'];
         }
         if (! empty($data['reactionner_tag'])) {
            $a_commands[$i]['reactionner_tag'] = $data['reactionner_tag'];
         }

         if ($data['command_name'] == "reload-shinken") {
            $reload_shinken_found = true;
            // No prefix for this command (WS arbiter)
            $a_commands[$i]['command_name'] = $data['command_name'];
         }
         if ($data['command_name'] == "restart-shinken") {
            $restart_shinken_found = true;
            // No prefix for this command (WS arbiter)
            $a_commands[$i]['command_name'] = $data['command_name'];
         }
         if ($data['command_name'] == "restart_shinken") {
            $restart_shinken_1_4_found = true;
         }
         PluginMonitoringToolbox::logIfExtradebug(
            'pm-shinken',
            "- command: ".$a_commands[$i]['command_name']." -> ".$a_commands[$i]['name']."\n"
         );
         $i++;
      }
      if (! $restart_shinken_1_4_found) {
         // * Restart shinken command
         $a_commands[$i]['name'] = 'Restart Shinken (1.4)';
         $a_commands[$i]['command_name'] = 'restart_shinken';
         $a_commands[$i]['command_line'] = "nohup sh -c '/usr/local/shinken/bin/stop_arbiter.sh && sleep 3 && /usr/local/shinken/bin/launch_arbiter.sh'  > /dev/null 2>&1 &";
      }
      if (! $reload_shinken_found) {
         // * Reload shinken command (2.0)
         $a_commands[$i]['name'] = 'Reload Shinken configuration';
         $a_commands[$i]['command_name'] = 'reload-shinken';
         $a_commands[$i]['command_line'] = "nohup sh -c '/etc/init.d/shinken reload'    > /dev/null 2>&1 &";
      }
      if (! $restart_shinken_found) {
         // * Restart shinken command (2.0)
         $a_commands[$i]['name'] = 'Restart Shinken';
         $a_commands[$i]['command_name'] = 'restart-shinken';
         $a_commands[$i]['command_line'] = "nohup sh -c '/etc/init.d/shinken restart'    > /dev/null 2>&1 &";
      }

      // Event handlers
      $a_list = $pmEventhandler->find("`is_active`='1'");
      foreach ($a_list as $data) {
         if ($data['command_name'] != "bp_rule") {
            $a_commands[$i]['name'] = $data['name'];

            $a_commands[$i]['command_name'] = PluginMonitoringCommand::$command_prefix . $data['command_name'];
            $a_commands[$i]['command_line'] = $data['command_line'];
            PluginMonitoringToolbox::logIfExtradebug(
               'pm-shinken',
               "- command: ".$a_commands[$i]['command_name']." -> ".$a_commands[$i]['name']."\n"
            );
            $i++;
         }
      }
      PluginMonitoringToolbox::logIfExtradebug(
         'pm-shinken',
         "End generateCommandsCfg\n"
      );

      if ($file == "1") {
         $config = "# Generated by plugin monitoring for GLPI\n# on ".date("Y-m-d H:i:s")."\n\n";
         foreach ($a_commands as $data) {
            $config .= "# ".$data['name']."\n";
            unset($data['name']);
            $config .= $this->writeFile("command", $data);
         }
         return array('commands.cfg', $config);
      } else {
         return $a_commands;
      }
   }