function sendRestartArbiter($force = 0) { $pmTag = new PluginMonitoringTag(); $pmLog = new PluginMonitoringLog(); $a_tags = $pmTag->find(); foreach ($a_tags as $data) { if (!$pmLog->isRestartLessThanFiveMinutes() || $force) { $url = 'http://' . $data['ip'] . ':7760/'; $action = 'restart'; $a_fields = array(); $auth = $pmTag->getAuth($data['tag']); $restart = $this->sendCommand($url, $action, $a_fields, '', $auth); if ($restart) { $input = array(); $input['user_name'] = $_SESSION['glpifirstname'] . ' ' . $_SESSION['glpirealname'] . ' (' . $_SESSION['glpiname'] . ')'; $input['action'] = "restart_planned"; $input['date_mod'] = date("Y-m-d H:i:s"); $pmLog->add($input); } } } }
/** * Restart Shinken buttons : * - on main Monitoring plugin page * - one button per each declared Shinken tag * - one button to restart all Shinken instances * * @global type $CFG_GLPI */ static function restartShinken() { global $CFG_GLPI; if (Session::haveRight("plugin_monitoring_restartshinken", CREATE)) { $pmTag = new PluginMonitoringTag(); $a_tagsBrut = $pmTag->find(); $a_tags = array(); foreach ($a_tagsBrut as $data) { if (!isset($a_tags[$data['ip'] . ':' . $data['port']])) { $a_tags[$data['ip'] . ':' . $data['port']] = $data; } } if (count($a_tags) > 0) { $shinken_commands = ['reload' => ['command' => 'reload', 'title' => __('Reload Shinken configuration from Glpi database', 'monitoring'), 'button' => __('Reload Shinken config', 'monitoring')], 'restart' => ['command' => 'restart', 'title' => __('Restart all Shinken daemons', 'monitoring'), 'button' => __('Restart Shinken', 'monitoring')]]; foreach ($shinken_commands as $command) { echo "<table class='tab_cadre_fixe' width='950'>"; echo "<tr class='tab_bg_1'>"; echo "<th width='400'>"; echo $command['title'] . ' : '; echo '</th>'; echo '<td> | '; echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/restartshinken.form.php?action=" . $command['command'] . "&tag=0'>" . __('All instances', 'monitoring') . "</a> | "; if (count($a_tags) > 1) { foreach ($a_tags as $taginfo => $data) { echo "<a href='" . $CFG_GLPI['root_doc'] . "/plugins/monitoring/front/restartshinken.form.php?action=" . $command['command'] . "&tag=" . $data['id'] . "'>" . $taginfo . "</a> | "; } } echo '</td>'; echo '</tr>'; echo '</table>'; } echo '<br/>'; } } }
function sendRestartArbiter($force = 0, $tag = 0, $command = 'reload') { $pmTag = new PluginMonitoringTag(); $pmLog = new PluginMonitoringLog(); if (!$pmLog->isRestartLessThanFiveMinutes() || $force) { if ($tag > 0) { $pmTag->getFromDB($tag); $url = 'http://' . $pmTag->fields['ip'] . ':' . $pmTag->fields['port'] . '/'; $auth = $pmTag->getAuth($pmTag->fields['tag']); if ($this->sendCommand($url, $command, array(), '', $auth)) { $input = array(); $input['user_name'] = $_SESSION['glpifirstname'] . ' ' . $_SESSION['glpirealname'] . ' (' . $_SESSION['glpiname'] . ')'; $input['action'] = $command . "_planned"; $input['date_mod'] = date("Y-m-d H:i:s"); $input['value'] = $pmTag->fields['tag']; $pmLog->add($input); } } else { $a_tagsBrut = $pmTag->find(); $a_tags = array(); foreach ($a_tagsBrut as $data) { if (!isset($a_tags[$data['ip'] . ':' . $data['port']])) { $a_tags[$data['ip'] . ':' . $data['port']] = $data; } } foreach ($a_tags as $data) { // TODO : should be parameters ... Shinken arbiter may use another port and may use HTTPS ! $url = 'http://' . $data['ip'] . ':' . $data['port'] . '/'; $auth = $pmTag->getAuth($data['tag']); if ($this->sendCommand($url, $command, array(), '', $auth)) { $input = array(); $input['user_name'] = $_SESSION['glpifirstname'] . ' ' . $_SESSION['glpirealname'] . ' (' . $_SESSION['glpiname'] . ')'; $input['action'] = $command . "_planned"; $input['date_mod'] = date("Y-m-d H:i:s"); $input['value'] = $data['tag']; $pmLog->add($input); } } } } }
"PluginMonitoringDashboard", "menu"); $pmMessage = new PluginMonitoringMessage(); $pmMessage->getMessages(); $toDisplayArea=0; // Restart Shinken buttons : // - on main Monitoring plugin page // - one button per each declared Shinken tag // - one button to restart all Shinken instances if (Session::haveRight("plugin_monitoring_restartshinken", CREATE)) { echo '<div style="position: absolute; float: left; width: 30%; max-width: 300px; background: #ccc; border: outset 2px white; padding: 0.5%;">'; $pmTag = new PluginMonitoringTag(); $a_tagsBrut = $pmTag->find(); $a_tags = array(); foreach ($a_tagsBrut as $data) { if (!isset($a_tags[$data['ip'].':'.$data['port']])) { $a_tags[$data['ip'].':'.$data['port']] = $data; } } if (count($a_tags) > 0) { $shinken_commands = [ 'reload' => [ 'command' => 'reload', 'title' => __('Reconfigure Shinken from Glpi database', 'monitoring'), 'button' => __('Reconfigure Shinken', 'monitoring'), ],