/***************************************************************************
* Copyright (C) 2008 by phpSysInfo - A PHP System Information Script *
* http://phpsysinfo.sourceforge.net/ *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
***************************************************************************/
//
// $Id: raid.js 679 2012-09-04 10:10:11Z namiltd $
//
/*global $, jQuery, buildBlock, genlang, createBar, plugin_translate, datetime */
"use strict";
var raid_show = false;
/**
* get the details of the raid
* @param {jQuery} xml part of the plugin-XML
* @param {number} id id of the device
* @param {jQuery} xml plugin-XML
*/
function raid_buildinfos(xml, id) {
var html = "", prog = "", devname = "", devstatus = "", devlevel = "", devcontroller = "", devfirmware = "", devtemperature = 0, devbattvolt = 0, devbatttemp = 0, devbattery = "", devsupported = "", devcachevault = 0, devcapacity = 0, devstride = 0, devsubsets = 0, devdevs = 0, devspares = 0, devchunk = 0, devstripe = 0, devalgor = "", devpersist = 0, devreg = 0, devact = 0, devcache = 0, devbad = 0, devread = "", devwrite = "", devdiskcache = "", button = "";
prog = $(xml).attr("Program");
devname = $(xml).attr("Name");
devstatus = $(xml).attr("Status");
devlevel = $(xml).attr("Level");
devcontroller = $(xml).attr("Controller");
devfirmware = $(xml).attr("Firmware");
devtemperature = parseFloat($(xml).attr("Temperature"));
devbattvolt = parseFloat($(xml).attr("Batt_Volt"));
devbatttemp = parseFloat($(xml).attr("Batt_Temp"));
devbattery = $(xml).attr("Battery");
devsupported = $(xml).attr("Supported");
devcachevault = parseInt($(xml).attr("Cachevault_Size"), 10);
devcapacity = parseInt($(xml).attr("Capacity"), 10);
devstride = parseInt($(xml).attr("Stride"), 10);
devsubsets = parseInt($(xml).attr("Subsets"), 10);
devdevs = parseInt($(xml).attr("Devs"), 10);
devspares = parseInt($(xml).attr("Spares"), 10);
devchunk = parseInt($(xml).attr("Chunk_Size"), 10);
devstripe = parseInt($(xml).attr("Stripe_Size"), 10);
devalgor = $(xml).attr("Algorithm");
devpersist = parseInt($(xml).attr("Persistend_Superblock"), 10);
devreg = parseInt($(xml).attr("Disks_Registered"), 10);
devact = parseInt($(xml).attr("Disks_Active"), 10);
devcache = parseInt($(xml).attr("Cache_Size"), 10);
devbad = parseInt($(xml).attr("Bad_Blocks"), 10);
devread = $(xml).attr("ReadPolicy");
devwrite = $(xml).attr("WritePolicy");
devdiskcache = $(xml).attr("DiskCache");
html += "
" + genlang(22, "Raid") + " | " + prog + " |
";
if (devname !== undefined) html += "" + genlang(3, "Raid") + " | " + devname + " |
";
html += "" + genlang(4, "Raid") + " | " + devstatus + " |
";
if (devlevel !== undefined) html += "" + genlang(5, "Raid") + " | " + devlevel + " |
";
if (!isNaN(devcapacity)) html += "" + genlang(6, "Raid") + " | " + formatBytes(devcapacity, xml.parent().parent().parent()) + " |
";
if (!isNaN(devstride)) html += "" + genlang(7, "Raid") + " | " + devstride + " |
";
if (!isNaN(devsubsets)) html += "" + genlang(8, "Raid") + " | " + devsubsets + " |
";
if (!isNaN(devdevs)) html += "" + genlang(9, "Raid") + " | " + devdevs + " |
";
if (!isNaN(devspares)) html += "" + genlang(10, "Raid") + " | " + devspares + " |
";
if (!isNaN(devchunk)) html += "" + genlang(13, "Raid") + " | " + formatBytes(1024*devchunk, xml.parent().parent().parent()) + " |
";
if (!isNaN(devstripe)) html += "" + genlang(28, "Raid") + " | " + formatBytes(devstripe, xml.parent().parent().parent()) + " |
";
if (devalgor !== undefined) html += "" + genlang(14, "Raid") + " | " + devalgor + " |
";
if (!isNaN(devpersist)) {
if (devpersist == 1) {
html += "" + genlang(15, "Raid") + " | " + genlang(16, "Raid") + " |
";
} else {
html += "" + genlang(15, "Raid") + " | " + genlang(17, "Raid") + " |
";
}
}
if (!isNaN(devreg) && !isNaN(devact)) html += "" + genlang(18, "Raid") + " | " + devreg + "/" + devact + " |
";
if (devcontroller !== undefined) html += "" + genlang(19, "Raid") + " | " + devcontroller + " |
";
if (devfirmware !== undefined) html += "" + genlang(29, "Raid") + " | " + devfirmware + " |
";
if (isFinite(devtemperature)) html += "" + genlang(30, "Raid") + " | " + formatTemp(devtemperature, xml.parent().parent().parent()) + " |
";
if (devbattery !== undefined) html += "" + genlang(20, "Raid") + " | " + devbattery + " |
";
if (isFinite(devbattvolt)) html += "" + genlang(31, "Raid") + " | " + round(devbattvolt, 3) + " " + genlang(82) +" |
";
if (isFinite(devbatttemp)) html += "" + genlang(32, "Raid") + " | " + formatTemp(devbatttemp, xml.parent().parent().parent()) + " |
";
if (devsupported !== undefined) html += "" + genlang(21, "Raid") + " | " + devsupported + " |
";
if (!isNaN(devcache)) html += "" + genlang(25, "Raid") + " | " + formatBytes(devcache, xml.parent().parent().parent()) + " |
";
if (devread !== undefined) html += "" + genlang(23, "Raid") + " | " + devread + " |
";
if (devwrite !== undefined) html += "" + genlang(24, "Raid") + " | " + devwrite + " |
";
if (!isNaN(devcachevault)) html += "" + genlang(33, "Raid") + " | " + formatBytes(devcachevault, xml.parent().parent().parent()) + " |
";
if (devdiskcache !== undefined) html += "" + genlang(27, "Raid") + " | " + devdiskcache + " |
";
if (!isNaN(devbad)) html += "" + genlang(26, "Raid") + " | " + devbad + " |
";
button += "
" + genlang(2, "Raid") + "
";
button += "
" + genlang(2, "Raid") + "
";
button += "";
return button;
}
/**
* generate a html string with the current action on the disks
* @param {jQuery} xml part of the plugin-XML
* @param {jQuery} xml plugin-XML
*/
function raid_buildaction(xml) {
var html = "", name = "", time = "", tunit = "", percent = 0;
$("Action", xml).each(function mdstatus_getaction(id) {
name = $(this).attr("Name");
if (parseInt(name, 10) !== -1) {
time = $(this).attr("Time_To_Finish");
tunit = $(this).attr("Time_Unit");
percent = parseFloat($(this).attr("Percent"));
html += "";
html += genlang(11, "Raid") + ": " + name + "
";
html += createBar(percent);
if ((time !== undefined) && (tunit !== undefined)) {
html += "
";
html += genlang(12, "Raid") + ": " + time + " " + tunit;
}
html += "
";
}
});
return html;
}
/**
* choose the right diskdrive icon
* @param {jQuery} xml part of the plugin-XML
* @param {jQuery} xml plugin-XML
*/
function raid_diskicon(xml, id) {
$("RaidItems Item", xml).each(function raid_getitems(itemid) {
var status = "", name = "", type = "", info = "", bus = "", cap = "", model = "", minfo = "", serial = "", capacity = 0, temperature = 0, parentid = 0;
status = $(this).attr("Status");
bus = $(this).attr("Bus");
name = $(this).attr("Name");
type = $(this).attr("Type");
info = $(this).attr("Info");
model = $(this).attr("Model");
serial = $(this).attr("Serial");
capacity = parseInt($(this).attr("Capacity"), 10);
temperature = parseFloat($(this).attr("Temperature"));
parentid = parseInt($(this).attr("ParentID"), 10);
var imgh = "", imgs = "", alt = "", bcolor = "";
switch (status) {
case "ok":
imgh = "harddriveok.png";
imgs = "soliddriveok.png";
alt = "ok";
bcolor = "green";
break;
case "F":
imgh = "harddrivefail.png";
imgs = "soliddrivefail.png";
alt = "fail";
bcolor = "red";
break;
case "U":
imgh = "harddriveunc.png";
imgs = "soliddriveunc.png";
alt = "unconfigured";
bcolor = "purple";
break;
case "S":
imgh = "harddrivespare.png";
imgs = "soliddrivespare.png";
alt = "spare";
bcolor = "gray";
break;
case "W":
imgh = "harddrivewarn.png";
imgs = "soliddrivewarn.png";
alt = "warning";
bcolor = "orange";
break;
default:
// alert("--" + diskstatus + "--");
imgh = "error.png";
imgs = "error.png";
alt = "error";
break;
}
if (!isNaN(parentid)) {
if (type !== undefined) {
if (model !== undefined) {
minfo = "
" + model;
}
if (serial !== undefined) {
minfo += "
" + serial;
}
if (bus === undefined) {
bus = "";
}
if (!isNaN(capacity)) {
cap = formatBytes(capacity, xml.parent().parent().parent());
}
if ((bus !== "") || (cap !== "")) {
minfo += "
" + $.trim(bus + " " + cap);
}
if (isFinite(temperature)) {
minfo += "
" + formatTemp(temperature, xml.parent().parent().parent());
}
$("#Plugin_Raid_Item" + id + "-" + parentid).append("
" + name + minfo + " "); //onload IE6 PNG fix
} else {
if (parentid === 0) {
$("#Plugin_Raid_List-" + id).append("" + name + "
");
} else {
$("#Plugin_Raid_Item" + id + "-" + parentid).append("" + name + "
");
}
}
}
});
}
/**
* fill the plugin block
* @param {jQuery} xml plugin-XML
*/
function raid_populate(xml) {
var hostname = "";
$("#Plugin_RaidTable").empty();
hostname = $("Plugins Plugin_Raid", xml).attr('Hostname');
if (hostname !== undefined) {
$('span[class=Hostname_Raid]').html(hostname);
}
$("#Plugin_RaidTable").append("");
$("Plugins Plugin_Raid Raid", xml).each(function raid_getdevice(id) {
var htmldisks = "", buildedaction = "";
htmldisks += "";
htmldisks += " |
";
buildedaction = raid_buildaction($(this));
if (buildedaction) {
htmldisks += "" + buildedaction + " |
";
}
htmldisks += "" + raid_buildinfos($(this), id);
htmldisks += " |
";
htmldisks += "
";
$("#Plugin_RaidTable").append(" " + $(this).attr("Device_Name") + " | " + htmldisks + " |
");
raid_diskicon($(this), id);
$("#sPlugin_Raid_Info" + id).click(function raid_showinfo() {
$("#Plugin_Raid_InfoTable" + id).slideDown("fast");
$("#sPlugin_Raid_Info" + id).hide();
$("#hPlugin_Raid_Info" + id).show();
});
$("#hPlugin_Raid_Info" + id).click(function raid_hideinfo() {
$("#Plugin_Raid_InfoTable" + id).slideUp("fast");
$("#hPlugin_Raid_Info" + id).hide();
$("#sPlugin_Raid_Info" + id).show();
});
raid_show = true;
});
$("#Plugin_RaidTable").append("");
}
/**
* load the xml via ajax
*/
function raid_request() {
$("#Reload_RaidTable").attr("title", "reload");
$.ajax({
url: "xml.php?plugin=Raid",
dataType: "xml",
error: function raid_error() {
$.jGrowl("Error loading XML document for Plugin Raid");
},
success: function raid_buildblock(xml) {
populateErrors(xml);
raid_populate(xml);
if (raid_show) {
plugin_translate("Raid");
$("#Plugin_Raid").show();
}
}
});
}
$(document).ready(function raid_buildpage() {
var html = "";
$("#footer").before(buildBlock("Raid", 1, true));
html += " \n";
html += "
\n";
html += "
\n";
$("#Plugin_Raid").append(html);
$("#Plugin_Raid").addClass("fullsize");
raid_request();
$("#Reload_RaidTable").click(function raid_reload(id) {
raid_request();
$(this).attr("title", datetime());
});
});