static function get_all_server() { $db = mysqli_connect($_SESSION['db_host'], $_SESSION['db_user'], $_SESSION['db_password'], $_SESSION['db_database']); $result = mysqli_query($db, "SELECT * FROM `server` where test_system != 'true'"); while ($row = mysqli_fetch_object($result)) { $i = $row->server_id; $obj_name = "server" . $i; ${$obj_name} = new server(); ${$obj_name}->server_id = $row->server_id; ${$obj_name}->hostname = $row->hostname; # Fra Space $result2 = mysqli_query($db, "SELECT * FROM `system_parameter` WHERE `server_id` = {$row->server_id} and `parameter_name` = 'fra-space' order by time desc"); while ($row2 = mysqli_fetch_object($result2)) { ${$obj_name}->fra_space = $row2->value_string; } # Fra Used Space $result2 = mysqli_query($db, "SELECT * FROM `system_parameter` WHERE `server_id` = {$row->server_id} and `parameter_name` = 'fra-used-space' order by time desc"); while ($row2 = mysqli_fetch_object($result2)) { ${$obj_name}->fra_used_space = $row2->value_string; } # Build all instance objects ${$obj_name}->instances = instance_actions::get_instance_by_server($row->hostname); $arr_obj[] = ${$obj_name}; } return $arr_obj; }
static function get_all_instance_search_json() { $arr_instance_objs = instance_actions::get_all_instances(); foreach ($arr_instance_objs as $instance) { $data[$instance->db_id]['info_string'] = $instance->service_name . " " . $instance->hostname . " " . $instance->sid . " " . $instance->status . " " . $instance->charset; } return json_encode($data); }
<?php error_reporting(E_ALL); ini_set('display_errors', '1'); session_start(); if ($_SESSION['login'] != true) { header("Location: login.php"); exit; } include_once "../classes/class_parameter.php"; include_once "../classes/class_parameter_actions.php"; include_once "../classes/class_instance.php"; include_once "../classes/class_instance_actions.php"; $instances_arr = instance_actions::get_instance_by_server($_POST['hostname']); foreach ($instances_arr as $instance) { $fra_space_obj = parameter_actions::get_parameter_by_id(1089, $instance->db_id); $fra_data[$instance->db_id]['fra_space'] = $fra_space_obj->get_current_value(); $fra_used_space_obj = parameter_actions::get_parameter_by_id(9003, $instance->db_id); $fra_data[$instance->db_id]['used_fra_space'] = $fra_used_space_obj->get_current_value(); $fra_reclaimable_space_obj = parameter_actions::get_parameter_by_id(9004, $instance->db_id); $fra_data[$instance->db_id]['reclaimable_fra_space'] = $fra_reclaimable_space_obj->get_current_value(); $fra_data[$instance->db_id]['used_fra_percentage'] = round($fra_used_space_obj->current_value / $fra_space_obj->current_value * 100, 0); $fra_data[$instance->db_id]['reclaimable_fra_percentage'] = round(($fra_used_space_obj->current_value - $fra_reclaimable_space_obj->current_value) / $fra_space_obj->current_value * 100, 0); } ?> <script> <?php foreach ($instances_arr as $instance) { ?> $(function() { var instance_fra_usage = <?php
<div onclick="show_prod_db_details(<?php echo $instance->db_id; ?> );" id="prod-db-item_<?php echo $instance->db_id; ?> " class="prod-db-item"> <img class="db_icon_flat" src="images/db_icon_flat.png"> <div class="attribute service_name" title="<?php echo $instance->get_service_name(); ?> " id="service_name_<?php echo $instance->db_id; ?> "><?php echo instance_actions::truncate($instance->get_service_name(true), 30); ?> </div> <div class="attribute sid"><?php echo $instance->get_sid(); ?> </div> <div class="attribute host"><?php echo $instance->get_hostname(); ?> </div> <div class="attribute status"> <?php if ($instance->status == 'OPEN') { echo '<img src="images/icon_online.png">'; } else { echo '<img src="images/icon_standby.png">';
static function get_all_switchover_as_array() { # Generating instance objects $db = mysqli_connect($_SESSION['db_host'], $_SESSION['db_user'], $_SESSION['db_password'], $_SESSION['db_database']); $arr_instance_objs = instance_actions::get_all_instances(); foreach ($arr_instance_objs as $instance) { if (strpos($instance->service_name, 'RZ1') !== false) { # Check if there was a failover/switchover during the last 14 days $query = "select count(*) as failover_count from (SELECT distinct `value_string` FROM `values` WHERE `parameter_id` = 9002 and `db_id` = " . $instance->db_id . " and time > DATE_FORMAT(now(), '%Y-%m-%d') - INTERVAL 14 DAY limit 2) as a"; $result = mysqli_query($db, $query); while ($row = mysqli_fetch_object($result)) { $failover_count = $row->failover_count; } if ($failover_count > 1) { unset($rz2_db_id); unset($rz1_status); unset($so_time); # Check current status of RZ1 db $query = "SELECT ID, dba_notice, lower(`value_string`) as value_string, DATE_FORMAT(time, '%d.%m.%y (%k:%i)') as time_formated FROM `values` WHERE `parameter_id` = 9002 and db_id = " . $instance->db_id . " order by time desc limit 1;"; $result = mysqli_query($db, $query); while ($row = mysqli_fetch_object($result)) { $rz1_status = $row->value_string; $so_time = $row->time_formated; $so_data_arr[$so_time]['value_id'] = $row->ID; $so_data_arr[$so_time]['dba_notice'] = $row->dba_notice; } if (strtolower($rz1_status) == "open") { $so_direction = "to_rz1"; } if (strtolower($rz1_status) == "mounted") { $so_direction = "to_rz2"; } # Get RZ2 DB $query = "SELECT db_id FROM `values` WHERE `parameter_id` = 1698 and `value_string` like '%" . $instance->sid . "_rz2%' limit 1"; $result = mysqli_query($db, $query); while ($row = mysqli_fetch_object($result)) { $rz2_db_id = $row->db_id; } if (isset($rz2_db_id) && isset($so_direction)) { $rz2_server_obj = instance_actions::get_instance_by_id($rz2_db_id); $so_data_arr[$so_time]['rz1_hostname'] = $instance->get_hostname(); $so_data_arr[$so_time]['rz1_sid'] = $instance->sid . '_RZ1'; $so_data_arr[$so_time]['rz1_db_id'] = $instance->db_id; $so_data_arr[$so_time]['rz2_hostname'] = $rz2_server_obj->get_hostname(); $so_data_arr[$so_time]['rz2_sid'] = $rz2_server_obj->sid . '_RZ2'; $so_data_arr[$so_time]['rz2_db_id'] = $rz2_server_obj->db_id; $so_data_arr[$so_time]['direction'] = $so_direction; } } } } return $so_data_arr; }
static function send_switchover_notification($switchover_arr, $email_address) { $rz1_instance = instance_actions::get_instance_by_id($switchover_arr['rz1_db_id']); $rz2_instance = instance_actions::get_instance_by_id($switchover_arr['rz2_db_id']); $html_rz1_db = '<table> <tr> <td style="border: 1px dotted; padding: 5px; width: 200px;"><b>Hostname</b></td> <td style="border: 1px dotted; padding: 5px; width: 300px;">' . $switchover_arr['rz1_hostname'] . '</td> </tr> <tr> <td style="border: 1px dotted; padding: 5px; width: 200px;"><b>SID</b></td> <td style="border: 1px dotted; padding: 5px; width: 300px;">' . $switchover_arr['rz1_sid'] . '</td> </tr> <tr> <td style="border: 1px dotted; padding: 5px; width: 200px;"><b>Service Name</b></td> <td style="border: 1px dotted; padding: 5px; width: 300px;">' . $rz1_instance->get_service_name(true) . '</td> </tr> </table>'; $html_rz2_db = '<table> <tr> <td style="border: 1px dotted; padding: 5px; width: 200px;"><b>Hostname</b></td> <td style="border: 1px dotted; padding: 5px; width: 300px;">' . $switchover_arr['rz2_hostname'] . '</td> </tr> <tr> <td style="border: 1px dotted; padding: 5px; width: 200px;"><b>SID</b></td> <td style="border: 1px dotted; padding: 5px; width: 300px;">' . $switchover_arr['rz2_sid'] . '</td> </tr> <tr> <td style="border: 1px dotted; padding: 5px; width: 200px;"><b>Service Name</b></td> <td style="border: 1px dotted; padding: 5px; width: 300px;">' . $rz2_instance->get_service_name(true) . '</td> </tr> </table>'; if ($switchover_arr['direction'] == 'to_rz2') { $mail_text = '<h2>Source DB:</h2>' . $html_rz1_db . '<h2>Destination DB:</h2>' . $html_rz2_db . '<h2>DBA Notice:</h2>' . '<div style="width: 530px; height: 123px;">' . nl2br($switchover_arr['dba_notice']) . '</div>'; } else { $mail_text = '<h2>Source DB:</h2>' . $html_rz2_db . '<h2>Destination DB:</h2>' . $html_rz1_db . '<h2>DBA Notice:</h2>' . '<div style="width: 530px; height: 123px;">' . nl2br($switchover_arr['dba_notice']) . '</div>'; } ############################################ # Send E-Mail ############################################ $subject = '[Switchover-Monitor Alert] Swichover/Failover on ' . $rz1_instance->get_sid() . ' detected noapplix'; $headers = "From: Switchover-Monitor\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($email_address, $subject, $mail_text, $headers); echo $mail_text . '<br>'; }