Commit 63e2cfc1 authored by Franco Fichtner's avatar Franco Fichtner

src: purge unreachable gmirror files

Spotted by: @fabianfrz
parent febe94f4
......@@ -457,6 +457,6 @@
</monitor_type>
</load_balancer>
<widgets>
<sequence>system_information-container:col1:show,captive_portal_status-container:col1:close,carp_status-container:col1:close,cpu_graphs-container:col1:close,gateways-container:col1:close,gmirror_status-container:col1:close,installed_packages-container:col1:close,interface_statistics-container:col1:close,interface_list-container:col2:show,ipsec-container:col2:close,load_balancer_status-container:col2:close,log-container:col2:close,picture-container:col2:close,rss-container:col2:close,services_status-container:col2:close,traffic_graphs-container:col2:close</sequence>
<sequence>system_information-container:col1:show,captive_portal_status-container:col1:close,carp_status-container:col1:close,cpu_graphs-container:col1:close,gateways-container:col1:close,interface_statistics-container:col1:close,interface_list-container:col2:show,ipsec-container:col2:close,load_balancer_status-container:col2:close,log-container:col2:close,picture-container:col2:close,rss-container:col2:close,services_status-container:col2:close,traffic_graphs-container:col2:close</sequence>
</widgets>
</opnsense>
<?php
/*
gmirror.inc
Copyright (C) 2009-2014 Jim Pingle
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
/* Create a status array for each mirror and its disk components. */
function gmirror_get_status() {
$status = "";
exec("/sbin/gmirror status -s", $status);
$mirrors = array();
/* Empty output = no mirrors found */
if (count($status) > 0) {
/* Loop through gmirror status output. */
foreach ($status as $line) {
/* Split the line by whitespace */
$all = preg_split("/[\s\t]+/", trim($line), 3);
if (count($all) == 3) {
/* If there are three items on a line, it is mirror name, status, and component */
$currentmirror = basename($all[0]);
$mirrors[$currentmirror]['name'] = basename($all[0]);
$mirrors[$currentmirror]['status'] = $all[1];
if (!is_array($mirrors[$currentmirror]['components']))
$mirrors[$currentmirror]['components'] = array();
$mirrors[$currentmirror]['components'][] = $all[2];
}
}
}
/* Return an hash of mirrors and components */
return $mirrors;
}
/* List all disks in the system (potential gmirror targets) */
function gmirror_get_disks() {
$disklist = "";
/* Get a list of disks in a scriptable way, exclude optical drives */
exec("/sbin/geom disk status -s | /usr/bin/grep -v '[[:blank:]]*cd[[:digit:]]*' | /usr/bin/awk '{print $1;}'", $disklist);
return $disklist;
}
/* List all potential gmirror consumers */
function gmirror_get_unused_consumers() {
$consumerlist = "";
/* Get a list of consumers, exclude existing mirrors and diskid entries */
exec("/sbin/geom part status -s | /usr/bin/egrep -v '(mirror|diskid)' | /usr/bin/awk '{print $1, $3;}'", $consumerlist);
$all_consumers = array();
foreach ($consumerlist as $cl) {
$parts = explode(" ", $cl);
foreach ($parts as $part)
$all_consumers[] = $part;
}
return $all_consumers;
}
/* List all existing geom mirrors */
function gmirror_get_mirrors() {
$mirrorlist = "";
exec("/sbin/gmirror list | /usr/bin/grep '^Geom name:' | /usr/bin/awk '{print $3;}'", $mirrorlist);
return $mirrorlist;
}
/* List all consumers for a given mirror */
function gmirror_get_consumers_in_mirror($mirror) {
if (!is_valid_mirror($mirror))
return array();
$consumers = array();
exec("/sbin/gmirror status -s " . escapeshellarg($mirror) . " | /usr/bin/awk '{print $3;}'", $consumers);
return $consumers;
}
/* Test if a mirror exists */
function is_valid_mirror($mirror) {
$mirrors = gmirror_get_mirrors();
return in_array($mirror, $mirrors);
}
/* Test if a disk is valid/exists */
function is_valid_disk($disk) {
$adisks = gmirror_get_disks();
return in_array(basename($disk), $adisks);
}
/* Test if a consumer is valid and in use in a mirror */
function is_consumer_used($consumer) {
$found = false;
$mirrors = gmirror_get_mirrors();
foreach ($mirrors as $mirror) {
$consumers = gmirror_get_consumers_in_mirror($mirror);
if (in_array($consumer, $consumers))
return true;
}
return false;
}
/* Test if a consumer is valid and not in use */
function is_consumer_unused($consumer) {
$consumers = gmirror_get_unused_consumers();
return in_array($consumer, $consumers);
}
/* Test if a consumer is valid (either a disk or partition) */
function is_valid_consumer($consumer) {
return (is_consumer_unused($consumer) || is_consumer_used($consumer));
}
/* Show all metadata on the physical consumer */
function gmirror_get_consumer_metadata($consumer) {
if (!is_valid_consumer($consumer))
return array();
$output = "";
exec("/sbin/gmirror dump " . escapeshellarg($consumer), $output);
return array_map('trim', $output);
}
/* Return a list of all potential consumers on a disk with sizes. The geom part
list output is a little odd, we can't get the output for just the disk, if the disk contains
slices those get output also. */
function gmirror_get_all_unused_consumer_sizes_on_disk($disk) {
if (!is_valid_disk($disk) || !is_consumer_unused($disk))
return array();
$output = "";
exec("/sbin/geom part list " . escapeshellarg($disk) . " | /usr/bin/egrep '(Name:|Mediasize:)' | /usr/bin/cut -c4- | /usr/bin/sed -l -e 'N;s/\\nMediasize://;P;D;' | /usr/bin/cut -c7-", $output);
$disk_contents = array();
foreach ($output as $line) {
list($name, $size, $humansize) = explode(" ", $line, 3);
$consumer = array();
$consumer['name'] = $name;
$consumer['size'] = $size;
$consumer['humansize'] = $humansize;
$disk_contents[] = $consumer;
}
return $disk_contents;
}
?>
......@@ -249,15 +249,6 @@ minicron 3600 /var/run/expire_accounts.pid /usr/local/etc/rc.expireaccounts
# Start alias url updater every 24 hours
minicron 86400 /var/run/update_alias_url_data.pid /usr/local/etc/rc.update_alias_url_data
# Check for GEOM mirrors
GMIRROR_STATUS=`/sbin/gmirror status`
if [ "${GMIRROR_STATUS}" != "" ]; then
# Using a flag file at bootup saves an expensive exec/check on each page load.
touch /var/run/gmirror_active
# Setup monitoring/notifications
minicron 60 /var/run/gmirror_status_check.pid /usr/local/sbin/gmirror_status_check.php
fi
/usr/local/sbin/beep.sh start
/usr/local/etc/rc.initial.banner
......
#!/usr/local/bin/php
<?php
/*
Copyright (C) 2014 Jim Pingle
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
require_once("config.inc");
require_once("gmirror.inc");
global $g;
$status_file = '/var/run/gmirror.status';
$mirror_status = gmirror_get_status();
$mirror_list = array_keys($mirror_status);
sort($mirror_list);
$notices = array();
// Check for gmirror.status
if (file_exists($status_file)) {
// If it exists, read status in
$previous_mirror_status = unserialize(file_get_contents($status_file));
$previous_mirror_list = array_keys($previous_mirror_status);
sort($previous_mirror_list);
if (count($previous_mirror_status) > 0) {
// Check list of current mirrors vs old mirrors, notify if one has appeared/disappeared
if ($mirror_list != $previous_mirror_list) {
$notices[] = sprintf(gettext("List of mirrors changed. Old: (%s) New: (%s)"), implode(", ", $previous_mirror_list), implode(", ", $mirror_list));
}
// For each mirror, check the mirror status, notify if changed
foreach ($mirror_list as $mirror) {
if (is_array($previous_mirror_status[$mirror])) {
// Notify if the status changed
if ($mirror_status[$mirror]['status'] != $previous_mirror_status[$mirror]['status']) {
$notices[] = sprintf(gettext("Mirror %s status changed from %s to %s."), $mirror, $previous_mirror_status[$mirror]['status'], $mirror_status[$mirror]['status']);
}
// Notify if the drive count changed
if (count($mirror_status[$mirror]['components']) != count($previous_mirror_status[$mirror]['components'])) {
// Notify if the consumer count changed.
$notices[] = sprintf(gettext("Mirror %s consumer count changed from %d to %d."), $mirror, count($previous_mirror_status[$mirror]['components']), count($mirror_status[$mirror]['components']));
}
if (strtoupper($mirror_status[$mirror]['status']) == "DEGRADED") {
// Check the drive status as it may be different.
asort($mirror_status[$mirror]['components']);
asort($previous_mirror_status[$mirror]['components']);
if ($mirror_status[$mirror]['components'] != $previous_mirror_status[$mirror]['components']) {
$notices[] = sprintf(
gettext("Mirror %s drive status changed. Old: (%s) New: (%s)"),
$mirror,
implode(", ", $previous_mirror_status[$mirror]['components']),
implode(", ", $mirror_status[$mirror]['components'])
);
}
}
}
}
}
}
if (count($notices)) {
file_notice("gmirror", implode("\n ", $notices), "GEOM Mirror Status Change", 1);
}
// Write out current status if changed
if ($mirror_status != $previous_mirror_status) {
file_put_contents($status_file, serialize($mirror_status));
}
This diff is collapsed.
<?php
/*
Copyright (C) 2014 Deciso B.V.
Copyright (C) 2009-2010 Jim Pingle
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
INClUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
$nocsrf = true;
require_once("guiconfig.inc");
require_once("gmirror.inc");
/* Generate an HTML formatted status for mirrors and disks in a small format for the widget */
function gmirror_html_status() {
$mirrors = gmirror_get_status();
$output = "";
if (count($mirrors) > 0) {
$output .= "<tr>\n";
$output .= "<td width=\"40%\" class=\"vncellt\">".gettext('Name')."</td>\n";
$output .= "<td width=\"40%\" class=\"vncellt\">".gettext('Status')."</td>\n";
$output .= "<td width=\"20%\" class=\"vncellt\">".gettext('Component')."</td>\n";
$output .= "</tr>\n";
foreach ($mirrors as $mirror => $name) {
$components = count($name["components"]);
$output .= "<tr>\n";
$output .= "<td width=\"40%\" rowspan=\"{$components}\" class=\"listr\">{$name['name']}</td>\n";
$output .= "<td width=\"40%\" rowspan=\"{$components}\" class=\"listr\">{$name['status']}</td>\n";
$output .= "<td width=\"20%\" class=\"listr\">{$name['components'][0]}</td>\n";
$output .= "</tr>\n";
if (count($name["components"]) > 1) {
$morecomponents = array_slice($name["components"], 1);
foreach ($morecomponents as $component) {
$output .= "<tr>\n";
$output .= "<td width=\"20%\" class=\"listr\">{$component}</td>\n";
$output .= "</tr>\n";
}
}
}
} else {
$output .= "<tr><td colspan=\"3\" class=\"listr\">".gettext('No Mirrors Found')."</td></tr>\n";
}
// $output .= "<tr><td colspan=\"3\" class=\"listr\">Updated at " . date("F j, Y, g:i:s a") . "</td></tr>\n";
return $output;
}
if ($_GET['textonly'] == "true") {
header("Cache-Control: no-cache");
echo gmirror_html_status();
exit;
}
?>
<table class="table table-striped" width="100%" border="0" cellspacing="0" cellpadding="0" summary="gmirror status">
<tbody id="gmirror_status_table">
<?php echo gmirror_html_status(); ?>
</tbody>
</table>
<script type="text/javascript">
//<![CDATA[
var gmirrorupdater = function() {
jQuery.ajax({
url: '/widgets/widgets/gmirror_status.widget.php?textonly=true',
dataType: 'text',
success: function(code) {
jQuery("#gmirror_status_table").html(code);
}
});
};
setInterval(gmirrorupdater, 5000);
//]]>
</script>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment