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>';
    }