Portions created by the Initial Developer are Copyright (C) 2008-2023 the Initial Developer. All Rights Reserved. Contributor(s): Mark J Crane */ //includes files require_once dirname(__DIR__, 2) . "/resources/require.php"; //check permissions require_once "resources/check_auth.php"; if (permission_exists('bdr_view')) { //access granted } else { echo "access denied"; exit; } //add multi-lingual support $language = new text; $text = $language->get(); //additional includes require_once "resources/header.php"; require_once "resources/paging.php"; //show the header echo "

FusionPBX BDR

"; //get the my node id $sql = "select bdr.bdr_get_local_nodeid()"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(); $result_count = count($result); unset ($prep_statement, $sql); $replace[] = '('; $replace[] = ')'; $my_node_id = explode(',',str_replace($replace,'',$result[0]['bdr_get_local_nodeid'])); //get the node list $sql = "select * from bdr.bdr_nodes"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(); $result_count = count($result); unset ($prep_statement, $sql); $sql = "SELECT bdr.bdr_version()"; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $resultversion = $prep_statement->fetchAll(); unset ($prep_statement, $sql); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
BDR Information
\n"; echo "BDR Version\n"; echo "\n"; echo $resultversion[0]['bdr_version'] . "\n"; echo "
\n"; echo "Node Count\n"; echo "\n"; echo " $result_count\n"; echo "
\n

"; //table headers $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; echo "\n"; //echo "\n"; //echo "\n"; //echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; foreach ($result as $row) { //get the status, bytes, database list $sql = "SELECT slot_name, database, active, pg_xlog_location_diff(pg_current_xlog_insert_location(), restart_lsn) AS retained_bytes"; $sql .= " FROM pg_replication_slots WHERE plugin = 'bdr'"; $sql .= " AND slot_name like '%" . $row['node_sysid'] . "%' "; $sql .= " AND database = 'fusionpbx' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result1 = $prep_statement->fetchAll(); unset ($prep_statement, $sql); //get lag bytes $sql = "select pg_xlog_location_diff(pg_current_xlog_insert_location(), flush_location) AS lag_bytes"; $sql .= " FROM pg_stat_replication WHERE "; $sql .= " application_name like '%" . $row['node_sysid'] . "%". $row['node_dboid'] ."%' "; $prep_statement = $db->prepare(check_sql($sql)); $prep_statement->execute(); $result2 = $prep_statement->fetchAll(); unset ($prep_statement, $sql); echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; if ($c==0) { $c=1; } else { $c=0; } } echo "
Nodes
IDStatusNameLocalDatabaseActiveRetained BytesLag Bytes 
" . $row['node_sysid'] . "_" . $row['node_dboid'] . ""; if ($row['node_status'] == "r") { echo "Ready"; } else if ($row['node_status'] == "k") { echo "Removed/Killed"; } else if ($row['node_status'] == "i") { echo "Initializing"; } else if ($row['node_status'] == "b") { echo "Bootstrapping"; } else if ($row['node_status'] == "c") { echo "Catching Up"; } else if ($row['node_status'] == "o") { echo "Caught Up/Waiting"; } else { echo "Unknown"; } echo "" . $row['node_name'] . ""; if ($row['node_sysid'] == $my_node_id[0]) { echo "Yes"; $is_current = 1; } else { echo "No"; $is_current = 0; } echo "" . $result1[0]['database'] . ""; if ($is_current != 1) {if ($result1[0]['active'] == 1) { echo "Yes"; } else { echo "No"; }}; echo "" . $result1[0]['retained_bytes'] . "" . $result2[0]['lag_bytes'] . ""; //if (permission_exists('extension_edit')) { // echo "$v_link_label_edit"; //} if (permission_exists('bdr_delete')) { echo "$v_link_label_delete"; } echo "
\n"; //show the header echo "

Freeswitch BDR

"; //connect to the switch database $db_fs = new PDO("pgsql:host=$db_host port=$db_port dbname=freeswitch user=$db_username password=$db_password"); //get the my node id $sql = "select bdr.bdr_get_local_nodeid()"; $prep_statement = $db_fs->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(); $result_count = count($result); unset ($prep_statement, $sql); $replace[] = '('; $replace[] = ')'; $my_node_id = explode(',',str_replace($replace,'',$result[0]['bdr_get_local_nodeid'])); //get the node list $sql = "select * from bdr.bdr_nodes"; $prep_statement = $db_fs->prepare(check_sql($sql)); $prep_statement->execute(); $result = $prep_statement->fetchAll(); $result_count = count($result); unset ($prep_statement, $sql); $sql = "SELECT bdr.bdr_version()"; $prep_statement = $db_fs->prepare(check_sql($sql)); $prep_statement->execute(); $resultversion = $prep_statement->fetchAll(); unset ($prep_statement, $sql); echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "
BDR Information
\n"; echo "BDR Version\n"; echo "\n"; echo $resultversion[0]['bdr_version'] . "\n"; echo "
\n"; echo "Node Count\n"; echo "\n"; echo " $result_count\n"; echo "
\n

"; //table headers $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; echo "\n"; $c = 0; $row_style["0"] = "row_style0"; $row_style["1"] = "row_style1"; foreach ($result as $row) { //get the status, bytes, database list $sql = "SELECT slot_name, database, active, pg_xlog_location_diff(pg_current_xlog_insert_location(), restart_lsn) AS retained_bytes"; $sql .= " FROM pg_replication_slots WHERE plugin = 'bdr'"; $sql .= " AND slot_name like '%" . $row['node_sysid'] . "%' "; $sql .= " AND database ='freeswitch' "; $prep_statement = $db_fs->prepare(check_sql($sql)); $prep_statement->execute(); $result1 = $prep_statement->fetchAll(); unset ($prep_statement, $sql); //get lag bytes $sql = "select pg_xlog_location_diff(pg_current_xlog_insert_location(), flush_location) AS lag_bytes"; $sql .= " FROM pg_stat_replication WHERE "; $sql .= " application_name like '%" . $row['node_sysid'] . "%". $row['node_dboid'] ."%' "; $prep_statement = $db_fs->prepare(check_sql($sql)); $prep_statement->execute(); $result2 = $prep_statement->fetchAll(); unset ($prep_statement, $sql); echo "\n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo " \n"; echo "\n"; if ($c==0) { $c=1; } else { $c=0; } } echo "
IDStatusNameLocalDatabaseActiveRetained BytesLag Bytes 
" . $row['node_sysid'] . "_" . $row['node_dboid'] . ""; if ($row['node_status'] == "r") { echo "Ready"; } else if ($row['node_status'] == "k") { echo "Removed/Killed"; } else if ($row['node_status'] == "i") { echo "Initializing"; } else if ($row['node_status'] == "b") { echo "Bootstrapping"; } else if ($row['node_status'] == "c") { echo "Catching Up"; } else if ($row['node_status'] == "o") { echo "Caught Up/Waiting"; } else { echo "Unknown"; } echo "" . $row['node_name'] . ""; if ($row['node_sysid'] == $my_node_id[0]) { echo "Yes"; $is_current = 1; } else { echo "No"; $is_current = 0; } echo "" . $result1[0]['database'] . ""; if ($is_current != 1) {if ($result1[0]['active'] == 1) { echo "Yes"; } else { echo "No"; }}; echo "" . $result1[0]['retained_bytes'] . "" . $result2[0]['lag_bytes'] . ""; //if (permission_exists('extension_edit')) { // echo "$v_link_label_edit"; //} if (permission_exists('bdr_delete')) { echo "$v_link_label_delete"; } echo "
\n"; //include the footer require_once "resources/footer.php"; ?>